tx-macro.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166
  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, 0x02, 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, 0x02, 0x00);
  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. /*
  775. * Minimum 1 clk cycle delay is required as per HW spec
  776. */
  777. usleep_range(1000, 1010);
  778. hpf_cut_off_freq = (
  779. snd_soc_component_read32(component, dec_cfg_reg) &
  780. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  781. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
  782. hpf_cut_off_freq;
  783. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
  784. snd_soc_component_update_bits(component, dec_cfg_reg,
  785. TX_HPF_CUT_OFF_FREQ_MASK,
  786. CF_MIN_3DB_150HZ << 5);
  787. /* schedule work queue to Remove Mute */
  788. schedule_delayed_work(&tx_priv->tx_mute_dwork[decimator].dwork,
  789. msecs_to_jiffies(tx_unmute_delay));
  790. if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
  791. CF_MIN_3DB_150HZ) {
  792. schedule_delayed_work(
  793. &tx_priv->tx_hpf_work[decimator].dwork,
  794. msecs_to_jiffies(300));
  795. snd_soc_component_update_bits(component,
  796. hpf_gate_reg, 0x03, 0x03);
  797. /*
  798. * Minimum 1 clk cycle delay is required as per HW spec
  799. */
  800. usleep_range(1000, 1010);
  801. snd_soc_component_update_bits(component,
  802. hpf_gate_reg, 0x02, 0x00);
  803. }
  804. /* apply gain after decimator is enabled */
  805. snd_soc_component_write(component, tx_gain_ctl_reg,
  806. snd_soc_component_read32(component,
  807. tx_gain_ctl_reg));
  808. if (tx_priv->bcs_enable) {
  809. snd_soc_component_update_bits(component, dec_cfg_reg,
  810. 0x01, 0x01);
  811. tx_priv->bcs_clk_en = true;
  812. if (tx_priv->hs_slow_insert_complete)
  813. snd_soc_component_update_bits(component,
  814. BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40,
  815. 0x40);
  816. }
  817. break;
  818. case SND_SOC_DAPM_PRE_PMD:
  819. hpf_cut_off_freq =
  820. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
  821. snd_soc_component_update_bits(component,
  822. tx_vol_ctl_reg, 0x10, 0x10);
  823. if (cancel_delayed_work_sync(
  824. &tx_priv->tx_hpf_work[decimator].dwork)) {
  825. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  826. snd_soc_component_update_bits(
  827. component, dec_cfg_reg,
  828. TX_HPF_CUT_OFF_FREQ_MASK,
  829. hpf_cut_off_freq << 5);
  830. snd_soc_component_update_bits(component,
  831. hpf_gate_reg,
  832. 0x02, 0x02);
  833. /*
  834. * Minimum 1 clk cycle delay is required
  835. * as per HW spec
  836. */
  837. usleep_range(1000, 1010);
  838. snd_soc_component_update_bits(component,
  839. hpf_gate_reg,
  840. 0x02, 0x00);
  841. }
  842. }
  843. cancel_delayed_work_sync(
  844. &tx_priv->tx_mute_dwork[decimator].dwork);
  845. break;
  846. case SND_SOC_DAPM_POST_PMD:
  847. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  848. 0x20, 0x00);
  849. snd_soc_component_update_bits(component,
  850. dec_cfg_reg, 0x06, 0x00);
  851. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  852. 0x10, 0x00);
  853. if (tx_priv->bcs_enable) {
  854. snd_soc_component_update_bits(component, dec_cfg_reg,
  855. 0x01, 0x00);
  856. snd_soc_component_update_bits(component,
  857. BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, 0x00);
  858. tx_priv->bcs_clk_en = false;
  859. }
  860. break;
  861. }
  862. return 0;
  863. }
  864. static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  865. struct snd_kcontrol *kcontrol, int event)
  866. {
  867. return 0;
  868. }
  869. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  870. struct snd_pcm_hw_params *params,
  871. struct snd_soc_dai *dai)
  872. {
  873. int tx_fs_rate = -EINVAL;
  874. struct snd_soc_component *component = dai->component;
  875. u32 decimator = 0;
  876. u32 sample_rate = 0;
  877. u16 tx_fs_reg = 0;
  878. struct device *tx_dev = NULL;
  879. struct tx_macro_priv *tx_priv = NULL;
  880. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  881. return -EINVAL;
  882. pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  883. dai->name, dai->id, params_rate(params),
  884. params_channels(params));
  885. sample_rate = params_rate(params);
  886. switch (sample_rate) {
  887. case 8000:
  888. tx_fs_rate = 0;
  889. break;
  890. case 16000:
  891. tx_fs_rate = 1;
  892. break;
  893. case 32000:
  894. tx_fs_rate = 3;
  895. break;
  896. case 48000:
  897. tx_fs_rate = 4;
  898. break;
  899. case 96000:
  900. tx_fs_rate = 5;
  901. break;
  902. case 192000:
  903. tx_fs_rate = 6;
  904. break;
  905. case 384000:
  906. tx_fs_rate = 7;
  907. break;
  908. default:
  909. dev_err(component->dev, "%s: Invalid TX sample rate: %d\n",
  910. __func__, params_rate(params));
  911. return -EINVAL;
  912. }
  913. for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
  914. TX_MACRO_DEC_MAX) {
  915. if (decimator >= 0) {
  916. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  917. TX_MACRO_TX_PATH_OFFSET * decimator;
  918. dev_dbg(component->dev, "%s: set DEC%u rate to %u\n",
  919. __func__, decimator, sample_rate);
  920. snd_soc_component_update_bits(component, tx_fs_reg,
  921. 0x0F, tx_fs_rate);
  922. } else {
  923. dev_err(component->dev,
  924. "%s: ERROR: Invalid decimator: %d\n",
  925. __func__, decimator);
  926. return -EINVAL;
  927. }
  928. }
  929. return 0;
  930. }
  931. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  932. unsigned int *tx_num, unsigned int *tx_slot,
  933. unsigned int *rx_num, unsigned int *rx_slot)
  934. {
  935. struct snd_soc_component *component = dai->component;
  936. struct device *tx_dev = NULL;
  937. struct tx_macro_priv *tx_priv = NULL;
  938. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  939. return -EINVAL;
  940. switch (dai->id) {
  941. case TX_MACRO_AIF1_CAP:
  942. case TX_MACRO_AIF2_CAP:
  943. case TX_MACRO_AIF3_CAP:
  944. *tx_slot = tx_priv->active_ch_mask[dai->id];
  945. *tx_num = tx_priv->active_ch_cnt[dai->id];
  946. break;
  947. default:
  948. dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
  949. break;
  950. }
  951. return 0;
  952. }
  953. static struct snd_soc_dai_ops tx_macro_dai_ops = {
  954. .hw_params = tx_macro_hw_params,
  955. .get_channel_map = tx_macro_get_channel_map,
  956. };
  957. static struct snd_soc_dai_driver tx_macro_dai[] = {
  958. {
  959. .name = "tx_macro_tx1",
  960. .id = TX_MACRO_AIF1_CAP,
  961. .capture = {
  962. .stream_name = "TX_AIF1 Capture",
  963. .rates = TX_MACRO_RATES,
  964. .formats = TX_MACRO_FORMATS,
  965. .rate_max = 192000,
  966. .rate_min = 8000,
  967. .channels_min = 1,
  968. .channels_max = 8,
  969. },
  970. .ops = &tx_macro_dai_ops,
  971. },
  972. {
  973. .name = "tx_macro_tx2",
  974. .id = TX_MACRO_AIF2_CAP,
  975. .capture = {
  976. .stream_name = "TX_AIF2 Capture",
  977. .rates = TX_MACRO_RATES,
  978. .formats = TX_MACRO_FORMATS,
  979. .rate_max = 192000,
  980. .rate_min = 8000,
  981. .channels_min = 1,
  982. .channels_max = 8,
  983. },
  984. .ops = &tx_macro_dai_ops,
  985. },
  986. {
  987. .name = "tx_macro_tx3",
  988. .id = TX_MACRO_AIF3_CAP,
  989. .capture = {
  990. .stream_name = "TX_AIF3 Capture",
  991. .rates = TX_MACRO_RATES,
  992. .formats = TX_MACRO_FORMATS,
  993. .rate_max = 192000,
  994. .rate_min = 8000,
  995. .channels_min = 1,
  996. .channels_max = 8,
  997. },
  998. .ops = &tx_macro_dai_ops,
  999. },
  1000. };
  1001. #define STRING(name) #name
  1002. #define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  1003. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  1004. static const struct snd_kcontrol_new name##_mux = \
  1005. SOC_DAPM_ENUM(STRING(name), name##_enum)
  1006. #define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  1007. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  1008. static const struct snd_kcontrol_new name##_mux = \
  1009. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  1010. #define TX_MACRO_DAPM_MUX(name, shift, kctl) \
  1011. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  1012. static const char * const adc_mux_text[] = {
  1013. "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
  1014. };
  1015. TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
  1016. 0, adc_mux_text);
  1017. TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
  1018. 0, adc_mux_text);
  1019. TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
  1020. 0, adc_mux_text);
  1021. TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
  1022. 0, adc_mux_text);
  1023. TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
  1024. 0, adc_mux_text);
  1025. TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
  1026. 0, adc_mux_text);
  1027. TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
  1028. 0, adc_mux_text);
  1029. TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
  1030. 0, adc_mux_text);
  1031. static const char * const dmic_mux_text[] = {
  1032. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  1033. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  1034. };
  1035. TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1036. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1037. tx_macro_put_dec_enum);
  1038. TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1039. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1040. tx_macro_put_dec_enum);
  1041. TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1042. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1043. tx_macro_put_dec_enum);
  1044. TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1045. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1046. tx_macro_put_dec_enum);
  1047. TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1048. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1049. tx_macro_put_dec_enum);
  1050. TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1051. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1052. tx_macro_put_dec_enum);
  1053. TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1054. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1055. tx_macro_put_dec_enum);
  1056. TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1057. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1058. tx_macro_put_dec_enum);
  1059. static const char * const smic_mux_text[] = {
  1060. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "SWR_DMIC0",
  1061. "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3", "SWR_DMIC4",
  1062. "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  1063. };
  1064. TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1065. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1066. tx_macro_put_dec_enum);
  1067. TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1068. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1069. tx_macro_put_dec_enum);
  1070. TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1071. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1072. tx_macro_put_dec_enum);
  1073. TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1074. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1075. tx_macro_put_dec_enum);
  1076. TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1077. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1078. tx_macro_put_dec_enum);
  1079. TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1080. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1081. tx_macro_put_dec_enum);
  1082. TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1083. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1084. tx_macro_put_dec_enum);
  1085. TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1086. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1087. tx_macro_put_dec_enum);
  1088. static const char * const smic_mux_text_v2[] = {
  1089. "ZERO", "SWR_MIC0", "SWR_MIC1", "SWR_MIC2", "SWR_MIC3",
  1090. "SWR_MIC4", "SWR_MIC5", "SWR_MIC6", "SWR_MIC7",
  1091. "SWR_MIC8", "SWR_MIC9", "SWR_MIC10", "SWR_MIC11"
  1092. };
  1093. TX_MACRO_DAPM_ENUM_EXT(tx_smic0_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1094. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1095. tx_macro_put_dec_enum);
  1096. TX_MACRO_DAPM_ENUM_EXT(tx_smic1_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1097. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1098. tx_macro_put_dec_enum);
  1099. TX_MACRO_DAPM_ENUM_EXT(tx_smic2_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1100. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1101. tx_macro_put_dec_enum);
  1102. TX_MACRO_DAPM_ENUM_EXT(tx_smic3_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1103. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1104. tx_macro_put_dec_enum);
  1105. TX_MACRO_DAPM_ENUM_EXT(tx_smic4_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1106. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1107. tx_macro_put_dec_enum);
  1108. TX_MACRO_DAPM_ENUM_EXT(tx_smic5_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1109. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1110. tx_macro_put_dec_enum);
  1111. TX_MACRO_DAPM_ENUM_EXT(tx_smic6_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1112. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1113. tx_macro_put_dec_enum);
  1114. TX_MACRO_DAPM_ENUM_EXT(tx_smic7_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1115. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1116. tx_macro_put_dec_enum);
  1117. static const char * const dec_mode_mux_text[] = {
  1118. "ADC_DEFAULT", "ADC_LOW_PWR", "ADC_HIGH_PERF",
  1119. };
  1120. static const struct soc_enum dec_mode_mux_enum =
  1121. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dec_mode_mux_text),
  1122. dec_mode_mux_text);
  1123. static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
  1124. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1125. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1126. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1127. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1128. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1129. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1130. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1131. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1132. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1133. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1134. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1135. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1136. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1137. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1138. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1139. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1140. };
  1141. static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
  1142. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1143. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1144. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1145. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1146. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1147. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1148. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1149. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1150. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1151. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1152. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1153. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1154. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1155. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1156. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1157. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1158. };
  1159. static const struct snd_kcontrol_new tx_aif3_cap_mixer[] = {
  1160. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1161. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1162. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1163. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1164. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1165. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1166. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1167. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1168. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1169. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1170. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1171. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1172. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1173. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1174. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1175. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1176. };
  1177. static const struct snd_kcontrol_new tx_aif1_cap_mixer_v2[] = {
  1178. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1179. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1180. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1181. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1182. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1183. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1184. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1185. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1186. };
  1187. static const struct snd_kcontrol_new tx_aif2_cap_mixer_v2[] = {
  1188. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1189. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1190. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1191. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1192. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1193. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1194. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1195. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1196. };
  1197. static const struct snd_kcontrol_new tx_aif3_cap_mixer_v2[] = {
  1198. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1199. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1200. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1201. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1202. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1203. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1204. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1205. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1206. };
  1207. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_common[] = {
  1208. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  1209. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  1210. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  1211. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  1212. SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
  1213. SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
  1214. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  1215. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  1216. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  1217. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  1218. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0_v2),
  1219. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1_v2),
  1220. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2_v2),
  1221. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3_v2),
  1222. SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1223. tx_macro_enable_micbias,
  1224. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1225. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1226. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1227. SND_SOC_DAPM_POST_PMD),
  1228. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1229. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1230. SND_SOC_DAPM_POST_PMD),
  1231. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1232. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1233. SND_SOC_DAPM_POST_PMD),
  1234. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1235. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1236. SND_SOC_DAPM_POST_PMD),
  1237. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1238. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1239. SND_SOC_DAPM_POST_PMD),
  1240. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1241. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1242. SND_SOC_DAPM_POST_PMD),
  1243. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1244. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1245. SND_SOC_DAPM_POST_PMD),
  1246. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1247. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1248. SND_SOC_DAPM_POST_PMD),
  1249. SND_SOC_DAPM_INPUT("TX SWR_MIC0"),
  1250. SND_SOC_DAPM_INPUT("TX SWR_MIC1"),
  1251. SND_SOC_DAPM_INPUT("TX SWR_MIC2"),
  1252. SND_SOC_DAPM_INPUT("TX SWR_MIC3"),
  1253. SND_SOC_DAPM_INPUT("TX SWR_MIC4"),
  1254. SND_SOC_DAPM_INPUT("TX SWR_MIC5"),
  1255. SND_SOC_DAPM_INPUT("TX SWR_MIC6"),
  1256. SND_SOC_DAPM_INPUT("TX SWR_MIC7"),
  1257. SND_SOC_DAPM_INPUT("TX SWR_MIC8"),
  1258. SND_SOC_DAPM_INPUT("TX SWR_MIC9"),
  1259. SND_SOC_DAPM_INPUT("TX SWR_MIC10"),
  1260. SND_SOC_DAPM_INPUT("TX SWR_MIC11"),
  1261. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  1262. TX_MACRO_DEC0, 0,
  1263. &tx_dec0_mux, tx_macro_enable_dec,
  1264. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1265. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1266. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  1267. TX_MACRO_DEC1, 0,
  1268. &tx_dec1_mux, tx_macro_enable_dec,
  1269. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1270. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1271. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  1272. TX_MACRO_DEC2, 0,
  1273. &tx_dec2_mux, tx_macro_enable_dec,
  1274. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1275. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1276. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  1277. TX_MACRO_DEC3, 0,
  1278. &tx_dec3_mux, tx_macro_enable_dec,
  1279. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1280. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1281. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1282. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1283. };
  1284. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v2[] = {
  1285. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
  1286. TX_MACRO_AIF1_CAP, 0,
  1287. tx_aif1_cap_mixer_v2, ARRAY_SIZE(tx_aif1_cap_mixer_v2)),
  1288. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
  1289. TX_MACRO_AIF2_CAP, 0,
  1290. tx_aif2_cap_mixer_v2, ARRAY_SIZE(tx_aif2_cap_mixer_v2)),
  1291. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
  1292. TX_MACRO_AIF3_CAP, 0,
  1293. tx_aif3_cap_mixer_v2, ARRAY_SIZE(tx_aif3_cap_mixer_v2)),
  1294. SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1295. tx_macro_tx_swr_clk_event,
  1296. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1297. };
  1298. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v3[] = {
  1299. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
  1300. TX_MACRO_AIF1_CAP, 0,
  1301. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  1302. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
  1303. TX_MACRO_AIF2_CAP, 0,
  1304. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  1305. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
  1306. TX_MACRO_AIF3_CAP, 0,
  1307. tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
  1308. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  1309. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  1310. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  1311. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  1312. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4_v3),
  1313. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5_v3),
  1314. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6_v3),
  1315. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7_v3),
  1316. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  1317. TX_MACRO_DEC4, 0,
  1318. &tx_dec4_mux, tx_macro_enable_dec,
  1319. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1320. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1321. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  1322. TX_MACRO_DEC5, 0,
  1323. &tx_dec5_mux, tx_macro_enable_dec,
  1324. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1325. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1326. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  1327. TX_MACRO_DEC6, 0,
  1328. &tx_dec6_mux, tx_macro_enable_dec,
  1329. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1330. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1331. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  1332. TX_MACRO_DEC7, 0,
  1333. &tx_dec7_mux, tx_macro_enable_dec,
  1334. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1335. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1336. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1337. tx_macro_va_swr_clk_event,
  1338. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1339. };
  1340. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
  1341. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  1342. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  1343. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  1344. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  1345. SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
  1346. SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
  1347. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
  1348. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  1349. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
  1350. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  1351. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0,
  1352. tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
  1353. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  1354. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  1355. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  1356. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  1357. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  1358. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  1359. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  1360. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  1361. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
  1362. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
  1363. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
  1364. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
  1365. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
  1366. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
  1367. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
  1368. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
  1369. SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1370. tx_macro_enable_micbias,
  1371. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1372. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1373. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1374. SND_SOC_DAPM_POST_PMD),
  1375. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1376. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1377. SND_SOC_DAPM_POST_PMD),
  1378. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1379. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1380. SND_SOC_DAPM_POST_PMD),
  1381. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1382. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1383. SND_SOC_DAPM_POST_PMD),
  1384. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1385. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1386. SND_SOC_DAPM_POST_PMD),
  1387. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1388. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1389. SND_SOC_DAPM_POST_PMD),
  1390. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1391. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1392. SND_SOC_DAPM_POST_PMD),
  1393. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1394. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1395. SND_SOC_DAPM_POST_PMD),
  1396. SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
  1397. SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
  1398. SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
  1399. SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
  1400. SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
  1401. SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
  1402. SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
  1403. SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
  1404. SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
  1405. SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
  1406. SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
  1407. SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
  1408. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  1409. TX_MACRO_DEC0, 0,
  1410. &tx_dec0_mux, tx_macro_enable_dec,
  1411. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1412. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1413. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  1414. TX_MACRO_DEC1, 0,
  1415. &tx_dec1_mux, tx_macro_enable_dec,
  1416. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1417. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1418. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  1419. TX_MACRO_DEC2, 0,
  1420. &tx_dec2_mux, tx_macro_enable_dec,
  1421. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1422. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1423. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  1424. TX_MACRO_DEC3, 0,
  1425. &tx_dec3_mux, tx_macro_enable_dec,
  1426. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1427. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1428. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  1429. TX_MACRO_DEC4, 0,
  1430. &tx_dec4_mux, tx_macro_enable_dec,
  1431. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1432. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1433. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  1434. TX_MACRO_DEC5, 0,
  1435. &tx_dec5_mux, tx_macro_enable_dec,
  1436. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1437. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1438. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  1439. TX_MACRO_DEC6, 0,
  1440. &tx_dec6_mux, tx_macro_enable_dec,
  1441. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1442. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1443. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  1444. TX_MACRO_DEC7, 0,
  1445. &tx_dec7_mux, tx_macro_enable_dec,
  1446. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1447. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1448. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1449. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1450. SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1451. tx_macro_tx_swr_clk_event,
  1452. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1453. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1454. tx_macro_va_swr_clk_event,
  1455. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1456. };
  1457. static const struct snd_soc_dapm_route tx_audio_map_common[] = {
  1458. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  1459. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  1460. {"TX_AIF3 CAP", NULL, "TX_MCLK"},
  1461. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  1462. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  1463. {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
  1464. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1465. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1466. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1467. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1468. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1469. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1470. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1471. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1472. {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1473. {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1474. {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1475. {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1476. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  1477. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  1478. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  1479. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  1480. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  1481. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  1482. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  1483. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  1484. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  1485. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  1486. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  1487. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  1488. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  1489. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  1490. {"TX SMIC MUX0", "SWR_MIC0", "TX SWR_MIC0"},
  1491. {"TX SMIC MUX0", "SWR_MIC1", "TX SWR_MIC1"},
  1492. {"TX SMIC MUX0", "SWR_MIC2", "TX SWR_MIC2"},
  1493. {"TX SMIC MUX0", "SWR_MIC3", "TX SWR_MIC3"},
  1494. {"TX SMIC MUX0", "SWR_MIC4", "TX SWR_MIC4"},
  1495. {"TX SMIC MUX0", "SWR_MIC5", "TX SWR_MIC5"},
  1496. {"TX SMIC MUX0", "SWR_MIC6", "TX SWR_MIC6"},
  1497. {"TX SMIC MUX0", "SWR_MIC7", "TX SWR_MIC7"},
  1498. {"TX SMIC MUX0", "SWR_MIC8", "TX SWR_MIC8"},
  1499. {"TX SMIC MUX0", "SWR_MIC9", "TX SWR_MIC9"},
  1500. {"TX SMIC MUX0", "SWR_MIC10", "TX SWR_MIC10"},
  1501. {"TX SMIC MUX0", "SWR_MIC11", "TX SWR_MIC11"},
  1502. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  1503. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  1504. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  1505. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  1506. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  1507. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  1508. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  1509. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  1510. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  1511. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  1512. {"TX SMIC MUX1", "SWR_MIC0", "TX SWR_MIC0"},
  1513. {"TX SMIC MUX1", "SWR_MIC1", "TX SWR_MIC1"},
  1514. {"TX SMIC MUX1", "SWR_MIC2", "TX SWR_MIC2"},
  1515. {"TX SMIC MUX1", "SWR_MIC3", "TX SWR_MIC3"},
  1516. {"TX SMIC MUX1", "SWR_MIC4", "TX SWR_MIC4"},
  1517. {"TX SMIC MUX1", "SWR_MIC5", "TX SWR_MIC5"},
  1518. {"TX SMIC MUX1", "SWR_MIC6", "TX SWR_MIC6"},
  1519. {"TX SMIC MUX1", "SWR_MIC7", "TX SWR_MIC7"},
  1520. {"TX SMIC MUX1", "SWR_MIC8", "TX SWR_MIC8"},
  1521. {"TX SMIC MUX1", "SWR_MIC9", "TX SWR_MIC9"},
  1522. {"TX SMIC MUX1", "SWR_MIC10", "TX SWR_MIC10"},
  1523. {"TX SMIC MUX1", "SWR_MIC11", "TX SWR_MIC11"},
  1524. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  1525. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  1526. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  1527. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  1528. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  1529. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  1530. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  1531. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  1532. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  1533. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  1534. {"TX SMIC MUX2", "SWR_MIC0", "TX SWR_MIC0"},
  1535. {"TX SMIC MUX2", "SWR_MIC1", "TX SWR_MIC1"},
  1536. {"TX SMIC MUX2", "SWR_MIC2", "TX SWR_MIC2"},
  1537. {"TX SMIC MUX2", "SWR_MIC3", "TX SWR_MIC3"},
  1538. {"TX SMIC MUX2", "SWR_MIC4", "TX SWR_MIC4"},
  1539. {"TX SMIC MUX2", "SWR_MIC5", "TX SWR_MIC5"},
  1540. {"TX SMIC MUX2", "SWR_MIC6", "TX SWR_MIC6"},
  1541. {"TX SMIC MUX2", "SWR_MIC7", "TX SWR_MIC7"},
  1542. {"TX SMIC MUX2", "SWR_MIC8", "TX SWR_MIC8"},
  1543. {"TX SMIC MUX2", "SWR_MIC9", "TX SWR_MIC9"},
  1544. {"TX SMIC MUX2", "SWR_MIC10", "TX SWR_MIC10"},
  1545. {"TX SMIC MUX2", "SWR_MIC11", "TX SWR_MIC11"},
  1546. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  1547. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  1548. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  1549. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  1550. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  1551. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  1552. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  1553. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  1554. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  1555. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  1556. {"TX SMIC MUX3", "SWR_MIC0", "TX SWR_MIC0"},
  1557. {"TX SMIC MUX3", "SWR_MIC1", "TX SWR_MIC1"},
  1558. {"TX SMIC MUX3", "SWR_MIC2", "TX SWR_MIC2"},
  1559. {"TX SMIC MUX3", "SWR_MIC3", "TX SWR_MIC3"},
  1560. {"TX SMIC MUX3", "SWR_MIC4", "TX SWR_MIC4"},
  1561. {"TX SMIC MUX3", "SWR_MIC5", "TX SWR_MIC5"},
  1562. {"TX SMIC MUX3", "SWR_MIC6", "TX SWR_MIC6"},
  1563. {"TX SMIC MUX3", "SWR_MIC7", "TX SWR_MIC7"},
  1564. {"TX SMIC MUX3", "SWR_MIC8", "TX SWR_MIC8"},
  1565. {"TX SMIC MUX3", "SWR_MIC9", "TX SWR_MIC9"},
  1566. {"TX SMIC MUX3", "SWR_MIC10", "TX SWR_MIC10"},
  1567. {"TX SMIC MUX3", "SWR_MIC11", "TX SWR_MIC11"},
  1568. };
  1569. static const struct snd_soc_dapm_route tx_audio_map_v3[] = {
  1570. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1571. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1572. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1573. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1574. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1575. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1576. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1577. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1578. {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1579. {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1580. {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1581. {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1582. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  1583. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  1584. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  1585. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  1586. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  1587. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  1588. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  1589. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  1590. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  1591. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  1592. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  1593. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  1594. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  1595. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  1596. {"TX SMIC MUX4", "SWR_MIC0", "TX SWR_MIC0"},
  1597. {"TX SMIC MUX4", "SWR_MIC1", "TX SWR_MIC1"},
  1598. {"TX SMIC MUX4", "SWR_MIC2", "TX SWR_MIC2"},
  1599. {"TX SMIC MUX4", "SWR_MIC3", "TX SWR_MIC3"},
  1600. {"TX SMIC MUX4", "SWR_MIC4", "TX SWR_MIC4"},
  1601. {"TX SMIC MUX4", "SWR_MIC5", "TX SWR_MIC5"},
  1602. {"TX SMIC MUX4", "SWR_MIC6", "TX SWR_MIC6"},
  1603. {"TX SMIC MUX4", "SWR_MIC7", "TX SWR_MIC7"},
  1604. {"TX SMIC MUX4", "SWR_MIC8", "TX SWR_MIC8"},
  1605. {"TX SMIC MUX4", "SWR_MIC9", "TX SWR_MIC9"},
  1606. {"TX SMIC MUX4", "SWR_MIC10", "TX SWR_MIC10"},
  1607. {"TX SMIC MUX4", "SWR_MIC11", "TX SWR_MIC11"},
  1608. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  1609. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  1610. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  1611. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  1612. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  1613. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  1614. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  1615. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  1616. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  1617. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  1618. {"TX SMIC MUX5", "SWR_MIC0", "TX SWR_MIC0"},
  1619. {"TX SMIC MUX5", "SWR_MIC1", "TX SWR_MIC1"},
  1620. {"TX SMIC MUX5", "SWR_MIC2", "TX SWR_MIC2"},
  1621. {"TX SMIC MUX5", "SWR_MIC3", "TX SWR_MIC3"},
  1622. {"TX SMIC MUX5", "SWR_MIC4", "TX SWR_MIC4"},
  1623. {"TX SMIC MUX5", "SWR_MIC5", "TX SWR_MIC5"},
  1624. {"TX SMIC MUX5", "SWR_MIC6", "TX SWR_MIC6"},
  1625. {"TX SMIC MUX5", "SWR_MIC7", "TX SWR_MIC7"},
  1626. {"TX SMIC MUX5", "SWR_MIC8", "TX SWR_MIC8"},
  1627. {"TX SMIC MUX5", "SWR_MIC9", "TX SWR_MIC9"},
  1628. {"TX SMIC MUX5", "SWR_MIC10", "TX SWR_MIC10"},
  1629. {"TX SMIC MUX5", "SWR_MIC11", "TX SWR_MIC11"},
  1630. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  1631. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  1632. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  1633. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  1634. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  1635. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  1636. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  1637. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  1638. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  1639. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  1640. {"TX SMIC MUX6", "SWR_MIC0", "TX SWR_MIC0"},
  1641. {"TX SMIC MUX6", "SWR_MIC1", "TX SWR_MIC1"},
  1642. {"TX SMIC MUX6", "SWR_MIC2", "TX SWR_MIC2"},
  1643. {"TX SMIC MUX6", "SWR_MIC3", "TX SWR_MIC3"},
  1644. {"TX SMIC MUX6", "SWR_MIC4", "TX SWR_MIC4"},
  1645. {"TX SMIC MUX6", "SWR_MIC5", "TX SWR_MIC5"},
  1646. {"TX SMIC MUX6", "SWR_MIC6", "TX SWR_MIC6"},
  1647. {"TX SMIC MUX6", "SWR_MIC7", "TX SWR_MIC7"},
  1648. {"TX SMIC MUX6", "SWR_MIC8", "TX SWR_MIC8"},
  1649. {"TX SMIC MUX6", "SWR_MIC9", "TX SWR_MIC9"},
  1650. {"TX SMIC MUX6", "SWR_MIC10", "TX SWR_MIC10"},
  1651. {"TX SMIC MUX6", "SWR_MIC11", "TX SWR_MIC11"},
  1652. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  1653. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  1654. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  1655. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  1656. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  1657. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  1658. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  1659. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  1660. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  1661. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  1662. {"TX SMIC MUX7", "SWR_MIC0", "TX SWR_MIC0"},
  1663. {"TX SMIC MUX7", "SWR_MIC1", "TX SWR_MIC1"},
  1664. {"TX SMIC MUX7", "SWR_MIC2", "TX SWR_MIC2"},
  1665. {"TX SMIC MUX7", "SWR_MIC3", "TX SWR_MIC3"},
  1666. {"TX SMIC MUX7", "SWR_MIC4", "TX SWR_MIC4"},
  1667. {"TX SMIC MUX7", "SWR_MIC5", "TX SWR_MIC5"},
  1668. {"TX SMIC MUX7", "SWR_MIC6", "TX SWR_MIC6"},
  1669. {"TX SMIC MUX7", "SWR_MIC7", "TX SWR_MIC7"},
  1670. {"TX SMIC MUX7", "SWR_MIC8", "TX SWR_MIC8"},
  1671. {"TX SMIC MUX7", "SWR_MIC9", "TX SWR_MIC9"},
  1672. {"TX SMIC MUX7", "SWR_MIC10", "TX SWR_MIC10"},
  1673. {"TX SMIC MUX7", "SWR_MIC11", "TX SWR_MIC11"},
  1674. };
  1675. static const struct snd_soc_dapm_route tx_audio_map[] = {
  1676. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  1677. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  1678. {"TX_AIF3 CAP", NULL, "TX_MCLK"},
  1679. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  1680. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  1681. {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
  1682. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1683. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1684. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1685. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1686. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1687. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1688. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1689. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1690. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1691. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1692. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1693. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1694. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1695. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1696. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1697. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1698. {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1699. {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1700. {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1701. {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1702. {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1703. {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1704. {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1705. {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1706. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  1707. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  1708. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  1709. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  1710. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  1711. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  1712. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  1713. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  1714. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  1715. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  1716. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  1717. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  1718. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  1719. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  1720. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  1721. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  1722. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  1723. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  1724. {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
  1725. {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
  1726. {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
  1727. {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
  1728. {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
  1729. {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
  1730. {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
  1731. {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
  1732. {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
  1733. {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
  1734. {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
  1735. {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
  1736. {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
  1737. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  1738. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  1739. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  1740. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  1741. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  1742. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  1743. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  1744. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  1745. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  1746. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  1747. {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
  1748. {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
  1749. {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
  1750. {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
  1751. {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
  1752. {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
  1753. {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
  1754. {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
  1755. {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
  1756. {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
  1757. {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
  1758. {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
  1759. {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
  1760. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  1761. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  1762. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  1763. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  1764. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  1765. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  1766. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  1767. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  1768. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  1769. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  1770. {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
  1771. {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
  1772. {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
  1773. {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
  1774. {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
  1775. {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
  1776. {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
  1777. {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
  1778. {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
  1779. {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
  1780. {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
  1781. {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
  1782. {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
  1783. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  1784. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  1785. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  1786. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  1787. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  1788. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  1789. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  1790. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  1791. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  1792. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  1793. {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
  1794. {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
  1795. {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
  1796. {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
  1797. {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
  1798. {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
  1799. {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
  1800. {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
  1801. {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
  1802. {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
  1803. {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
  1804. {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
  1805. {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
  1806. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  1807. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  1808. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  1809. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  1810. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  1811. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  1812. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  1813. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  1814. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  1815. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  1816. {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
  1817. {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
  1818. {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
  1819. {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
  1820. {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
  1821. {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
  1822. {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
  1823. {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
  1824. {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
  1825. {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
  1826. {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
  1827. {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
  1828. {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
  1829. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  1830. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  1831. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  1832. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  1833. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  1834. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  1835. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  1836. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  1837. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  1838. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  1839. {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
  1840. {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
  1841. {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
  1842. {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
  1843. {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
  1844. {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
  1845. {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
  1846. {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
  1847. {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
  1848. {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
  1849. {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
  1850. {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
  1851. {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
  1852. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  1853. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  1854. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  1855. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  1856. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  1857. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  1858. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  1859. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  1860. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  1861. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  1862. {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
  1863. {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
  1864. {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
  1865. {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
  1866. {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
  1867. {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
  1868. {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
  1869. {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
  1870. {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
  1871. {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
  1872. {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
  1873. {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
  1874. {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
  1875. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  1876. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  1877. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  1878. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  1879. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  1880. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  1881. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  1882. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  1883. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  1884. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  1885. {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
  1886. {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
  1887. {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
  1888. {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
  1889. {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
  1890. {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
  1891. {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
  1892. {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
  1893. {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
  1894. {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
  1895. {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
  1896. {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
  1897. {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
  1898. };
  1899. static const struct snd_kcontrol_new tx_macro_snd_controls_common[] = {
  1900. SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
  1901. BOLERO_CDC_TX0_TX_VOL_CTL,
  1902. 0, -84, 40, digital_gain),
  1903. SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
  1904. BOLERO_CDC_TX1_TX_VOL_CTL,
  1905. 0, -84, 40, digital_gain),
  1906. SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
  1907. BOLERO_CDC_TX2_TX_VOL_CTL,
  1908. 0, -84, 40, digital_gain),
  1909. SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
  1910. BOLERO_CDC_TX3_TX_VOL_CTL,
  1911. 0, -84, 40, digital_gain),
  1912. SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum,
  1913. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1914. SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum,
  1915. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1916. SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum,
  1917. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1918. SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum,
  1919. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1920. SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
  1921. tx_macro_get_bcs, tx_macro_set_bcs),
  1922. };
  1923. static const struct snd_kcontrol_new tx_macro_snd_controls_v3[] = {
  1924. SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
  1925. BOLERO_CDC_TX4_TX_VOL_CTL,
  1926. 0, -84, 40, digital_gain),
  1927. SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
  1928. BOLERO_CDC_TX5_TX_VOL_CTL,
  1929. 0, -84, 40, digital_gain),
  1930. SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
  1931. BOLERO_CDC_TX6_TX_VOL_CTL,
  1932. 0, -84, 40, digital_gain),
  1933. SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
  1934. BOLERO_CDC_TX7_TX_VOL_CTL,
  1935. 0, -84, 40, digital_gain),
  1936. SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum,
  1937. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1938. SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum,
  1939. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1940. SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum,
  1941. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1942. SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum,
  1943. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1944. };
  1945. static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
  1946. SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
  1947. BOLERO_CDC_TX0_TX_VOL_CTL,
  1948. 0, -84, 40, digital_gain),
  1949. SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
  1950. BOLERO_CDC_TX1_TX_VOL_CTL,
  1951. 0, -84, 40, digital_gain),
  1952. SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
  1953. BOLERO_CDC_TX2_TX_VOL_CTL,
  1954. 0, -84, 40, digital_gain),
  1955. SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
  1956. BOLERO_CDC_TX3_TX_VOL_CTL,
  1957. 0, -84, 40, digital_gain),
  1958. SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
  1959. BOLERO_CDC_TX4_TX_VOL_CTL,
  1960. 0, -84, 40, digital_gain),
  1961. SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
  1962. BOLERO_CDC_TX5_TX_VOL_CTL,
  1963. 0, -84, 40, digital_gain),
  1964. SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
  1965. BOLERO_CDC_TX6_TX_VOL_CTL,
  1966. 0, -84, 40, digital_gain),
  1967. SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
  1968. BOLERO_CDC_TX7_TX_VOL_CTL,
  1969. 0, -84, 40, digital_gain),
  1970. SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum,
  1971. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1972. SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum,
  1973. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1974. SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum,
  1975. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1976. SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum,
  1977. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1978. SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum,
  1979. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1980. SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum,
  1981. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1982. SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum,
  1983. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1984. SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum,
  1985. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  1986. SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
  1987. tx_macro_get_bcs, tx_macro_set_bcs),
  1988. };
  1989. static int tx_macro_register_event_listener(struct snd_soc_component *component,
  1990. bool enable)
  1991. {
  1992. struct device *tx_dev = NULL;
  1993. struct tx_macro_priv *tx_priv = NULL;
  1994. int ret = 0;
  1995. if (!component)
  1996. return -EINVAL;
  1997. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  1998. if (!tx_dev) {
  1999. dev_err(component->dev,
  2000. "%s: null device for macro!\n", __func__);
  2001. return -EINVAL;
  2002. }
  2003. tx_priv = dev_get_drvdata(tx_dev);
  2004. if (!tx_priv) {
  2005. dev_err(component->dev,
  2006. "%s: priv is null for macro!\n", __func__);
  2007. return -EINVAL;
  2008. }
  2009. if (tx_priv->swr_ctrl_data) {
  2010. if (enable) {
  2011. ret = swrm_wcd_notify(
  2012. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2013. SWR_REGISTER_WAKEUP, NULL);
  2014. msm_cdc_pinctrl_set_wakeup_capable(
  2015. tx_priv->tx_swr_gpio_p, false);
  2016. } else {
  2017. msm_cdc_pinctrl_set_wakeup_capable(
  2018. tx_priv->tx_swr_gpio_p, true);
  2019. ret = swrm_wcd_notify(
  2020. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2021. SWR_DEREGISTER_WAKEUP, NULL);
  2022. }
  2023. }
  2024. return ret;
  2025. }
  2026. static int tx_macro_tx_va_mclk_enable(struct tx_macro_priv *tx_priv,
  2027. struct regmap *regmap, int clk_type,
  2028. bool enable)
  2029. {
  2030. int ret = 0, clk_tx_ret = 0;
  2031. dev_dbg(tx_priv->dev,
  2032. "%s: clock type %s, enable: %s tx_mclk_users: %d\n",
  2033. __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
  2034. (enable ? "enable" : "disable"), tx_priv->tx_mclk_users);
  2035. if (enable) {
  2036. if (tx_priv->swr_clk_users == 0) {
  2037. ret = msm_cdc_pinctrl_select_active_state(
  2038. tx_priv->tx_swr_gpio_p);
  2039. if (ret < 0) {
  2040. dev_err_ratelimited(tx_priv->dev,
  2041. "%s: tx swr pinctrl enable failed\n",
  2042. __func__);
  2043. goto exit;
  2044. }
  2045. }
  2046. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2047. TX_CORE_CLK,
  2048. TX_CORE_CLK,
  2049. true);
  2050. if (clk_type == TX_MCLK) {
  2051. ret = tx_macro_mclk_enable(tx_priv, 1);
  2052. if (ret < 0) {
  2053. if (tx_priv->swr_clk_users == 0)
  2054. msm_cdc_pinctrl_select_sleep_state(
  2055. tx_priv->tx_swr_gpio_p);
  2056. dev_err_ratelimited(tx_priv->dev,
  2057. "%s: request clock enable failed\n",
  2058. __func__);
  2059. goto done;
  2060. }
  2061. }
  2062. if (clk_type == VA_MCLK) {
  2063. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2064. TX_CORE_CLK,
  2065. VA_CORE_CLK,
  2066. true);
  2067. if (ret < 0) {
  2068. if (tx_priv->swr_clk_users == 0)
  2069. msm_cdc_pinctrl_select_sleep_state(
  2070. tx_priv->tx_swr_gpio_p);
  2071. dev_err_ratelimited(tx_priv->dev,
  2072. "%s: swr request clk failed\n",
  2073. __func__);
  2074. goto done;
  2075. }
  2076. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  2077. true);
  2078. if (tx_priv->tx_mclk_users == 0) {
  2079. regmap_update_bits(regmap,
  2080. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK,
  2081. 0x01, 0x01);
  2082. regmap_update_bits(regmap,
  2083. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  2084. 0x01, 0x01);
  2085. regmap_update_bits(regmap,
  2086. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  2087. 0x01, 0x01);
  2088. }
  2089. }
  2090. if (tx_priv->swr_clk_users == 0) {
  2091. dev_dbg(tx_priv->dev, "%s: reset_swr: %d\n",
  2092. __func__, tx_priv->reset_swr);
  2093. if (tx_priv->reset_swr)
  2094. regmap_update_bits(regmap,
  2095. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2096. 0x02, 0x02);
  2097. regmap_update_bits(regmap,
  2098. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2099. 0x01, 0x01);
  2100. if (tx_priv->reset_swr)
  2101. regmap_update_bits(regmap,
  2102. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2103. 0x02, 0x00);
  2104. tx_priv->reset_swr = false;
  2105. }
  2106. if (!clk_tx_ret)
  2107. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2108. TX_CORE_CLK,
  2109. TX_CORE_CLK,
  2110. false);
  2111. tx_priv->swr_clk_users++;
  2112. } else {
  2113. if (tx_priv->swr_clk_users <= 0) {
  2114. dev_err_ratelimited(tx_priv->dev,
  2115. "tx swrm clock users already 0\n");
  2116. tx_priv->swr_clk_users = 0;
  2117. return 0;
  2118. }
  2119. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2120. TX_CORE_CLK,
  2121. TX_CORE_CLK,
  2122. true);
  2123. tx_priv->swr_clk_users--;
  2124. if (tx_priv->swr_clk_users == 0)
  2125. regmap_update_bits(regmap,
  2126. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2127. 0x01, 0x00);
  2128. if (clk_type == TX_MCLK)
  2129. tx_macro_mclk_enable(tx_priv, 0);
  2130. if (clk_type == VA_MCLK) {
  2131. if (tx_priv->tx_mclk_users == 0) {
  2132. regmap_update_bits(regmap,
  2133. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  2134. 0x01, 0x00);
  2135. regmap_update_bits(regmap,
  2136. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  2137. 0x01, 0x00);
  2138. }
  2139. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  2140. false);
  2141. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2142. TX_CORE_CLK,
  2143. VA_CORE_CLK,
  2144. false);
  2145. if (ret < 0) {
  2146. dev_err_ratelimited(tx_priv->dev,
  2147. "%s: swr request clk failed\n",
  2148. __func__);
  2149. goto done;
  2150. }
  2151. }
  2152. if (!clk_tx_ret)
  2153. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2154. TX_CORE_CLK,
  2155. TX_CORE_CLK,
  2156. false);
  2157. if (tx_priv->swr_clk_users == 0) {
  2158. ret = msm_cdc_pinctrl_select_sleep_state(
  2159. tx_priv->tx_swr_gpio_p);
  2160. if (ret < 0) {
  2161. dev_err_ratelimited(tx_priv->dev,
  2162. "%s: tx swr pinctrl disable failed\n",
  2163. __func__);
  2164. goto exit;
  2165. }
  2166. }
  2167. }
  2168. return 0;
  2169. done:
  2170. if (!clk_tx_ret)
  2171. bolero_clk_rsc_request_clock(tx_priv->dev,
  2172. TX_CORE_CLK,
  2173. TX_CORE_CLK,
  2174. false);
  2175. exit:
  2176. return ret;
  2177. }
  2178. static int tx_macro_clk_switch(struct snd_soc_component *component)
  2179. {
  2180. struct device *tx_dev = NULL;
  2181. struct tx_macro_priv *tx_priv = NULL;
  2182. int ret = 0;
  2183. if (!component)
  2184. return -EINVAL;
  2185. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  2186. if (!tx_dev) {
  2187. dev_err(component->dev,
  2188. "%s: null device for macro!\n", __func__);
  2189. return -EINVAL;
  2190. }
  2191. tx_priv = dev_get_drvdata(tx_dev);
  2192. if (!tx_priv) {
  2193. dev_err(component->dev,
  2194. "%s: priv is null for macro!\n", __func__);
  2195. return -EINVAL;
  2196. }
  2197. if (tx_priv->swr_ctrl_data) {
  2198. ret = swrm_wcd_notify(
  2199. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2200. SWR_REQ_CLK_SWITCH, NULL);
  2201. }
  2202. return ret;
  2203. }
  2204. static int tx_macro_core_vote(void *handle, bool enable)
  2205. {
  2206. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  2207. if (tx_priv == NULL) {
  2208. pr_err("%s: tx priv data is NULL\n", __func__);
  2209. return -EINVAL;
  2210. }
  2211. if (enable) {
  2212. pm_runtime_get_sync(tx_priv->dev);
  2213. pm_runtime_put_autosuspend(tx_priv->dev);
  2214. pm_runtime_mark_last_busy(tx_priv->dev);
  2215. }
  2216. if (bolero_check_core_votes(tx_priv->dev))
  2217. return 0;
  2218. else
  2219. return -EINVAL;
  2220. }
  2221. static int tx_macro_swrm_clock(void *handle, bool enable)
  2222. {
  2223. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  2224. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  2225. int ret = 0;
  2226. if (regmap == NULL) {
  2227. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  2228. return -EINVAL;
  2229. }
  2230. mutex_lock(&tx_priv->swr_clk_lock);
  2231. dev_dbg(tx_priv->dev,
  2232. "%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n",
  2233. __func__, (enable ? "enable" : "disable"),
  2234. tx_priv->tx_swr_clk_cnt, tx_priv->va_swr_clk_cnt);
  2235. if (enable) {
  2236. pm_runtime_get_sync(tx_priv->dev);
  2237. if (tx_priv->va_swr_clk_cnt && !tx_priv->tx_swr_clk_cnt) {
  2238. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2239. VA_MCLK, enable);
  2240. if (ret) {
  2241. pm_runtime_mark_last_busy(tx_priv->dev);
  2242. pm_runtime_put_autosuspend(tx_priv->dev);
  2243. goto done;
  2244. }
  2245. tx_priv->va_clk_status++;
  2246. } else {
  2247. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2248. TX_MCLK, enable);
  2249. if (ret) {
  2250. pm_runtime_mark_last_busy(tx_priv->dev);
  2251. pm_runtime_put_autosuspend(tx_priv->dev);
  2252. goto done;
  2253. }
  2254. tx_priv->tx_clk_status++;
  2255. }
  2256. pm_runtime_mark_last_busy(tx_priv->dev);
  2257. pm_runtime_put_autosuspend(tx_priv->dev);
  2258. } else {
  2259. if (tx_priv->va_clk_status && !tx_priv->tx_clk_status) {
  2260. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2261. VA_MCLK, enable);
  2262. if (ret)
  2263. goto done;
  2264. --tx_priv->va_clk_status;
  2265. } else if (!tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  2266. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2267. TX_MCLK, enable);
  2268. if (ret)
  2269. goto done;
  2270. --tx_priv->tx_clk_status;
  2271. } else if (tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  2272. if (!tx_priv->va_swr_clk_cnt && tx_priv->tx_swr_clk_cnt) {
  2273. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2274. VA_MCLK, enable);
  2275. if (ret)
  2276. goto done;
  2277. --tx_priv->va_clk_status;
  2278. } else {
  2279. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2280. TX_MCLK, enable);
  2281. if (ret)
  2282. goto done;
  2283. --tx_priv->tx_clk_status;
  2284. }
  2285. } else {
  2286. dev_dbg(tx_priv->dev,
  2287. "%s: Both clocks are disabled\n", __func__);
  2288. }
  2289. }
  2290. dev_dbg(tx_priv->dev,
  2291. "%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n",
  2292. __func__, tx_priv->swr_clk_users, tx_priv->tx_clk_status,
  2293. tx_priv->va_clk_status);
  2294. done:
  2295. mutex_unlock(&tx_priv->swr_clk_lock);
  2296. return ret;
  2297. }
  2298. static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  2299. struct tx_macro_priv *tx_priv)
  2300. {
  2301. u32 div_factor = TX_MACRO_CLK_DIV_2;
  2302. u32 mclk_rate = TX_MACRO_MCLK_FREQ;
  2303. if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  2304. mclk_rate % dmic_sample_rate != 0)
  2305. goto undefined_rate;
  2306. div_factor = mclk_rate / dmic_sample_rate;
  2307. switch (div_factor) {
  2308. case 2:
  2309. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  2310. break;
  2311. case 3:
  2312. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
  2313. break;
  2314. case 4:
  2315. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
  2316. break;
  2317. case 6:
  2318. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
  2319. break;
  2320. case 8:
  2321. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
  2322. break;
  2323. case 16:
  2324. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
  2325. break;
  2326. default:
  2327. /* Any other DIV factor is invalid */
  2328. goto undefined_rate;
  2329. }
  2330. /* Valid dmic DIV factors */
  2331. dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  2332. __func__, div_factor, mclk_rate);
  2333. return dmic_sample_rate;
  2334. undefined_rate:
  2335. dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  2336. __func__, dmic_sample_rate, mclk_rate);
  2337. dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  2338. return dmic_sample_rate;
  2339. }
  2340. static const struct tx_macro_reg_mask_val tx_macro_reg_init[] = {
  2341. {BOLERO_CDC_TX0_TX_PATH_SEC7, 0x3F, 0x02},
  2342. };
  2343. static int tx_macro_init(struct snd_soc_component *component)
  2344. {
  2345. struct snd_soc_dapm_context *dapm =
  2346. snd_soc_component_get_dapm(component);
  2347. int ret = 0, i = 0;
  2348. struct device *tx_dev = NULL;
  2349. struct tx_macro_priv *tx_priv = NULL;
  2350. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  2351. if (!tx_dev) {
  2352. dev_err(component->dev,
  2353. "%s: null device for macro!\n", __func__);
  2354. return -EINVAL;
  2355. }
  2356. tx_priv = dev_get_drvdata(tx_dev);
  2357. if (!tx_priv) {
  2358. dev_err(component->dev,
  2359. "%s: priv is null for macro!\n", __func__);
  2360. return -EINVAL;
  2361. }
  2362. tx_priv->version = bolero_get_version(tx_dev);
  2363. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2364. ret = snd_soc_dapm_new_controls(dapm,
  2365. tx_macro_dapm_widgets_common,
  2366. ARRAY_SIZE(tx_macro_dapm_widgets_common));
  2367. if (ret < 0) {
  2368. dev_err(tx_dev, "%s: Failed to add controls\n",
  2369. __func__);
  2370. return ret;
  2371. }
  2372. if (tx_priv->version == BOLERO_VERSION_2_1)
  2373. ret = snd_soc_dapm_new_controls(dapm,
  2374. tx_macro_dapm_widgets_v2,
  2375. ARRAY_SIZE(tx_macro_dapm_widgets_v2));
  2376. else if (tx_priv->version == BOLERO_VERSION_2_0)
  2377. ret = snd_soc_dapm_new_controls(dapm,
  2378. tx_macro_dapm_widgets_v3,
  2379. ARRAY_SIZE(tx_macro_dapm_widgets_v3));
  2380. if (ret < 0) {
  2381. dev_err(tx_dev, "%s: Failed to add controls\n",
  2382. __func__);
  2383. return ret;
  2384. }
  2385. } else {
  2386. ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
  2387. ARRAY_SIZE(tx_macro_dapm_widgets));
  2388. if (ret < 0) {
  2389. dev_err(tx_dev, "%s: Failed to add controls\n",
  2390. __func__);
  2391. return ret;
  2392. }
  2393. }
  2394. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2395. ret = snd_soc_dapm_add_routes(dapm,
  2396. tx_audio_map_common,
  2397. ARRAY_SIZE(tx_audio_map_common));
  2398. if (ret < 0) {
  2399. dev_err(tx_dev, "%s: Failed to add routes\n",
  2400. __func__);
  2401. return ret;
  2402. }
  2403. if (tx_priv->version == BOLERO_VERSION_2_0)
  2404. ret = snd_soc_dapm_add_routes(dapm,
  2405. tx_audio_map_v3,
  2406. ARRAY_SIZE(tx_audio_map_v3));
  2407. if (ret < 0) {
  2408. dev_err(tx_dev, "%s: Failed to add routes\n",
  2409. __func__);
  2410. return ret;
  2411. }
  2412. } else {
  2413. ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
  2414. ARRAY_SIZE(tx_audio_map));
  2415. if (ret < 0) {
  2416. dev_err(tx_dev, "%s: Failed to add routes\n",
  2417. __func__);
  2418. return ret;
  2419. }
  2420. }
  2421. ret = snd_soc_dapm_new_widgets(dapm->card);
  2422. if (ret < 0) {
  2423. dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
  2424. return ret;
  2425. }
  2426. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2427. ret = snd_soc_add_component_controls(component,
  2428. tx_macro_snd_controls_common,
  2429. ARRAY_SIZE(tx_macro_snd_controls_common));
  2430. if (ret < 0) {
  2431. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2432. __func__);
  2433. return ret;
  2434. }
  2435. if (tx_priv->version == BOLERO_VERSION_2_0)
  2436. ret = snd_soc_add_component_controls(component,
  2437. tx_macro_snd_controls_v3,
  2438. ARRAY_SIZE(tx_macro_snd_controls_v3));
  2439. if (ret < 0) {
  2440. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2441. __func__);
  2442. return ret;
  2443. }
  2444. } else {
  2445. ret = snd_soc_add_component_controls(component,
  2446. tx_macro_snd_controls,
  2447. ARRAY_SIZE(tx_macro_snd_controls));
  2448. if (ret < 0) {
  2449. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2450. __func__);
  2451. return ret;
  2452. }
  2453. }
  2454. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture");
  2455. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture");
  2456. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF3 Capture");
  2457. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2458. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC0");
  2459. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC1");
  2460. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC2");
  2461. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC3");
  2462. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC4");
  2463. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC5");
  2464. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC6");
  2465. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC7");
  2466. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC8");
  2467. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC9");
  2468. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC10");
  2469. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC11");
  2470. } else {
  2471. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0");
  2472. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1");
  2473. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2");
  2474. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3");
  2475. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC0");
  2476. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC1");
  2477. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC2");
  2478. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC3");
  2479. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC4");
  2480. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC5");
  2481. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC6");
  2482. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC7");
  2483. }
  2484. snd_soc_dapm_sync(dapm);
  2485. for (i = 0; i < NUM_DECIMATORS; i++) {
  2486. tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
  2487. tx_priv->tx_hpf_work[i].decimator = i;
  2488. INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
  2489. tx_macro_tx_hpf_corner_freq_callback);
  2490. }
  2491. for (i = 0; i < NUM_DECIMATORS; i++) {
  2492. tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
  2493. tx_priv->tx_mute_dwork[i].decimator = i;
  2494. INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
  2495. tx_macro_mute_update_callback);
  2496. }
  2497. tx_priv->component = component;
  2498. for (i = 0; i < ARRAY_SIZE(tx_macro_reg_init); i++)
  2499. snd_soc_component_update_bits(component,
  2500. tx_macro_reg_init[i].reg,
  2501. tx_macro_reg_init[i].mask,
  2502. tx_macro_reg_init[i].val);
  2503. return 0;
  2504. }
  2505. static int tx_macro_deinit(struct snd_soc_component *component)
  2506. {
  2507. struct device *tx_dev = NULL;
  2508. struct tx_macro_priv *tx_priv = NULL;
  2509. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  2510. return -EINVAL;
  2511. tx_priv->component = NULL;
  2512. return 0;
  2513. }
  2514. static void tx_macro_add_child_devices(struct work_struct *work)
  2515. {
  2516. struct tx_macro_priv *tx_priv = NULL;
  2517. struct platform_device *pdev = NULL;
  2518. struct device_node *node = NULL;
  2519. struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  2520. int ret = 0;
  2521. u16 count = 0, ctrl_num = 0;
  2522. struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
  2523. char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
  2524. bool tx_swr_master_node = false;
  2525. tx_priv = container_of(work, struct tx_macro_priv,
  2526. tx_macro_add_child_devices_work);
  2527. if (!tx_priv) {
  2528. pr_err("%s: Memory for tx_priv does not exist\n",
  2529. __func__);
  2530. return;
  2531. }
  2532. if (!tx_priv->dev) {
  2533. pr_err("%s: tx dev does not exist\n", __func__);
  2534. return;
  2535. }
  2536. if (!tx_priv->dev->of_node) {
  2537. dev_err(tx_priv->dev,
  2538. "%s: DT node for tx_priv does not exist\n", __func__);
  2539. return;
  2540. }
  2541. platdata = &tx_priv->swr_plat_data;
  2542. tx_priv->child_count = 0;
  2543. for_each_available_child_of_node(tx_priv->dev->of_node, node) {
  2544. tx_swr_master_node = false;
  2545. if (strnstr(node->name, "tx_swr_master",
  2546. strlen("tx_swr_master")) != NULL)
  2547. tx_swr_master_node = true;
  2548. if (tx_swr_master_node)
  2549. strlcpy(plat_dev_name, "tx_swr_ctrl",
  2550. (TX_MACRO_SWR_STRING_LEN - 1));
  2551. else
  2552. strlcpy(plat_dev_name, node->name,
  2553. (TX_MACRO_SWR_STRING_LEN - 1));
  2554. pdev = platform_device_alloc(plat_dev_name, -1);
  2555. if (!pdev) {
  2556. dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
  2557. __func__);
  2558. ret = -ENOMEM;
  2559. goto err;
  2560. }
  2561. pdev->dev.parent = tx_priv->dev;
  2562. pdev->dev.of_node = node;
  2563. if (tx_swr_master_node) {
  2564. ret = platform_device_add_data(pdev, platdata,
  2565. sizeof(*platdata));
  2566. if (ret) {
  2567. dev_err(&pdev->dev,
  2568. "%s: cannot add plat data ctrl:%d\n",
  2569. __func__, ctrl_num);
  2570. goto fail_pdev_add;
  2571. }
  2572. }
  2573. ret = platform_device_add(pdev);
  2574. if (ret) {
  2575. dev_err(&pdev->dev,
  2576. "%s: Cannot add platform device\n",
  2577. __func__);
  2578. goto fail_pdev_add;
  2579. }
  2580. if (tx_swr_master_node) {
  2581. temp = krealloc(swr_ctrl_data,
  2582. (ctrl_num + 1) * sizeof(
  2583. struct tx_macro_swr_ctrl_data),
  2584. GFP_KERNEL);
  2585. if (!temp) {
  2586. ret = -ENOMEM;
  2587. goto fail_pdev_add;
  2588. }
  2589. swr_ctrl_data = temp;
  2590. swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
  2591. ctrl_num++;
  2592. dev_dbg(&pdev->dev,
  2593. "%s: Added soundwire ctrl device(s)\n",
  2594. __func__);
  2595. tx_priv->swr_ctrl_data = swr_ctrl_data;
  2596. }
  2597. if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
  2598. tx_priv->pdev_child_devices[
  2599. tx_priv->child_count++] = pdev;
  2600. else
  2601. goto err;
  2602. }
  2603. return;
  2604. fail_pdev_add:
  2605. for (count = 0; count < tx_priv->child_count; count++)
  2606. platform_device_put(tx_priv->pdev_child_devices[count]);
  2607. err:
  2608. return;
  2609. }
  2610. static int tx_macro_set_port_map(struct snd_soc_component *component,
  2611. u32 usecase, u32 size, void *data)
  2612. {
  2613. struct device *tx_dev = NULL;
  2614. struct tx_macro_priv *tx_priv = NULL;
  2615. struct swrm_port_config port_cfg;
  2616. int ret = 0;
  2617. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  2618. return -EINVAL;
  2619. memset(&port_cfg, 0, sizeof(port_cfg));
  2620. port_cfg.uc = usecase;
  2621. port_cfg.size = size;
  2622. port_cfg.params = data;
  2623. if (tx_priv->swr_ctrl_data)
  2624. ret = swrm_wcd_notify(
  2625. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2626. SWR_SET_PORT_MAP, &port_cfg);
  2627. return ret;
  2628. }
  2629. static void tx_macro_init_ops(struct macro_ops *ops,
  2630. char __iomem *tx_io_base)
  2631. {
  2632. memset(ops, 0, sizeof(struct macro_ops));
  2633. ops->init = tx_macro_init;
  2634. ops->exit = tx_macro_deinit;
  2635. ops->io_base = tx_io_base;
  2636. ops->dai_ptr = tx_macro_dai;
  2637. ops->num_dais = ARRAY_SIZE(tx_macro_dai);
  2638. ops->event_handler = tx_macro_event_handler;
  2639. ops->reg_wake_irq = tx_macro_reg_wake_irq;
  2640. ops->set_port_map = tx_macro_set_port_map;
  2641. ops->clk_switch = tx_macro_clk_switch;
  2642. ops->reg_evt_listener = tx_macro_register_event_listener;
  2643. }
  2644. static int tx_macro_probe(struct platform_device *pdev)
  2645. {
  2646. struct macro_ops ops = {0};
  2647. struct tx_macro_priv *tx_priv = NULL;
  2648. u32 tx_base_addr = 0, sample_rate = 0;
  2649. char __iomem *tx_io_base = NULL;
  2650. int ret = 0;
  2651. const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
  2652. u32 is_used_tx_swr_gpio = 1;
  2653. const char *is_used_tx_swr_gpio_dt = "qcom,is-used-swr-gpio";
  2654. tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
  2655. GFP_KERNEL);
  2656. if (!tx_priv)
  2657. return -ENOMEM;
  2658. platform_set_drvdata(pdev, tx_priv);
  2659. tx_priv->dev = &pdev->dev;
  2660. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  2661. &tx_base_addr);
  2662. if (ret) {
  2663. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2664. __func__, "reg");
  2665. return ret;
  2666. }
  2667. dev_set_drvdata(&pdev->dev, tx_priv);
  2668. if (of_find_property(pdev->dev.of_node, is_used_tx_swr_gpio_dt,
  2669. NULL)) {
  2670. ret = of_property_read_u32(pdev->dev.of_node,
  2671. is_used_tx_swr_gpio_dt,
  2672. &is_used_tx_swr_gpio);
  2673. if (ret) {
  2674. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  2675. __func__, is_used_tx_swr_gpio_dt);
  2676. is_used_tx_swr_gpio = 1;
  2677. }
  2678. }
  2679. tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2680. "qcom,tx-swr-gpios", 0);
  2681. if (!tx_priv->tx_swr_gpio_p && is_used_tx_swr_gpio) {
  2682. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  2683. __func__);
  2684. return -EINVAL;
  2685. }
  2686. if (msm_cdc_pinctrl_get_state(tx_priv->tx_swr_gpio_p) < 0 &&
  2687. is_used_tx_swr_gpio) {
  2688. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  2689. __func__);
  2690. return -EPROBE_DEFER;
  2691. }
  2692. tx_io_base = devm_ioremap(&pdev->dev,
  2693. tx_base_addr, TX_MACRO_MAX_OFFSET);
  2694. if (!tx_io_base) {
  2695. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  2696. return -ENOMEM;
  2697. }
  2698. tx_priv->tx_io_base = tx_io_base;
  2699. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  2700. &sample_rate);
  2701. if (ret) {
  2702. dev_err(&pdev->dev,
  2703. "%s: could not find sample_rate entry in dt\n",
  2704. __func__);
  2705. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  2706. } else {
  2707. if (tx_macro_validate_dmic_sample_rate(
  2708. sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  2709. return -EINVAL;
  2710. }
  2711. if (is_used_tx_swr_gpio) {
  2712. tx_priv->reset_swr = true;
  2713. INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
  2714. tx_macro_add_child_devices);
  2715. tx_priv->swr_plat_data.handle = (void *) tx_priv;
  2716. tx_priv->swr_plat_data.read = NULL;
  2717. tx_priv->swr_plat_data.write = NULL;
  2718. tx_priv->swr_plat_data.bulk_write = NULL;
  2719. tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
  2720. tx_priv->swr_plat_data.core_vote = tx_macro_core_vote;
  2721. tx_priv->swr_plat_data.handle_irq = NULL;
  2722. mutex_init(&tx_priv->swr_clk_lock);
  2723. }
  2724. tx_priv->is_used_tx_swr_gpio = is_used_tx_swr_gpio;
  2725. mutex_init(&tx_priv->mclk_lock);
  2726. tx_macro_init_ops(&ops, tx_io_base);
  2727. ops.clk_id_req = TX_CORE_CLK;
  2728. ops.default_clk_id = TX_CORE_CLK;
  2729. ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
  2730. if (ret) {
  2731. dev_err(&pdev->dev,
  2732. "%s: register macro failed\n", __func__);
  2733. goto err_reg_macro;
  2734. }
  2735. if (is_used_tx_swr_gpio)
  2736. schedule_work(&tx_priv->tx_macro_add_child_devices_work);
  2737. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  2738. pm_runtime_use_autosuspend(&pdev->dev);
  2739. pm_runtime_set_suspended(&pdev->dev);
  2740. pm_suspend_ignore_children(&pdev->dev, true);
  2741. pm_runtime_enable(&pdev->dev);
  2742. return 0;
  2743. err_reg_macro:
  2744. mutex_destroy(&tx_priv->mclk_lock);
  2745. if (is_used_tx_swr_gpio)
  2746. mutex_destroy(&tx_priv->swr_clk_lock);
  2747. return ret;
  2748. }
  2749. static int tx_macro_remove(struct platform_device *pdev)
  2750. {
  2751. struct tx_macro_priv *tx_priv = NULL;
  2752. u16 count = 0;
  2753. tx_priv = platform_get_drvdata(pdev);
  2754. if (!tx_priv)
  2755. return -EINVAL;
  2756. if (tx_priv->is_used_tx_swr_gpio) {
  2757. if (tx_priv->swr_ctrl_data)
  2758. kfree(tx_priv->swr_ctrl_data);
  2759. for (count = 0; count < tx_priv->child_count &&
  2760. count < TX_MACRO_CHILD_DEVICES_MAX; count++)
  2761. platform_device_unregister(
  2762. tx_priv->pdev_child_devices[count]);
  2763. }
  2764. pm_runtime_disable(&pdev->dev);
  2765. pm_runtime_set_suspended(&pdev->dev);
  2766. mutex_destroy(&tx_priv->mclk_lock);
  2767. if (tx_priv->is_used_tx_swr_gpio)
  2768. mutex_destroy(&tx_priv->swr_clk_lock);
  2769. bolero_unregister_macro(&pdev->dev, TX_MACRO);
  2770. return 0;
  2771. }
  2772. static const struct of_device_id tx_macro_dt_match[] = {
  2773. {.compatible = "qcom,tx-macro"},
  2774. {}
  2775. };
  2776. static const struct dev_pm_ops bolero_dev_pm_ops = {
  2777. SET_RUNTIME_PM_OPS(
  2778. bolero_runtime_suspend,
  2779. bolero_runtime_resume,
  2780. NULL
  2781. )
  2782. };
  2783. static struct platform_driver tx_macro_driver = {
  2784. .driver = {
  2785. .name = "tx_macro",
  2786. .owner = THIS_MODULE,
  2787. .pm = &bolero_dev_pm_ops,
  2788. .of_match_table = tx_macro_dt_match,
  2789. .suppress_bind_attrs = true,
  2790. },
  2791. .probe = tx_macro_probe,
  2792. .remove = tx_macro_remove,
  2793. };
  2794. module_platform_driver(tx_macro_driver);
  2795. MODULE_DESCRIPTION("TX macro driver");
  2796. MODULE_LICENSE("GPL v2");