tx-macro.c 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/init.h>
  7. #include <linux/bitops.h>
  8. #include <linux/clk.h>
  9. #include <linux/io.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/regmap.h>
  12. #include <linux/pm_runtime.h>
  13. #include <sound/soc.h>
  14. #include <sound/soc-dapm.h>
  15. #include <sound/tlv.h>
  16. #include <soc/swr-common.h>
  17. #include <soc/swr-wcd.h>
  18. #include <asoc/msm-cdc-pinctrl.h>
  19. #include "bolero-cdc.h"
  20. #include "bolero-cdc-registers.h"
  21. #include "bolero-clk-rsc.h"
  22. #define AUTO_SUSPEND_DELAY 50 /* delay in msec */
  23. #define TX_MACRO_MAX_OFFSET 0x1000
  24. #define NUM_DECIMATORS 8
  25. #define TX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  26. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  27. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  28. #define TX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  29. SNDRV_PCM_FMTBIT_S24_LE |\
  30. SNDRV_PCM_FMTBIT_S24_3LE)
  31. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  32. #define CF_MIN_3DB_4HZ 0x0
  33. #define CF_MIN_3DB_75HZ 0x1
  34. #define CF_MIN_3DB_150HZ 0x2
  35. #define TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED 0
  36. #define TX_MACRO_MCLK_FREQ 9600000
  37. #define TX_MACRO_TX_PATH_OFFSET 0x80
  38. #define TX_MACRO_SWR_MIC_MUX_SEL_MASK 0xF
  39. #define TX_MACRO_ADC_MUX_CFG_OFFSET 0x8
  40. #define TX_MACRO_ADC_MODE_CFG0_SHIFT 1
  41. #define TX_MACRO_DMIC_UNMUTE_DELAY_MS 40
  42. #define TX_MACRO_AMIC_UNMUTE_DELAY_MS 100
  43. #define TX_MACRO_DMIC_HPF_DELAY_MS 300
  44. #define TX_MACRO_AMIC_HPF_DELAY_MS 300
  45. static int tx_unmute_delay = TX_MACRO_DMIC_UNMUTE_DELAY_MS;
  46. module_param(tx_unmute_delay, int, 0664);
  47. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  48. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  49. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  50. struct snd_pcm_hw_params *params,
  51. struct snd_soc_dai *dai);
  52. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  53. unsigned int *tx_num, unsigned int *tx_slot,
  54. unsigned int *rx_num, unsigned int *rx_slot);
  55. #define TX_MACRO_SWR_STRING_LEN 80
  56. #define TX_MACRO_CHILD_DEVICES_MAX 3
  57. /* Hold instance to soundwire platform device */
  58. struct tx_macro_swr_ctrl_data {
  59. struct platform_device *tx_swr_pdev;
  60. };
  61. struct tx_macro_swr_ctrl_platform_data {
  62. void *handle; /* holds codec private data */
  63. int (*read)(void *handle, int reg);
  64. int (*write)(void *handle, int reg, int val);
  65. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  66. int (*clk)(void *handle, bool enable);
  67. int (*core_vote)(void *handle, bool enable);
  68. int (*handle_irq)(void *handle,
  69. irqreturn_t (*swrm_irq_handler)(int irq,
  70. void *data),
  71. void *swrm_handle,
  72. int action);
  73. };
  74. enum {
  75. TX_MACRO_AIF_INVALID = 0,
  76. TX_MACRO_AIF1_CAP,
  77. TX_MACRO_AIF2_CAP,
  78. TX_MACRO_AIF3_CAP,
  79. TX_MACRO_MAX_DAIS
  80. };
  81. enum {
  82. TX_MACRO_DEC0,
  83. TX_MACRO_DEC1,
  84. TX_MACRO_DEC2,
  85. TX_MACRO_DEC3,
  86. TX_MACRO_DEC4,
  87. TX_MACRO_DEC5,
  88. TX_MACRO_DEC6,
  89. TX_MACRO_DEC7,
  90. TX_MACRO_DEC_MAX,
  91. };
  92. enum {
  93. TX_MACRO_CLK_DIV_2,
  94. TX_MACRO_CLK_DIV_3,
  95. TX_MACRO_CLK_DIV_4,
  96. TX_MACRO_CLK_DIV_6,
  97. TX_MACRO_CLK_DIV_8,
  98. TX_MACRO_CLK_DIV_16,
  99. };
  100. enum {
  101. MSM_DMIC,
  102. SWR_MIC,
  103. ANC_FB_TUNE1
  104. };
  105. enum {
  106. TX_MCLK,
  107. VA_MCLK,
  108. };
  109. struct tx_macro_reg_mask_val {
  110. u16 reg;
  111. u8 mask;
  112. u8 val;
  113. };
  114. struct tx_mute_work {
  115. struct tx_macro_priv *tx_priv;
  116. u32 decimator;
  117. struct delayed_work dwork;
  118. };
  119. struct hpf_work {
  120. struct tx_macro_priv *tx_priv;
  121. u8 decimator;
  122. u8 hpf_cut_off_freq;
  123. struct delayed_work dwork;
  124. };
  125. struct tx_macro_priv {
  126. struct device *dev;
  127. bool dec_active[NUM_DECIMATORS];
  128. int tx_mclk_users;
  129. int swr_clk_users;
  130. bool dapm_mclk_enable;
  131. bool reset_swr;
  132. struct mutex mclk_lock;
  133. struct mutex swr_clk_lock;
  134. struct snd_soc_component *component;
  135. struct device_node *tx_swr_gpio_p;
  136. struct tx_macro_swr_ctrl_data *swr_ctrl_data;
  137. struct tx_macro_swr_ctrl_platform_data swr_plat_data;
  138. struct work_struct tx_macro_add_child_devices_work;
  139. struct hpf_work tx_hpf_work[NUM_DECIMATORS];
  140. struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS];
  141. u16 dmic_clk_div;
  142. u32 version;
  143. u32 is_used_tx_swr_gpio;
  144. unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
  145. char __iomem *tx_io_base;
  146. struct platform_device *pdev_child_devices
  147. [TX_MACRO_CHILD_DEVICES_MAX];
  148. int child_count;
  149. int tx_swr_clk_cnt;
  150. int va_swr_clk_cnt;
  151. int va_clk_status;
  152. int tx_clk_status;
  153. bool bcs_enable;
  154. int dec_mode[NUM_DECIMATORS];
  155. int bcs_ch;
  156. bool bcs_clk_en;
  157. bool hs_slow_insert_complete;
  158. int pcm_rate[NUM_DECIMATORS];
  159. bool lpi_enable;
  160. bool register_event_listener;
  161. u16 current_clk_id;
  162. int disable_afe_wakeup_event_listener;
  163. };
  164. static bool tx_macro_get_data(struct snd_soc_component *component,
  165. struct device **tx_dev,
  166. struct tx_macro_priv **tx_priv,
  167. const char *func_name)
  168. {
  169. *tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  170. if (!(*tx_dev)) {
  171. dev_err(component->dev,
  172. "%s: null device for macro!\n", func_name);
  173. return false;
  174. }
  175. *tx_priv = dev_get_drvdata((*tx_dev));
  176. if (!(*tx_priv)) {
  177. dev_err(component->dev,
  178. "%s: priv is null for macro!\n", func_name);
  179. return false;
  180. }
  181. if (!(*tx_priv)->component) {
  182. dev_err(component->dev,
  183. "%s: tx_priv->component not initialized!\n", func_name);
  184. return false;
  185. }
  186. return true;
  187. }
  188. static int tx_macro_mclk_enable(struct tx_macro_priv *tx_priv,
  189. bool mclk_enable)
  190. {
  191. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  192. int ret = 0;
  193. if (regmap == NULL) {
  194. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  195. return -EINVAL;
  196. }
  197. dev_dbg(tx_priv->dev, "%s: mclk_enable = %u,clk_users= %d\n",
  198. __func__, mclk_enable, tx_priv->tx_mclk_users);
  199. mutex_lock(&tx_priv->mclk_lock);
  200. if (mclk_enable) {
  201. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  202. TX_CORE_CLK,
  203. TX_CORE_CLK,
  204. true);
  205. if (ret < 0) {
  206. dev_err_ratelimited(tx_priv->dev,
  207. "%s: request clock enable failed\n",
  208. __func__);
  209. goto exit;
  210. }
  211. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  212. true);
  213. regcache_mark_dirty(regmap);
  214. regcache_sync_region(regmap,
  215. TX_START_OFFSET,
  216. TX_MAX_OFFSET);
  217. if (tx_priv->tx_mclk_users == 0) {
  218. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  219. regmap_update_bits(regmap,
  220. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01);
  221. regmap_update_bits(regmap,
  222. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  223. 0x01, 0x01);
  224. regmap_update_bits(regmap,
  225. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  226. 0x01, 0x01);
  227. }
  228. tx_priv->tx_mclk_users++;
  229. } else {
  230. if (tx_priv->tx_mclk_users <= 0) {
  231. dev_err(tx_priv->dev, "%s: clock already disabled\n",
  232. __func__);
  233. tx_priv->tx_mclk_users = 0;
  234. goto exit;
  235. }
  236. tx_priv->tx_mclk_users--;
  237. if (tx_priv->tx_mclk_users == 0) {
  238. regmap_update_bits(regmap,
  239. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  240. 0x01, 0x00);
  241. regmap_update_bits(regmap,
  242. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  243. 0x01, 0x00);
  244. }
  245. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  246. false);
  247. bolero_clk_rsc_request_clock(tx_priv->dev,
  248. TX_CORE_CLK,
  249. TX_CORE_CLK,
  250. false);
  251. }
  252. exit:
  253. mutex_unlock(&tx_priv->mclk_lock);
  254. return ret;
  255. }
  256. static int __tx_macro_mclk_enable(struct snd_soc_component *component,
  257. bool enable)
  258. {
  259. struct device *tx_dev = NULL;
  260. struct tx_macro_priv *tx_priv = NULL;
  261. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  262. return -EINVAL;
  263. return tx_macro_mclk_enable(tx_priv, enable);
  264. }
  265. static int tx_macro_va_swr_clk_event(struct snd_soc_dapm_widget *w,
  266. struct snd_kcontrol *kcontrol, int event)
  267. {
  268. struct device *tx_dev = NULL;
  269. struct tx_macro_priv *tx_priv = NULL;
  270. struct snd_soc_component *component =
  271. snd_soc_dapm_to_component(w->dapm);
  272. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  273. return -EINVAL;
  274. if (SND_SOC_DAPM_EVENT_ON(event))
  275. ++tx_priv->va_swr_clk_cnt;
  276. if (SND_SOC_DAPM_EVENT_OFF(event))
  277. --tx_priv->va_swr_clk_cnt;
  278. return 0;
  279. }
  280. static int tx_macro_tx_swr_clk_event(struct snd_soc_dapm_widget *w,
  281. struct snd_kcontrol *kcontrol, int event)
  282. {
  283. struct device *tx_dev = NULL;
  284. struct tx_macro_priv *tx_priv = NULL;
  285. struct snd_soc_component *component =
  286. snd_soc_dapm_to_component(w->dapm);
  287. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  288. return -EINVAL;
  289. if (SND_SOC_DAPM_EVENT_ON(event))
  290. ++tx_priv->tx_swr_clk_cnt;
  291. if (SND_SOC_DAPM_EVENT_OFF(event))
  292. --tx_priv->tx_swr_clk_cnt;
  293. return 0;
  294. }
  295. static int tx_macro_swr_pwr_event(struct snd_soc_dapm_widget *w,
  296. struct snd_kcontrol *kcontrol, int event)
  297. {
  298. struct snd_soc_component *component =
  299. snd_soc_dapm_to_component(w->dapm);
  300. int ret = 0;
  301. struct device *tx_dev = NULL;
  302. struct tx_macro_priv *tx_priv = NULL;
  303. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  304. return -EINVAL;
  305. dev_dbg(tx_dev, "%s: event = %d, lpi_enable = %d\n",
  306. __func__, event, tx_priv->lpi_enable);
  307. if (!tx_priv->lpi_enable)
  308. return ret;
  309. switch (event) {
  310. case SND_SOC_DAPM_PRE_PMU:
  311. if (tx_priv->lpi_enable) {
  312. bolero_register_event_listener(component, true);
  313. tx_priv->register_event_listener = true;
  314. }
  315. break;
  316. case SND_SOC_DAPM_POST_PMD:
  317. if (tx_priv->register_event_listener) {
  318. tx_priv->register_event_listener = false;
  319. bolero_register_event_listener(component, false);
  320. }
  321. break;
  322. default:
  323. dev_err(tx_priv->dev,
  324. "%s: invalid DAPM event %d\n", __func__, event);
  325. ret = -EINVAL;
  326. }
  327. return ret;
  328. }
  329. static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  330. struct snd_kcontrol *kcontrol, int event)
  331. {
  332. struct snd_soc_component *component =
  333. snd_soc_dapm_to_component(w->dapm);
  334. int ret = 0;
  335. struct device *tx_dev = NULL;
  336. struct tx_macro_priv *tx_priv = NULL;
  337. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  338. return -EINVAL;
  339. dev_dbg(tx_dev, "%s: event = %d\n", __func__, event);
  340. switch (event) {
  341. case SND_SOC_DAPM_PRE_PMU:
  342. ret = tx_macro_mclk_enable(tx_priv, 1);
  343. if (ret)
  344. tx_priv->dapm_mclk_enable = false;
  345. else
  346. tx_priv->dapm_mclk_enable = true;
  347. break;
  348. case SND_SOC_DAPM_POST_PMD:
  349. if (tx_priv->dapm_mclk_enable)
  350. ret = tx_macro_mclk_enable(tx_priv, 0);
  351. break;
  352. default:
  353. dev_err(tx_priv->dev,
  354. "%s: invalid DAPM event %d\n", __func__, event);
  355. ret = -EINVAL;
  356. }
  357. return ret;
  358. }
  359. static int tx_macro_event_handler(struct snd_soc_component *component,
  360. u16 event, u32 data)
  361. {
  362. struct device *tx_dev = NULL;
  363. struct tx_macro_priv *tx_priv = NULL;
  364. int ret = 0;
  365. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  366. return -EINVAL;
  367. switch (event) {
  368. case BOLERO_MACRO_EVT_SSR_DOWN:
  369. if (tx_priv->swr_ctrl_data) {
  370. swrm_wcd_notify(
  371. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  372. SWR_DEVICE_SSR_DOWN, NULL);
  373. }
  374. if ((!pm_runtime_enabled(tx_dev) ||
  375. !pm_runtime_suspended(tx_dev))) {
  376. ret = bolero_runtime_suspend(tx_dev);
  377. if (!ret) {
  378. pm_runtime_disable(tx_dev);
  379. pm_runtime_set_suspended(tx_dev);
  380. pm_runtime_enable(tx_dev);
  381. }
  382. }
  383. break;
  384. case BOLERO_MACRO_EVT_SSR_UP:
  385. /* reset swr after ssr/pdr */
  386. tx_priv->reset_swr = true;
  387. if (tx_priv->swr_ctrl_data)
  388. swrm_wcd_notify(
  389. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  390. SWR_DEVICE_SSR_UP, NULL);
  391. break;
  392. case BOLERO_MACRO_EVT_CLK_RESET:
  393. bolero_rsc_clk_reset(tx_dev, TX_CORE_CLK);
  394. break;
  395. case BOLERO_MACRO_EVT_BCS_CLK_OFF:
  396. if (tx_priv->bcs_clk_en)
  397. snd_soc_component_update_bits(component,
  398. BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, data << 6);
  399. if (data)
  400. tx_priv->hs_slow_insert_complete = true;
  401. else
  402. tx_priv->hs_slow_insert_complete = false;
  403. break;
  404. default:
  405. pr_debug("%s Invalid Event\n", __func__);
  406. break;
  407. }
  408. return 0;
  409. }
  410. static int tx_macro_reg_wake_irq(struct snd_soc_component *component,
  411. u32 data)
  412. {
  413. struct device *tx_dev = NULL;
  414. struct tx_macro_priv *tx_priv = NULL;
  415. u32 ipc_wakeup = data;
  416. int ret = 0;
  417. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  418. return -EINVAL;
  419. if (tx_priv->swr_ctrl_data)
  420. ret = swrm_wcd_notify(
  421. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  422. SWR_REGISTER_WAKE_IRQ, &ipc_wakeup);
  423. return ret;
  424. }
  425. static bool is_amic_enabled(struct snd_soc_component *component, int decimator)
  426. {
  427. u16 adc_mux_reg = 0, adc_reg = 0;
  428. u16 adc_n = BOLERO_ADC_MAX;
  429. bool ret = false;
  430. struct device *tx_dev = NULL;
  431. struct tx_macro_priv *tx_priv = NULL;
  432. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  433. return ret;
  434. adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  435. TX_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  436. if (snd_soc_component_read(component, adc_mux_reg) & SWR_MIC) {
  437. if (tx_priv->version == BOLERO_VERSION_2_1)
  438. return true;
  439. adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  440. TX_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  441. adc_n = snd_soc_component_read(component, adc_reg) &
  442. TX_MACRO_SWR_MIC_MUX_SEL_MASK;
  443. if (adc_n < BOLERO_ADC_MAX)
  444. return true;
  445. }
  446. return ret;
  447. }
  448. static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
  449. {
  450. struct delayed_work *hpf_delayed_work = NULL;
  451. struct hpf_work *hpf_work = NULL;
  452. struct tx_macro_priv *tx_priv = NULL;
  453. struct snd_soc_component *component = NULL;
  454. u16 dec_cfg_reg = 0, hpf_gate_reg = 0;
  455. u8 hpf_cut_off_freq = 0;
  456. u16 adc_reg = 0, adc_n = 0;
  457. hpf_delayed_work = to_delayed_work(work);
  458. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  459. tx_priv = hpf_work->tx_priv;
  460. component = tx_priv->component;
  461. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  462. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  463. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  464. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  465. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  466. dev_dbg(component->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  467. __func__, hpf_work->decimator, hpf_cut_off_freq);
  468. if (is_amic_enabled(component, hpf_work->decimator)) {
  469. adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  470. TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  471. adc_n = snd_soc_component_read(component, adc_reg) &
  472. TX_MACRO_SWR_MIC_MUX_SEL_MASK;
  473. /* analog mic clear TX hold */
  474. bolero_clear_amic_tx_hold(component->dev, adc_n);
  475. snd_soc_component_update_bits(component,
  476. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  477. hpf_cut_off_freq << 5);
  478. snd_soc_component_update_bits(component, hpf_gate_reg,
  479. 0x03, 0x02);
  480. /* Add delay between toggle hpf gate based on sample rate */
  481. switch (tx_priv->pcm_rate[hpf_work->decimator]) {
  482. case 0:
  483. usleep_range(125, 130);
  484. break;
  485. case 1:
  486. usleep_range(62, 65);
  487. break;
  488. case 3:
  489. usleep_range(31, 32);
  490. break;
  491. case 4:
  492. usleep_range(20, 21);
  493. break;
  494. case 5:
  495. usleep_range(10, 11);
  496. break;
  497. case 6:
  498. usleep_range(5, 6);
  499. break;
  500. default:
  501. usleep_range(125, 130);
  502. }
  503. snd_soc_component_update_bits(component, hpf_gate_reg,
  504. 0x03, 0x01);
  505. } else {
  506. snd_soc_component_update_bits(component,
  507. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  508. hpf_cut_off_freq << 5);
  509. snd_soc_component_update_bits(component, hpf_gate_reg,
  510. 0x02, 0x02);
  511. /* Minimum 1 clk cycle delay is required as per HW spec */
  512. usleep_range(1000, 1010);
  513. snd_soc_component_update_bits(component, hpf_gate_reg,
  514. 0x02, 0x00);
  515. }
  516. }
  517. static void tx_macro_mute_update_callback(struct work_struct *work)
  518. {
  519. struct tx_mute_work *tx_mute_dwork = NULL;
  520. struct snd_soc_component *component = NULL;
  521. struct tx_macro_priv *tx_priv = NULL;
  522. struct delayed_work *delayed_work = NULL;
  523. u16 tx_vol_ctl_reg = 0;
  524. u8 decimator = 0;
  525. delayed_work = to_delayed_work(work);
  526. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  527. tx_priv = tx_mute_dwork->tx_priv;
  528. component = tx_priv->component;
  529. decimator = tx_mute_dwork->decimator;
  530. tx_vol_ctl_reg =
  531. BOLERO_CDC_TX0_TX_PATH_CTL +
  532. TX_MACRO_TX_PATH_OFFSET * decimator;
  533. snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00);
  534. dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n",
  535. __func__, decimator);
  536. }
  537. static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  538. struct snd_ctl_elem_value *ucontrol)
  539. {
  540. struct snd_soc_dapm_widget *widget =
  541. snd_soc_dapm_kcontrol_widget(kcontrol);
  542. struct snd_soc_component *component =
  543. snd_soc_dapm_to_component(widget->dapm);
  544. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  545. unsigned int val = 0;
  546. u16 mic_sel_reg = 0;
  547. u16 dmic_clk_reg = 0;
  548. struct device *tx_dev = NULL;
  549. struct tx_macro_priv *tx_priv = NULL;
  550. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  551. return -EINVAL;
  552. val = ucontrol->value.enumerated.item[0];
  553. if (val > e->items - 1)
  554. return -EINVAL;
  555. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  556. widget->name, val);
  557. switch (e->reg) {
  558. case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
  559. mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
  560. break;
  561. case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
  562. mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
  563. break;
  564. case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
  565. mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
  566. break;
  567. case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
  568. mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
  569. break;
  570. case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0:
  571. mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0;
  572. break;
  573. case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0:
  574. mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0;
  575. break;
  576. case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0:
  577. mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0;
  578. break;
  579. case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0:
  580. mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0;
  581. break;
  582. default:
  583. dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
  584. __func__, e->reg);
  585. return -EINVAL;
  586. }
  587. if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
  588. if (val != 0) {
  589. if (val < 5) {
  590. snd_soc_component_update_bits(component,
  591. mic_sel_reg,
  592. 1 << 7, 0x0 << 7);
  593. } else {
  594. snd_soc_component_update_bits(component,
  595. mic_sel_reg,
  596. 1 << 7, 0x1 << 7);
  597. snd_soc_component_update_bits(component,
  598. BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  599. 0x80, 0x00);
  600. dmic_clk_reg =
  601. BOLERO_CDC_TX_TOP_CSR_SWR_DMIC0_CTL +
  602. ((val - 5)/2) * 4;
  603. snd_soc_component_update_bits(component,
  604. dmic_clk_reg,
  605. 0x0E, tx_priv->dmic_clk_div << 0x1);
  606. }
  607. }
  608. } else {
  609. /* DMIC selected */
  610. if (val != 0)
  611. snd_soc_component_update_bits(component, mic_sel_reg,
  612. 1 << 7, 1 << 7);
  613. }
  614. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  615. }
  616. static int tx_macro_put_dec_enum_v2(struct snd_kcontrol *kcontrol,
  617. struct snd_ctl_elem_value *ucontrol)
  618. {
  619. struct snd_soc_dapm_widget *widget =
  620. snd_soc_dapm_kcontrol_widget(kcontrol);
  621. struct snd_soc_component *component =
  622. snd_soc_dapm_to_component(widget->dapm);
  623. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  624. unsigned int val = 0;
  625. u16 mic_sel_reg = 0;
  626. struct device *tx_dev = NULL;
  627. struct tx_macro_priv *tx_priv = NULL;
  628. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  629. return -EINVAL;
  630. val = ucontrol->value.enumerated.item[0];
  631. if (val > e->items - 1)
  632. return -EINVAL;
  633. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  634. widget->name, val);
  635. switch (e->reg) {
  636. case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
  637. mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
  638. break;
  639. case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
  640. mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
  641. break;
  642. case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
  643. mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
  644. break;
  645. case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
  646. mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
  647. break;
  648. default:
  649. dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
  650. __func__, e->reg);
  651. return -EINVAL;
  652. }
  653. if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
  654. if (val != 0) {
  655. snd_soc_component_update_bits(component,
  656. mic_sel_reg,
  657. 1 << 7, 0x0 << 7);
  658. }
  659. } else {
  660. /* DMIC selected */
  661. if (val != 0)
  662. snd_soc_component_update_bits(component, mic_sel_reg,
  663. 1 << 7, 1 << 7);
  664. }
  665. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  666. }
  667. static int tx_macro_put_pcm_in_enum(struct snd_kcontrol *kcontrol,
  668. struct snd_ctl_elem_value *ucontrol)
  669. {
  670. struct snd_soc_dapm_widget *widget =
  671. snd_soc_dapm_kcontrol_widget(kcontrol);
  672. struct snd_soc_component *component =
  673. snd_soc_dapm_to_component(widget->dapm);
  674. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  675. unsigned int val = 0;
  676. struct device *tx_dev = NULL;
  677. struct tx_macro_priv *tx_priv = NULL;
  678. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  679. return -EINVAL;
  680. val = ucontrol->value.enumerated.item[0];
  681. if (val > e->items - 1)
  682. return -EINVAL;
  683. dev_dbg(component->dev, "%s: wname: %s\n", __func__, widget->name);
  684. snd_soc_component_update_bits(component,
  685. BOLERO_CDC_TX_TOP_CSR_I2S_CLK,
  686. 0x1, val);
  687. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  688. }
  689. static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  690. struct snd_ctl_elem_value *ucontrol)
  691. {
  692. struct snd_soc_dapm_widget *widget =
  693. snd_soc_dapm_kcontrol_widget(kcontrol);
  694. struct snd_soc_component *component =
  695. snd_soc_dapm_to_component(widget->dapm);
  696. struct soc_multi_mixer_control *mixer =
  697. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  698. u32 dai_id = widget->shift;
  699. u32 dec_id = mixer->shift;
  700. struct device *tx_dev = NULL;
  701. struct tx_macro_priv *tx_priv = NULL;
  702. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  703. return -EINVAL;
  704. if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id]))
  705. ucontrol->value.integer.value[0] = 1;
  706. else
  707. ucontrol->value.integer.value[0] = 0;
  708. return 0;
  709. }
  710. static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  711. struct snd_ctl_elem_value *ucontrol)
  712. {
  713. struct snd_soc_dapm_widget *widget =
  714. snd_soc_dapm_kcontrol_widget(kcontrol);
  715. struct snd_soc_component *component =
  716. snd_soc_dapm_to_component(widget->dapm);
  717. struct snd_soc_dapm_update *update = NULL;
  718. struct soc_multi_mixer_control *mixer =
  719. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  720. u32 dai_id = widget->shift;
  721. u32 dec_id = mixer->shift;
  722. u32 enable = ucontrol->value.integer.value[0];
  723. struct device *tx_dev = NULL;
  724. struct tx_macro_priv *tx_priv = NULL;
  725. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  726. return -EINVAL;
  727. if (enable)
  728. set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  729. else
  730. clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  731. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  732. return 0;
  733. }
  734. static inline int tx_macro_path_get(const char *wname,
  735. unsigned int *path_num)
  736. {
  737. int ret = 0;
  738. char *widget_name = NULL;
  739. char *w_name = NULL;
  740. char *path_num_char = NULL;
  741. char *path_name = NULL;
  742. widget_name = kstrndup(wname, 10, GFP_KERNEL);
  743. if (!widget_name)
  744. return -EINVAL;
  745. w_name = widget_name;
  746. path_name = strsep(&widget_name, " ");
  747. if (!path_name) {
  748. pr_err("%s: Invalid widget name = %s\n",
  749. __func__, widget_name);
  750. ret = -EINVAL;
  751. goto err;
  752. }
  753. path_num_char = strpbrk(path_name, "01234567");
  754. if (!path_num_char) {
  755. pr_err("%s: tx path index not found\n",
  756. __func__);
  757. ret = -EINVAL;
  758. goto err;
  759. }
  760. ret = kstrtouint(path_num_char, 10, path_num);
  761. if (ret < 0)
  762. pr_err("%s: Invalid tx path = %s\n",
  763. __func__, w_name);
  764. err:
  765. kfree(w_name);
  766. return ret;
  767. }
  768. static int tx_macro_dec_mode_get(struct snd_kcontrol *kcontrol,
  769. struct snd_ctl_elem_value *ucontrol)
  770. {
  771. struct snd_soc_component *component =
  772. snd_soc_kcontrol_component(kcontrol);
  773. struct tx_macro_priv *tx_priv = NULL;
  774. struct device *tx_dev = NULL;
  775. int ret = 0;
  776. int path = 0;
  777. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  778. return -EINVAL;
  779. ret = tx_macro_path_get(kcontrol->id.name, &path);
  780. if (ret)
  781. return ret;
  782. ucontrol->value.integer.value[0] = tx_priv->dec_mode[path];
  783. return 0;
  784. }
  785. static int tx_macro_dec_mode_put(struct snd_kcontrol *kcontrol,
  786. struct snd_ctl_elem_value *ucontrol)
  787. {
  788. struct snd_soc_component *component =
  789. snd_soc_kcontrol_component(kcontrol);
  790. struct tx_macro_priv *tx_priv = NULL;
  791. struct device *tx_dev = NULL;
  792. int value = ucontrol->value.integer.value[0];
  793. int ret = 0;
  794. int path = 0;
  795. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  796. return -EINVAL;
  797. ret = tx_macro_path_get(kcontrol->id.name, &path);
  798. if (ret)
  799. return ret;
  800. tx_priv->dec_mode[path] = value;
  801. return 0;
  802. }
  803. static int tx_macro_lpi_get(struct snd_kcontrol *kcontrol,
  804. struct snd_ctl_elem_value *ucontrol)
  805. {
  806. struct snd_soc_component *component =
  807. snd_soc_kcontrol_component(kcontrol);
  808. struct device *tx_dev = NULL;
  809. struct tx_macro_priv *tx_priv = NULL;
  810. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  811. return -EINVAL;
  812. ucontrol->value.integer.value[0] = tx_priv->lpi_enable;
  813. return 0;
  814. }
  815. static int tx_macro_lpi_put(struct snd_kcontrol *kcontrol,
  816. struct snd_ctl_elem_value *ucontrol)
  817. {
  818. struct snd_soc_component *component =
  819. snd_soc_kcontrol_component(kcontrol);
  820. struct device *tx_dev = NULL;
  821. struct tx_macro_priv *tx_priv = NULL;
  822. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  823. return -EINVAL;
  824. tx_priv->lpi_enable = ucontrol->value.integer.value[0];
  825. return 0;
  826. }
  827. static int tx_macro_bcs_ch_get(struct snd_kcontrol *kcontrol,
  828. struct snd_ctl_elem_value *ucontrol)
  829. {
  830. struct snd_soc_component *component =
  831. snd_soc_kcontrol_component(kcontrol);
  832. struct tx_macro_priv *tx_priv = NULL;
  833. struct device *tx_dev = NULL;
  834. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  835. return -EINVAL;
  836. ucontrol->value.enumerated.item[0] = tx_priv->bcs_ch;
  837. return 0;
  838. }
  839. static int tx_macro_bcs_ch_put(struct snd_kcontrol *kcontrol,
  840. struct snd_ctl_elem_value *ucontrol)
  841. {
  842. struct snd_soc_component *component =
  843. snd_soc_kcontrol_component(kcontrol);
  844. struct tx_macro_priv *tx_priv = NULL;
  845. struct device *tx_dev = NULL;
  846. int value = ucontrol->value.enumerated.item[0];
  847. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  848. return -EINVAL;
  849. tx_priv->bcs_ch = value;
  850. return 0;
  851. }
  852. static int tx_macro_get_bcs(struct snd_kcontrol *kcontrol,
  853. struct snd_ctl_elem_value *ucontrol)
  854. {
  855. struct snd_soc_component *component =
  856. snd_soc_kcontrol_component(kcontrol);
  857. struct tx_macro_priv *tx_priv = NULL;
  858. struct device *tx_dev = NULL;
  859. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  860. return -EINVAL;
  861. ucontrol->value.integer.value[0] = tx_priv->bcs_enable;
  862. return 0;
  863. }
  864. static int tx_macro_set_bcs(struct snd_kcontrol *kcontrol,
  865. struct snd_ctl_elem_value *ucontrol)
  866. {
  867. struct snd_soc_component *component =
  868. snd_soc_kcontrol_component(kcontrol);
  869. struct tx_macro_priv *tx_priv = NULL;
  870. struct device *tx_dev = NULL;
  871. int value = ucontrol->value.integer.value[0];
  872. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  873. return -EINVAL;
  874. tx_priv->bcs_enable = value;
  875. return 0;
  876. }
  877. static const char * const bcs_ch_sel_mux_text[] = {
  878. "SWR_MIC0", "SWR_MIC1", "SWR_MIC2", "SWR_MIC3",
  879. "SWR_MIC4", "SWR_MIC5", "SWR_MIC6", "SWR_MIC7",
  880. "SWR_MIC8", "SWR_MIC9", "SWR_MIC10", "SWR_MIC11",
  881. };
  882. static const struct soc_enum bcs_ch_sel_mux_enum =
  883. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(bcs_ch_sel_mux_text),
  884. bcs_ch_sel_mux_text);
  885. static int tx_macro_get_bcs_ch_sel(struct snd_kcontrol *kcontrol,
  886. struct snd_ctl_elem_value *ucontrol)
  887. {
  888. struct snd_soc_component *component =
  889. snd_soc_kcontrol_component(kcontrol);
  890. struct tx_macro_priv *tx_priv = NULL;
  891. struct device *tx_dev = NULL;
  892. int value = 0;
  893. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  894. return -EINVAL;
  895. if ((tx_priv->version == BOLERO_VERSION_2_1) ||
  896. (tx_priv->version == BOLERO_VERSION_2_2))
  897. value = (snd_soc_component_read(component,
  898. BOLERO_CDC_VA_TOP_CSR_SWR_CTRL)) & 0x0F;
  899. else if (tx_priv->version == BOLERO_VERSION_2_0)
  900. value = (snd_soc_component_read(component,
  901. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL)) & 0x0F;
  902. ucontrol->value.integer.value[0] = value;
  903. return 0;
  904. }
  905. static int tx_macro_put_bcs_ch_sel(struct snd_kcontrol *kcontrol,
  906. struct snd_ctl_elem_value *ucontrol)
  907. {
  908. struct snd_soc_component *component =
  909. snd_soc_kcontrol_component(kcontrol);
  910. struct tx_macro_priv *tx_priv = NULL;
  911. struct device *tx_dev = NULL;
  912. int value;
  913. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  914. return -EINVAL;
  915. if (ucontrol->value.integer.value[0] < 0 ||
  916. ucontrol->value.integer.value[0] > ARRAY_SIZE(bcs_ch_sel_mux_text))
  917. return -EINVAL;
  918. value = ucontrol->value.integer.value[0];
  919. if ((tx_priv->version == BOLERO_VERSION_2_1) ||
  920. (tx_priv->version == BOLERO_VERSION_2_2))
  921. snd_soc_component_update_bits(component,
  922. BOLERO_CDC_VA_TOP_CSR_SWR_CTRL, 0x0F, value);
  923. else if (tx_priv->version == BOLERO_VERSION_2_0)
  924. snd_soc_component_update_bits(component,
  925. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL, 0x0F, value);
  926. return 0;
  927. }
  928. static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  929. struct snd_kcontrol *kcontrol, int event)
  930. {
  931. struct snd_soc_component *component =
  932. snd_soc_dapm_to_component(w->dapm);
  933. unsigned int dmic = 0;
  934. int ret = 0;
  935. char *wname = NULL;
  936. wname = strpbrk(w->name, "01234567");
  937. if (!wname) {
  938. dev_err(component->dev, "%s: widget not found\n", __func__);
  939. return -EINVAL;
  940. }
  941. ret = kstrtouint(wname, 10, &dmic);
  942. if (ret < 0) {
  943. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  944. __func__);
  945. return -EINVAL;
  946. }
  947. dev_dbg(component->dev, "%s: event %d DMIC%d\n",
  948. __func__, event, dmic);
  949. switch (event) {
  950. case SND_SOC_DAPM_PRE_PMU:
  951. bolero_dmic_clk_enable(component, dmic, DMIC_TX, true);
  952. break;
  953. case SND_SOC_DAPM_POST_PMD:
  954. bolero_dmic_clk_enable(component, dmic, DMIC_TX, false);
  955. break;
  956. }
  957. return 0;
  958. }
  959. static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
  960. struct snd_kcontrol *kcontrol, int event)
  961. {
  962. struct snd_soc_component *component =
  963. snd_soc_dapm_to_component(w->dapm);
  964. unsigned int decimator = 0;
  965. u16 tx_vol_ctl_reg = 0;
  966. u16 dec_cfg_reg = 0;
  967. u16 hpf_gate_reg = 0;
  968. u16 tx_gain_ctl_reg = 0;
  969. u16 tx_fs_reg = 0;
  970. u8 hpf_cut_off_freq = 0;
  971. u16 adc_mux_reg = 0;
  972. int hpf_delay = TX_MACRO_DMIC_HPF_DELAY_MS;
  973. int unmute_delay = TX_MACRO_DMIC_UNMUTE_DELAY_MS;
  974. struct device *tx_dev = NULL;
  975. struct tx_macro_priv *tx_priv = NULL;
  976. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  977. return -EINVAL;
  978. decimator = w->shift;
  979. dev_dbg(component->dev, "%s(): widget = %s decimator = %u\n", __func__,
  980. w->name, decimator);
  981. tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  982. TX_MACRO_TX_PATH_OFFSET * decimator;
  983. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  984. TX_MACRO_TX_PATH_OFFSET * decimator;
  985. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  986. TX_MACRO_TX_PATH_OFFSET * decimator;
  987. tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL +
  988. TX_MACRO_TX_PATH_OFFSET * decimator;
  989. adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  990. TX_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  991. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  992. TX_MACRO_TX_PATH_OFFSET * decimator;
  993. tx_priv->pcm_rate[decimator] = (snd_soc_component_read(component,
  994. tx_fs_reg) & 0x0F);
  995. switch (event) {
  996. case SND_SOC_DAPM_PRE_PMU:
  997. snd_soc_component_update_bits(component,
  998. dec_cfg_reg, 0x06, tx_priv->dec_mode[decimator] <<
  999. TX_MACRO_ADC_MODE_CFG0_SHIFT);
  1000. /* Enable TX PGA Mute */
  1001. snd_soc_component_update_bits(component,
  1002. tx_vol_ctl_reg, 0x10, 0x10);
  1003. break;
  1004. case SND_SOC_DAPM_POST_PMU:
  1005. snd_soc_component_update_bits(component,
  1006. tx_vol_ctl_reg, 0x20, 0x20);
  1007. if (!is_amic_enabled(component, decimator)) {
  1008. snd_soc_component_update_bits(component,
  1009. hpf_gate_reg, 0x01, 0x00);
  1010. /*
  1011. * Minimum 1 clk cycle delay is required as per HW spec
  1012. */
  1013. usleep_range(1000, 1010);
  1014. }
  1015. hpf_cut_off_freq = (
  1016. snd_soc_component_read(component, dec_cfg_reg) &
  1017. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  1018. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
  1019. hpf_cut_off_freq;
  1020. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
  1021. snd_soc_component_update_bits(component, dec_cfg_reg,
  1022. TX_HPF_CUT_OFF_FREQ_MASK,
  1023. CF_MIN_3DB_150HZ << 5);
  1024. if (is_amic_enabled(component, decimator)) {
  1025. hpf_delay = TX_MACRO_AMIC_HPF_DELAY_MS;
  1026. unmute_delay = TX_MACRO_AMIC_UNMUTE_DELAY_MS;
  1027. }
  1028. if (tx_unmute_delay < unmute_delay)
  1029. tx_unmute_delay = unmute_delay;
  1030. /* schedule work queue to Remove Mute */
  1031. queue_delayed_work(system_freezable_wq,
  1032. &tx_priv->tx_mute_dwork[decimator].dwork,
  1033. msecs_to_jiffies(tx_unmute_delay));
  1034. if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
  1035. CF_MIN_3DB_150HZ) {
  1036. queue_delayed_work(system_freezable_wq,
  1037. &tx_priv->tx_hpf_work[decimator].dwork,
  1038. msecs_to_jiffies(hpf_delay));
  1039. snd_soc_component_update_bits(component,
  1040. hpf_gate_reg, 0x03, 0x02);
  1041. if (!is_amic_enabled(component, decimator))
  1042. snd_soc_component_update_bits(component,
  1043. hpf_gate_reg, 0x03, 0x00);
  1044. snd_soc_component_update_bits(component,
  1045. hpf_gate_reg, 0x03, 0x01);
  1046. /*
  1047. * 6ms delay is required as per HW spec
  1048. */
  1049. usleep_range(6000, 6010);
  1050. }
  1051. /* apply gain after decimator is enabled */
  1052. snd_soc_component_write(component, tx_gain_ctl_reg,
  1053. snd_soc_component_read(component,
  1054. tx_gain_ctl_reg));
  1055. if (tx_priv->bcs_enable) {
  1056. if ((tx_priv->version == BOLERO_VERSION_2_1) ||
  1057. (tx_priv->version == BOLERO_VERSION_2_2))
  1058. snd_soc_component_update_bits(component,
  1059. BOLERO_CDC_VA_TOP_CSR_SWR_CTRL, 0x0F,
  1060. tx_priv->bcs_ch);
  1061. else if (tx_priv->version == BOLERO_VERSION_2_0)
  1062. snd_soc_component_update_bits(component,
  1063. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL, 0xF0,
  1064. (tx_priv->bcs_ch << 4));
  1065. snd_soc_component_update_bits(component, dec_cfg_reg,
  1066. 0x01, 0x01);
  1067. tx_priv->bcs_clk_en = true;
  1068. if (tx_priv->hs_slow_insert_complete)
  1069. snd_soc_component_update_bits(component,
  1070. BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40,
  1071. 0x40);
  1072. }
  1073. if (tx_priv->version == BOLERO_VERSION_2_0) {
  1074. if (snd_soc_component_read(component, adc_mux_reg)
  1075. & SWR_MIC) {
  1076. snd_soc_component_update_bits(component,
  1077. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL,
  1078. 0x01, 0x01);
  1079. snd_soc_component_update_bits(component,
  1080. BOLERO_CDC_TX_TOP_CSR_SWR_MIC0_CTL,
  1081. 0x0E, 0x0C);
  1082. snd_soc_component_update_bits(component,
  1083. BOLERO_CDC_TX_TOP_CSR_SWR_MIC1_CTL,
  1084. 0x0E, 0x0C);
  1085. snd_soc_component_update_bits(component,
  1086. BOLERO_CDC_TX_TOP_CSR_SWR_MIC2_CTL,
  1087. 0x0E, 0x00);
  1088. snd_soc_component_update_bits(component,
  1089. BOLERO_CDC_TX_TOP_CSR_SWR_MIC3_CTL,
  1090. 0x0E, 0x00);
  1091. snd_soc_component_update_bits(component,
  1092. BOLERO_CDC_TX_TOP_CSR_SWR_MIC4_CTL,
  1093. 0x0E, 0x00);
  1094. snd_soc_component_update_bits(component,
  1095. BOLERO_CDC_TX_TOP_CSR_SWR_MIC5_CTL,
  1096. 0x0E, 0x00);
  1097. }
  1098. }
  1099. break;
  1100. case SND_SOC_DAPM_PRE_PMD:
  1101. hpf_cut_off_freq =
  1102. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
  1103. snd_soc_component_update_bits(component,
  1104. tx_vol_ctl_reg, 0x10, 0x10);
  1105. if (cancel_delayed_work_sync(
  1106. &tx_priv->tx_hpf_work[decimator].dwork)) {
  1107. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  1108. snd_soc_component_update_bits(
  1109. component, dec_cfg_reg,
  1110. TX_HPF_CUT_OFF_FREQ_MASK,
  1111. hpf_cut_off_freq << 5);
  1112. if (is_amic_enabled(component, decimator))
  1113. snd_soc_component_update_bits(component,
  1114. hpf_gate_reg,
  1115. 0x03, 0x02);
  1116. else
  1117. snd_soc_component_update_bits(component,
  1118. hpf_gate_reg,
  1119. 0x03, 0x03);
  1120. /*
  1121. * Minimum 1 clk cycle delay is required
  1122. * as per HW spec
  1123. */
  1124. usleep_range(1000, 1010);
  1125. snd_soc_component_update_bits(component,
  1126. hpf_gate_reg,
  1127. 0x03, 0x01);
  1128. }
  1129. }
  1130. cancel_delayed_work_sync(
  1131. &tx_priv->tx_mute_dwork[decimator].dwork);
  1132. if (tx_priv->version == BOLERO_VERSION_2_0) {
  1133. if (snd_soc_component_read(component, adc_mux_reg)
  1134. & SWR_MIC)
  1135. snd_soc_component_update_bits(component,
  1136. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL,
  1137. 0x01, 0x00);
  1138. }
  1139. break;
  1140. case SND_SOC_DAPM_POST_PMD:
  1141. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1142. 0x20, 0x00);
  1143. snd_soc_component_update_bits(component,
  1144. dec_cfg_reg, 0x06, 0x00);
  1145. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1146. 0x40, 0x40);
  1147. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1148. 0x40, 0x00);
  1149. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1150. 0x10, 0x00);
  1151. if (tx_priv->bcs_enable) {
  1152. snd_soc_component_update_bits(component, dec_cfg_reg,
  1153. 0x01, 0x00);
  1154. snd_soc_component_update_bits(component,
  1155. BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, 0x00);
  1156. tx_priv->bcs_clk_en = false;
  1157. if ((tx_priv->version == BOLERO_VERSION_2_1) ||
  1158. (tx_priv->version == BOLERO_VERSION_2_2))
  1159. snd_soc_component_update_bits(component,
  1160. BOLERO_CDC_VA_TOP_CSR_SWR_CTRL, 0x0F,
  1161. 0x00);
  1162. else if (tx_priv->version == BOLERO_VERSION_2_0)
  1163. snd_soc_component_update_bits(component,
  1164. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL, 0xF0,
  1165. 0x00);
  1166. }
  1167. break;
  1168. }
  1169. return 0;
  1170. }
  1171. static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  1172. struct snd_kcontrol *kcontrol, int event)
  1173. {
  1174. return 0;
  1175. }
  1176. /* Cutoff frequency for high pass filter */
  1177. static const char * const cf_text[] = {
  1178. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ"
  1179. };
  1180. static SOC_ENUM_SINGLE_DECL(cf_dec0_enum, BOLERO_CDC_TX0_TX_PATH_CFG0, 5,
  1181. cf_text);
  1182. static SOC_ENUM_SINGLE_DECL(cf_dec1_enum, BOLERO_CDC_TX1_TX_PATH_CFG0, 5,
  1183. cf_text);
  1184. static SOC_ENUM_SINGLE_DECL(cf_dec2_enum, BOLERO_CDC_TX2_TX_PATH_CFG0, 5,
  1185. cf_text);
  1186. static SOC_ENUM_SINGLE_DECL(cf_dec3_enum, BOLERO_CDC_TX3_TX_PATH_CFG0, 5,
  1187. cf_text);
  1188. static SOC_ENUM_SINGLE_DECL(cf_dec4_enum, BOLERO_CDC_TX4_TX_PATH_CFG0, 5,
  1189. cf_text);
  1190. static SOC_ENUM_SINGLE_DECL(cf_dec5_enum, BOLERO_CDC_TX5_TX_PATH_CFG0, 5,
  1191. cf_text);
  1192. static SOC_ENUM_SINGLE_DECL(cf_dec6_enum, BOLERO_CDC_TX6_TX_PATH_CFG0, 5,
  1193. cf_text);
  1194. static SOC_ENUM_SINGLE_DECL(cf_dec7_enum, BOLERO_CDC_TX7_TX_PATH_CFG0, 5,
  1195. cf_text);
  1196. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  1197. struct snd_pcm_hw_params *params,
  1198. struct snd_soc_dai *dai)
  1199. {
  1200. int tx_fs_rate = -EINVAL;
  1201. struct snd_soc_component *component = dai->component;
  1202. u32 decimator = 0;
  1203. u32 sample_rate = 0;
  1204. u16 tx_fs_reg = 0;
  1205. struct device *tx_dev = NULL;
  1206. struct tx_macro_priv *tx_priv = NULL;
  1207. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  1208. return -EINVAL;
  1209. pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  1210. dai->name, dai->id, params_rate(params),
  1211. params_channels(params));
  1212. sample_rate = params_rate(params);
  1213. switch (sample_rate) {
  1214. case 8000:
  1215. tx_fs_rate = 0;
  1216. break;
  1217. case 16000:
  1218. tx_fs_rate = 1;
  1219. break;
  1220. case 32000:
  1221. tx_fs_rate = 3;
  1222. break;
  1223. case 48000:
  1224. tx_fs_rate = 4;
  1225. break;
  1226. case 96000:
  1227. tx_fs_rate = 5;
  1228. break;
  1229. case 192000:
  1230. tx_fs_rate = 6;
  1231. break;
  1232. case 384000:
  1233. tx_fs_rate = 7;
  1234. break;
  1235. default:
  1236. dev_err(component->dev, "%s: Invalid TX sample rate: %d\n",
  1237. __func__, params_rate(params));
  1238. return -EINVAL;
  1239. }
  1240. for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
  1241. TX_MACRO_DEC_MAX) {
  1242. if (decimator >= 0) {
  1243. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  1244. TX_MACRO_TX_PATH_OFFSET * decimator;
  1245. dev_dbg(component->dev, "%s: set DEC%u rate to %u\n",
  1246. __func__, decimator, sample_rate);
  1247. snd_soc_component_update_bits(component, tx_fs_reg,
  1248. 0x0F, tx_fs_rate);
  1249. } else {
  1250. dev_err(component->dev,
  1251. "%s: ERROR: Invalid decimator: %d\n",
  1252. __func__, decimator);
  1253. return -EINVAL;
  1254. }
  1255. }
  1256. return 0;
  1257. }
  1258. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  1259. unsigned int *tx_num, unsigned int *tx_slot,
  1260. unsigned int *rx_num, unsigned int *rx_slot)
  1261. {
  1262. struct snd_soc_component *component = dai->component;
  1263. struct device *tx_dev = NULL;
  1264. struct tx_macro_priv *tx_priv = NULL;
  1265. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  1266. return -EINVAL;
  1267. switch (dai->id) {
  1268. case TX_MACRO_AIF1_CAP:
  1269. case TX_MACRO_AIF2_CAP:
  1270. case TX_MACRO_AIF3_CAP:
  1271. *tx_slot = tx_priv->active_ch_mask[dai->id];
  1272. *tx_num = hweight_long(tx_priv->active_ch_mask[dai->id]);
  1273. break;
  1274. default:
  1275. dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
  1276. break;
  1277. }
  1278. return 0;
  1279. }
  1280. static struct snd_soc_dai_ops tx_macro_dai_ops = {
  1281. .hw_params = tx_macro_hw_params,
  1282. .get_channel_map = tx_macro_get_channel_map,
  1283. };
  1284. static struct snd_soc_dai_driver tx_macro_dai[] = {
  1285. {
  1286. .name = "tx_macro_tx1",
  1287. .id = TX_MACRO_AIF1_CAP,
  1288. .capture = {
  1289. .stream_name = "TX_AIF1 Capture",
  1290. .rates = TX_MACRO_RATES,
  1291. .formats = TX_MACRO_FORMATS,
  1292. .rate_max = 192000,
  1293. .rate_min = 8000,
  1294. .channels_min = 1,
  1295. .channels_max = 8,
  1296. },
  1297. .ops = &tx_macro_dai_ops,
  1298. },
  1299. {
  1300. .name = "tx_macro_tx2",
  1301. .id = TX_MACRO_AIF2_CAP,
  1302. .capture = {
  1303. .stream_name = "TX_AIF2 Capture",
  1304. .rates = TX_MACRO_RATES,
  1305. .formats = TX_MACRO_FORMATS,
  1306. .rate_max = 192000,
  1307. .rate_min = 8000,
  1308. .channels_min = 1,
  1309. .channels_max = 8,
  1310. },
  1311. .ops = &tx_macro_dai_ops,
  1312. },
  1313. {
  1314. .name = "tx_macro_tx3",
  1315. .id = TX_MACRO_AIF3_CAP,
  1316. .capture = {
  1317. .stream_name = "TX_AIF3 Capture",
  1318. .rates = TX_MACRO_RATES,
  1319. .formats = TX_MACRO_FORMATS,
  1320. .rate_max = 192000,
  1321. .rate_min = 8000,
  1322. .channels_min = 1,
  1323. .channels_max = 8,
  1324. },
  1325. .ops = &tx_macro_dai_ops,
  1326. },
  1327. };
  1328. #define STRING(name) #name
  1329. #define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  1330. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  1331. static const struct snd_kcontrol_new name##_mux = \
  1332. SOC_DAPM_ENUM(STRING(name), name##_enum)
  1333. #define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  1334. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  1335. static const struct snd_kcontrol_new name##_mux = \
  1336. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  1337. #define TX_MACRO_DAPM_MUX(name, shift, kctl) \
  1338. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  1339. static const char * const adc_mux_text[] = {
  1340. "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
  1341. };
  1342. TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
  1343. 0, adc_mux_text);
  1344. TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
  1345. 0, adc_mux_text);
  1346. TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
  1347. 0, adc_mux_text);
  1348. TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
  1349. 0, adc_mux_text);
  1350. TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
  1351. 0, adc_mux_text);
  1352. TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
  1353. 0, adc_mux_text);
  1354. TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
  1355. 0, adc_mux_text);
  1356. TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
  1357. 0, adc_mux_text);
  1358. static const char * const dmic_mux_text[] = {
  1359. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  1360. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  1361. };
  1362. TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1363. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1364. tx_macro_put_dec_enum);
  1365. TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1366. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1367. tx_macro_put_dec_enum);
  1368. TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1369. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1370. tx_macro_put_dec_enum);
  1371. TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1372. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1373. tx_macro_put_dec_enum);
  1374. TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1375. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1376. tx_macro_put_dec_enum);
  1377. TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1378. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1379. tx_macro_put_dec_enum);
  1380. TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1381. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1382. tx_macro_put_dec_enum);
  1383. TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1384. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1385. tx_macro_put_dec_enum);
  1386. static const char * const smic_mux_text[] = {
  1387. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "SWR_DMIC0",
  1388. "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3", "SWR_DMIC4",
  1389. "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  1390. };
  1391. TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1392. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1393. tx_macro_put_dec_enum);
  1394. TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1395. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1396. tx_macro_put_dec_enum);
  1397. TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1398. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1399. tx_macro_put_dec_enum);
  1400. TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1401. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1402. tx_macro_put_dec_enum);
  1403. TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1404. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1405. tx_macro_put_dec_enum);
  1406. TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1407. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1408. tx_macro_put_dec_enum);
  1409. TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1410. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1411. tx_macro_put_dec_enum);
  1412. TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1413. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1414. tx_macro_put_dec_enum);
  1415. static const char * const smic_mux_text_v2[] = {
  1416. "ZERO", "SWR_MIC0", "SWR_MIC1", "SWR_MIC2", "SWR_MIC3",
  1417. "SWR_MIC4", "SWR_MIC5", "SWR_MIC6", "SWR_MIC7",
  1418. "SWR_MIC8", "SWR_MIC9", "SWR_MIC10", "SWR_MIC11"
  1419. };
  1420. TX_MACRO_DAPM_ENUM_EXT(tx_smic0_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1421. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1422. tx_macro_put_dec_enum);
  1423. TX_MACRO_DAPM_ENUM_EXT(tx_smic1_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1424. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1425. tx_macro_put_dec_enum);
  1426. TX_MACRO_DAPM_ENUM_EXT(tx_smic2_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1427. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1428. tx_macro_put_dec_enum);
  1429. TX_MACRO_DAPM_ENUM_EXT(tx_smic3_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1430. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1431. tx_macro_put_dec_enum);
  1432. TX_MACRO_DAPM_ENUM_EXT(tx_smic4_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1433. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1434. tx_macro_put_dec_enum);
  1435. TX_MACRO_DAPM_ENUM_EXT(tx_smic5_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1436. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1437. tx_macro_put_dec_enum);
  1438. TX_MACRO_DAPM_ENUM_EXT(tx_smic6_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1439. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1440. tx_macro_put_dec_enum);
  1441. TX_MACRO_DAPM_ENUM_EXT(tx_smic7_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1442. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1443. tx_macro_put_dec_enum);
  1444. TX_MACRO_DAPM_ENUM_EXT(tx_smic0_v4, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1445. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1446. tx_macro_put_dec_enum_v2);
  1447. TX_MACRO_DAPM_ENUM_EXT(tx_smic1_v4, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1448. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1449. tx_macro_put_dec_enum_v2);
  1450. TX_MACRO_DAPM_ENUM_EXT(tx_smic2_v4, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1451. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1452. tx_macro_put_dec_enum_v2);
  1453. TX_MACRO_DAPM_ENUM_EXT(tx_smic3_v4, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1454. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1455. tx_macro_put_dec_enum_v2);
  1456. static const char * const pcm_in0_mux_text[] = {
  1457. "SWR_MIC", "RX_SWR_TX_PCM_IN0",
  1458. };
  1459. static const char * const pcm_in1_mux_text[] = {
  1460. "SWR_MIC", "RX_SWR_TX_PCM_IN1",
  1461. };
  1462. TX_MACRO_DAPM_ENUM_EXT(rx_swr_tx_pcm_in0, SND_SOC_NOPM,
  1463. 0, pcm_in0_mux_text, snd_soc_dapm_get_enum_double,
  1464. tx_macro_put_pcm_in_enum);
  1465. TX_MACRO_DAPM_ENUM_EXT(rx_swr_tx_pcm_in1, SND_SOC_NOPM,
  1466. 0, pcm_in1_mux_text, snd_soc_dapm_get_enum_double,
  1467. tx_macro_put_pcm_in_enum);
  1468. static const char * const dec_mode_mux_text[] = {
  1469. "ADC_DEFAULT", "ADC_LOW_PWR", "ADC_HIGH_PERF",
  1470. };
  1471. static const struct soc_enum dec_mode_mux_enum =
  1472. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dec_mode_mux_text),
  1473. dec_mode_mux_text);
  1474. static const char * const bcs_ch_enum_text[] = {
  1475. "CH0", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8", "CH9",
  1476. "CH10", "CH11",
  1477. };
  1478. static const struct soc_enum bcs_ch_enum =
  1479. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(bcs_ch_enum_text),
  1480. bcs_ch_enum_text);
  1481. static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
  1482. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1483. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1484. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1485. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1486. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1487. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1488. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1489. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1490. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1491. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1492. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1493. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1494. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1495. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1496. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1497. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1498. };
  1499. static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
  1500. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1501. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1502. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1503. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1504. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1505. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1506. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1507. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1508. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1509. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1510. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1511. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1512. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1513. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1514. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1515. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1516. };
  1517. static const struct snd_kcontrol_new tx_aif3_cap_mixer[] = {
  1518. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1519. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1520. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1521. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1522. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1523. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1524. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1525. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1526. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1527. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1528. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1529. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1530. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1531. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1532. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1533. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1534. };
  1535. static const struct snd_kcontrol_new tx_aif1_cap_mixer_v2[] = {
  1536. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1537. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1538. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1539. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1540. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1541. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1542. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1543. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1544. };
  1545. static const struct snd_kcontrol_new tx_aif2_cap_mixer_v2[] = {
  1546. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1547. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1548. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1549. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1550. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1551. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1552. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1553. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1554. };
  1555. static const struct snd_kcontrol_new tx_aif3_cap_mixer_v2[] = {
  1556. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1557. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1558. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1559. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1560. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1561. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1562. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1563. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1564. };
  1565. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_common[] = {
  1566. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  1567. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  1568. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  1569. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  1570. SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
  1571. SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
  1572. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  1573. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  1574. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  1575. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  1576. SND_SOC_DAPM_SUPPLY("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1577. tx_macro_enable_micbias,
  1578. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1579. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1580. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1581. SND_SOC_DAPM_POST_PMD),
  1582. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1583. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1584. SND_SOC_DAPM_POST_PMD),
  1585. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1586. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1587. SND_SOC_DAPM_POST_PMD),
  1588. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1589. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1590. SND_SOC_DAPM_POST_PMD),
  1591. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1592. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1593. SND_SOC_DAPM_POST_PMD),
  1594. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1595. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1596. SND_SOC_DAPM_POST_PMD),
  1597. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1598. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1599. SND_SOC_DAPM_POST_PMD),
  1600. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1601. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1602. SND_SOC_DAPM_POST_PMD),
  1603. SND_SOC_DAPM_INPUT("TX SWR_INPUT"),
  1604. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  1605. TX_MACRO_DEC0, 0,
  1606. &tx_dec0_mux, tx_macro_enable_dec,
  1607. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1608. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1609. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  1610. TX_MACRO_DEC1, 0,
  1611. &tx_dec1_mux, tx_macro_enable_dec,
  1612. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1613. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1614. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  1615. TX_MACRO_DEC2, 0,
  1616. &tx_dec2_mux, tx_macro_enable_dec,
  1617. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1618. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1619. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  1620. TX_MACRO_DEC3, 0,
  1621. &tx_dec3_mux, tx_macro_enable_dec,
  1622. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1623. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1624. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1625. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1626. SND_SOC_DAPM_SUPPLY_S("TX_SWR_PWR", -1, SND_SOC_NOPM, 0, 0,
  1627. tx_macro_swr_pwr_event,
  1628. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1629. };
  1630. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v2[] = {
  1631. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
  1632. TX_MACRO_AIF1_CAP, 0,
  1633. tx_aif1_cap_mixer_v2, ARRAY_SIZE(tx_aif1_cap_mixer_v2)),
  1634. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
  1635. TX_MACRO_AIF2_CAP, 0,
  1636. tx_aif2_cap_mixer_v2, ARRAY_SIZE(tx_aif2_cap_mixer_v2)),
  1637. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
  1638. TX_MACRO_AIF3_CAP, 0,
  1639. tx_aif3_cap_mixer_v2, ARRAY_SIZE(tx_aif3_cap_mixer_v2)),
  1640. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0_v2),
  1641. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1_v2),
  1642. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2_v2),
  1643. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3_v2),
  1644. };
  1645. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v3[] = {
  1646. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
  1647. TX_MACRO_AIF1_CAP, 0,
  1648. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  1649. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
  1650. TX_MACRO_AIF2_CAP, 0,
  1651. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  1652. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
  1653. TX_MACRO_AIF3_CAP, 0,
  1654. tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
  1655. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  1656. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  1657. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  1658. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  1659. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0_v2),
  1660. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1_v2),
  1661. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2_v2),
  1662. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3_v2),
  1663. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4_v3),
  1664. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5_v3),
  1665. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6_v3),
  1666. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7_v3),
  1667. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  1668. TX_MACRO_DEC4, 0,
  1669. &tx_dec4_mux, tx_macro_enable_dec,
  1670. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1671. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1672. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  1673. TX_MACRO_DEC5, 0,
  1674. &tx_dec5_mux, tx_macro_enable_dec,
  1675. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1676. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1677. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  1678. TX_MACRO_DEC6, 0,
  1679. &tx_dec6_mux, tx_macro_enable_dec,
  1680. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1681. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1682. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  1683. TX_MACRO_DEC7, 0,
  1684. &tx_dec7_mux, tx_macro_enable_dec,
  1685. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1686. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1687. SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", -1, SND_SOC_NOPM, 0, 0,
  1688. tx_macro_tx_swr_clk_event,
  1689. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1690. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", -1, SND_SOC_NOPM, 0, 0,
  1691. tx_macro_va_swr_clk_event,
  1692. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1693. };
  1694. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v4[] = {
  1695. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
  1696. TX_MACRO_AIF1_CAP, 0,
  1697. tx_aif1_cap_mixer_v2, ARRAY_SIZE(tx_aif1_cap_mixer_v2)),
  1698. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
  1699. TX_MACRO_AIF2_CAP, 0,
  1700. tx_aif2_cap_mixer_v2, ARRAY_SIZE(tx_aif2_cap_mixer_v2)),
  1701. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
  1702. TX_MACRO_AIF3_CAP, 0,
  1703. tx_aif3_cap_mixer_v2, ARRAY_SIZE(tx_aif3_cap_mixer_v2)),
  1704. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0_v4),
  1705. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1_v4),
  1706. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2_v4),
  1707. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3_v4),
  1708. TX_MACRO_DAPM_MUX("RX SWR TX MUX0", 0, rx_swr_tx_pcm_in0),
  1709. TX_MACRO_DAPM_MUX("RX SWR TX MUX1", 0, rx_swr_tx_pcm_in1),
  1710. SND_SOC_DAPM_INPUT("RX_SWR_TX_PCM_IN0"),
  1711. SND_SOC_DAPM_INPUT("RX_SWR_TX_PCM_IN1"),
  1712. };
  1713. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
  1714. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  1715. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  1716. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  1717. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  1718. SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
  1719. SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
  1720. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
  1721. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  1722. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
  1723. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  1724. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0,
  1725. tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
  1726. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  1727. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  1728. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  1729. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  1730. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  1731. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  1732. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  1733. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  1734. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
  1735. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
  1736. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
  1737. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
  1738. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
  1739. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
  1740. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
  1741. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
  1742. SND_SOC_DAPM_SUPPLY("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1743. tx_macro_enable_micbias,
  1744. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1745. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1746. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1747. SND_SOC_DAPM_POST_PMD),
  1748. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1749. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1750. SND_SOC_DAPM_POST_PMD),
  1751. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1752. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1753. SND_SOC_DAPM_POST_PMD),
  1754. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1755. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1756. SND_SOC_DAPM_POST_PMD),
  1757. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1758. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1759. SND_SOC_DAPM_POST_PMD),
  1760. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1761. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1762. SND_SOC_DAPM_POST_PMD),
  1763. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1764. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1765. SND_SOC_DAPM_POST_PMD),
  1766. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1767. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1768. SND_SOC_DAPM_POST_PMD),
  1769. SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
  1770. SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
  1771. SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
  1772. SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
  1773. SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
  1774. SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
  1775. SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
  1776. SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
  1777. SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
  1778. SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
  1779. SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
  1780. SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
  1781. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  1782. TX_MACRO_DEC0, 0,
  1783. &tx_dec0_mux, tx_macro_enable_dec,
  1784. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1785. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1786. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  1787. TX_MACRO_DEC1, 0,
  1788. &tx_dec1_mux, tx_macro_enable_dec,
  1789. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1790. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1791. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  1792. TX_MACRO_DEC2, 0,
  1793. &tx_dec2_mux, tx_macro_enable_dec,
  1794. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1795. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1796. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  1797. TX_MACRO_DEC3, 0,
  1798. &tx_dec3_mux, tx_macro_enable_dec,
  1799. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1800. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1801. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  1802. TX_MACRO_DEC4, 0,
  1803. &tx_dec4_mux, tx_macro_enable_dec,
  1804. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1805. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1806. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  1807. TX_MACRO_DEC5, 0,
  1808. &tx_dec5_mux, tx_macro_enable_dec,
  1809. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1810. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1811. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  1812. TX_MACRO_DEC6, 0,
  1813. &tx_dec6_mux, tx_macro_enable_dec,
  1814. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1815. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1816. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  1817. TX_MACRO_DEC7, 0,
  1818. &tx_dec7_mux, tx_macro_enable_dec,
  1819. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1820. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1821. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1822. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1823. SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1824. tx_macro_tx_swr_clk_event,
  1825. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1826. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1827. tx_macro_va_swr_clk_event,
  1828. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1829. };
  1830. static const struct snd_soc_dapm_route tx_audio_map_common[] = {
  1831. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  1832. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  1833. {"TX_AIF3 CAP", NULL, "TX_MCLK"},
  1834. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  1835. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  1836. {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
  1837. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1838. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1839. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1840. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1841. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1842. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1843. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1844. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1845. {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1846. {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1847. {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1848. {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1849. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  1850. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  1851. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  1852. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  1853. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  1854. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  1855. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  1856. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  1857. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  1858. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  1859. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  1860. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  1861. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  1862. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  1863. {"TX SMIC MUX0", "SWR_MIC0", "TX SWR_INPUT"},
  1864. {"TX SMIC MUX0", "SWR_MIC1", "TX SWR_INPUT"},
  1865. {"TX SMIC MUX0", "SWR_MIC2", "TX SWR_INPUT"},
  1866. {"TX SMIC MUX0", "SWR_MIC3", "TX SWR_INPUT"},
  1867. {"TX SMIC MUX0", "SWR_MIC4", "TX SWR_INPUT"},
  1868. {"TX SMIC MUX0", "SWR_MIC5", "TX SWR_INPUT"},
  1869. {"TX SMIC MUX0", "SWR_MIC6", "TX SWR_INPUT"},
  1870. {"TX SMIC MUX0", "SWR_MIC7", "TX SWR_INPUT"},
  1871. {"TX SMIC MUX0", "SWR_MIC8", "TX SWR_INPUT"},
  1872. {"TX SMIC MUX0", "SWR_MIC9", "TX SWR_INPUT"},
  1873. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  1874. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  1875. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  1876. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  1877. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  1878. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  1879. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  1880. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  1881. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  1882. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  1883. {"TX SMIC MUX1", "SWR_MIC0", "TX SWR_INPUT"},
  1884. {"TX SMIC MUX1", "SWR_MIC1", "TX SWR_INPUT"},
  1885. {"TX SMIC MUX1", "SWR_MIC2", "TX SWR_INPUT"},
  1886. {"TX SMIC MUX1", "SWR_MIC3", "TX SWR_INPUT"},
  1887. {"TX SMIC MUX1", "SWR_MIC4", "TX SWR_INPUT"},
  1888. {"TX SMIC MUX1", "SWR_MIC5", "TX SWR_INPUT"},
  1889. {"TX SMIC MUX1", "SWR_MIC6", "TX SWR_INPUT"},
  1890. {"TX SMIC MUX1", "SWR_MIC7", "TX SWR_INPUT"},
  1891. {"TX SMIC MUX1", "SWR_MIC8", "TX SWR_INPUT"},
  1892. {"TX SMIC MUX1", "SWR_MIC9", "TX SWR_INPUT"},
  1893. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  1894. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  1895. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  1896. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  1897. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  1898. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  1899. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  1900. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  1901. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  1902. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  1903. {"TX SMIC MUX2", "SWR_MIC0", "TX SWR_INPUT"},
  1904. {"TX SMIC MUX2", "SWR_MIC1", "TX SWR_INPUT"},
  1905. {"TX SMIC MUX2", "SWR_MIC2", "TX SWR_INPUT"},
  1906. {"TX SMIC MUX2", "SWR_MIC3", "TX SWR_INPUT"},
  1907. {"TX SMIC MUX2", "SWR_MIC4", "TX SWR_INPUT"},
  1908. {"TX SMIC MUX2", "SWR_MIC5", "TX SWR_INPUT"},
  1909. {"TX SMIC MUX2", "SWR_MIC6", "TX SWR_INPUT"},
  1910. {"TX SMIC MUX2", "SWR_MIC7", "TX SWR_INPUT"},
  1911. {"TX SMIC MUX2", "SWR_MIC8", "TX SWR_INPUT"},
  1912. {"TX SMIC MUX2", "SWR_MIC9", "TX SWR_INPUT"},
  1913. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  1914. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  1915. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  1916. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  1917. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  1918. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  1919. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  1920. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  1921. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  1922. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  1923. {"TX SMIC MUX3", "SWR_MIC0", "TX SWR_INPUT"},
  1924. {"TX SMIC MUX3", "SWR_MIC1", "TX SWR_INPUT"},
  1925. {"TX SMIC MUX3", "SWR_MIC2", "TX SWR_INPUT"},
  1926. {"TX SMIC MUX3", "SWR_MIC3", "TX SWR_INPUT"},
  1927. {"TX SMIC MUX3", "SWR_MIC4", "TX SWR_INPUT"},
  1928. {"TX SMIC MUX3", "SWR_MIC5", "TX SWR_INPUT"},
  1929. {"TX SMIC MUX3", "SWR_MIC6", "TX SWR_INPUT"},
  1930. {"TX SMIC MUX3", "SWR_MIC7", "TX SWR_INPUT"},
  1931. {"TX SMIC MUX3", "SWR_MIC8", "TX SWR_INPUT"},
  1932. {"TX SMIC MUX3", "SWR_MIC9", "TX SWR_INPUT"},
  1933. };
  1934. static const struct snd_soc_dapm_route tx_audio_map_v2[] = {
  1935. {"TX SMIC MUX0", "SWR_MIC10", "TX SWR_INPUT"},
  1936. {"TX SMIC MUX0", "SWR_MIC11", "TX SWR_INPUT"},
  1937. {"TX SMIC MUX1", "SWR_MIC10", "TX SWR_INPUT"},
  1938. {"TX SMIC MUX1", "SWR_MIC11", "TX SWR_INPUT"},
  1939. {"TX SMIC MUX2", "SWR_MIC10", "TX SWR_INPUT"},
  1940. {"TX SMIC MUX2", "SWR_MIC11", "TX SWR_INPUT"},
  1941. {"TX SMIC MUX3", "SWR_MIC10", "TX SWR_INPUT"},
  1942. {"TX SMIC MUX3", "SWR_MIC11", "TX SWR_INPUT"},
  1943. };
  1944. static const struct snd_soc_dapm_route tx_audio_map_v3[] = {
  1945. {"TX SMIC MUX0", "SWR_MIC10", "TX SWR_INPUT"},
  1946. {"TX SMIC MUX0", "SWR_MIC11", "TX SWR_INPUT"},
  1947. {"TX SMIC MUX1", "SWR_MIC10", "TX SWR_INPUT"},
  1948. {"TX SMIC MUX1", "SWR_MIC11", "TX SWR_INPUT"},
  1949. {"TX SMIC MUX2", "SWR_MIC10", "TX SWR_INPUT"},
  1950. {"TX SMIC MUX2", "SWR_MIC11", "TX SWR_INPUT"},
  1951. {"TX SMIC MUX3", "SWR_MIC10", "TX SWR_INPUT"},
  1952. {"TX SMIC MUX3", "SWR_MIC11", "TX SWR_INPUT"},
  1953. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1954. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1955. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1956. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1957. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1958. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1959. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1960. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1961. {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1962. {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1963. {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1964. {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1965. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  1966. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  1967. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  1968. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  1969. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  1970. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  1971. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  1972. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  1973. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  1974. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  1975. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  1976. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  1977. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  1978. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  1979. {"TX SMIC MUX4", "SWR_MIC0", "TX SWR_INPUT"},
  1980. {"TX SMIC MUX4", "SWR_MIC1", "TX SWR_INPUT"},
  1981. {"TX SMIC MUX4", "SWR_MIC2", "TX SWR_INPUT"},
  1982. {"TX SMIC MUX4", "SWR_MIC3", "TX SWR_INPUT"},
  1983. {"TX SMIC MUX4", "SWR_MIC4", "TX SWR_INPUT"},
  1984. {"TX SMIC MUX4", "SWR_MIC5", "TX SWR_INPUT"},
  1985. {"TX SMIC MUX4", "SWR_MIC6", "TX SWR_INPUT"},
  1986. {"TX SMIC MUX4", "SWR_MIC7", "TX SWR_INPUT"},
  1987. {"TX SMIC MUX4", "SWR_MIC8", "TX SWR_INPUT"},
  1988. {"TX SMIC MUX4", "SWR_MIC9", "TX SWR_INPUT"},
  1989. {"TX SMIC MUX4", "SWR_MIC10", "TX SWR_INPUT"},
  1990. {"TX SMIC MUX4", "SWR_MIC11", "TX SWR_INPUT"},
  1991. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  1992. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  1993. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  1994. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  1995. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  1996. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  1997. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  1998. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  1999. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  2000. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  2001. {"TX SMIC MUX5", "SWR_MIC0", "TX SWR_INPUT"},
  2002. {"TX SMIC MUX5", "SWR_MIC1", "TX SWR_INPUT"},
  2003. {"TX SMIC MUX5", "SWR_MIC2", "TX SWR_INPUT"},
  2004. {"TX SMIC MUX5", "SWR_MIC3", "TX SWR_INPUT"},
  2005. {"TX SMIC MUX5", "SWR_MIC4", "TX SWR_INPUT"},
  2006. {"TX SMIC MUX5", "SWR_MIC5", "TX SWR_INPUT"},
  2007. {"TX SMIC MUX5", "SWR_MIC6", "TX SWR_INPUT"},
  2008. {"TX SMIC MUX5", "SWR_MIC7", "TX SWR_INPUT"},
  2009. {"TX SMIC MUX5", "SWR_MIC8", "TX SWR_INPUT"},
  2010. {"TX SMIC MUX5", "SWR_MIC9", "TX SWR_INPUT"},
  2011. {"TX SMIC MUX5", "SWR_MIC10", "TX SWR_INPUT"},
  2012. {"TX SMIC MUX5", "SWR_MIC11", "TX SWR_INPUT"},
  2013. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  2014. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  2015. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  2016. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  2017. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  2018. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  2019. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  2020. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  2021. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  2022. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  2023. {"TX SMIC MUX6", "SWR_MIC0", "TX SWR_INPUT"},
  2024. {"TX SMIC MUX6", "SWR_MIC1", "TX SWR_INPUT"},
  2025. {"TX SMIC MUX6", "SWR_MIC2", "TX SWR_INPUT"},
  2026. {"TX SMIC MUX6", "SWR_MIC3", "TX SWR_INPUT"},
  2027. {"TX SMIC MUX6", "SWR_MIC4", "TX SWR_INPUT"},
  2028. {"TX SMIC MUX6", "SWR_MIC5", "TX SWR_INPUT"},
  2029. {"TX SMIC MUX6", "SWR_MIC6", "TX SWR_INPUT"},
  2030. {"TX SMIC MUX6", "SWR_MIC7", "TX SWR_INPUT"},
  2031. {"TX SMIC MUX6", "SWR_MIC8", "TX SWR_INPUT"},
  2032. {"TX SMIC MUX6", "SWR_MIC9", "TX SWR_INPUT"},
  2033. {"TX SMIC MUX6", "SWR_MIC10", "TX SWR_INPUT"},
  2034. {"TX SMIC MUX6", "SWR_MIC11", "TX SWR_INPUT"},
  2035. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  2036. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  2037. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  2038. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  2039. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  2040. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  2041. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  2042. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  2043. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  2044. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  2045. {"TX SMIC MUX7", "SWR_MIC0", "TX SWR_INPUT"},
  2046. {"TX SMIC MUX7", "SWR_MIC1", "TX SWR_INPUT"},
  2047. {"TX SMIC MUX7", "SWR_MIC2", "TX SWR_INPUT"},
  2048. {"TX SMIC MUX7", "SWR_MIC3", "TX SWR_INPUT"},
  2049. {"TX SMIC MUX7", "SWR_MIC4", "TX SWR_INPUT"},
  2050. {"TX SMIC MUX7", "SWR_MIC5", "TX SWR_INPUT"},
  2051. {"TX SMIC MUX7", "SWR_MIC6", "TX SWR_INPUT"},
  2052. {"TX SMIC MUX7", "SWR_MIC7", "TX SWR_INPUT"},
  2053. {"TX SMIC MUX7", "SWR_MIC8", "TX SWR_INPUT"},
  2054. {"TX SMIC MUX7", "SWR_MIC9", "TX SWR_INPUT"},
  2055. {"TX SMIC MUX7", "SWR_MIC10", "TX SWR_INPUT"},
  2056. {"TX SMIC MUX7", "SWR_MIC11", "TX SWR_INPUT"},
  2057. {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
  2058. {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
  2059. {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
  2060. {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
  2061. {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
  2062. {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
  2063. {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
  2064. {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
  2065. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2066. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2067. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2068. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2069. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2070. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2071. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2072. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2073. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2074. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2075. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2076. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  2077. };
  2078. static const struct snd_soc_dapm_route tx_audio_map_v4[] = {
  2079. {"TX SMIC MUX0", "SWR_MIC10", "RX SWR TX MUX0"},
  2080. {"RX SWR TX MUX0", "SWR_MIC", "TX SWR_INPUT"},
  2081. {"RX SWR TX MUX0", "RX_SWR_TX_PCM_IN0", "RX_SWR_TX_PCM_IN0"},
  2082. {"TX SMIC MUX0", "SWR_MIC11", "RX SWR TX MUX1"},
  2083. {"RX SWR TX MUX1", "SWR_MIC", "TX SWR_INPUT"},
  2084. {"RX SWR TX MUX1", "RX_SWR_TX_PCM_IN1", "RX_SWR_TX_PCM_IN1"},
  2085. {"TX SMIC MUX1", "SWR_MIC10", "RX SWR TX MUX0"},
  2086. {"RX SWR TX MUX0", "SWR_MIC", "TX SWR_INPUT"},
  2087. {"RX SWR TX MUX0", "RX_SWR_TX_PCM_IN0", "RX_SWR_TX_PCM_IN0"},
  2088. {"TX SMIC MUX1", "SWR_MIC11", "RX SWR TX MUX1"},
  2089. {"RX SWR TX MUX1", "SWR_MIC", "TX SWR_INPUT"},
  2090. {"RX SWR TX MUX1", "RX_SWR_TX_PCM_IN1", "RX_SWR_TX_PCM_IN1"},
  2091. {"TX SMIC MUX2", "SWR_MIC10", "RX SWR TX MUX0"},
  2092. {"RX SWR TX MUX0", "SWR_MIC", "TX SWR_INPUT"},
  2093. {"RX SWR TX MUX0", "RX_SWR_TX_PCM_IN0", "RX_SWR_TX_PCM_IN0"},
  2094. {"TX SMIC MUX2", "SWR_MIC11", "RX SWR TX MUX1"},
  2095. {"RX SWR TX MUX1", "SWR_MIC", "TX SWR_INPUT"},
  2096. {"RX SWR TX MUX1", "RX_SWR_TX_PCM_IN1", "RX_SWR_TX_PCM_IN1"},
  2097. {"TX SMIC MUX3", "SWR_MIC10", "RX SWR TX MUX0"},
  2098. {"RX SWR TX MUX0", "SWR_MIC", "TX SWR_INPUT"},
  2099. {"RX SWR TX MUX0", "RX_SWR_TX_PCM_IN0", "RX_SWR_TX_PCM_IN0"},
  2100. {"TX SMIC MUX3", "SWR_MIC11", "RX SWR TX MUX1"},
  2101. {"RX SWR TX MUX1", "SWR_MIC", "TX SWR_INPUT"},
  2102. {"RX SWR TX MUX1", "RX_SWR_TX_PCM_IN1", "RX_SWR_TX_PCM_IN1"},
  2103. {"RX SWR TX MUX0", NULL, "TX_MCLK"},
  2104. {"RX SWR TX MUX1", NULL, "TX_MCLK"},
  2105. };
  2106. static const struct snd_soc_dapm_route tx_audio_map[] = {
  2107. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  2108. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  2109. {"TX_AIF3 CAP", NULL, "TX_MCLK"},
  2110. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  2111. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  2112. {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
  2113. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  2114. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  2115. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  2116. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  2117. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  2118. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  2119. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  2120. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  2121. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  2122. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  2123. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  2124. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  2125. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  2126. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  2127. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  2128. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  2129. {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  2130. {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  2131. {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  2132. {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  2133. {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  2134. {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  2135. {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  2136. {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  2137. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  2138. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  2139. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  2140. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  2141. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  2142. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  2143. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  2144. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  2145. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  2146. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  2147. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  2148. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  2149. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  2150. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  2151. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  2152. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  2153. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  2154. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  2155. {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
  2156. {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
  2157. {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
  2158. {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
  2159. {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
  2160. {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
  2161. {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
  2162. {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
  2163. {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
  2164. {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
  2165. {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
  2166. {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
  2167. {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
  2168. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  2169. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  2170. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  2171. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  2172. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  2173. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  2174. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  2175. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  2176. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  2177. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  2178. {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
  2179. {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
  2180. {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
  2181. {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
  2182. {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
  2183. {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
  2184. {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
  2185. {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
  2186. {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
  2187. {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
  2188. {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
  2189. {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
  2190. {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
  2191. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  2192. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  2193. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  2194. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  2195. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  2196. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  2197. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  2198. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  2199. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  2200. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  2201. {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
  2202. {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
  2203. {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
  2204. {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
  2205. {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
  2206. {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
  2207. {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
  2208. {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
  2209. {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
  2210. {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
  2211. {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
  2212. {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
  2213. {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
  2214. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  2215. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  2216. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  2217. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  2218. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  2219. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  2220. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  2221. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  2222. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  2223. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  2224. {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
  2225. {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
  2226. {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
  2227. {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
  2228. {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
  2229. {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
  2230. {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
  2231. {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
  2232. {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
  2233. {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
  2234. {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
  2235. {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
  2236. {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
  2237. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  2238. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  2239. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  2240. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  2241. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  2242. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  2243. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  2244. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  2245. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  2246. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  2247. {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
  2248. {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
  2249. {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
  2250. {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
  2251. {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
  2252. {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
  2253. {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
  2254. {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
  2255. {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
  2256. {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
  2257. {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
  2258. {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
  2259. {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
  2260. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  2261. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  2262. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  2263. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  2264. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  2265. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  2266. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  2267. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  2268. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  2269. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  2270. {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
  2271. {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
  2272. {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
  2273. {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
  2274. {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
  2275. {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
  2276. {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
  2277. {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
  2278. {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
  2279. {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
  2280. {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
  2281. {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
  2282. {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
  2283. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  2284. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  2285. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  2286. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  2287. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  2288. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  2289. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  2290. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  2291. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  2292. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  2293. {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
  2294. {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
  2295. {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
  2296. {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
  2297. {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
  2298. {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
  2299. {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
  2300. {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
  2301. {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
  2302. {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
  2303. {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
  2304. {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
  2305. {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
  2306. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  2307. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  2308. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  2309. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  2310. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  2311. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  2312. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  2313. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  2314. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  2315. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  2316. {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
  2317. {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
  2318. {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
  2319. {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
  2320. {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
  2321. {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
  2322. {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
  2323. {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
  2324. {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
  2325. {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
  2326. {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
  2327. {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
  2328. {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
  2329. };
  2330. static const struct snd_kcontrol_new tx_macro_snd_controls_common[] = {
  2331. SOC_SINGLE_S8_TLV("TX_DEC0 Volume",
  2332. BOLERO_CDC_TX0_TX_VOL_CTL,
  2333. -84, 40, digital_gain),
  2334. SOC_SINGLE_S8_TLV("TX_DEC1 Volume",
  2335. BOLERO_CDC_TX1_TX_VOL_CTL,
  2336. -84, 40, digital_gain),
  2337. SOC_SINGLE_S8_TLV("TX_DEC2 Volume",
  2338. BOLERO_CDC_TX2_TX_VOL_CTL,
  2339. -84, 40, digital_gain),
  2340. SOC_SINGLE_S8_TLV("TX_DEC3 Volume",
  2341. BOLERO_CDC_TX3_TX_VOL_CTL,
  2342. -84, 40, digital_gain),
  2343. SOC_SINGLE_EXT("TX LPI Enable", 0, 0, 1, 0,
  2344. tx_macro_lpi_get, tx_macro_lpi_put),
  2345. SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum,
  2346. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2347. SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum,
  2348. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2349. SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum,
  2350. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2351. SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum,
  2352. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2353. SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
  2354. tx_macro_get_bcs, tx_macro_set_bcs),
  2355. SOC_ENUM_EXT("BCS Channel", bcs_ch_enum,
  2356. tx_macro_bcs_ch_get, tx_macro_bcs_ch_put),
  2357. SOC_ENUM_EXT("BCS CH_SEL", bcs_ch_sel_mux_enum,
  2358. tx_macro_get_bcs_ch_sel, tx_macro_put_bcs_ch_sel),
  2359. };
  2360. static const struct snd_kcontrol_new tx_macro_snd_controls_v3[] = {
  2361. SOC_SINGLE_S8_TLV("TX_DEC4 Volume",
  2362. BOLERO_CDC_TX4_TX_VOL_CTL,
  2363. -84, 40, digital_gain),
  2364. SOC_SINGLE_S8_TLV("TX_DEC5 Volume",
  2365. BOLERO_CDC_TX5_TX_VOL_CTL,
  2366. -84, 40, digital_gain),
  2367. SOC_SINGLE_S8_TLV("TX_DEC6 Volume",
  2368. BOLERO_CDC_TX6_TX_VOL_CTL,
  2369. -84, 40, digital_gain),
  2370. SOC_SINGLE_S8_TLV("TX_DEC7 Volume",
  2371. BOLERO_CDC_TX7_TX_VOL_CTL,
  2372. -84, 40, digital_gain),
  2373. SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum,
  2374. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2375. SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum,
  2376. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2377. SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum,
  2378. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2379. SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum,
  2380. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2381. };
  2382. static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
  2383. SOC_SINGLE_S8_TLV("TX_DEC0 Volume",
  2384. BOLERO_CDC_TX0_TX_VOL_CTL,
  2385. -84, 40, digital_gain),
  2386. SOC_SINGLE_S8_TLV("TX_DEC1 Volume",
  2387. BOLERO_CDC_TX1_TX_VOL_CTL,
  2388. -84, 40, digital_gain),
  2389. SOC_SINGLE_S8_TLV("TX_DEC2 Volume",
  2390. BOLERO_CDC_TX2_TX_VOL_CTL,
  2391. -84, 40, digital_gain),
  2392. SOC_SINGLE_S8_TLV("TX_DEC3 Volume",
  2393. BOLERO_CDC_TX3_TX_VOL_CTL,
  2394. -84, 40, digital_gain),
  2395. SOC_SINGLE_S8_TLV("TX_DEC4 Volume",
  2396. BOLERO_CDC_TX4_TX_VOL_CTL,
  2397. -84, 40, digital_gain),
  2398. SOC_SINGLE_S8_TLV("TX_DEC5 Volume",
  2399. BOLERO_CDC_TX5_TX_VOL_CTL,
  2400. -84, 40, digital_gain),
  2401. SOC_SINGLE_S8_TLV("TX_DEC6 Volume",
  2402. BOLERO_CDC_TX6_TX_VOL_CTL,
  2403. -84, 40, digital_gain),
  2404. SOC_SINGLE_S8_TLV("TX_DEC7 Volume",
  2405. BOLERO_CDC_TX7_TX_VOL_CTL,
  2406. -84, 40, digital_gain),
  2407. SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum,
  2408. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2409. SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum,
  2410. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2411. SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum,
  2412. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2413. SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum,
  2414. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2415. SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum,
  2416. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2417. SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum,
  2418. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2419. SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum,
  2420. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2421. SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum,
  2422. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2423. SOC_ENUM("TX0 HPF cut off", cf_dec0_enum),
  2424. SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
  2425. SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
  2426. SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
  2427. SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
  2428. SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
  2429. SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
  2430. SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
  2431. SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
  2432. tx_macro_get_bcs, tx_macro_set_bcs),
  2433. };
  2434. static int tx_macro_register_event_listener(struct snd_soc_component *component,
  2435. bool enable)
  2436. {
  2437. struct device *tx_dev = NULL;
  2438. struct tx_macro_priv *tx_priv = NULL;
  2439. int ret = 0;
  2440. if (!component)
  2441. return -EINVAL;
  2442. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  2443. if (!tx_dev) {
  2444. dev_err(component->dev,
  2445. "%s: null device for macro!\n", __func__);
  2446. return -EINVAL;
  2447. }
  2448. tx_priv = dev_get_drvdata(tx_dev);
  2449. if (!tx_priv) {
  2450. dev_err(component->dev,
  2451. "%s: priv is null for macro!\n", __func__);
  2452. return -EINVAL;
  2453. }
  2454. if (tx_priv->swr_ctrl_data &&
  2455. (!tx_priv->tx_swr_clk_cnt || !tx_priv->va_swr_clk_cnt)) {
  2456. if (enable) {
  2457. if (!tx_priv->disable_afe_wakeup_event_listener)
  2458. ret = swrm_wcd_notify(
  2459. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2460. SWR_REGISTER_WAKEUP, NULL);
  2461. } else {
  2462. if (!tx_priv->disable_afe_wakeup_event_listener)
  2463. ret = swrm_wcd_notify(
  2464. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2465. SWR_DEREGISTER_WAKEUP, NULL);
  2466. }
  2467. }
  2468. return ret;
  2469. }
  2470. static int tx_macro_tx_va_mclk_enable(struct tx_macro_priv *tx_priv,
  2471. struct regmap *regmap, int clk_type,
  2472. bool enable)
  2473. {
  2474. int ret = 0, clk_tx_ret = 0;
  2475. dev_dbg(tx_priv->dev,
  2476. "%s: clock type %s, enable: %s tx_mclk_users: %d\n",
  2477. __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
  2478. (enable ? "enable" : "disable"), tx_priv->tx_mclk_users);
  2479. if (enable) {
  2480. if (tx_priv->swr_clk_users == 0) {
  2481. ret = msm_cdc_pinctrl_select_active_state(
  2482. tx_priv->tx_swr_gpio_p);
  2483. if (ret < 0) {
  2484. dev_err_ratelimited(tx_priv->dev,
  2485. "%s: tx swr pinctrl enable failed\n",
  2486. __func__);
  2487. goto exit;
  2488. }
  2489. msm_cdc_pinctrl_set_wakeup_capable(
  2490. tx_priv->tx_swr_gpio_p, false);
  2491. }
  2492. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2493. TX_CORE_CLK,
  2494. TX_CORE_CLK,
  2495. true);
  2496. if (clk_type == TX_MCLK) {
  2497. ret = tx_macro_mclk_enable(tx_priv, 1);
  2498. if (ret < 0) {
  2499. if (tx_priv->swr_clk_users == 0)
  2500. msm_cdc_pinctrl_select_sleep_state(
  2501. tx_priv->tx_swr_gpio_p);
  2502. dev_err_ratelimited(tx_priv->dev,
  2503. "%s: request clock enable failed\n",
  2504. __func__);
  2505. goto done;
  2506. }
  2507. }
  2508. if (clk_type == VA_MCLK) {
  2509. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2510. TX_CORE_CLK,
  2511. VA_CORE_CLK,
  2512. true);
  2513. if (ret < 0) {
  2514. if (tx_priv->swr_clk_users == 0)
  2515. msm_cdc_pinctrl_select_sleep_state(
  2516. tx_priv->tx_swr_gpio_p);
  2517. dev_err_ratelimited(tx_priv->dev,
  2518. "%s: swr request clk failed\n",
  2519. __func__);
  2520. goto done;
  2521. }
  2522. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  2523. true);
  2524. mutex_lock(&tx_priv->mclk_lock);
  2525. if (tx_priv->tx_mclk_users == 0) {
  2526. regmap_update_bits(regmap,
  2527. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK,
  2528. 0x01, 0x01);
  2529. regmap_update_bits(regmap,
  2530. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  2531. 0x01, 0x01);
  2532. regmap_update_bits(regmap,
  2533. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  2534. 0x01, 0x01);
  2535. }
  2536. tx_priv->tx_mclk_users++;
  2537. mutex_unlock(&tx_priv->mclk_lock);
  2538. }
  2539. if (tx_priv->swr_clk_users == 0) {
  2540. dev_dbg(tx_priv->dev, "%s: reset_swr: %d\n",
  2541. __func__, tx_priv->reset_swr);
  2542. if (tx_priv->reset_swr)
  2543. regmap_update_bits(regmap,
  2544. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2545. 0x02, 0x02);
  2546. regmap_update_bits(regmap,
  2547. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2548. 0x01, 0x01);
  2549. if (tx_priv->reset_swr)
  2550. regmap_update_bits(regmap,
  2551. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2552. 0x02, 0x00);
  2553. tx_priv->reset_swr = false;
  2554. }
  2555. if (!clk_tx_ret)
  2556. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2557. TX_CORE_CLK,
  2558. TX_CORE_CLK,
  2559. false);
  2560. tx_priv->swr_clk_users++;
  2561. } else {
  2562. if (tx_priv->swr_clk_users <= 0) {
  2563. dev_err_ratelimited(tx_priv->dev,
  2564. "tx swrm clock users already 0\n");
  2565. tx_priv->swr_clk_users = 0;
  2566. return 0;
  2567. }
  2568. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2569. TX_CORE_CLK,
  2570. TX_CORE_CLK,
  2571. true);
  2572. tx_priv->swr_clk_users--;
  2573. if (tx_priv->swr_clk_users == 0)
  2574. regmap_update_bits(regmap,
  2575. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2576. 0x01, 0x00);
  2577. if (clk_type == TX_MCLK)
  2578. tx_macro_mclk_enable(tx_priv, 0);
  2579. if (clk_type == VA_MCLK) {
  2580. mutex_lock(&tx_priv->mclk_lock);
  2581. if (tx_priv->tx_mclk_users <= 0) {
  2582. dev_err(tx_priv->dev, "%s: clock already disabled\n",
  2583. __func__);
  2584. tx_priv->tx_mclk_users = 0;
  2585. mutex_unlock(&tx_priv->mclk_lock);
  2586. goto tx_clk;
  2587. }
  2588. tx_priv->tx_mclk_users--;
  2589. if (tx_priv->tx_mclk_users == 0) {
  2590. regmap_update_bits(regmap,
  2591. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  2592. 0x01, 0x00);
  2593. regmap_update_bits(regmap,
  2594. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  2595. 0x01, 0x00);
  2596. }
  2597. mutex_unlock(&tx_priv->mclk_lock);
  2598. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  2599. false);
  2600. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2601. TX_CORE_CLK,
  2602. VA_CORE_CLK,
  2603. false);
  2604. if (ret < 0) {
  2605. dev_err_ratelimited(tx_priv->dev,
  2606. "%s: swr request clk failed\n",
  2607. __func__);
  2608. goto done;
  2609. }
  2610. }
  2611. tx_clk:
  2612. if (!clk_tx_ret)
  2613. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2614. TX_CORE_CLK,
  2615. TX_CORE_CLK,
  2616. false);
  2617. if (tx_priv->swr_clk_users == 0) {
  2618. msm_cdc_pinctrl_set_wakeup_capable(
  2619. tx_priv->tx_swr_gpio_p, true);
  2620. ret = msm_cdc_pinctrl_select_sleep_state(
  2621. tx_priv->tx_swr_gpio_p);
  2622. if (ret < 0) {
  2623. dev_err_ratelimited(tx_priv->dev,
  2624. "%s: tx swr pinctrl disable failed\n",
  2625. __func__);
  2626. goto exit;
  2627. }
  2628. }
  2629. }
  2630. return 0;
  2631. done:
  2632. if (!clk_tx_ret)
  2633. bolero_clk_rsc_request_clock(tx_priv->dev,
  2634. TX_CORE_CLK,
  2635. TX_CORE_CLK,
  2636. false);
  2637. exit:
  2638. return ret;
  2639. }
  2640. static int tx_macro_clk_div_get(struct snd_soc_component *component)
  2641. {
  2642. struct device *tx_dev = NULL;
  2643. struct tx_macro_priv *tx_priv = NULL;
  2644. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  2645. return -EINVAL;
  2646. return tx_priv->dmic_clk_div;
  2647. }
  2648. static int tx_macro_clk_switch(struct snd_soc_component *component, int clk_src)
  2649. {
  2650. struct device *tx_dev = NULL;
  2651. struct tx_macro_priv *tx_priv = NULL;
  2652. int ret = 0;
  2653. if (!component)
  2654. return -EINVAL;
  2655. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  2656. if (!tx_dev) {
  2657. dev_err(component->dev,
  2658. "%s: null device for macro!\n", __func__);
  2659. return -EINVAL;
  2660. }
  2661. tx_priv = dev_get_drvdata(tx_dev);
  2662. if (!tx_priv) {
  2663. dev_err(component->dev,
  2664. "%s: priv is null for macro!\n", __func__);
  2665. return -EINVAL;
  2666. }
  2667. dev_dbg(component->dev,
  2668. "%s: va_swr_clk_cnt %d, tx_swr_clk_cnt %d, tx_clk_status %d\n",
  2669. __func__, tx_priv->va_swr_clk_cnt,
  2670. tx_priv->tx_swr_clk_cnt, tx_priv->tx_clk_status);
  2671. if (tx_priv->current_clk_id == clk_src) {
  2672. dev_dbg(component->dev,
  2673. "%s: requested clk %d is same as current\n",
  2674. __func__, clk_src);
  2675. return 0;
  2676. } else if (tx_priv->va_swr_clk_cnt != 0 && tx_priv->tx_clk_status) {
  2677. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2678. TX_CORE_CLK,
  2679. clk_src,
  2680. true);
  2681. if (ret) {
  2682. dev_dbg(component->dev,
  2683. "%s: request clock %d enable failed\n",
  2684. __func__, clk_src);
  2685. goto ret;
  2686. }
  2687. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2688. TX_CORE_CLK,
  2689. tx_priv->current_clk_id,
  2690. false);
  2691. if (ret) {
  2692. dev_dbg(component->dev,
  2693. "%s: request clock disable failed\n",
  2694. __func__);
  2695. bolero_clk_rsc_request_clock(tx_priv->dev,
  2696. TX_CORE_CLK,
  2697. clk_src,
  2698. false);
  2699. goto ret;
  2700. }
  2701. tx_priv->current_clk_id = clk_src;
  2702. } else {
  2703. ret = -EBUSY;
  2704. }
  2705. ret:
  2706. return ret;
  2707. }
  2708. static int tx_macro_core_vote(void *handle, bool enable)
  2709. {
  2710. int rc = 0;
  2711. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  2712. if (tx_priv == NULL) {
  2713. pr_err("%s: tx priv data is NULL\n", __func__);
  2714. return -EINVAL;
  2715. }
  2716. if (enable) {
  2717. pm_runtime_get_sync(tx_priv->dev);
  2718. if (bolero_check_core_votes(tx_priv->dev))
  2719. rc = 0;
  2720. else
  2721. rc = -ENOTSYNC;
  2722. } else {
  2723. pm_runtime_put_autosuspend(tx_priv->dev);
  2724. pm_runtime_mark_last_busy(tx_priv->dev);
  2725. }
  2726. return rc;
  2727. }
  2728. static int tx_macro_swrm_clock(void *handle, bool enable)
  2729. {
  2730. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  2731. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  2732. int ret = 0;
  2733. if (regmap == NULL) {
  2734. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  2735. return -EINVAL;
  2736. }
  2737. mutex_lock(&tx_priv->swr_clk_lock);
  2738. dev_dbg(tx_priv->dev,
  2739. "%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n",
  2740. __func__, (enable ? "enable" : "disable"),
  2741. tx_priv->tx_swr_clk_cnt, tx_priv->va_swr_clk_cnt);
  2742. if (enable) {
  2743. pm_runtime_get_sync(tx_priv->dev);
  2744. if (tx_priv->va_swr_clk_cnt && !tx_priv->tx_swr_clk_cnt) {
  2745. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2746. VA_MCLK, enable);
  2747. if (ret) {
  2748. pm_runtime_mark_last_busy(tx_priv->dev);
  2749. pm_runtime_put_autosuspend(tx_priv->dev);
  2750. goto done;
  2751. }
  2752. tx_priv->va_clk_status++;
  2753. } else {
  2754. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2755. TX_MCLK, enable);
  2756. if (ret) {
  2757. pm_runtime_mark_last_busy(tx_priv->dev);
  2758. pm_runtime_put_autosuspend(tx_priv->dev);
  2759. goto done;
  2760. }
  2761. tx_priv->tx_clk_status++;
  2762. }
  2763. pm_runtime_mark_last_busy(tx_priv->dev);
  2764. pm_runtime_put_autosuspend(tx_priv->dev);
  2765. } else {
  2766. if (tx_priv->va_clk_status && !tx_priv->tx_clk_status) {
  2767. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2768. VA_MCLK, enable);
  2769. if (ret)
  2770. goto done;
  2771. --tx_priv->va_clk_status;
  2772. } else if (!tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  2773. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2774. TX_MCLK, enable);
  2775. if (ret)
  2776. goto done;
  2777. --tx_priv->tx_clk_status;
  2778. } else if (tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  2779. if (!tx_priv->va_swr_clk_cnt && tx_priv->tx_swr_clk_cnt) {
  2780. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2781. VA_MCLK, enable);
  2782. if (ret)
  2783. goto done;
  2784. --tx_priv->va_clk_status;
  2785. } else {
  2786. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2787. TX_MCLK, enable);
  2788. if (ret)
  2789. goto done;
  2790. --tx_priv->tx_clk_status;
  2791. }
  2792. } else {
  2793. dev_dbg(tx_priv->dev,
  2794. "%s: Both clocks are disabled\n", __func__);
  2795. }
  2796. }
  2797. dev_dbg(tx_priv->dev,
  2798. "%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n",
  2799. __func__, tx_priv->swr_clk_users, tx_priv->tx_clk_status,
  2800. tx_priv->va_clk_status);
  2801. done:
  2802. mutex_unlock(&tx_priv->swr_clk_lock);
  2803. return ret;
  2804. }
  2805. static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  2806. struct tx_macro_priv *tx_priv)
  2807. {
  2808. u32 div_factor = TX_MACRO_CLK_DIV_2;
  2809. u32 mclk_rate = TX_MACRO_MCLK_FREQ;
  2810. if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  2811. mclk_rate % dmic_sample_rate != 0)
  2812. goto undefined_rate;
  2813. div_factor = mclk_rate / dmic_sample_rate;
  2814. switch (div_factor) {
  2815. case 2:
  2816. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  2817. break;
  2818. case 3:
  2819. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
  2820. break;
  2821. case 4:
  2822. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
  2823. break;
  2824. case 6:
  2825. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
  2826. break;
  2827. case 8:
  2828. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
  2829. break;
  2830. case 16:
  2831. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
  2832. break;
  2833. default:
  2834. /* Any other DIV factor is invalid */
  2835. goto undefined_rate;
  2836. }
  2837. /* Valid dmic DIV factors */
  2838. dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  2839. __func__, div_factor, mclk_rate);
  2840. return dmic_sample_rate;
  2841. undefined_rate:
  2842. dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  2843. __func__, dmic_sample_rate, mclk_rate);
  2844. dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  2845. return dmic_sample_rate;
  2846. }
  2847. static const struct tx_macro_reg_mask_val tx_macro_reg_init[] = {
  2848. {BOLERO_CDC_TX0_TX_PATH_SEC7, 0x3F, 0x0A},
  2849. };
  2850. static int tx_macro_init(struct snd_soc_component *component)
  2851. {
  2852. struct snd_soc_dapm_context *dapm =
  2853. snd_soc_component_get_dapm(component);
  2854. int ret = 0, i = 0;
  2855. struct device *tx_dev = NULL;
  2856. struct tx_macro_priv *tx_priv = NULL;
  2857. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  2858. if (!tx_dev) {
  2859. dev_err(component->dev,
  2860. "%s: null device for macro!\n", __func__);
  2861. return -EINVAL;
  2862. }
  2863. tx_priv = dev_get_drvdata(tx_dev);
  2864. if (!tx_priv) {
  2865. dev_err(component->dev,
  2866. "%s: priv is null for macro!\n", __func__);
  2867. return -EINVAL;
  2868. }
  2869. tx_priv->lpi_enable = false;
  2870. tx_priv->register_event_listener = false;
  2871. tx_priv->version = bolero_get_version(tx_dev);
  2872. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2873. ret = snd_soc_dapm_new_controls(dapm,
  2874. tx_macro_dapm_widgets_common,
  2875. ARRAY_SIZE(tx_macro_dapm_widgets_common));
  2876. if (ret < 0) {
  2877. dev_err(tx_dev, "%s: Failed to add controls\n",
  2878. __func__);
  2879. return ret;
  2880. }
  2881. if (tx_priv->version == BOLERO_VERSION_2_1)
  2882. ret = snd_soc_dapm_new_controls(dapm,
  2883. tx_macro_dapm_widgets_v2,
  2884. ARRAY_SIZE(tx_macro_dapm_widgets_v2));
  2885. else if (tx_priv->version == BOLERO_VERSION_2_0)
  2886. ret = snd_soc_dapm_new_controls(dapm,
  2887. tx_macro_dapm_widgets_v3,
  2888. ARRAY_SIZE(tx_macro_dapm_widgets_v3));
  2889. else if (tx_priv->version == BOLERO_VERSION_2_2)
  2890. ret = snd_soc_dapm_new_controls(dapm,
  2891. tx_macro_dapm_widgets_v4,
  2892. ARRAY_SIZE(tx_macro_dapm_widgets_v4));
  2893. if (ret < 0) {
  2894. dev_err(tx_dev, "%s: Failed to add controls\n",
  2895. __func__);
  2896. return ret;
  2897. }
  2898. } else {
  2899. ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
  2900. ARRAY_SIZE(tx_macro_dapm_widgets));
  2901. if (ret < 0) {
  2902. dev_err(tx_dev, "%s: Failed to add controls\n",
  2903. __func__);
  2904. return ret;
  2905. }
  2906. }
  2907. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2908. ret = snd_soc_dapm_add_routes(dapm,
  2909. tx_audio_map_common,
  2910. ARRAY_SIZE(tx_audio_map_common));
  2911. if (ret < 0) {
  2912. dev_err(tx_dev, "%s: Failed to add routes\n",
  2913. __func__);
  2914. return ret;
  2915. }
  2916. if (tx_priv->version == BOLERO_VERSION_2_1)
  2917. ret = snd_soc_dapm_add_routes(dapm,
  2918. tx_audio_map_v2,
  2919. ARRAY_SIZE(tx_audio_map_v2));
  2920. if (tx_priv->version == BOLERO_VERSION_2_0)
  2921. ret = snd_soc_dapm_add_routes(dapm,
  2922. tx_audio_map_v3,
  2923. ARRAY_SIZE(tx_audio_map_v3));
  2924. if (tx_priv->version == BOLERO_VERSION_2_2)
  2925. ret = snd_soc_dapm_add_routes(dapm,
  2926. tx_audio_map_v4,
  2927. ARRAY_SIZE(tx_audio_map_v4));
  2928. if (ret < 0) {
  2929. dev_err(tx_dev, "%s: Failed to add routes\n",
  2930. __func__);
  2931. return ret;
  2932. }
  2933. } else {
  2934. ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
  2935. ARRAY_SIZE(tx_audio_map));
  2936. if (ret < 0) {
  2937. dev_err(tx_dev, "%s: Failed to add routes\n",
  2938. __func__);
  2939. return ret;
  2940. }
  2941. }
  2942. ret = snd_soc_dapm_new_widgets(dapm->card);
  2943. if (ret < 0) {
  2944. dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
  2945. return ret;
  2946. }
  2947. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2948. ret = snd_soc_add_component_controls(component,
  2949. tx_macro_snd_controls_common,
  2950. ARRAY_SIZE(tx_macro_snd_controls_common));
  2951. if (ret < 0) {
  2952. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2953. __func__);
  2954. return ret;
  2955. }
  2956. if (tx_priv->version == BOLERO_VERSION_2_0)
  2957. ret = snd_soc_add_component_controls(component,
  2958. tx_macro_snd_controls_v3,
  2959. ARRAY_SIZE(tx_macro_snd_controls_v3));
  2960. if (ret < 0) {
  2961. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2962. __func__);
  2963. return ret;
  2964. }
  2965. } else {
  2966. ret = snd_soc_add_component_controls(component,
  2967. tx_macro_snd_controls,
  2968. ARRAY_SIZE(tx_macro_snd_controls));
  2969. if (ret < 0) {
  2970. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2971. __func__);
  2972. return ret;
  2973. }
  2974. }
  2975. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture");
  2976. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture");
  2977. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF3 Capture");
  2978. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2979. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_INPUT");
  2980. } else {
  2981. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0");
  2982. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1");
  2983. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2");
  2984. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3");
  2985. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC0");
  2986. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC1");
  2987. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC2");
  2988. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC3");
  2989. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC4");
  2990. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC5");
  2991. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC6");
  2992. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC7");
  2993. }
  2994. snd_soc_dapm_sync(dapm);
  2995. for (i = 0; i < NUM_DECIMATORS; i++) {
  2996. tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
  2997. tx_priv->tx_hpf_work[i].decimator = i;
  2998. INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
  2999. tx_macro_tx_hpf_corner_freq_callback);
  3000. }
  3001. for (i = 0; i < NUM_DECIMATORS; i++) {
  3002. tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
  3003. tx_priv->tx_mute_dwork[i].decimator = i;
  3004. INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
  3005. tx_macro_mute_update_callback);
  3006. }
  3007. tx_priv->component = component;
  3008. for (i = 0; i < ARRAY_SIZE(tx_macro_reg_init); i++)
  3009. snd_soc_component_update_bits(component,
  3010. tx_macro_reg_init[i].reg,
  3011. tx_macro_reg_init[i].mask,
  3012. tx_macro_reg_init[i].val);
  3013. return 0;
  3014. }
  3015. static int tx_macro_deinit(struct snd_soc_component *component)
  3016. {
  3017. struct device *tx_dev = NULL;
  3018. struct tx_macro_priv *tx_priv = NULL;
  3019. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  3020. return -EINVAL;
  3021. tx_priv->component = NULL;
  3022. return 0;
  3023. }
  3024. static void tx_macro_add_child_devices(struct work_struct *work)
  3025. {
  3026. struct tx_macro_priv *tx_priv = NULL;
  3027. struct platform_device *pdev = NULL;
  3028. struct device_node *node = NULL;
  3029. struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  3030. int ret = 0;
  3031. u16 count = 0, ctrl_num = 0;
  3032. struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
  3033. char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
  3034. bool tx_swr_master_node = false;
  3035. tx_priv = container_of(work, struct tx_macro_priv,
  3036. tx_macro_add_child_devices_work);
  3037. if (!tx_priv) {
  3038. pr_err("%s: Memory for tx_priv does not exist\n",
  3039. __func__);
  3040. return;
  3041. }
  3042. if (!tx_priv->dev) {
  3043. pr_err("%s: tx dev does not exist\n", __func__);
  3044. return;
  3045. }
  3046. if (!tx_priv->dev->of_node) {
  3047. dev_err(tx_priv->dev,
  3048. "%s: DT node for tx_priv does not exist\n", __func__);
  3049. return;
  3050. }
  3051. platdata = &tx_priv->swr_plat_data;
  3052. tx_priv->child_count = 0;
  3053. for_each_available_child_of_node(tx_priv->dev->of_node, node) {
  3054. tx_swr_master_node = false;
  3055. if (strnstr(node->name, "tx_swr_master",
  3056. strlen("tx_swr_master")) != NULL)
  3057. tx_swr_master_node = true;
  3058. if (tx_swr_master_node)
  3059. strlcpy(plat_dev_name, "tx_swr_ctrl",
  3060. (TX_MACRO_SWR_STRING_LEN - 1));
  3061. else
  3062. strlcpy(plat_dev_name, node->name,
  3063. (TX_MACRO_SWR_STRING_LEN - 1));
  3064. pdev = platform_device_alloc(plat_dev_name, -1);
  3065. if (!pdev) {
  3066. dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
  3067. __func__);
  3068. ret = -ENOMEM;
  3069. goto err;
  3070. }
  3071. pdev->dev.parent = tx_priv->dev;
  3072. pdev->dev.of_node = node;
  3073. if (tx_swr_master_node) {
  3074. ret = platform_device_add_data(pdev, platdata,
  3075. sizeof(*platdata));
  3076. if (ret) {
  3077. dev_err(&pdev->dev,
  3078. "%s: cannot add plat data ctrl:%d\n",
  3079. __func__, ctrl_num);
  3080. goto fail_pdev_add;
  3081. }
  3082. temp = krealloc(swr_ctrl_data,
  3083. (ctrl_num + 1) * sizeof(
  3084. struct tx_macro_swr_ctrl_data),
  3085. GFP_KERNEL);
  3086. if (!temp) {
  3087. ret = -ENOMEM;
  3088. goto fail_pdev_add;
  3089. }
  3090. swr_ctrl_data = temp;
  3091. swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
  3092. ctrl_num++;
  3093. dev_dbg(&pdev->dev,
  3094. "%s: Adding soundwire ctrl device(s)\n",
  3095. __func__);
  3096. tx_priv->swr_ctrl_data = swr_ctrl_data;
  3097. }
  3098. ret = platform_device_add(pdev);
  3099. if (ret) {
  3100. dev_err(&pdev->dev,
  3101. "%s: Cannot add platform device\n",
  3102. __func__);
  3103. goto fail_pdev_add;
  3104. }
  3105. if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
  3106. tx_priv->pdev_child_devices[
  3107. tx_priv->child_count++] = pdev;
  3108. else
  3109. goto err;
  3110. }
  3111. return;
  3112. fail_pdev_add:
  3113. for (count = 0; count < tx_priv->child_count; count++)
  3114. platform_device_put(tx_priv->pdev_child_devices[count]);
  3115. err:
  3116. return;
  3117. }
  3118. static int tx_macro_set_port_map(struct snd_soc_component *component,
  3119. u32 usecase, u32 size, void *data)
  3120. {
  3121. struct device *tx_dev = NULL;
  3122. struct tx_macro_priv *tx_priv = NULL;
  3123. struct swrm_port_config port_cfg;
  3124. int ret = 0;
  3125. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  3126. return -EINVAL;
  3127. memset(&port_cfg, 0, sizeof(port_cfg));
  3128. port_cfg.uc = usecase;
  3129. port_cfg.size = size;
  3130. port_cfg.params = data;
  3131. if (tx_priv->swr_ctrl_data)
  3132. ret = swrm_wcd_notify(
  3133. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  3134. SWR_SET_PORT_MAP, &port_cfg);
  3135. return ret;
  3136. }
  3137. static void tx_macro_init_ops(struct macro_ops *ops,
  3138. char __iomem *tx_io_base)
  3139. {
  3140. memset(ops, 0, sizeof(struct macro_ops));
  3141. ops->init = tx_macro_init;
  3142. ops->exit = tx_macro_deinit;
  3143. ops->io_base = tx_io_base;
  3144. ops->dai_ptr = tx_macro_dai;
  3145. ops->num_dais = ARRAY_SIZE(tx_macro_dai);
  3146. ops->event_handler = tx_macro_event_handler;
  3147. ops->reg_wake_irq = tx_macro_reg_wake_irq;
  3148. ops->set_port_map = tx_macro_set_port_map;
  3149. ops->clk_div_get = tx_macro_clk_div_get;
  3150. ops->clk_switch = tx_macro_clk_switch;
  3151. ops->reg_evt_listener = tx_macro_register_event_listener;
  3152. ops->clk_enable = __tx_macro_mclk_enable;
  3153. }
  3154. static int tx_macro_probe(struct platform_device *pdev)
  3155. {
  3156. struct macro_ops ops = {0};
  3157. struct tx_macro_priv *tx_priv = NULL;
  3158. u32 tx_base_addr = 0, sample_rate = 0;
  3159. char __iomem *tx_io_base = NULL;
  3160. int ret = 0;
  3161. const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
  3162. u32 is_used_tx_swr_gpio = 1;
  3163. const char *is_used_tx_swr_gpio_dt = "qcom,is-used-swr-gpio";
  3164. u32 disable_afe_wakeup_event_listener = 0;
  3165. const char *disable_afe_wakeup_event_listener_dt =
  3166. "qcom,disable-afe-wakeup-event-listener";
  3167. if (!bolero_is_va_macro_registered(&pdev->dev)) {
  3168. dev_err(&pdev->dev,
  3169. "%s: va-macro not registered yet, defer\n", __func__);
  3170. return -EPROBE_DEFER;
  3171. }
  3172. tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
  3173. GFP_KERNEL);
  3174. if (!tx_priv)
  3175. return -ENOMEM;
  3176. platform_set_drvdata(pdev, tx_priv);
  3177. tx_priv->dev = &pdev->dev;
  3178. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  3179. &tx_base_addr);
  3180. if (ret) {
  3181. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3182. __func__, "reg");
  3183. return ret;
  3184. }
  3185. dev_set_drvdata(&pdev->dev, tx_priv);
  3186. if (of_find_property(pdev->dev.of_node, is_used_tx_swr_gpio_dt,
  3187. NULL)) {
  3188. ret = of_property_read_u32(pdev->dev.of_node,
  3189. is_used_tx_swr_gpio_dt,
  3190. &is_used_tx_swr_gpio);
  3191. if (ret) {
  3192. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  3193. __func__, is_used_tx_swr_gpio_dt);
  3194. is_used_tx_swr_gpio = 1;
  3195. }
  3196. }
  3197. tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  3198. "qcom,tx-swr-gpios", 0);
  3199. if (!tx_priv->tx_swr_gpio_p && is_used_tx_swr_gpio) {
  3200. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  3201. __func__);
  3202. return -EINVAL;
  3203. }
  3204. if (msm_cdc_pinctrl_get_state(tx_priv->tx_swr_gpio_p) < 0 &&
  3205. is_used_tx_swr_gpio) {
  3206. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  3207. __func__);
  3208. return -EPROBE_DEFER;
  3209. }
  3210. tx_io_base = devm_ioremap(&pdev->dev,
  3211. tx_base_addr, TX_MACRO_MAX_OFFSET);
  3212. if (!tx_io_base) {
  3213. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  3214. return -ENOMEM;
  3215. }
  3216. tx_priv->tx_io_base = tx_io_base;
  3217. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  3218. &sample_rate);
  3219. if (ret) {
  3220. dev_err(&pdev->dev,
  3221. "%s: could not find sample_rate entry in dt\n",
  3222. __func__);
  3223. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  3224. } else {
  3225. if (tx_macro_validate_dmic_sample_rate(
  3226. sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  3227. return -EINVAL;
  3228. }
  3229. if (of_find_property(pdev->dev.of_node,
  3230. disable_afe_wakeup_event_listener_dt, NULL)) {
  3231. ret = of_property_read_u32(pdev->dev.of_node,
  3232. disable_afe_wakeup_event_listener_dt,
  3233. &disable_afe_wakeup_event_listener);
  3234. if (ret)
  3235. dev_dbg(&pdev->dev, "%s: error reading %s in dt\n",
  3236. __func__, disable_afe_wakeup_event_listener_dt);
  3237. }
  3238. tx_priv->disable_afe_wakeup_event_listener =
  3239. disable_afe_wakeup_event_listener;
  3240. if (is_used_tx_swr_gpio) {
  3241. tx_priv->reset_swr = true;
  3242. INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
  3243. tx_macro_add_child_devices);
  3244. tx_priv->swr_plat_data.handle = (void *) tx_priv;
  3245. tx_priv->swr_plat_data.read = NULL;
  3246. tx_priv->swr_plat_data.write = NULL;
  3247. tx_priv->swr_plat_data.bulk_write = NULL;
  3248. tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
  3249. tx_priv->swr_plat_data.core_vote = tx_macro_core_vote;
  3250. tx_priv->swr_plat_data.handle_irq = NULL;
  3251. mutex_init(&tx_priv->swr_clk_lock);
  3252. }
  3253. tx_priv->is_used_tx_swr_gpio = is_used_tx_swr_gpio;
  3254. mutex_init(&tx_priv->mclk_lock);
  3255. tx_macro_init_ops(&ops, tx_io_base);
  3256. ops.clk_id_req = TX_CORE_CLK;
  3257. ops.default_clk_id = TX_CORE_CLK;
  3258. tx_priv->current_clk_id = TX_CORE_CLK;
  3259. ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
  3260. if (ret) {
  3261. dev_err(&pdev->dev,
  3262. "%s: register macro failed\n", __func__);
  3263. goto err_reg_macro;
  3264. }
  3265. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  3266. pm_runtime_use_autosuspend(&pdev->dev);
  3267. pm_runtime_set_suspended(&pdev->dev);
  3268. pm_suspend_ignore_children(&pdev->dev, true);
  3269. pm_runtime_enable(&pdev->dev);
  3270. if (is_used_tx_swr_gpio)
  3271. schedule_work(&tx_priv->tx_macro_add_child_devices_work);
  3272. return 0;
  3273. err_reg_macro:
  3274. mutex_destroy(&tx_priv->mclk_lock);
  3275. if (is_used_tx_swr_gpio)
  3276. mutex_destroy(&tx_priv->swr_clk_lock);
  3277. return ret;
  3278. }
  3279. static int tx_macro_remove(struct platform_device *pdev)
  3280. {
  3281. struct tx_macro_priv *tx_priv = NULL;
  3282. u16 count = 0;
  3283. tx_priv = platform_get_drvdata(pdev);
  3284. if (!tx_priv)
  3285. return -EINVAL;
  3286. if (tx_priv->is_used_tx_swr_gpio) {
  3287. if (tx_priv->swr_ctrl_data)
  3288. kfree(tx_priv->swr_ctrl_data);
  3289. for (count = 0; count < tx_priv->child_count &&
  3290. count < TX_MACRO_CHILD_DEVICES_MAX; count++)
  3291. platform_device_unregister(
  3292. tx_priv->pdev_child_devices[count]);
  3293. }
  3294. pm_runtime_disable(&pdev->dev);
  3295. pm_runtime_set_suspended(&pdev->dev);
  3296. mutex_destroy(&tx_priv->mclk_lock);
  3297. if (tx_priv->is_used_tx_swr_gpio)
  3298. mutex_destroy(&tx_priv->swr_clk_lock);
  3299. bolero_unregister_macro(&pdev->dev, TX_MACRO);
  3300. return 0;
  3301. }
  3302. static const struct of_device_id tx_macro_dt_match[] = {
  3303. {.compatible = "qcom,tx-macro"},
  3304. {}
  3305. };
  3306. static const struct dev_pm_ops bolero_dev_pm_ops = {
  3307. SET_SYSTEM_SLEEP_PM_OPS(
  3308. pm_runtime_force_suspend,
  3309. pm_runtime_force_resume
  3310. )
  3311. SET_RUNTIME_PM_OPS(
  3312. bolero_runtime_suspend,
  3313. bolero_runtime_resume,
  3314. NULL
  3315. )
  3316. };
  3317. static struct platform_driver tx_macro_driver = {
  3318. .driver = {
  3319. .name = "tx_macro",
  3320. .owner = THIS_MODULE,
  3321. .pm = &bolero_dev_pm_ops,
  3322. .of_match_table = tx_macro_dt_match,
  3323. .suppress_bind_attrs = true,
  3324. },
  3325. .probe = tx_macro_probe,
  3326. .remove = tx_macro_remove,
  3327. };
  3328. module_platform_driver(tx_macro_driver);
  3329. MODULE_DESCRIPTION("TX macro driver");
  3330. MODULE_LICENSE("GPL v2");