t7xx_cldma.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, MediaTek Inc.
  4. * Copyright (c) 2021-2022, Intel Corporation.
  5. *
  6. * Authors:
  7. * Haijun Liu <[email protected]>
  8. * Moises Veleta <[email protected]>
  9. * Ricardo Martinez <[email protected]>
  10. *
  11. * Contributors:
  12. * Amir Hanania <[email protected]>
  13. * Andy Shevchenko <[email protected]>
  14. * Eliot Lee <[email protected]>
  15. * Sreehari Kancharla <[email protected]>
  16. */
  17. #include <linux/bits.h>
  18. #include <linux/delay.h>
  19. #include <linux/io.h>
  20. #include <linux/io-64-nonatomic-lo-hi.h>
  21. #include <linux/types.h>
  22. #include "t7xx_cldma.h"
  23. #define ADDR_SIZE 8
  24. void t7xx_cldma_clear_ip_busy(struct t7xx_cldma_hw *hw_info)
  25. {
  26. u32 val;
  27. val = ioread32(hw_info->ap_pdn_base + REG_CLDMA_IP_BUSY);
  28. val |= IP_BUSY_WAKEUP;
  29. iowrite32(val, hw_info->ap_pdn_base + REG_CLDMA_IP_BUSY);
  30. }
  31. /**
  32. * t7xx_cldma_hw_restore() - Restore CLDMA HW registers.
  33. * @hw_info: Pointer to struct t7xx_cldma_hw.
  34. *
  35. * Restore HW after resume. Writes uplink configuration for CLDMA HW.
  36. */
  37. void t7xx_cldma_hw_restore(struct t7xx_cldma_hw *hw_info)
  38. {
  39. u32 ul_cfg;
  40. ul_cfg = ioread32(hw_info->ap_pdn_base + REG_CLDMA_UL_CFG);
  41. ul_cfg &= ~UL_CFG_BIT_MODE_MASK;
  42. if (hw_info->hw_mode == MODE_BIT_64)
  43. ul_cfg |= UL_CFG_BIT_MODE_64;
  44. else if (hw_info->hw_mode == MODE_BIT_40)
  45. ul_cfg |= UL_CFG_BIT_MODE_40;
  46. else if (hw_info->hw_mode == MODE_BIT_36)
  47. ul_cfg |= UL_CFG_BIT_MODE_36;
  48. iowrite32(ul_cfg, hw_info->ap_pdn_base + REG_CLDMA_UL_CFG);
  49. /* Disable TX and RX invalid address check */
  50. iowrite32(UL_MEM_CHECK_DIS, hw_info->ap_pdn_base + REG_CLDMA_UL_MEM);
  51. iowrite32(DL_MEM_CHECK_DIS, hw_info->ap_pdn_base + REG_CLDMA_DL_MEM);
  52. }
  53. void t7xx_cldma_hw_start_queue(struct t7xx_cldma_hw *hw_info, unsigned int qno,
  54. enum mtk_txrx tx_rx)
  55. {
  56. void __iomem *reg;
  57. u32 val;
  58. reg = tx_rx == MTK_RX ? hw_info->ap_pdn_base + REG_CLDMA_DL_START_CMD :
  59. hw_info->ap_pdn_base + REG_CLDMA_UL_START_CMD;
  60. val = qno == CLDMA_ALL_Q ? CLDMA_ALL_Q : BIT(qno);
  61. iowrite32(val, reg);
  62. }
  63. void t7xx_cldma_hw_start(struct t7xx_cldma_hw *hw_info)
  64. {
  65. /* Enable the TX & RX interrupts */
  66. iowrite32(TXRX_STATUS_BITMASK, hw_info->ap_pdn_base + REG_CLDMA_L2TIMCR0);
  67. iowrite32(TXRX_STATUS_BITMASK, hw_info->ap_ao_base + REG_CLDMA_L2RIMCR0);
  68. /* Enable the empty queue interrupt */
  69. iowrite32(EMPTY_STATUS_BITMASK, hw_info->ap_pdn_base + REG_CLDMA_L2TIMCR0);
  70. iowrite32(EMPTY_STATUS_BITMASK, hw_info->ap_ao_base + REG_CLDMA_L2RIMCR0);
  71. }
  72. void t7xx_cldma_hw_reset(void __iomem *ao_base)
  73. {
  74. u32 val;
  75. val = ioread32(ao_base + REG_INFRA_RST2_SET);
  76. val |= RST2_PMIC_SW_RST_SET;
  77. iowrite32(val, ao_base + REG_INFRA_RST2_SET);
  78. val = ioread32(ao_base + REG_INFRA_RST4_SET);
  79. val |= RST4_CLDMA1_SW_RST_SET;
  80. iowrite32(val, ao_base + REG_INFRA_RST4_SET);
  81. udelay(1);
  82. val = ioread32(ao_base + REG_INFRA_RST4_CLR);
  83. val |= RST4_CLDMA1_SW_RST_CLR;
  84. iowrite32(val, ao_base + REG_INFRA_RST4_CLR);
  85. val = ioread32(ao_base + REG_INFRA_RST2_CLR);
  86. val |= RST2_PMIC_SW_RST_CLR;
  87. iowrite32(val, ao_base + REG_INFRA_RST2_CLR);
  88. }
  89. bool t7xx_cldma_tx_addr_is_set(struct t7xx_cldma_hw *hw_info, unsigned int qno)
  90. {
  91. u32 offset = REG_CLDMA_UL_START_ADDRL_0 + qno * ADDR_SIZE;
  92. return ioread64(hw_info->ap_pdn_base + offset);
  93. }
  94. void t7xx_cldma_hw_set_start_addr(struct t7xx_cldma_hw *hw_info, unsigned int qno, u64 address,
  95. enum mtk_txrx tx_rx)
  96. {
  97. u32 offset = qno * ADDR_SIZE;
  98. void __iomem *reg;
  99. reg = tx_rx == MTK_RX ? hw_info->ap_ao_base + REG_CLDMA_DL_START_ADDRL_0 :
  100. hw_info->ap_pdn_base + REG_CLDMA_UL_START_ADDRL_0;
  101. iowrite64(address, reg + offset);
  102. }
  103. void t7xx_cldma_hw_resume_queue(struct t7xx_cldma_hw *hw_info, unsigned int qno,
  104. enum mtk_txrx tx_rx)
  105. {
  106. void __iomem *base = hw_info->ap_pdn_base;
  107. if (tx_rx == MTK_RX)
  108. iowrite32(BIT(qno), base + REG_CLDMA_DL_RESUME_CMD);
  109. else
  110. iowrite32(BIT(qno), base + REG_CLDMA_UL_RESUME_CMD);
  111. }
  112. unsigned int t7xx_cldma_hw_queue_status(struct t7xx_cldma_hw *hw_info, unsigned int qno,
  113. enum mtk_txrx tx_rx)
  114. {
  115. void __iomem *reg;
  116. u32 mask, val;
  117. mask = qno == CLDMA_ALL_Q ? CLDMA_ALL_Q : BIT(qno);
  118. reg = tx_rx == MTK_RX ? hw_info->ap_ao_base + REG_CLDMA_DL_STATUS :
  119. hw_info->ap_pdn_base + REG_CLDMA_UL_STATUS;
  120. val = ioread32(reg);
  121. return val & mask;
  122. }
  123. void t7xx_cldma_hw_tx_done(struct t7xx_cldma_hw *hw_info, unsigned int bitmask)
  124. {
  125. unsigned int ch_id;
  126. ch_id = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0);
  127. ch_id &= bitmask;
  128. /* Clear the ch IDs in the TX interrupt status register */
  129. iowrite32(ch_id, hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0);
  130. ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0);
  131. }
  132. void t7xx_cldma_hw_rx_done(struct t7xx_cldma_hw *hw_info, unsigned int bitmask)
  133. {
  134. unsigned int ch_id;
  135. ch_id = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0);
  136. ch_id &= bitmask;
  137. /* Clear the ch IDs in the RX interrupt status register */
  138. iowrite32(ch_id, hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0);
  139. ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0);
  140. }
  141. unsigned int t7xx_cldma_hw_int_status(struct t7xx_cldma_hw *hw_info, unsigned int bitmask,
  142. enum mtk_txrx tx_rx)
  143. {
  144. void __iomem *reg;
  145. u32 val;
  146. reg = tx_rx == MTK_RX ? hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0 :
  147. hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0;
  148. val = ioread32(reg);
  149. return val & bitmask;
  150. }
  151. void t7xx_cldma_hw_irq_dis_txrx(struct t7xx_cldma_hw *hw_info, unsigned int qno,
  152. enum mtk_txrx tx_rx)
  153. {
  154. void __iomem *reg;
  155. u32 val;
  156. reg = tx_rx == MTK_RX ? hw_info->ap_ao_base + REG_CLDMA_L2RIMSR0 :
  157. hw_info->ap_pdn_base + REG_CLDMA_L2TIMSR0;
  158. val = qno == CLDMA_ALL_Q ? CLDMA_ALL_Q : BIT(qno);
  159. iowrite32(val, reg);
  160. }
  161. void t7xx_cldma_hw_irq_dis_eq(struct t7xx_cldma_hw *hw_info, unsigned int qno, enum mtk_txrx tx_rx)
  162. {
  163. void __iomem *reg;
  164. u32 val;
  165. reg = tx_rx == MTK_RX ? hw_info->ap_ao_base + REG_CLDMA_L2RIMSR0 :
  166. hw_info->ap_pdn_base + REG_CLDMA_L2TIMSR0;
  167. val = qno == CLDMA_ALL_Q ? CLDMA_ALL_Q : BIT(qno);
  168. iowrite32(val << EQ_STA_BIT_OFFSET, reg);
  169. }
  170. void t7xx_cldma_hw_irq_en_txrx(struct t7xx_cldma_hw *hw_info, unsigned int qno,
  171. enum mtk_txrx tx_rx)
  172. {
  173. void __iomem *reg;
  174. u32 val;
  175. reg = tx_rx == MTK_RX ? hw_info->ap_ao_base + REG_CLDMA_L2RIMCR0 :
  176. hw_info->ap_pdn_base + REG_CLDMA_L2TIMCR0;
  177. val = qno == CLDMA_ALL_Q ? CLDMA_ALL_Q : BIT(qno);
  178. iowrite32(val, reg);
  179. }
  180. void t7xx_cldma_hw_irq_en_eq(struct t7xx_cldma_hw *hw_info, unsigned int qno, enum mtk_txrx tx_rx)
  181. {
  182. void __iomem *reg;
  183. u32 val;
  184. reg = tx_rx == MTK_RX ? hw_info->ap_ao_base + REG_CLDMA_L2RIMCR0 :
  185. hw_info->ap_pdn_base + REG_CLDMA_L2TIMCR0;
  186. val = qno == CLDMA_ALL_Q ? CLDMA_ALL_Q : BIT(qno);
  187. iowrite32(val << EQ_STA_BIT_OFFSET, reg);
  188. }
  189. /**
  190. * t7xx_cldma_hw_init() - Initialize CLDMA HW.
  191. * @hw_info: Pointer to struct t7xx_cldma_hw.
  192. *
  193. * Write uplink and downlink configuration to CLDMA HW.
  194. */
  195. void t7xx_cldma_hw_init(struct t7xx_cldma_hw *hw_info)
  196. {
  197. u32 ul_cfg, dl_cfg;
  198. ul_cfg = ioread32(hw_info->ap_pdn_base + REG_CLDMA_UL_CFG);
  199. dl_cfg = ioread32(hw_info->ap_ao_base + REG_CLDMA_DL_CFG);
  200. /* Configure the DRAM address mode */
  201. ul_cfg &= ~UL_CFG_BIT_MODE_MASK;
  202. dl_cfg &= ~DL_CFG_BIT_MODE_MASK;
  203. if (hw_info->hw_mode == MODE_BIT_64) {
  204. ul_cfg |= UL_CFG_BIT_MODE_64;
  205. dl_cfg |= DL_CFG_BIT_MODE_64;
  206. } else if (hw_info->hw_mode == MODE_BIT_40) {
  207. ul_cfg |= UL_CFG_BIT_MODE_40;
  208. dl_cfg |= DL_CFG_BIT_MODE_40;
  209. } else if (hw_info->hw_mode == MODE_BIT_36) {
  210. ul_cfg |= UL_CFG_BIT_MODE_36;
  211. dl_cfg |= DL_CFG_BIT_MODE_36;
  212. }
  213. iowrite32(ul_cfg, hw_info->ap_pdn_base + REG_CLDMA_UL_CFG);
  214. dl_cfg |= DL_CFG_UP_HW_LAST;
  215. iowrite32(dl_cfg, hw_info->ap_ao_base + REG_CLDMA_DL_CFG);
  216. iowrite32(0, hw_info->ap_ao_base + REG_CLDMA_INT_MASK);
  217. iowrite32(BUSY_MASK_MD, hw_info->ap_ao_base + REG_CLDMA_BUSY_MASK);
  218. iowrite32(UL_MEM_CHECK_DIS, hw_info->ap_pdn_base + REG_CLDMA_UL_MEM);
  219. iowrite32(DL_MEM_CHECK_DIS, hw_info->ap_pdn_base + REG_CLDMA_DL_MEM);
  220. }
  221. void t7xx_cldma_hw_stop_all_qs(struct t7xx_cldma_hw *hw_info, enum mtk_txrx tx_rx)
  222. {
  223. void __iomem *reg;
  224. reg = tx_rx == MTK_RX ? hw_info->ap_pdn_base + REG_CLDMA_DL_STOP_CMD :
  225. hw_info->ap_pdn_base + REG_CLDMA_UL_STOP_CMD;
  226. iowrite32(CLDMA_ALL_Q, reg);
  227. }
  228. void t7xx_cldma_hw_stop(struct t7xx_cldma_hw *hw_info, enum mtk_txrx tx_rx)
  229. {
  230. void __iomem *reg;
  231. reg = tx_rx == MTK_RX ? hw_info->ap_ao_base + REG_CLDMA_L2RIMSR0 :
  232. hw_info->ap_pdn_base + REG_CLDMA_L2TIMSR0;
  233. iowrite32(TXRX_STATUS_BITMASK, reg);
  234. iowrite32(EMPTY_STATUS_BITMASK, reg);
  235. }