tx-macro.c 107 KB

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