st_fdma.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * DMA driver header for STMicroelectronics STi FDMA controller
  3. *
  4. * Copyright (C) 2014 STMicroelectronics
  5. *
  6. * Author: Ludovic Barre <Ludovic.barre@st.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #ifndef __DMA_ST_FDMA_H
  14. #define __DMA_ST_FDMA_H
  15. #include <linux/dmaengine.h>
  16. #include <linux/dmapool.h>
  17. #include <linux/io.h>
  18. #include <linux/remoteproc/st_slim_rproc.h>
  19. #include "virt-dma.h"
  20. #define ST_FDMA_NR_DREQS 32
  21. #define FW_NAME_SIZE 30
  22. #define DRIVER_NAME "st-fdma"
  23. /**
  24. * struct st_fdma_generic_node - Free running/paced generic node
  25. *
  26. * @length: Length in bytes of a line in a 2D mem to mem
  27. * @sstride: Stride, in bytes, between source lines in a 2D data move
  28. * @dstride: Stride, in bytes, between destination lines in a 2D data move
  29. */
  30. struct st_fdma_generic_node {
  31. u32 length;
  32. u32 sstride;
  33. u32 dstride;
  34. };
  35. /**
  36. * struct st_fdma_hw_node - Node structure used by fdma hw
  37. *
  38. * @next: Pointer to next node
  39. * @control: Transfer Control Parameters
  40. * @nbytes: Number of Bytes to read
  41. * @saddr: Source address
  42. * @daddr: Destination address
  43. *
  44. * @generic: generic node for free running/paced transfert type
  45. * 2 others transfert type are possible, but not yet implemented
  46. *
  47. * The NODE structures must be aligned to a 32 byte boundary
  48. */
  49. struct st_fdma_hw_node {
  50. u32 next;
  51. u32 control;
  52. u32 nbytes;
  53. u32 saddr;
  54. u32 daddr;
  55. union {
  56. struct st_fdma_generic_node generic;
  57. };
  58. } __aligned(32);
  59. /*
  60. * node control parameters
  61. */
  62. #define FDMA_NODE_CTRL_REQ_MAP_MASK GENMASK(4, 0)
  63. #define FDMA_NODE_CTRL_REQ_MAP_FREE_RUN 0x0
  64. #define FDMA_NODE_CTRL_REQ_MAP_DREQ(n) ((n)&FDMA_NODE_CTRL_REQ_MAP_MASK)
  65. #define FDMA_NODE_CTRL_REQ_MAP_EXT FDMA_NODE_CTRL_REQ_MAP_MASK
  66. #define FDMA_NODE_CTRL_SRC_MASK GENMASK(6, 5)
  67. #define FDMA_NODE_CTRL_SRC_STATIC BIT(5)
  68. #define FDMA_NODE_CTRL_SRC_INCR BIT(6)
  69. #define FDMA_NODE_CTRL_DST_MASK GENMASK(8, 7)
  70. #define FDMA_NODE_CTRL_DST_STATIC BIT(7)
  71. #define FDMA_NODE_CTRL_DST_INCR BIT(8)
  72. #define FDMA_NODE_CTRL_SECURE BIT(15)
  73. #define FDMA_NODE_CTRL_PAUSE_EON BIT(30)
  74. #define FDMA_NODE_CTRL_INT_EON BIT(31)
  75. /**
  76. * struct st_fdma_sw_node - descriptor structure for link list
  77. *
  78. * @pdesc: Physical address of desc
  79. * @node: link used for putting this into a channel queue
  80. */
  81. struct st_fdma_sw_node {
  82. dma_addr_t pdesc;
  83. struct st_fdma_hw_node *desc;
  84. };
  85. #define NAME_SZ 10
  86. struct st_fdma_driverdata {
  87. u32 id;
  88. char name[NAME_SZ];
  89. };
  90. struct st_fdma_desc {
  91. struct virt_dma_desc vdesc;
  92. struct st_fdma_chan *fchan;
  93. bool iscyclic;
  94. unsigned int n_nodes;
  95. struct st_fdma_sw_node node[];
  96. };
  97. enum st_fdma_type {
  98. ST_FDMA_TYPE_FREE_RUN,
  99. ST_FDMA_TYPE_PACED,
  100. };
  101. struct st_fdma_cfg {
  102. struct device_node *of_node;
  103. enum st_fdma_type type;
  104. dma_addr_t dev_addr;
  105. enum dma_transfer_direction dir;
  106. int req_line; /* request line */
  107. long req_ctrl; /* Request control */
  108. };
  109. struct st_fdma_chan {
  110. struct st_fdma_dev *fdev;
  111. struct dma_pool *node_pool;
  112. struct dma_slave_config scfg;
  113. struct st_fdma_cfg cfg;
  114. int dreq_line;
  115. struct virt_dma_chan vchan;
  116. struct st_fdma_desc *fdesc;
  117. enum dma_status status;
  118. };
  119. struct st_fdma_dev {
  120. struct device *dev;
  121. const struct st_fdma_driverdata *drvdata;
  122. struct dma_device dma_device;
  123. struct st_slim_rproc *slim_rproc;
  124. int irq;
  125. struct st_fdma_chan *chans;
  126. spinlock_t dreq_lock;
  127. unsigned long dreq_mask;
  128. u32 nr_channels;
  129. char fw_name[FW_NAME_SIZE];
  130. };
  131. /* Peripheral Registers*/
  132. #define FDMA_CMD_STA_OFST 0xFC0
  133. #define FDMA_CMD_SET_OFST 0xFC4
  134. #define FDMA_CMD_CLR_OFST 0xFC8
  135. #define FDMA_CMD_MASK_OFST 0xFCC
  136. #define FDMA_CMD_START(ch) (0x1 << (ch << 1))
  137. #define FDMA_CMD_PAUSE(ch) (0x2 << (ch << 1))
  138. #define FDMA_CMD_FLUSH(ch) (0x3 << (ch << 1))
  139. #define FDMA_INT_STA_OFST 0xFD0
  140. #define FDMA_INT_STA_CH 0x1
  141. #define FDMA_INT_STA_ERR 0x2
  142. #define FDMA_INT_SET_OFST 0xFD4
  143. #define FDMA_INT_CLR_OFST 0xFD8
  144. #define FDMA_INT_MASK_OFST 0xFDC
  145. #define fdma_read(fdev, name) \
  146. readl((fdev)->slim_rproc->peri + name)
  147. #define fdma_write(fdev, val, name) \
  148. writel((val), (fdev)->slim_rproc->peri + name)
  149. /* fchan interface (dmem) */
  150. #define FDMA_CH_CMD_OFST 0x200
  151. #define FDMA_CH_CMD_STA_MASK GENMASK(1, 0)
  152. #define FDMA_CH_CMD_STA_IDLE (0x0)
  153. #define FDMA_CH_CMD_STA_START (0x1)
  154. #define FDMA_CH_CMD_STA_RUNNING (0x2)
  155. #define FDMA_CH_CMD_STA_PAUSED (0x3)
  156. #define FDMA_CH_CMD_ERR_MASK GENMASK(4, 2)
  157. #define FDMA_CH_CMD_ERR_INT (0x0 << 2)
  158. #define FDMA_CH_CMD_ERR_NAND (0x1 << 2)
  159. #define FDMA_CH_CMD_ERR_MCHI (0x2 << 2)
  160. #define FDMA_CH_CMD_DATA_MASK GENMASK(31, 5)
  161. #define fchan_read(fchan, name) \
  162. readl((fchan)->fdev->slim_rproc->mem[ST_SLIM_DMEM].cpu_addr \
  163. + (fchan)->vchan.chan.chan_id * 0x4 \
  164. + name)
  165. #define fchan_write(fchan, val, name) \
  166. writel((val), (fchan)->fdev->slim_rproc->mem[ST_SLIM_DMEM].cpu_addr \
  167. + (fchan)->vchan.chan.chan_id * 0x4 \
  168. + name)
  169. /* req interface */
  170. #define FDMA_REQ_CTRL_OFST 0x240
  171. #define dreq_write(fchan, val, name) \
  172. writel((val), (fchan)->fdev->slim_rproc->mem[ST_SLIM_DMEM].cpu_addr \
  173. + fchan->dreq_line * 0x04 \
  174. + name)
  175. /* node interface */
  176. #define FDMA_NODE_SZ 128
  177. #define FDMA_PTRN_OFST 0x800
  178. #define FDMA_CNTN_OFST 0x808
  179. #define FDMA_SADDRN_OFST 0x80c
  180. #define FDMA_DADDRN_OFST 0x810
  181. #define fnode_read(fchan, name) \
  182. readl((fchan)->fdev->slim_rproc->mem[ST_SLIM_DMEM].cpu_addr \
  183. + (fchan)->vchan.chan.chan_id * FDMA_NODE_SZ \
  184. + name)
  185. #define fnode_write(fchan, val, name) \
  186. writel((val), (fchan)->fdev->slim_rproc->mem[ST_SLIM_DMEM].cpu_addr \
  187. + (fchan)->vchan.chan.chan_id * FDMA_NODE_SZ \
  188. + name)
  189. /*
  190. * request control bits
  191. */
  192. #define FDMA_REQ_CTRL_NUM_OPS_MASK GENMASK(31, 24)
  193. #define FDMA_REQ_CTRL_NUM_OPS(n) (FDMA_REQ_CTRL_NUM_OPS_MASK & \
  194. ((n) << 24))
  195. #define FDMA_REQ_CTRL_INITIATOR_MASK BIT(22)
  196. #define FDMA_REQ_CTRL_INIT0 (0x0 << 22)
  197. #define FDMA_REQ_CTRL_INIT1 (0x1 << 22)
  198. #define FDMA_REQ_CTRL_INC_ADDR_ON BIT(21)
  199. #define FDMA_REQ_CTRL_DATA_SWAP_ON BIT(17)
  200. #define FDMA_REQ_CTRL_WNR BIT(14)
  201. #define FDMA_REQ_CTRL_OPCODE_MASK GENMASK(7, 4)
  202. #define FDMA_REQ_CTRL_OPCODE_LD_ST1 (0x0 << 4)
  203. #define FDMA_REQ_CTRL_OPCODE_LD_ST2 (0x1 << 4)
  204. #define FDMA_REQ_CTRL_OPCODE_LD_ST4 (0x2 << 4)
  205. #define FDMA_REQ_CTRL_OPCODE_LD_ST8 (0x3 << 4)
  206. #define FDMA_REQ_CTRL_OPCODE_LD_ST16 (0x4 << 4)
  207. #define FDMA_REQ_CTRL_OPCODE_LD_ST32 (0x5 << 4)
  208. #define FDMA_REQ_CTRL_OPCODE_LD_ST64 (0x6 << 4)
  209. #define FDMA_REQ_CTRL_HOLDOFF_MASK GENMASK(2, 0)
  210. #define FDMA_REQ_CTRL_HOLDOFF(n) ((n) & FDMA_REQ_CTRL_HOLDOFF_MASK)
  211. /* bits used by client to configure request control */
  212. #define FDMA_REQ_CTRL_CFG_MASK (FDMA_REQ_CTRL_HOLDOFF_MASK | \
  213. FDMA_REQ_CTRL_DATA_SWAP_ON | \
  214. FDMA_REQ_CTRL_INC_ADDR_ON | \
  215. FDMA_REQ_CTRL_INITIATOR_MASK)
  216. #endif /* __DMA_ST_FDMA_H */