tx-macro.c 96 KB

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