tx-macro.c 56 KB

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