tx-macro.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187
  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_TX_UNMUTE_DELAY_MS 40
  39. static int tx_unmute_delay = TX_MACRO_TX_UNMUTE_DELAY_MS;
  40. module_param(tx_unmute_delay, int, 0664);
  41. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  42. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  43. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  44. struct snd_pcm_hw_params *params,
  45. struct snd_soc_dai *dai);
  46. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  47. unsigned int *tx_num, unsigned int *tx_slot,
  48. unsigned int *rx_num, unsigned int *rx_slot);
  49. #define TX_MACRO_SWR_STRING_LEN 80
  50. #define TX_MACRO_CHILD_DEVICES_MAX 3
  51. /* Hold instance to soundwire platform device */
  52. struct tx_macro_swr_ctrl_data {
  53. struct platform_device *tx_swr_pdev;
  54. };
  55. struct tx_macro_swr_ctrl_platform_data {
  56. void *handle; /* holds codec private data */
  57. int (*read)(void *handle, int reg);
  58. int (*write)(void *handle, int reg, int val);
  59. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  60. int (*clk)(void *handle, bool enable);
  61. int (*handle_irq)(void *handle,
  62. irqreturn_t (*swrm_irq_handler)(int irq,
  63. void *data),
  64. void *swrm_handle,
  65. int action);
  66. };
  67. enum {
  68. TX_MACRO_AIF_INVALID = 0,
  69. TX_MACRO_AIF1_CAP,
  70. TX_MACRO_AIF2_CAP,
  71. TX_MACRO_AIF3_CAP,
  72. TX_MACRO_MAX_DAIS
  73. };
  74. enum {
  75. TX_MACRO_DEC0,
  76. TX_MACRO_DEC1,
  77. TX_MACRO_DEC2,
  78. TX_MACRO_DEC3,
  79. TX_MACRO_DEC4,
  80. TX_MACRO_DEC5,
  81. TX_MACRO_DEC6,
  82. TX_MACRO_DEC7,
  83. TX_MACRO_DEC_MAX,
  84. };
  85. enum {
  86. TX_MACRO_CLK_DIV_2,
  87. TX_MACRO_CLK_DIV_3,
  88. TX_MACRO_CLK_DIV_4,
  89. TX_MACRO_CLK_DIV_6,
  90. TX_MACRO_CLK_DIV_8,
  91. TX_MACRO_CLK_DIV_16,
  92. };
  93. enum {
  94. MSM_DMIC,
  95. SWR_MIC,
  96. ANC_FB_TUNE1
  97. };
  98. enum {
  99. TX_MCLK,
  100. VA_MCLK,
  101. };
  102. struct tx_mute_work {
  103. struct tx_macro_priv *tx_priv;
  104. u32 decimator;
  105. struct delayed_work dwork;
  106. };
  107. struct hpf_work {
  108. struct tx_macro_priv *tx_priv;
  109. u8 decimator;
  110. u8 hpf_cut_off_freq;
  111. struct delayed_work dwork;
  112. };
  113. struct tx_macro_priv {
  114. struct device *dev;
  115. bool dec_active[NUM_DECIMATORS];
  116. int tx_mclk_users;
  117. int swr_clk_users;
  118. bool dapm_mclk_enable;
  119. bool reset_swr;
  120. struct mutex mclk_lock;
  121. struct mutex swr_clk_lock;
  122. struct snd_soc_component *component;
  123. struct device_node *tx_swr_gpio_p;
  124. struct tx_macro_swr_ctrl_data *swr_ctrl_data;
  125. struct tx_macro_swr_ctrl_platform_data swr_plat_data;
  126. struct work_struct tx_macro_add_child_devices_work;
  127. struct hpf_work tx_hpf_work[NUM_DECIMATORS];
  128. struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS];
  129. s32 dmic_0_1_clk_cnt;
  130. s32 dmic_2_3_clk_cnt;
  131. s32 dmic_4_5_clk_cnt;
  132. s32 dmic_6_7_clk_cnt;
  133. u16 dmic_clk_div;
  134. unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
  135. unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS];
  136. char __iomem *tx_io_base;
  137. struct platform_device *pdev_child_devices
  138. [TX_MACRO_CHILD_DEVICES_MAX];
  139. int child_count;
  140. int tx_swr_clk_cnt;
  141. int va_swr_clk_cnt;
  142. int va_clk_status;
  143. int tx_clk_status;
  144. };
  145. static bool tx_macro_get_data(struct snd_soc_component *component,
  146. struct device **tx_dev,
  147. struct tx_macro_priv **tx_priv,
  148. const char *func_name)
  149. {
  150. *tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  151. if (!(*tx_dev)) {
  152. dev_err(component->dev,
  153. "%s: null device for macro!\n", func_name);
  154. return false;
  155. }
  156. *tx_priv = dev_get_drvdata((*tx_dev));
  157. if (!(*tx_priv)) {
  158. dev_err(component->dev,
  159. "%s: priv is null for macro!\n", func_name);
  160. return false;
  161. }
  162. if (!(*tx_priv)->component) {
  163. dev_err(component->dev,
  164. "%s: tx_priv->component not initialized!\n", func_name);
  165. return false;
  166. }
  167. return true;
  168. }
  169. static int tx_macro_mclk_enable(struct tx_macro_priv *tx_priv,
  170. bool mclk_enable)
  171. {
  172. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  173. int ret = 0;
  174. if (regmap == NULL) {
  175. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  176. return -EINVAL;
  177. }
  178. dev_dbg(tx_priv->dev, "%s: mclk_enable = %u,clk_users= %d\n",
  179. __func__, mclk_enable, tx_priv->tx_mclk_users);
  180. mutex_lock(&tx_priv->mclk_lock);
  181. if (mclk_enable) {
  182. if (tx_priv->tx_mclk_users == 0) {
  183. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  184. TX_CORE_CLK,
  185. TX_CORE_CLK,
  186. true);
  187. if (ret < 0) {
  188. dev_err_ratelimited(tx_priv->dev,
  189. "%s: request clock enable failed\n",
  190. __func__);
  191. goto exit;
  192. }
  193. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  194. true);
  195. regcache_mark_dirty(regmap);
  196. regcache_sync_region(regmap,
  197. TX_START_OFFSET,
  198. TX_MAX_OFFSET);
  199. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  200. regmap_update_bits(regmap,
  201. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01);
  202. regmap_update_bits(regmap,
  203. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  204. 0x01, 0x01);
  205. regmap_update_bits(regmap,
  206. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  207. 0x01, 0x01);
  208. }
  209. tx_priv->tx_mclk_users++;
  210. } else {
  211. if (tx_priv->tx_mclk_users <= 0) {
  212. dev_err(tx_priv->dev, "%s: clock already disabled\n",
  213. __func__);
  214. tx_priv->tx_mclk_users = 0;
  215. goto exit;
  216. }
  217. tx_priv->tx_mclk_users--;
  218. if (tx_priv->tx_mclk_users == 0) {
  219. regmap_update_bits(regmap,
  220. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  221. 0x01, 0x00);
  222. regmap_update_bits(regmap,
  223. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  224. 0x01, 0x00);
  225. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  226. false);
  227. bolero_clk_rsc_request_clock(tx_priv->dev,
  228. TX_CORE_CLK,
  229. TX_CORE_CLK,
  230. false);
  231. }
  232. }
  233. exit:
  234. mutex_unlock(&tx_priv->mclk_lock);
  235. return ret;
  236. }
  237. static int tx_macro_va_swr_clk_event(struct snd_soc_dapm_widget *w,
  238. struct snd_kcontrol *kcontrol, int event)
  239. {
  240. struct device *tx_dev = NULL;
  241. struct tx_macro_priv *tx_priv = NULL;
  242. struct snd_soc_component *component =
  243. snd_soc_dapm_to_component(w->dapm);
  244. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  245. return -EINVAL;
  246. if (SND_SOC_DAPM_EVENT_ON(event))
  247. ++tx_priv->va_swr_clk_cnt;
  248. if (SND_SOC_DAPM_EVENT_OFF(event))
  249. --tx_priv->va_swr_clk_cnt;
  250. return 0;
  251. }
  252. static int tx_macro_tx_swr_clk_event(struct snd_soc_dapm_widget *w,
  253. struct snd_kcontrol *kcontrol, int event)
  254. {
  255. struct device *tx_dev = NULL;
  256. struct tx_macro_priv *tx_priv = NULL;
  257. struct snd_soc_component *component =
  258. snd_soc_dapm_to_component(w->dapm);
  259. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  260. return -EINVAL;
  261. if (SND_SOC_DAPM_EVENT_ON(event))
  262. ++tx_priv->tx_swr_clk_cnt;
  263. if (SND_SOC_DAPM_EVENT_OFF(event))
  264. --tx_priv->tx_swr_clk_cnt;
  265. return 0;
  266. }
  267. static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  268. struct snd_kcontrol *kcontrol, int event)
  269. {
  270. struct snd_soc_component *component =
  271. snd_soc_dapm_to_component(w->dapm);
  272. int ret = 0;
  273. struct device *tx_dev = NULL;
  274. struct tx_macro_priv *tx_priv = NULL;
  275. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  276. return -EINVAL;
  277. dev_dbg(tx_dev, "%s: event = %d\n", __func__, event);
  278. switch (event) {
  279. case SND_SOC_DAPM_PRE_PMU:
  280. ret = tx_macro_mclk_enable(tx_priv, 1);
  281. if (ret)
  282. tx_priv->dapm_mclk_enable = false;
  283. else
  284. tx_priv->dapm_mclk_enable = true;
  285. break;
  286. case SND_SOC_DAPM_POST_PMD:
  287. if (tx_priv->dapm_mclk_enable)
  288. ret = tx_macro_mclk_enable(tx_priv, 0);
  289. break;
  290. default:
  291. dev_err(tx_priv->dev,
  292. "%s: invalid DAPM event %d\n", __func__, event);
  293. ret = -EINVAL;
  294. }
  295. return ret;
  296. }
  297. static int tx_macro_event_handler(struct snd_soc_component *component,
  298. u16 event, u32 data)
  299. {
  300. struct device *tx_dev = NULL;
  301. struct tx_macro_priv *tx_priv = NULL;
  302. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  303. return -EINVAL;
  304. switch (event) {
  305. case BOLERO_MACRO_EVT_SSR_DOWN:
  306. if (tx_priv->swr_ctrl_data) {
  307. swrm_wcd_notify(
  308. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  309. SWR_DEVICE_DOWN, NULL);
  310. swrm_wcd_notify(
  311. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  312. SWR_DEVICE_SSR_DOWN, NULL);
  313. }
  314. if (!pm_runtime_status_suspended(tx_dev))
  315. bolero_runtime_suspend(tx_dev);
  316. break;
  317. case BOLERO_MACRO_EVT_SSR_UP:
  318. /* reset swr after ssr/pdr */
  319. tx_priv->reset_swr = true;
  320. if (tx_priv->swr_ctrl_data)
  321. swrm_wcd_notify(
  322. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  323. SWR_DEVICE_SSR_UP, NULL);
  324. break;
  325. case BOLERO_MACRO_EVT_CLK_RESET:
  326. bolero_rsc_clk_reset(tx_dev, TX_CORE_CLK);
  327. break;
  328. }
  329. return 0;
  330. }
  331. static int tx_macro_reg_wake_irq(struct snd_soc_component *component,
  332. u32 data)
  333. {
  334. struct device *tx_dev = NULL;
  335. struct tx_macro_priv *tx_priv = NULL;
  336. u32 ipc_wakeup = data;
  337. int ret = 0;
  338. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  339. return -EINVAL;
  340. if (tx_priv->swr_ctrl_data)
  341. ret = swrm_wcd_notify(
  342. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  343. SWR_REGISTER_WAKE_IRQ, &ipc_wakeup);
  344. return ret;
  345. }
  346. static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
  347. {
  348. struct delayed_work *hpf_delayed_work = NULL;
  349. struct hpf_work *hpf_work = NULL;
  350. struct tx_macro_priv *tx_priv = NULL;
  351. struct snd_soc_component *component = NULL;
  352. u16 dec_cfg_reg = 0, hpf_gate_reg = 0;
  353. u8 hpf_cut_off_freq = 0;
  354. u16 adc_mux_reg = 0, adc_n = 0, adc_reg = 0;
  355. hpf_delayed_work = to_delayed_work(work);
  356. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  357. tx_priv = hpf_work->tx_priv;
  358. component = tx_priv->component;
  359. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  360. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  361. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  362. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  363. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  364. dev_dbg(component->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  365. __func__, hpf_work->decimator, hpf_cut_off_freq);
  366. adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  367. TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  368. if (snd_soc_component_read32(component, adc_mux_reg) & SWR_MIC) {
  369. adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  370. TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  371. adc_n = snd_soc_component_read32(component, adc_reg) &
  372. TX_MACRO_SWR_MIC_MUX_SEL_MASK;
  373. if (adc_n >= BOLERO_ADC_MAX)
  374. goto tx_hpf_set;
  375. /* analog mic clear TX hold */
  376. bolero_clear_amic_tx_hold(component->dev, adc_n);
  377. }
  378. tx_hpf_set:
  379. snd_soc_component_update_bits(component,
  380. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  381. hpf_cut_off_freq << 5);
  382. snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x02);
  383. /* Minimum 1 clk cycle delay is required as per HW spec */
  384. usleep_range(1000, 1010);
  385. snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x01);
  386. }
  387. static void tx_macro_mute_update_callback(struct work_struct *work)
  388. {
  389. struct tx_mute_work *tx_mute_dwork = NULL;
  390. struct snd_soc_component *component = NULL;
  391. struct tx_macro_priv *tx_priv = NULL;
  392. struct delayed_work *delayed_work = NULL;
  393. u16 tx_vol_ctl_reg = 0;
  394. u8 decimator = 0;
  395. delayed_work = to_delayed_work(work);
  396. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  397. tx_priv = tx_mute_dwork->tx_priv;
  398. component = tx_priv->component;
  399. decimator = tx_mute_dwork->decimator;
  400. tx_vol_ctl_reg =
  401. BOLERO_CDC_TX0_TX_PATH_CTL +
  402. TX_MACRO_TX_PATH_OFFSET * decimator;
  403. snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00);
  404. dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n",
  405. __func__, decimator);
  406. }
  407. static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  408. struct snd_ctl_elem_value *ucontrol)
  409. {
  410. struct snd_soc_dapm_widget *widget =
  411. snd_soc_dapm_kcontrol_widget(kcontrol);
  412. struct snd_soc_component *component =
  413. snd_soc_dapm_to_component(widget->dapm);
  414. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  415. unsigned int val = 0;
  416. u16 mic_sel_reg = 0;
  417. val = ucontrol->value.enumerated.item[0];
  418. if (val > e->items - 1)
  419. return -EINVAL;
  420. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  421. widget->name, val);
  422. switch (e->reg) {
  423. case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
  424. mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
  425. break;
  426. case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
  427. mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
  428. break;
  429. case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
  430. mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
  431. break;
  432. case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
  433. mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
  434. break;
  435. case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0:
  436. mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0;
  437. break;
  438. case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0:
  439. mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0;
  440. break;
  441. case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0:
  442. mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0;
  443. break;
  444. case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0:
  445. mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0;
  446. break;
  447. default:
  448. dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
  449. __func__, e->reg);
  450. return -EINVAL;
  451. }
  452. if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
  453. if (val != 0) {
  454. if (val < 5)
  455. snd_soc_component_update_bits(component,
  456. mic_sel_reg,
  457. 1 << 7, 0x0 << 7);
  458. else
  459. snd_soc_component_update_bits(component,
  460. mic_sel_reg,
  461. 1 << 7, 0x1 << 7);
  462. }
  463. } else {
  464. /* DMIC selected */
  465. if (val != 0)
  466. snd_soc_component_update_bits(component, mic_sel_reg,
  467. 1 << 7, 1 << 7);
  468. }
  469. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  470. }
  471. static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  472. struct snd_ctl_elem_value *ucontrol)
  473. {
  474. struct snd_soc_dapm_widget *widget =
  475. snd_soc_dapm_kcontrol_widget(kcontrol);
  476. struct snd_soc_component *component =
  477. snd_soc_dapm_to_component(widget->dapm);
  478. struct soc_multi_mixer_control *mixer =
  479. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  480. u32 dai_id = widget->shift;
  481. u32 dec_id = mixer->shift;
  482. struct device *tx_dev = NULL;
  483. struct tx_macro_priv *tx_priv = NULL;
  484. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  485. return -EINVAL;
  486. if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id]))
  487. ucontrol->value.integer.value[0] = 1;
  488. else
  489. ucontrol->value.integer.value[0] = 0;
  490. return 0;
  491. }
  492. static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  493. struct snd_ctl_elem_value *ucontrol)
  494. {
  495. struct snd_soc_dapm_widget *widget =
  496. snd_soc_dapm_kcontrol_widget(kcontrol);
  497. struct snd_soc_component *component =
  498. snd_soc_dapm_to_component(widget->dapm);
  499. struct snd_soc_dapm_update *update = NULL;
  500. struct soc_multi_mixer_control *mixer =
  501. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  502. u32 dai_id = widget->shift;
  503. u32 dec_id = mixer->shift;
  504. u32 enable = ucontrol->value.integer.value[0];
  505. struct device *tx_dev = NULL;
  506. struct tx_macro_priv *tx_priv = NULL;
  507. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  508. return -EINVAL;
  509. if (enable) {
  510. set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  511. tx_priv->active_ch_cnt[dai_id]++;
  512. } else {
  513. tx_priv->active_ch_cnt[dai_id]--;
  514. clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  515. }
  516. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  517. return 0;
  518. }
  519. static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  520. struct snd_kcontrol *kcontrol, int event)
  521. {
  522. struct snd_soc_component *component =
  523. snd_soc_dapm_to_component(w->dapm);
  524. u8 dmic_clk_en = 0x01;
  525. u16 dmic_clk_reg = 0;
  526. s32 *dmic_clk_cnt = NULL;
  527. unsigned int dmic = 0;
  528. int ret = 0;
  529. char *wname = NULL;
  530. struct device *tx_dev = NULL;
  531. struct tx_macro_priv *tx_priv = NULL;
  532. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  533. return -EINVAL;
  534. wname = strpbrk(w->name, "01234567");
  535. if (!wname) {
  536. dev_err(component->dev, "%s: widget not found\n", __func__);
  537. return -EINVAL;
  538. }
  539. ret = kstrtouint(wname, 10, &dmic);
  540. if (ret < 0) {
  541. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  542. __func__);
  543. return -EINVAL;
  544. }
  545. switch (dmic) {
  546. case 0:
  547. case 1:
  548. dmic_clk_cnt = &(tx_priv->dmic_0_1_clk_cnt);
  549. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC0_CTL;
  550. break;
  551. case 2:
  552. case 3:
  553. dmic_clk_cnt = &(tx_priv->dmic_2_3_clk_cnt);
  554. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC1_CTL;
  555. break;
  556. case 4:
  557. case 5:
  558. dmic_clk_cnt = &(tx_priv->dmic_4_5_clk_cnt);
  559. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC2_CTL;
  560. break;
  561. case 6:
  562. case 7:
  563. dmic_clk_cnt = &(tx_priv->dmic_6_7_clk_cnt);
  564. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC3_CTL;
  565. break;
  566. default:
  567. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  568. __func__);
  569. return -EINVAL;
  570. }
  571. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  572. __func__, event, dmic, *dmic_clk_cnt);
  573. switch (event) {
  574. case SND_SOC_DAPM_PRE_PMU:
  575. (*dmic_clk_cnt)++;
  576. if (*dmic_clk_cnt == 1) {
  577. snd_soc_component_update_bits(component,
  578. BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  579. 0x80, 0x00);
  580. snd_soc_component_update_bits(component, dmic_clk_reg,
  581. 0x0E, tx_priv->dmic_clk_div << 0x1);
  582. snd_soc_component_update_bits(component, dmic_clk_reg,
  583. dmic_clk_en, dmic_clk_en);
  584. }
  585. break;
  586. case SND_SOC_DAPM_POST_PMD:
  587. (*dmic_clk_cnt)--;
  588. if (*dmic_clk_cnt == 0)
  589. snd_soc_component_update_bits(component, dmic_clk_reg,
  590. dmic_clk_en, 0);
  591. break;
  592. }
  593. return 0;
  594. }
  595. static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
  596. struct snd_kcontrol *kcontrol, int event)
  597. {
  598. struct snd_soc_component *component =
  599. snd_soc_dapm_to_component(w->dapm);
  600. unsigned int decimator = 0;
  601. u16 tx_vol_ctl_reg = 0;
  602. u16 dec_cfg_reg = 0;
  603. u16 hpf_gate_reg = 0;
  604. u16 tx_gain_ctl_reg = 0;
  605. u8 hpf_cut_off_freq = 0;
  606. struct device *tx_dev = NULL;
  607. struct tx_macro_priv *tx_priv = NULL;
  608. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  609. return -EINVAL;
  610. decimator = w->shift;
  611. dev_dbg(component->dev, "%s(): widget = %s decimator = %u\n", __func__,
  612. w->name, decimator);
  613. tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  614. TX_MACRO_TX_PATH_OFFSET * decimator;
  615. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  616. TX_MACRO_TX_PATH_OFFSET * decimator;
  617. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  618. TX_MACRO_TX_PATH_OFFSET * decimator;
  619. tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL +
  620. TX_MACRO_TX_PATH_OFFSET * decimator;
  621. switch (event) {
  622. case SND_SOC_DAPM_PRE_PMU:
  623. /* Enable TX PGA Mute */
  624. snd_soc_component_update_bits(component,
  625. tx_vol_ctl_reg, 0x10, 0x10);
  626. break;
  627. case SND_SOC_DAPM_POST_PMU:
  628. snd_soc_component_update_bits(component,
  629. tx_vol_ctl_reg, 0x20, 0x20);
  630. snd_soc_component_update_bits(component,
  631. hpf_gate_reg, 0x01, 0x00);
  632. hpf_cut_off_freq = (
  633. snd_soc_component_read32(component, dec_cfg_reg) &
  634. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  635. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
  636. hpf_cut_off_freq;
  637. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
  638. snd_soc_component_update_bits(component, dec_cfg_reg,
  639. TX_HPF_CUT_OFF_FREQ_MASK,
  640. CF_MIN_3DB_150HZ << 5);
  641. /* schedule work queue to Remove Mute */
  642. schedule_delayed_work(&tx_priv->tx_mute_dwork[decimator].dwork,
  643. msecs_to_jiffies(tx_unmute_delay));
  644. if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
  645. CF_MIN_3DB_150HZ) {
  646. schedule_delayed_work(
  647. &tx_priv->tx_hpf_work[decimator].dwork,
  648. msecs_to_jiffies(50));
  649. snd_soc_component_update_bits(component,
  650. hpf_gate_reg, 0x02, 0x02);
  651. /*
  652. * Minimum 1 clk cycle delay is required as per HW spec
  653. */
  654. usleep_range(1000, 1010);
  655. snd_soc_component_update_bits(component,
  656. hpf_gate_reg, 0x02, 0x00);
  657. }
  658. /* apply gain after decimator is enabled */
  659. snd_soc_component_write(component, tx_gain_ctl_reg,
  660. snd_soc_component_read32(component,
  661. tx_gain_ctl_reg));
  662. break;
  663. case SND_SOC_DAPM_PRE_PMD:
  664. hpf_cut_off_freq =
  665. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
  666. snd_soc_component_update_bits(component,
  667. tx_vol_ctl_reg, 0x10, 0x10);
  668. if (cancel_delayed_work_sync(
  669. &tx_priv->tx_hpf_work[decimator].dwork)) {
  670. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  671. snd_soc_component_update_bits(
  672. component, dec_cfg_reg,
  673. TX_HPF_CUT_OFF_FREQ_MASK,
  674. hpf_cut_off_freq << 5);
  675. snd_soc_component_update_bits(component,
  676. hpf_gate_reg,
  677. 0x02, 0x02);
  678. /*
  679. * Minimum 1 clk cycle delay is required
  680. * as per HW spec
  681. */
  682. usleep_range(1000, 1010);
  683. snd_soc_component_update_bits(component,
  684. hpf_gate_reg,
  685. 0x02, 0x00);
  686. }
  687. }
  688. cancel_delayed_work_sync(
  689. &tx_priv->tx_mute_dwork[decimator].dwork);
  690. break;
  691. case SND_SOC_DAPM_POST_PMD:
  692. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  693. 0x20, 0x00);
  694. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  695. 0x10, 0x00);
  696. break;
  697. }
  698. return 0;
  699. }
  700. static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  701. struct snd_kcontrol *kcontrol, int event)
  702. {
  703. return 0;
  704. }
  705. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  706. struct snd_pcm_hw_params *params,
  707. struct snd_soc_dai *dai)
  708. {
  709. int tx_fs_rate = -EINVAL;
  710. struct snd_soc_component *component = dai->component;
  711. u32 decimator = 0;
  712. u32 sample_rate = 0;
  713. u16 tx_fs_reg = 0;
  714. struct device *tx_dev = NULL;
  715. struct tx_macro_priv *tx_priv = NULL;
  716. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  717. return -EINVAL;
  718. pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  719. dai->name, dai->id, params_rate(params),
  720. params_channels(params));
  721. sample_rate = params_rate(params);
  722. switch (sample_rate) {
  723. case 8000:
  724. tx_fs_rate = 0;
  725. break;
  726. case 16000:
  727. tx_fs_rate = 1;
  728. break;
  729. case 32000:
  730. tx_fs_rate = 3;
  731. break;
  732. case 48000:
  733. tx_fs_rate = 4;
  734. break;
  735. case 96000:
  736. tx_fs_rate = 5;
  737. break;
  738. case 192000:
  739. tx_fs_rate = 6;
  740. break;
  741. case 384000:
  742. tx_fs_rate = 7;
  743. break;
  744. default:
  745. dev_err(component->dev, "%s: Invalid TX sample rate: %d\n",
  746. __func__, params_rate(params));
  747. return -EINVAL;
  748. }
  749. for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
  750. TX_MACRO_DEC_MAX) {
  751. if (decimator >= 0) {
  752. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  753. TX_MACRO_TX_PATH_OFFSET * decimator;
  754. dev_dbg(component->dev, "%s: set DEC%u rate to %u\n",
  755. __func__, decimator, sample_rate);
  756. snd_soc_component_update_bits(component, tx_fs_reg,
  757. 0x0F, tx_fs_rate);
  758. } else {
  759. dev_err(component->dev,
  760. "%s: ERROR: Invalid decimator: %d\n",
  761. __func__, decimator);
  762. return -EINVAL;
  763. }
  764. }
  765. return 0;
  766. }
  767. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  768. unsigned int *tx_num, unsigned int *tx_slot,
  769. unsigned int *rx_num, unsigned int *rx_slot)
  770. {
  771. struct snd_soc_component *component = dai->component;
  772. struct device *tx_dev = NULL;
  773. struct tx_macro_priv *tx_priv = NULL;
  774. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  775. return -EINVAL;
  776. switch (dai->id) {
  777. case TX_MACRO_AIF1_CAP:
  778. case TX_MACRO_AIF2_CAP:
  779. case TX_MACRO_AIF3_CAP:
  780. *tx_slot = tx_priv->active_ch_mask[dai->id];
  781. *tx_num = tx_priv->active_ch_cnt[dai->id];
  782. break;
  783. default:
  784. dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
  785. break;
  786. }
  787. return 0;
  788. }
  789. static struct snd_soc_dai_ops tx_macro_dai_ops = {
  790. .hw_params = tx_macro_hw_params,
  791. .get_channel_map = tx_macro_get_channel_map,
  792. };
  793. static struct snd_soc_dai_driver tx_macro_dai[] = {
  794. {
  795. .name = "tx_macro_tx1",
  796. .id = TX_MACRO_AIF1_CAP,
  797. .capture = {
  798. .stream_name = "TX_AIF1 Capture",
  799. .rates = TX_MACRO_RATES,
  800. .formats = TX_MACRO_FORMATS,
  801. .rate_max = 192000,
  802. .rate_min = 8000,
  803. .channels_min = 1,
  804. .channels_max = 8,
  805. },
  806. .ops = &tx_macro_dai_ops,
  807. },
  808. {
  809. .name = "tx_macro_tx2",
  810. .id = TX_MACRO_AIF2_CAP,
  811. .capture = {
  812. .stream_name = "TX_AIF2 Capture",
  813. .rates = TX_MACRO_RATES,
  814. .formats = TX_MACRO_FORMATS,
  815. .rate_max = 192000,
  816. .rate_min = 8000,
  817. .channels_min = 1,
  818. .channels_max = 8,
  819. },
  820. .ops = &tx_macro_dai_ops,
  821. },
  822. {
  823. .name = "tx_macro_tx3",
  824. .id = TX_MACRO_AIF3_CAP,
  825. .capture = {
  826. .stream_name = "TX_AIF3 Capture",
  827. .rates = TX_MACRO_RATES,
  828. .formats = TX_MACRO_FORMATS,
  829. .rate_max = 192000,
  830. .rate_min = 8000,
  831. .channels_min = 1,
  832. .channels_max = 8,
  833. },
  834. .ops = &tx_macro_dai_ops,
  835. },
  836. };
  837. #define STRING(name) #name
  838. #define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  839. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  840. static const struct snd_kcontrol_new name##_mux = \
  841. SOC_DAPM_ENUM(STRING(name), name##_enum)
  842. #define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  843. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  844. static const struct snd_kcontrol_new name##_mux = \
  845. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  846. #define TX_MACRO_DAPM_MUX(name, shift, kctl) \
  847. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  848. static const char * const adc_mux_text[] = {
  849. "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
  850. };
  851. TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
  852. 0, adc_mux_text);
  853. TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
  854. 0, adc_mux_text);
  855. TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
  856. 0, adc_mux_text);
  857. TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
  858. 0, adc_mux_text);
  859. TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
  860. 0, adc_mux_text);
  861. TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
  862. 0, adc_mux_text);
  863. TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
  864. 0, adc_mux_text);
  865. TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
  866. 0, adc_mux_text);
  867. static const char * const dmic_mux_text[] = {
  868. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  869. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  870. };
  871. TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  872. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  873. tx_macro_put_dec_enum);
  874. TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  875. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  876. tx_macro_put_dec_enum);
  877. TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  878. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  879. tx_macro_put_dec_enum);
  880. TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  881. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  882. tx_macro_put_dec_enum);
  883. TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  884. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  885. tx_macro_put_dec_enum);
  886. TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  887. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  888. tx_macro_put_dec_enum);
  889. TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  890. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  891. tx_macro_put_dec_enum);
  892. TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  893. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  894. tx_macro_put_dec_enum);
  895. static const char * const smic_mux_text[] = {
  896. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "SWR_DMIC0",
  897. "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3", "SWR_DMIC4",
  898. "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  899. };
  900. TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  901. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  902. tx_macro_put_dec_enum);
  903. TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  904. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  905. tx_macro_put_dec_enum);
  906. TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  907. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  908. tx_macro_put_dec_enum);
  909. TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  910. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  911. tx_macro_put_dec_enum);
  912. TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  913. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  914. tx_macro_put_dec_enum);
  915. TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  916. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  917. tx_macro_put_dec_enum);
  918. TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  919. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  920. tx_macro_put_dec_enum);
  921. TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  922. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  923. tx_macro_put_dec_enum);
  924. static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
  925. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  926. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  927. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  928. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  929. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  930. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  931. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  932. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  933. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  934. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  935. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  936. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  937. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  938. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  939. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  940. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  941. };
  942. static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
  943. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  944. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  945. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  946. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  947. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  948. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  949. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  950. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  951. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  952. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  953. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  954. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  955. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  956. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  957. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  958. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  959. };
  960. static const struct snd_kcontrol_new tx_aif3_cap_mixer[] = {
  961. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  962. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  963. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  964. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  965. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  966. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  967. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  968. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  969. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  970. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  971. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  972. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  973. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  974. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  975. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  976. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  977. };
  978. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
  979. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  980. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  981. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  982. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  983. SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
  984. SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
  985. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
  986. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  987. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
  988. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  989. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0,
  990. tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
  991. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  992. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  993. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  994. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  995. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  996. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  997. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  998. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  999. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
  1000. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
  1001. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
  1002. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
  1003. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
  1004. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
  1005. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
  1006. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
  1007. SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1008. tx_macro_enable_micbias,
  1009. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1010. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1011. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1012. SND_SOC_DAPM_POST_PMD),
  1013. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1014. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1015. SND_SOC_DAPM_POST_PMD),
  1016. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1017. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1018. SND_SOC_DAPM_POST_PMD),
  1019. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1020. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1021. SND_SOC_DAPM_POST_PMD),
  1022. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1023. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1024. SND_SOC_DAPM_POST_PMD),
  1025. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1026. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1027. SND_SOC_DAPM_POST_PMD),
  1028. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1029. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1030. SND_SOC_DAPM_POST_PMD),
  1031. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1032. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1033. SND_SOC_DAPM_POST_PMD),
  1034. SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
  1035. SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
  1036. SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
  1037. SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
  1038. SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
  1039. SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
  1040. SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
  1041. SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
  1042. SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
  1043. SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
  1044. SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
  1045. SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
  1046. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  1047. TX_MACRO_DEC0, 0,
  1048. &tx_dec0_mux, tx_macro_enable_dec,
  1049. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1050. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1051. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  1052. TX_MACRO_DEC1, 0,
  1053. &tx_dec1_mux, tx_macro_enable_dec,
  1054. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1055. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1056. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  1057. TX_MACRO_DEC2, 0,
  1058. &tx_dec2_mux, tx_macro_enable_dec,
  1059. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1060. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1061. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  1062. TX_MACRO_DEC3, 0,
  1063. &tx_dec3_mux, tx_macro_enable_dec,
  1064. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1065. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1066. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  1067. TX_MACRO_DEC4, 0,
  1068. &tx_dec4_mux, tx_macro_enable_dec,
  1069. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1070. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1071. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  1072. TX_MACRO_DEC5, 0,
  1073. &tx_dec5_mux, tx_macro_enable_dec,
  1074. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1075. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1076. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  1077. TX_MACRO_DEC6, 0,
  1078. &tx_dec6_mux, tx_macro_enable_dec,
  1079. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1080. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1081. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  1082. TX_MACRO_DEC7, 0,
  1083. &tx_dec7_mux, tx_macro_enable_dec,
  1084. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1085. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1086. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1087. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1088. SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1089. tx_macro_tx_swr_clk_event,
  1090. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1091. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1092. tx_macro_va_swr_clk_event,
  1093. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1094. };
  1095. static const struct snd_soc_dapm_route tx_audio_map[] = {
  1096. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  1097. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  1098. {"TX_AIF3 CAP", NULL, "TX_MCLK"},
  1099. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  1100. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  1101. {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
  1102. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1103. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1104. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1105. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1106. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1107. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1108. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1109. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1110. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1111. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1112. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1113. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1114. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1115. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1116. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1117. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1118. {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1119. {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1120. {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1121. {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1122. {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1123. {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1124. {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1125. {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1126. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  1127. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  1128. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  1129. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  1130. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  1131. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  1132. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  1133. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  1134. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  1135. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  1136. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  1137. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  1138. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  1139. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  1140. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  1141. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  1142. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  1143. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  1144. {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
  1145. {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
  1146. {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
  1147. {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
  1148. {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
  1149. {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
  1150. {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
  1151. {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
  1152. {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
  1153. {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
  1154. {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
  1155. {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
  1156. {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
  1157. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  1158. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  1159. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  1160. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  1161. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  1162. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  1163. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  1164. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  1165. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  1166. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  1167. {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
  1168. {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
  1169. {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
  1170. {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
  1171. {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
  1172. {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
  1173. {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
  1174. {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
  1175. {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
  1176. {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
  1177. {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
  1178. {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
  1179. {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
  1180. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  1181. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  1182. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  1183. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  1184. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  1185. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  1186. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  1187. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  1188. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  1189. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  1190. {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
  1191. {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
  1192. {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
  1193. {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
  1194. {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
  1195. {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
  1196. {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
  1197. {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
  1198. {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
  1199. {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
  1200. {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
  1201. {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
  1202. {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
  1203. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  1204. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  1205. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  1206. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  1207. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  1208. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  1209. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  1210. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  1211. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  1212. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  1213. {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
  1214. {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
  1215. {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
  1216. {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
  1217. {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
  1218. {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
  1219. {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
  1220. {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
  1221. {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
  1222. {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
  1223. {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
  1224. {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
  1225. {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
  1226. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  1227. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  1228. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  1229. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  1230. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  1231. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  1232. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  1233. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  1234. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  1235. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  1236. {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
  1237. {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
  1238. {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
  1239. {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
  1240. {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
  1241. {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
  1242. {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
  1243. {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
  1244. {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
  1245. {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
  1246. {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
  1247. {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
  1248. {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
  1249. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  1250. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  1251. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  1252. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  1253. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  1254. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  1255. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  1256. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  1257. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  1258. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  1259. {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
  1260. {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
  1261. {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
  1262. {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
  1263. {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
  1264. {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
  1265. {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
  1266. {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
  1267. {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
  1268. {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
  1269. {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
  1270. {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
  1271. {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
  1272. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  1273. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  1274. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  1275. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  1276. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  1277. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  1278. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  1279. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  1280. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  1281. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  1282. {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
  1283. {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
  1284. {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
  1285. {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
  1286. {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
  1287. {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
  1288. {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
  1289. {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
  1290. {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
  1291. {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
  1292. {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
  1293. {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
  1294. {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
  1295. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  1296. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  1297. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  1298. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  1299. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  1300. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  1301. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  1302. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  1303. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  1304. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  1305. {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
  1306. {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
  1307. {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
  1308. {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
  1309. {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
  1310. {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
  1311. {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
  1312. {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
  1313. {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
  1314. {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
  1315. {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
  1316. {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
  1317. {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
  1318. };
  1319. static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
  1320. SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
  1321. BOLERO_CDC_TX0_TX_VOL_CTL,
  1322. 0, -84, 40, digital_gain),
  1323. SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
  1324. BOLERO_CDC_TX1_TX_VOL_CTL,
  1325. 0, -84, 40, digital_gain),
  1326. SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
  1327. BOLERO_CDC_TX2_TX_VOL_CTL,
  1328. 0, -84, 40, digital_gain),
  1329. SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
  1330. BOLERO_CDC_TX3_TX_VOL_CTL,
  1331. 0, -84, 40, digital_gain),
  1332. SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
  1333. BOLERO_CDC_TX4_TX_VOL_CTL,
  1334. 0, -84, 40, digital_gain),
  1335. SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
  1336. BOLERO_CDC_TX5_TX_VOL_CTL,
  1337. 0, -84, 40, digital_gain),
  1338. SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
  1339. BOLERO_CDC_TX6_TX_VOL_CTL,
  1340. 0, -84, 40, digital_gain),
  1341. SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
  1342. BOLERO_CDC_TX7_TX_VOL_CTL,
  1343. 0, -84, 40, digital_gain),
  1344. };
  1345. static int tx_macro_tx_va_mclk_enable(struct tx_macro_priv *tx_priv,
  1346. struct regmap *regmap, int clk_type,
  1347. bool enable)
  1348. {
  1349. int ret = 0, clk_tx_ret = 0;
  1350. dev_dbg(tx_priv->dev,
  1351. "%s: clock type %s, enable: %s tx_mclk_users: %d\n",
  1352. __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
  1353. (enable ? "enable" : "disable"), tx_priv->tx_mclk_users);
  1354. if (enable) {
  1355. if (tx_priv->swr_clk_users == 0)
  1356. msm_cdc_pinctrl_select_active_state(
  1357. tx_priv->tx_swr_gpio_p);
  1358. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1359. TX_CORE_CLK,
  1360. TX_CORE_CLK,
  1361. true);
  1362. if (clk_type == TX_MCLK) {
  1363. ret = tx_macro_mclk_enable(tx_priv, 1);
  1364. if (ret < 0) {
  1365. if (tx_priv->swr_clk_users == 0)
  1366. msm_cdc_pinctrl_select_sleep_state(
  1367. tx_priv->tx_swr_gpio_p);
  1368. dev_err_ratelimited(tx_priv->dev,
  1369. "%s: request clock enable failed\n",
  1370. __func__);
  1371. goto done;
  1372. }
  1373. }
  1374. if (clk_type == VA_MCLK) {
  1375. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1376. TX_CORE_CLK,
  1377. VA_CORE_CLK,
  1378. true);
  1379. if (ret < 0) {
  1380. if (tx_priv->swr_clk_users == 0)
  1381. msm_cdc_pinctrl_select_sleep_state(
  1382. tx_priv->tx_swr_gpio_p);
  1383. dev_err_ratelimited(tx_priv->dev,
  1384. "%s: swr request clk failed\n",
  1385. __func__);
  1386. goto done;
  1387. }
  1388. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  1389. true);
  1390. if (tx_priv->tx_mclk_users == 0) {
  1391. regmap_update_bits(regmap,
  1392. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK,
  1393. 0x01, 0x01);
  1394. regmap_update_bits(regmap,
  1395. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  1396. 0x01, 0x01);
  1397. regmap_update_bits(regmap,
  1398. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  1399. 0x01, 0x01);
  1400. }
  1401. }
  1402. if (tx_priv->swr_clk_users == 0) {
  1403. dev_dbg(tx_priv->dev, "%s: reset_swr: %d\n",
  1404. __func__, tx_priv->reset_swr);
  1405. if (tx_priv->reset_swr)
  1406. regmap_update_bits(regmap,
  1407. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1408. 0x02, 0x02);
  1409. regmap_update_bits(regmap,
  1410. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1411. 0x01, 0x01);
  1412. if (tx_priv->reset_swr)
  1413. regmap_update_bits(regmap,
  1414. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1415. 0x02, 0x00);
  1416. tx_priv->reset_swr = false;
  1417. }
  1418. if (!clk_tx_ret)
  1419. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1420. TX_CORE_CLK,
  1421. TX_CORE_CLK,
  1422. false);
  1423. tx_priv->swr_clk_users++;
  1424. } else {
  1425. if (tx_priv->swr_clk_users <= 0) {
  1426. dev_err_ratelimited(tx_priv->dev,
  1427. "tx swrm clock users already 0\n");
  1428. tx_priv->swr_clk_users = 0;
  1429. return 0;
  1430. }
  1431. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1432. TX_CORE_CLK,
  1433. TX_CORE_CLK,
  1434. true);
  1435. tx_priv->swr_clk_users--;
  1436. if (tx_priv->swr_clk_users == 0)
  1437. regmap_update_bits(regmap,
  1438. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1439. 0x01, 0x00);
  1440. if (clk_type == TX_MCLK)
  1441. tx_macro_mclk_enable(tx_priv, 0);
  1442. if (clk_type == VA_MCLK) {
  1443. if (tx_priv->tx_mclk_users == 0) {
  1444. regmap_update_bits(regmap,
  1445. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  1446. 0x01, 0x00);
  1447. regmap_update_bits(regmap,
  1448. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  1449. 0x01, 0x00);
  1450. }
  1451. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  1452. false);
  1453. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1454. TX_CORE_CLK,
  1455. VA_CORE_CLK,
  1456. false);
  1457. if (ret < 0) {
  1458. dev_err_ratelimited(tx_priv->dev,
  1459. "%s: swr request clk failed\n",
  1460. __func__);
  1461. goto done;
  1462. }
  1463. }
  1464. if (!clk_tx_ret)
  1465. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1466. TX_CORE_CLK,
  1467. TX_CORE_CLK,
  1468. false);
  1469. if (tx_priv->swr_clk_users == 0)
  1470. msm_cdc_pinctrl_select_sleep_state(
  1471. tx_priv->tx_swr_gpio_p);
  1472. }
  1473. return 0;
  1474. done:
  1475. if (!clk_tx_ret)
  1476. bolero_clk_rsc_request_clock(tx_priv->dev,
  1477. TX_CORE_CLK,
  1478. TX_CORE_CLK,
  1479. false);
  1480. return ret;
  1481. }
  1482. static int tx_macro_swrm_clock(void *handle, bool enable)
  1483. {
  1484. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  1485. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  1486. int ret = 0;
  1487. if (regmap == NULL) {
  1488. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  1489. return -EINVAL;
  1490. }
  1491. mutex_lock(&tx_priv->swr_clk_lock);
  1492. dev_dbg(tx_priv->dev,
  1493. "%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n",
  1494. __func__, (enable ? "enable" : "disable"),
  1495. tx_priv->tx_swr_clk_cnt, tx_priv->va_swr_clk_cnt);
  1496. if (enable) {
  1497. pm_runtime_get_sync(tx_priv->dev);
  1498. if (tx_priv->va_swr_clk_cnt && !tx_priv->tx_swr_clk_cnt) {
  1499. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1500. VA_MCLK, enable);
  1501. if (ret)
  1502. goto done;
  1503. tx_priv->va_clk_status++;
  1504. } else {
  1505. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1506. TX_MCLK, enable);
  1507. if (ret)
  1508. goto done;
  1509. tx_priv->tx_clk_status++;
  1510. }
  1511. pm_runtime_mark_last_busy(tx_priv->dev);
  1512. pm_runtime_put_autosuspend(tx_priv->dev);
  1513. } else {
  1514. if (tx_priv->va_clk_status && !tx_priv->tx_clk_status) {
  1515. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1516. VA_MCLK, enable);
  1517. if (ret)
  1518. goto done;
  1519. --tx_priv->va_clk_status;
  1520. } else if (!tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  1521. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1522. TX_MCLK, enable);
  1523. if (ret)
  1524. goto done;
  1525. --tx_priv->tx_clk_status;
  1526. } else if (tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  1527. if (!tx_priv->va_swr_clk_cnt && tx_priv->tx_swr_clk_cnt) {
  1528. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1529. VA_MCLK, enable);
  1530. if (ret)
  1531. goto done;
  1532. --tx_priv->va_clk_status;
  1533. } else {
  1534. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1535. TX_MCLK, enable);
  1536. if (ret)
  1537. goto done;
  1538. --tx_priv->tx_clk_status;
  1539. }
  1540. } else {
  1541. dev_dbg(tx_priv->dev,
  1542. "%s: Both clocks are disabled\n", __func__);
  1543. }
  1544. }
  1545. dev_dbg(tx_priv->dev,
  1546. "%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n",
  1547. __func__, tx_priv->swr_clk_users, tx_priv->tx_clk_status,
  1548. tx_priv->va_clk_status);
  1549. done:
  1550. mutex_unlock(&tx_priv->swr_clk_lock);
  1551. return ret;
  1552. }
  1553. static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  1554. struct tx_macro_priv *tx_priv)
  1555. {
  1556. u32 div_factor = TX_MACRO_CLK_DIV_2;
  1557. u32 mclk_rate = TX_MACRO_MCLK_FREQ;
  1558. if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  1559. mclk_rate % dmic_sample_rate != 0)
  1560. goto undefined_rate;
  1561. div_factor = mclk_rate / dmic_sample_rate;
  1562. switch (div_factor) {
  1563. case 2:
  1564. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  1565. break;
  1566. case 3:
  1567. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
  1568. break;
  1569. case 4:
  1570. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
  1571. break;
  1572. case 6:
  1573. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
  1574. break;
  1575. case 8:
  1576. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
  1577. break;
  1578. case 16:
  1579. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
  1580. break;
  1581. default:
  1582. /* Any other DIV factor is invalid */
  1583. goto undefined_rate;
  1584. }
  1585. /* Valid dmic DIV factors */
  1586. dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  1587. __func__, div_factor, mclk_rate);
  1588. return dmic_sample_rate;
  1589. undefined_rate:
  1590. dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  1591. __func__, dmic_sample_rate, mclk_rate);
  1592. dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  1593. return dmic_sample_rate;
  1594. }
  1595. static int tx_macro_init(struct snd_soc_component *component)
  1596. {
  1597. struct snd_soc_dapm_context *dapm =
  1598. snd_soc_component_get_dapm(component);
  1599. int ret = 0, i = 0;
  1600. struct device *tx_dev = NULL;
  1601. struct tx_macro_priv *tx_priv = NULL;
  1602. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  1603. if (!tx_dev) {
  1604. dev_err(component->dev,
  1605. "%s: null device for macro!\n", __func__);
  1606. return -EINVAL;
  1607. }
  1608. tx_priv = dev_get_drvdata(tx_dev);
  1609. if (!tx_priv) {
  1610. dev_err(component->dev,
  1611. "%s: priv is null for macro!\n", __func__);
  1612. return -EINVAL;
  1613. }
  1614. ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
  1615. ARRAY_SIZE(tx_macro_dapm_widgets));
  1616. if (ret < 0) {
  1617. dev_err(tx_dev, "%s: Failed to add controls\n", __func__);
  1618. return ret;
  1619. }
  1620. ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
  1621. ARRAY_SIZE(tx_audio_map));
  1622. if (ret < 0) {
  1623. dev_err(tx_dev, "%s: Failed to add routes\n", __func__);
  1624. return ret;
  1625. }
  1626. ret = snd_soc_dapm_new_widgets(dapm->card);
  1627. if (ret < 0) {
  1628. dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
  1629. return ret;
  1630. }
  1631. ret = snd_soc_add_component_controls(component, tx_macro_snd_controls,
  1632. ARRAY_SIZE(tx_macro_snd_controls));
  1633. if (ret < 0) {
  1634. dev_err(tx_dev, "%s: Failed to add snd_ctls\n", __func__);
  1635. return ret;
  1636. }
  1637. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture");
  1638. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture");
  1639. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF3 Capture");
  1640. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0");
  1641. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1");
  1642. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2");
  1643. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3");
  1644. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC0");
  1645. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC1");
  1646. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC2");
  1647. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC3");
  1648. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC4");
  1649. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC5");
  1650. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC6");
  1651. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC7");
  1652. snd_soc_dapm_sync(dapm);
  1653. for (i = 0; i < NUM_DECIMATORS; i++) {
  1654. tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
  1655. tx_priv->tx_hpf_work[i].decimator = i;
  1656. INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
  1657. tx_macro_tx_hpf_corner_freq_callback);
  1658. }
  1659. for (i = 0; i < NUM_DECIMATORS; i++) {
  1660. tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
  1661. tx_priv->tx_mute_dwork[i].decimator = i;
  1662. INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
  1663. tx_macro_mute_update_callback);
  1664. }
  1665. tx_priv->component = component;
  1666. return 0;
  1667. }
  1668. static int tx_macro_deinit(struct snd_soc_component *component)
  1669. {
  1670. struct device *tx_dev = NULL;
  1671. struct tx_macro_priv *tx_priv = NULL;
  1672. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  1673. return -EINVAL;
  1674. tx_priv->component = NULL;
  1675. return 0;
  1676. }
  1677. static void tx_macro_add_child_devices(struct work_struct *work)
  1678. {
  1679. struct tx_macro_priv *tx_priv = NULL;
  1680. struct platform_device *pdev = NULL;
  1681. struct device_node *node = NULL;
  1682. struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  1683. int ret = 0;
  1684. u16 count = 0, ctrl_num = 0;
  1685. struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
  1686. char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
  1687. bool tx_swr_master_node = false;
  1688. tx_priv = container_of(work, struct tx_macro_priv,
  1689. tx_macro_add_child_devices_work);
  1690. if (!tx_priv) {
  1691. pr_err("%s: Memory for tx_priv does not exist\n",
  1692. __func__);
  1693. return;
  1694. }
  1695. if (!tx_priv->dev) {
  1696. pr_err("%s: tx dev does not exist\n", __func__);
  1697. return;
  1698. }
  1699. if (!tx_priv->dev->of_node) {
  1700. dev_err(tx_priv->dev,
  1701. "%s: DT node for tx_priv does not exist\n", __func__);
  1702. return;
  1703. }
  1704. platdata = &tx_priv->swr_plat_data;
  1705. tx_priv->child_count = 0;
  1706. for_each_available_child_of_node(tx_priv->dev->of_node, node) {
  1707. tx_swr_master_node = false;
  1708. if (strnstr(node->name, "tx_swr_master",
  1709. strlen("tx_swr_master")) != NULL)
  1710. tx_swr_master_node = true;
  1711. if (tx_swr_master_node)
  1712. strlcpy(plat_dev_name, "tx_swr_ctrl",
  1713. (TX_MACRO_SWR_STRING_LEN - 1));
  1714. else
  1715. strlcpy(plat_dev_name, node->name,
  1716. (TX_MACRO_SWR_STRING_LEN - 1));
  1717. pdev = platform_device_alloc(plat_dev_name, -1);
  1718. if (!pdev) {
  1719. dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
  1720. __func__);
  1721. ret = -ENOMEM;
  1722. goto err;
  1723. }
  1724. pdev->dev.parent = tx_priv->dev;
  1725. pdev->dev.of_node = node;
  1726. if (tx_swr_master_node) {
  1727. ret = platform_device_add_data(pdev, platdata,
  1728. sizeof(*platdata));
  1729. if (ret) {
  1730. dev_err(&pdev->dev,
  1731. "%s: cannot add plat data ctrl:%d\n",
  1732. __func__, ctrl_num);
  1733. goto fail_pdev_add;
  1734. }
  1735. }
  1736. ret = platform_device_add(pdev);
  1737. if (ret) {
  1738. dev_err(&pdev->dev,
  1739. "%s: Cannot add platform device\n",
  1740. __func__);
  1741. goto fail_pdev_add;
  1742. }
  1743. if (tx_swr_master_node) {
  1744. temp = krealloc(swr_ctrl_data,
  1745. (ctrl_num + 1) * sizeof(
  1746. struct tx_macro_swr_ctrl_data),
  1747. GFP_KERNEL);
  1748. if (!temp) {
  1749. ret = -ENOMEM;
  1750. goto fail_pdev_add;
  1751. }
  1752. swr_ctrl_data = temp;
  1753. swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
  1754. ctrl_num++;
  1755. dev_dbg(&pdev->dev,
  1756. "%s: Added soundwire ctrl device(s)\n",
  1757. __func__);
  1758. tx_priv->swr_ctrl_data = swr_ctrl_data;
  1759. }
  1760. if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
  1761. tx_priv->pdev_child_devices[
  1762. tx_priv->child_count++] = pdev;
  1763. else
  1764. goto err;
  1765. }
  1766. return;
  1767. fail_pdev_add:
  1768. for (count = 0; count < tx_priv->child_count; count++)
  1769. platform_device_put(tx_priv->pdev_child_devices[count]);
  1770. err:
  1771. return;
  1772. }
  1773. static int tx_macro_set_port_map(struct snd_soc_component *component,
  1774. u32 usecase, u32 size, void *data)
  1775. {
  1776. struct device *tx_dev = NULL;
  1777. struct tx_macro_priv *tx_priv = NULL;
  1778. struct swrm_port_config port_cfg;
  1779. int ret = 0;
  1780. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  1781. return -EINVAL;
  1782. memset(&port_cfg, 0, sizeof(port_cfg));
  1783. port_cfg.uc = usecase;
  1784. port_cfg.size = size;
  1785. port_cfg.params = data;
  1786. if (tx_priv->swr_ctrl_data)
  1787. ret = swrm_wcd_notify(
  1788. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  1789. SWR_SET_PORT_MAP, &port_cfg);
  1790. return ret;
  1791. }
  1792. static void tx_macro_init_ops(struct macro_ops *ops,
  1793. char __iomem *tx_io_base)
  1794. {
  1795. memset(ops, 0, sizeof(struct macro_ops));
  1796. ops->init = tx_macro_init;
  1797. ops->exit = tx_macro_deinit;
  1798. ops->io_base = tx_io_base;
  1799. ops->dai_ptr = tx_macro_dai;
  1800. ops->num_dais = ARRAY_SIZE(tx_macro_dai);
  1801. ops->event_handler = tx_macro_event_handler;
  1802. ops->reg_wake_irq = tx_macro_reg_wake_irq;
  1803. ops->set_port_map = tx_macro_set_port_map;
  1804. }
  1805. static int tx_macro_probe(struct platform_device *pdev)
  1806. {
  1807. struct macro_ops ops = {0};
  1808. struct tx_macro_priv *tx_priv = NULL;
  1809. u32 tx_base_addr = 0, sample_rate = 0;
  1810. char __iomem *tx_io_base = NULL;
  1811. int ret = 0;
  1812. const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
  1813. u32 is_used_tx_swr_gpio = 1;
  1814. const char *is_used_tx_swr_gpio_dt = "qcom,is-used-swr-gpio";
  1815. tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
  1816. GFP_KERNEL);
  1817. if (!tx_priv)
  1818. return -ENOMEM;
  1819. platform_set_drvdata(pdev, tx_priv);
  1820. tx_priv->dev = &pdev->dev;
  1821. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  1822. &tx_base_addr);
  1823. if (ret) {
  1824. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1825. __func__, "reg");
  1826. return ret;
  1827. }
  1828. dev_set_drvdata(&pdev->dev, tx_priv);
  1829. if (of_find_property(pdev->dev.of_node, is_used_tx_swr_gpio_dt,
  1830. NULL)) {
  1831. ret = of_property_read_u32(pdev->dev.of_node,
  1832. is_used_tx_swr_gpio_dt,
  1833. &is_used_tx_swr_gpio);
  1834. if (ret) {
  1835. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  1836. __func__, is_used_tx_swr_gpio_dt);
  1837. is_used_tx_swr_gpio = 1;
  1838. }
  1839. }
  1840. tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1841. "qcom,tx-swr-gpios", 0);
  1842. if (!tx_priv->tx_swr_gpio_p && is_used_tx_swr_gpio) {
  1843. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  1844. __func__);
  1845. return -EINVAL;
  1846. }
  1847. if (msm_cdc_pinctrl_get_state(tx_priv->tx_swr_gpio_p) < 0) {
  1848. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  1849. __func__);
  1850. return -EPROBE_DEFER;
  1851. }
  1852. tx_io_base = devm_ioremap(&pdev->dev,
  1853. tx_base_addr, TX_MACRO_MAX_OFFSET);
  1854. if (!tx_io_base) {
  1855. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  1856. return -ENOMEM;
  1857. }
  1858. tx_priv->tx_io_base = tx_io_base;
  1859. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  1860. &sample_rate);
  1861. if (ret) {
  1862. dev_err(&pdev->dev,
  1863. "%s: could not find sample_rate entry in dt\n",
  1864. __func__);
  1865. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  1866. } else {
  1867. if (tx_macro_validate_dmic_sample_rate(
  1868. sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  1869. return -EINVAL;
  1870. }
  1871. tx_priv->reset_swr = true;
  1872. INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
  1873. tx_macro_add_child_devices);
  1874. tx_priv->swr_plat_data.handle = (void *) tx_priv;
  1875. tx_priv->swr_plat_data.read = NULL;
  1876. tx_priv->swr_plat_data.write = NULL;
  1877. tx_priv->swr_plat_data.bulk_write = NULL;
  1878. tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
  1879. tx_priv->swr_plat_data.handle_irq = NULL;
  1880. mutex_init(&tx_priv->mclk_lock);
  1881. mutex_init(&tx_priv->swr_clk_lock);
  1882. tx_macro_init_ops(&ops, tx_io_base);
  1883. ops.clk_id_req = TX_CORE_CLK;
  1884. ops.default_clk_id = TX_CORE_CLK;
  1885. ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
  1886. if (ret) {
  1887. dev_err(&pdev->dev,
  1888. "%s: register macro failed\n", __func__);
  1889. goto err_reg_macro;
  1890. }
  1891. schedule_work(&tx_priv->tx_macro_add_child_devices_work);
  1892. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  1893. pm_runtime_use_autosuspend(&pdev->dev);
  1894. pm_runtime_set_suspended(&pdev->dev);
  1895. pm_suspend_ignore_children(&pdev->dev, true);
  1896. pm_runtime_enable(&pdev->dev);
  1897. return 0;
  1898. err_reg_macro:
  1899. mutex_destroy(&tx_priv->mclk_lock);
  1900. mutex_destroy(&tx_priv->swr_clk_lock);
  1901. return ret;
  1902. }
  1903. static int tx_macro_remove(struct platform_device *pdev)
  1904. {
  1905. struct tx_macro_priv *tx_priv = NULL;
  1906. u16 count = 0;
  1907. tx_priv = platform_get_drvdata(pdev);
  1908. if (!tx_priv)
  1909. return -EINVAL;
  1910. if (tx_priv->swr_ctrl_data)
  1911. kfree(tx_priv->swr_ctrl_data);
  1912. for (count = 0; count < tx_priv->child_count &&
  1913. count < TX_MACRO_CHILD_DEVICES_MAX; count++)
  1914. platform_device_unregister(tx_priv->pdev_child_devices[count]);
  1915. pm_runtime_disable(&pdev->dev);
  1916. pm_runtime_set_suspended(&pdev->dev);
  1917. mutex_destroy(&tx_priv->mclk_lock);
  1918. mutex_destroy(&tx_priv->swr_clk_lock);
  1919. bolero_unregister_macro(&pdev->dev, TX_MACRO);
  1920. return 0;
  1921. }
  1922. static const struct of_device_id tx_macro_dt_match[] = {
  1923. {.compatible = "qcom,tx-macro"},
  1924. {}
  1925. };
  1926. static const struct dev_pm_ops bolero_dev_pm_ops = {
  1927. SET_RUNTIME_PM_OPS(
  1928. bolero_runtime_suspend,
  1929. bolero_runtime_resume,
  1930. NULL
  1931. )
  1932. };
  1933. static struct platform_driver tx_macro_driver = {
  1934. .driver = {
  1935. .name = "tx_macro",
  1936. .owner = THIS_MODULE,
  1937. .pm = &bolero_dev_pm_ops,
  1938. .of_match_table = tx_macro_dt_match,
  1939. .suppress_bind_attrs = true,
  1940. },
  1941. .probe = tx_macro_probe,
  1942. .remove = tx_macro_remove,
  1943. };
  1944. module_platform_driver(tx_macro_driver);
  1945. MODULE_DESCRIPTION("TX macro driver");
  1946. MODULE_LICENSE("GPL v2");