qcom-geni-se.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _LINUX_QCOM_GENI_SE
  6. #define _LINUX_QCOM_GENI_SE
  7. /* Transfer mode supported by GENI Serial Engines */
  8. enum geni_se_xfer_mode {
  9. GENI_SE_INVALID,
  10. GENI_SE_FIFO,
  11. GENI_SE_DMA,
  12. };
  13. /* Protocols supported by GENI Serial Engines */
  14. enum geni_se_protocol_type {
  15. GENI_SE_NONE,
  16. GENI_SE_SPI,
  17. GENI_SE_UART,
  18. GENI_SE_I2C,
  19. GENI_SE_I3C,
  20. };
  21. struct geni_wrapper;
  22. struct clk;
  23. /**
  24. * struct geni_se - GENI Serial Engine
  25. * @base: Base Address of the Serial Engine's register block
  26. * @dev: Pointer to the Serial Engine device
  27. * @wrapper: Pointer to the parent QUP Wrapper core
  28. * @clk: Handle to the core serial engine clock
  29. * @num_clk_levels: Number of valid clock levels in clk_perf_tbl
  30. * @clk_perf_tbl: Table of clock frequency input to serial engine clock
  31. */
  32. struct geni_se {
  33. void __iomem *base;
  34. struct device *dev;
  35. struct geni_wrapper *wrapper;
  36. struct clk *clk;
  37. unsigned int num_clk_levels;
  38. unsigned long *clk_perf_tbl;
  39. };
  40. /* Common SE registers */
  41. #define GENI_FORCE_DEFAULT_REG 0x20
  42. #define SE_GENI_STATUS 0x40
  43. #define GENI_SER_M_CLK_CFG 0x48
  44. #define GENI_SER_S_CLK_CFG 0x4c
  45. #define GENI_FW_REVISION_RO 0x68
  46. #define SE_GENI_CLK_SEL 0x7c
  47. #define SE_GENI_DMA_MODE_EN 0x258
  48. #define SE_GENI_M_CMD0 0x600
  49. #define SE_GENI_M_CMD_CTRL_REG 0x604
  50. #define SE_GENI_M_IRQ_STATUS 0x610
  51. #define SE_GENI_M_IRQ_EN 0x614
  52. #define SE_GENI_M_IRQ_CLEAR 0x618
  53. #define SE_GENI_S_CMD0 0x630
  54. #define SE_GENI_S_CMD_CTRL_REG 0x634
  55. #define SE_GENI_S_IRQ_STATUS 0x640
  56. #define SE_GENI_S_IRQ_EN 0x644
  57. #define SE_GENI_S_IRQ_CLEAR 0x648
  58. #define SE_GENI_TX_FIFOn 0x700
  59. #define SE_GENI_RX_FIFOn 0x780
  60. #define SE_GENI_TX_FIFO_STATUS 0x800
  61. #define SE_GENI_RX_FIFO_STATUS 0x804
  62. #define SE_GENI_TX_WATERMARK_REG 0x80c
  63. #define SE_GENI_RX_WATERMARK_REG 0x810
  64. #define SE_GENI_RX_RFR_WATERMARK_REG 0x814
  65. #define SE_GENI_IOS 0x908
  66. #define SE_DMA_TX_IRQ_STAT 0xc40
  67. #define SE_DMA_TX_IRQ_CLR 0xc44
  68. #define SE_DMA_TX_FSM_RST 0xc58
  69. #define SE_DMA_RX_IRQ_STAT 0xd40
  70. #define SE_DMA_RX_IRQ_CLR 0xd44
  71. #define SE_DMA_RX_FSM_RST 0xd58
  72. #define SE_HW_PARAM_0 0xe24
  73. #define SE_HW_PARAM_1 0xe28
  74. /* GENI_FORCE_DEFAULT_REG fields */
  75. #define FORCE_DEFAULT BIT(0)
  76. /* GENI_STATUS fields */
  77. #define M_GENI_CMD_ACTIVE BIT(0)
  78. #define S_GENI_CMD_ACTIVE BIT(12)
  79. /* GENI_SER_M_CLK_CFG/GENI_SER_S_CLK_CFG */
  80. #define SER_CLK_EN BIT(0)
  81. #define CLK_DIV_MSK GENMASK(15, 4)
  82. #define CLK_DIV_SHFT 4
  83. /* GENI_FW_REVISION_RO fields */
  84. #define FW_REV_PROTOCOL_MSK GENMASK(15, 8)
  85. #define FW_REV_PROTOCOL_SHFT 8
  86. /* GENI_CLK_SEL fields */
  87. #define CLK_SEL_MSK GENMASK(2, 0)
  88. /* SE_GENI_DMA_MODE_EN */
  89. #define GENI_DMA_MODE_EN BIT(0)
  90. /* GENI_M_CMD0 fields */
  91. #define M_OPCODE_MSK GENMASK(31, 27)
  92. #define M_OPCODE_SHFT 27
  93. #define M_PARAMS_MSK GENMASK(26, 0)
  94. /* GENI_M_CMD_CTRL_REG */
  95. #define M_GENI_CMD_CANCEL BIT(2)
  96. #define M_GENI_CMD_ABORT BIT(1)
  97. #define M_GENI_DISABLE BIT(0)
  98. /* GENI_S_CMD0 fields */
  99. #define S_OPCODE_MSK GENMASK(31, 27)
  100. #define S_OPCODE_SHFT 27
  101. #define S_PARAMS_MSK GENMASK(26, 0)
  102. /* GENI_S_CMD_CTRL_REG */
  103. #define S_GENI_CMD_CANCEL BIT(2)
  104. #define S_GENI_CMD_ABORT BIT(1)
  105. #define S_GENI_DISABLE BIT(0)
  106. /* GENI_M_IRQ_EN fields */
  107. #define M_CMD_DONE_EN BIT(0)
  108. #define M_CMD_OVERRUN_EN BIT(1)
  109. #define M_ILLEGAL_CMD_EN BIT(2)
  110. #define M_CMD_FAILURE_EN BIT(3)
  111. #define M_CMD_CANCEL_EN BIT(4)
  112. #define M_CMD_ABORT_EN BIT(5)
  113. #define M_TIMESTAMP_EN BIT(6)
  114. #define M_RX_IRQ_EN BIT(7)
  115. #define M_GP_SYNC_IRQ_0_EN BIT(8)
  116. #define M_GP_IRQ_0_EN BIT(9)
  117. #define M_GP_IRQ_1_EN BIT(10)
  118. #define M_GP_IRQ_2_EN BIT(11)
  119. #define M_GP_IRQ_3_EN BIT(12)
  120. #define M_GP_IRQ_4_EN BIT(13)
  121. #define M_GP_IRQ_5_EN BIT(14)
  122. #define M_IO_DATA_DEASSERT_EN BIT(22)
  123. #define M_IO_DATA_ASSERT_EN BIT(23)
  124. #define M_RX_FIFO_RD_ERR_EN BIT(24)
  125. #define M_RX_FIFO_WR_ERR_EN BIT(25)
  126. #define M_RX_FIFO_WATERMARK_EN BIT(26)
  127. #define M_RX_FIFO_LAST_EN BIT(27)
  128. #define M_TX_FIFO_RD_ERR_EN BIT(28)
  129. #define M_TX_FIFO_WR_ERR_EN BIT(29)
  130. #define M_TX_FIFO_WATERMARK_EN BIT(30)
  131. #define M_SEC_IRQ_EN BIT(31)
  132. #define M_COMMON_GENI_M_IRQ_EN (GENMASK(6, 1) | \
  133. M_IO_DATA_DEASSERT_EN | \
  134. M_IO_DATA_ASSERT_EN | M_RX_FIFO_RD_ERR_EN | \
  135. M_RX_FIFO_WR_ERR_EN | M_TX_FIFO_RD_ERR_EN | \
  136. M_TX_FIFO_WR_ERR_EN)
  137. /* GENI_S_IRQ_EN fields */
  138. #define S_CMD_DONE_EN BIT(0)
  139. #define S_CMD_OVERRUN_EN BIT(1)
  140. #define S_ILLEGAL_CMD_EN BIT(2)
  141. #define S_CMD_FAILURE_EN BIT(3)
  142. #define S_CMD_CANCEL_EN BIT(4)
  143. #define S_CMD_ABORT_EN BIT(5)
  144. #define S_GP_SYNC_IRQ_0_EN BIT(8)
  145. #define S_GP_IRQ_0_EN BIT(9)
  146. #define S_GP_IRQ_1_EN BIT(10)
  147. #define S_GP_IRQ_2_EN BIT(11)
  148. #define S_GP_IRQ_3_EN BIT(12)
  149. #define S_GP_IRQ_4_EN BIT(13)
  150. #define S_GP_IRQ_5_EN BIT(14)
  151. #define S_IO_DATA_DEASSERT_EN BIT(22)
  152. #define S_IO_DATA_ASSERT_EN BIT(23)
  153. #define S_RX_FIFO_RD_ERR_EN BIT(24)
  154. #define S_RX_FIFO_WR_ERR_EN BIT(25)
  155. #define S_RX_FIFO_WATERMARK_EN BIT(26)
  156. #define S_RX_FIFO_LAST_EN BIT(27)
  157. #define S_COMMON_GENI_S_IRQ_EN (GENMASK(5, 1) | GENMASK(13, 9) | \
  158. S_RX_FIFO_RD_ERR_EN | S_RX_FIFO_WR_ERR_EN)
  159. /* GENI_/TX/RX/RX_RFR/_WATERMARK_REG fields */
  160. #define WATERMARK_MSK GENMASK(5, 0)
  161. /* GENI_TX_FIFO_STATUS fields */
  162. #define TX_FIFO_WC GENMASK(27, 0)
  163. /* GENI_RX_FIFO_STATUS fields */
  164. #define RX_LAST BIT(31)
  165. #define RX_LAST_BYTE_VALID_MSK GENMASK(30, 28)
  166. #define RX_LAST_BYTE_VALID_SHFT 28
  167. #define RX_FIFO_WC_MSK GENMASK(24, 0)
  168. /* SE_GENI_IOS fields */
  169. #define IO2_DATA_IN BIT(1)
  170. #define RX_DATA_IN BIT(0)
  171. /* SE_DMA_TX_IRQ_STAT Register fields */
  172. #define TX_DMA_DONE BIT(0)
  173. #define TX_EOT BIT(1)
  174. #define TX_SBE BIT(2)
  175. #define TX_RESET_DONE BIT(3)
  176. /* SE_DMA_RX_IRQ_STAT Register fields */
  177. #define RX_DMA_DONE BIT(0)
  178. #define RX_EOT BIT(1)
  179. #define RX_SBE BIT(2)
  180. #define RX_RESET_DONE BIT(3)
  181. #define RX_FLUSH_DONE BIT(4)
  182. #define RX_GENI_GP_IRQ GENMASK(10, 5)
  183. #define RX_GENI_CANCEL_IRQ BIT(11)
  184. #define RX_GENI_GP_IRQ_EXT GENMASK(13, 12)
  185. /* SE_HW_PARAM_0 fields */
  186. #define TX_FIFO_WIDTH_MSK GENMASK(29, 24)
  187. #define TX_FIFO_WIDTH_SHFT 24
  188. #define TX_FIFO_DEPTH_MSK GENMASK(21, 16)
  189. #define TX_FIFO_DEPTH_SHFT 16
  190. /* SE_HW_PARAM_1 fields */
  191. #define RX_FIFO_WIDTH_MSK GENMASK(29, 24)
  192. #define RX_FIFO_WIDTH_SHFT 24
  193. #define RX_FIFO_DEPTH_MSK GENMASK(21, 16)
  194. #define RX_FIFO_DEPTH_SHFT 16
  195. #define HW_VER_MAJOR_MASK GENMASK(31, 28)
  196. #define HW_VER_MAJOR_SHFT 28
  197. #define HW_VER_MINOR_MASK GENMASK(27, 16)
  198. #define HW_VER_MINOR_SHFT 16
  199. #define HW_VER_STEP_MASK GENMASK(15, 0)
  200. #if IS_ENABLED(CONFIG_QCOM_GENI_SE)
  201. u32 geni_se_get_qup_hw_version(struct geni_se *se);
  202. #define geni_se_get_wrapper_version(se, major, minor, step) do { \
  203. u32 ver; \
  204. \
  205. ver = geni_se_get_qup_hw_version(se); \
  206. major = (ver & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT; \
  207. minor = (ver & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT; \
  208. step = version & HW_VER_STEP_MASK; \
  209. } while (0)
  210. /**
  211. * geni_se_read_proto() - Read the protocol configured for a serial engine
  212. * @se: Pointer to the concerned serial engine.
  213. *
  214. * Return: Protocol value as configured in the serial engine.
  215. */
  216. static inline u32 geni_se_read_proto(struct geni_se *se)
  217. {
  218. u32 val;
  219. val = readl_relaxed(se->base + GENI_FW_REVISION_RO);
  220. return (val & FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT;
  221. }
  222. /**
  223. * geni_se_setup_m_cmd() - Setup the primary sequencer
  224. * @se: Pointer to the concerned serial engine.
  225. * @cmd: Command/Operation to setup in the primary sequencer.
  226. * @params: Parameter for the sequencer command.
  227. *
  228. * This function is used to configure the primary sequencer with the
  229. * command and its associated parameters.
  230. */
  231. static inline void geni_se_setup_m_cmd(struct geni_se *se, u32 cmd, u32 params)
  232. {
  233. u32 m_cmd;
  234. m_cmd = (cmd << M_OPCODE_SHFT) | (params & M_PARAMS_MSK);
  235. writel_relaxed(m_cmd, se->base + SE_GENI_M_CMD0);
  236. }
  237. /**
  238. * geni_se_setup_s_cmd() - Setup the secondary sequencer
  239. * @se: Pointer to the concerned serial engine.
  240. * @cmd: Command/Operation to setup in the secondary sequencer.
  241. * @params: Parameter for the sequencer command.
  242. *
  243. * This function is used to configure the secondary sequencer with the
  244. * command and its associated parameters.
  245. */
  246. static inline void geni_se_setup_s_cmd(struct geni_se *se, u32 cmd, u32 params)
  247. {
  248. u32 s_cmd;
  249. s_cmd = readl_relaxed(se->base + SE_GENI_S_CMD0);
  250. s_cmd &= ~(S_OPCODE_MSK | S_PARAMS_MSK);
  251. s_cmd |= (cmd << S_OPCODE_SHFT);
  252. s_cmd |= (params & S_PARAMS_MSK);
  253. writel_relaxed(s_cmd, se->base + SE_GENI_S_CMD0);
  254. }
  255. /**
  256. * geni_se_cancel_m_cmd() - Cancel the command configured in the primary
  257. * sequencer
  258. * @se: Pointer to the concerned serial engine.
  259. *
  260. * This function is used to cancel the currently configured command in the
  261. * primary sequencer.
  262. */
  263. static inline void geni_se_cancel_m_cmd(struct geni_se *se)
  264. {
  265. writel_relaxed(M_GENI_CMD_CANCEL, se->base + SE_GENI_M_CMD_CTRL_REG);
  266. }
  267. /**
  268. * geni_se_cancel_s_cmd() - Cancel the command configured in the secondary
  269. * sequencer
  270. * @se: Pointer to the concerned serial engine.
  271. *
  272. * This function is used to cancel the currently configured command in the
  273. * secondary sequencer.
  274. */
  275. static inline void geni_se_cancel_s_cmd(struct geni_se *se)
  276. {
  277. writel_relaxed(S_GENI_CMD_CANCEL, se->base + SE_GENI_S_CMD_CTRL_REG);
  278. }
  279. /**
  280. * geni_se_abort_m_cmd() - Abort the command configured in the primary sequencer
  281. * @se: Pointer to the concerned serial engine.
  282. *
  283. * This function is used to force abort the currently configured command in the
  284. * primary sequencer.
  285. */
  286. static inline void geni_se_abort_m_cmd(struct geni_se *se)
  287. {
  288. writel_relaxed(M_GENI_CMD_ABORT, se->base + SE_GENI_M_CMD_CTRL_REG);
  289. }
  290. /**
  291. * geni_se_abort_s_cmd() - Abort the command configured in the secondary
  292. * sequencer
  293. * @se: Pointer to the concerned serial engine.
  294. *
  295. * This function is used to force abort the currently configured command in the
  296. * secondary sequencer.
  297. */
  298. static inline void geni_se_abort_s_cmd(struct geni_se *se)
  299. {
  300. writel_relaxed(S_GENI_CMD_ABORT, se->base + SE_GENI_S_CMD_CTRL_REG);
  301. }
  302. /**
  303. * geni_se_get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
  304. * @se: Pointer to the concerned serial engine.
  305. *
  306. * This function is used to get the depth i.e. number of elements in the
  307. * TX fifo of the serial engine.
  308. *
  309. * Return: TX fifo depth in units of FIFO words.
  310. */
  311. static inline u32 geni_se_get_tx_fifo_depth(struct geni_se *se)
  312. {
  313. u32 val;
  314. val = readl_relaxed(se->base + SE_HW_PARAM_0);
  315. return (val & TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT;
  316. }
  317. /**
  318. * geni_se_get_tx_fifo_width() - Get the TX fifo width of the serial engine
  319. * @se: Pointer to the concerned serial engine.
  320. *
  321. * This function is used to get the width i.e. word size per element in the
  322. * TX fifo of the serial engine.
  323. *
  324. * Return: TX fifo width in bits
  325. */
  326. static inline u32 geni_se_get_tx_fifo_width(struct geni_se *se)
  327. {
  328. u32 val;
  329. val = readl_relaxed(se->base + SE_HW_PARAM_0);
  330. return (val & TX_FIFO_WIDTH_MSK) >> TX_FIFO_WIDTH_SHFT;
  331. }
  332. /**
  333. * geni_se_get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
  334. * @se: Pointer to the concerned serial engine.
  335. *
  336. * This function is used to get the depth i.e. number of elements in the
  337. * RX fifo of the serial engine.
  338. *
  339. * Return: RX fifo depth in units of FIFO words
  340. */
  341. static inline u32 geni_se_get_rx_fifo_depth(struct geni_se *se)
  342. {
  343. u32 val;
  344. val = readl_relaxed(se->base + SE_HW_PARAM_1);
  345. return (val & RX_FIFO_DEPTH_MSK) >> RX_FIFO_DEPTH_SHFT;
  346. }
  347. void geni_se_init(struct geni_se *se, u32 rx_wm, u32 rx_rfr);
  348. void geni_se_select_mode(struct geni_se *se, enum geni_se_xfer_mode mode);
  349. void geni_se_config_packing(struct geni_se *se, int bpw, int pack_words,
  350. bool msb_to_lsb, bool tx_cfg, bool rx_cfg);
  351. int geni_se_resources_off(struct geni_se *se);
  352. int geni_se_resources_on(struct geni_se *se);
  353. int geni_se_clk_tbl_get(struct geni_se *se, unsigned long **tbl);
  354. int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq,
  355. unsigned int *index, unsigned long *res_freq,
  356. bool exact);
  357. int geni_se_tx_dma_prep(struct geni_se *se, void *buf, size_t len,
  358. dma_addr_t *iova);
  359. int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len,
  360. dma_addr_t *iova);
  361. void geni_se_tx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
  362. void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
  363. #endif
  364. #endif