tx-macro.c 62 KB

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