ste_dma40.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2007-2010
  3. * Author: Per Forlin <per.forlin@stericsson.com> for ST-Ericsson
  4. * Author: Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson
  5. * License terms: GNU General Public License (GPL) version 2
  6. */
  7. #ifndef STE_DMA40_H
  8. #define STE_DMA40_H
  9. #include <linux/dmaengine.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/dmaengine.h>
  13. /* dev types for memcpy */
  14. #define STEDMA40_DEV_DST_MEMORY (-1)
  15. #define STEDMA40_DEV_SRC_MEMORY (-1)
  16. /*
  17. * Description of bitfields of channel_type variable is available in
  18. * the info structure.
  19. */
  20. /* Priority */
  21. #define STEDMA40_INFO_PRIO_TYPE_POS 2
  22. #define STEDMA40_HIGH_PRIORITY_CHANNEL (0x1 << STEDMA40_INFO_PRIO_TYPE_POS)
  23. #define STEDMA40_LOW_PRIORITY_CHANNEL (0x2 << STEDMA40_INFO_PRIO_TYPE_POS)
  24. /* Mode */
  25. #define STEDMA40_INFO_CH_MODE_TYPE_POS 6
  26. #define STEDMA40_CHANNEL_IN_PHY_MODE (0x1 << STEDMA40_INFO_CH_MODE_TYPE_POS)
  27. #define STEDMA40_CHANNEL_IN_LOG_MODE (0x2 << STEDMA40_INFO_CH_MODE_TYPE_POS)
  28. #define STEDMA40_CHANNEL_IN_OPER_MODE (0x3 << STEDMA40_INFO_CH_MODE_TYPE_POS)
  29. /* Mode options */
  30. #define STEDMA40_INFO_CH_MODE_OPT_POS 8
  31. #define STEDMA40_PCHAN_BASIC_MODE (0x1 << STEDMA40_INFO_CH_MODE_OPT_POS)
  32. #define STEDMA40_PCHAN_MODULO_MODE (0x2 << STEDMA40_INFO_CH_MODE_OPT_POS)
  33. #define STEDMA40_PCHAN_DOUBLE_DST_MODE (0x3 << STEDMA40_INFO_CH_MODE_OPT_POS)
  34. #define STEDMA40_LCHAN_SRC_PHY_DST_LOG (0x1 << STEDMA40_INFO_CH_MODE_OPT_POS)
  35. #define STEDMA40_LCHAN_SRC_LOG_DST_PHS (0x2 << STEDMA40_INFO_CH_MODE_OPT_POS)
  36. #define STEDMA40_LCHAN_SRC_LOG_DST_LOG (0x3 << STEDMA40_INFO_CH_MODE_OPT_POS)
  37. /* Interrupt */
  38. #define STEDMA40_INFO_TIM_POS 10
  39. #define STEDMA40_NO_TIM_FOR_LINK (0x0 << STEDMA40_INFO_TIM_POS)
  40. #define STEDMA40_TIM_FOR_LINK (0x1 << STEDMA40_INFO_TIM_POS)
  41. /* End of channel_type configuration */
  42. #define STEDMA40_ESIZE_8_BIT 0x0
  43. #define STEDMA40_ESIZE_16_BIT 0x1
  44. #define STEDMA40_ESIZE_32_BIT 0x2
  45. #define STEDMA40_ESIZE_64_BIT 0x3
  46. /* The value 4 indicates that PEN-reg shall be set to 0 */
  47. #define STEDMA40_PSIZE_PHY_1 0x4
  48. #define STEDMA40_PSIZE_PHY_2 0x0
  49. #define STEDMA40_PSIZE_PHY_4 0x1
  50. #define STEDMA40_PSIZE_PHY_8 0x2
  51. #define STEDMA40_PSIZE_PHY_16 0x3
  52. /*
  53. * The number of elements differ in logical and
  54. * physical mode
  55. */
  56. #define STEDMA40_PSIZE_LOG_1 STEDMA40_PSIZE_PHY_2
  57. #define STEDMA40_PSIZE_LOG_4 STEDMA40_PSIZE_PHY_4
  58. #define STEDMA40_PSIZE_LOG_8 STEDMA40_PSIZE_PHY_8
  59. #define STEDMA40_PSIZE_LOG_16 STEDMA40_PSIZE_PHY_16
  60. /* Maximum number of possible physical channels */
  61. #define STEDMA40_MAX_PHYS 32
  62. enum stedma40_flow_ctrl {
  63. STEDMA40_NO_FLOW_CTRL,
  64. STEDMA40_FLOW_CTRL,
  65. };
  66. enum stedma40_endianess {
  67. STEDMA40_LITTLE_ENDIAN,
  68. STEDMA40_BIG_ENDIAN
  69. };
  70. enum stedma40_periph_data_width {
  71. STEDMA40_BYTE_WIDTH = STEDMA40_ESIZE_8_BIT,
  72. STEDMA40_HALFWORD_WIDTH = STEDMA40_ESIZE_16_BIT,
  73. STEDMA40_WORD_WIDTH = STEDMA40_ESIZE_32_BIT,
  74. STEDMA40_DOUBLEWORD_WIDTH = STEDMA40_ESIZE_64_BIT
  75. };
  76. enum stedma40_xfer_dir {
  77. STEDMA40_MEM_TO_MEM = 1,
  78. STEDMA40_MEM_TO_PERIPH,
  79. STEDMA40_PERIPH_TO_MEM,
  80. STEDMA40_PERIPH_TO_PERIPH
  81. };
  82. /**
  83. * struct stedma40_chan_cfg - dst/src channel configuration
  84. *
  85. * @endianess: Endianess of the src/dst hardware
  86. * @data_width: Data width of the src/dst hardware
  87. * @p_size: Burst size
  88. * @flow_ctrl: Flow control on/off.
  89. */
  90. struct stedma40_half_channel_info {
  91. enum stedma40_endianess endianess;
  92. enum stedma40_periph_data_width data_width;
  93. int psize;
  94. enum stedma40_flow_ctrl flow_ctrl;
  95. };
  96. /**
  97. * struct stedma40_chan_cfg - Structure to be filled by client drivers.
  98. *
  99. * @dir: MEM 2 MEM, PERIPH 2 MEM , MEM 2 PERIPH, PERIPH 2 PERIPH
  100. * @channel_type: priority, mode, mode options and interrupt configuration.
  101. * @src_dev_type: Src device type
  102. * @dst_dev_type: Dst device type
  103. * @src_info: Parameters for dst half channel
  104. * @dst_info: Parameters for dst half channel
  105. *
  106. *
  107. * This structure has to be filled by the client drivers.
  108. * It is recommended to do all dma configurations for clients in the machine.
  109. *
  110. */
  111. struct stedma40_chan_cfg {
  112. enum stedma40_xfer_dir dir;
  113. unsigned int channel_type;
  114. int src_dev_type;
  115. int dst_dev_type;
  116. struct stedma40_half_channel_info src_info;
  117. struct stedma40_half_channel_info dst_info;
  118. };
  119. /**
  120. * struct stedma40_platform_data - Configuration struct for the dma device.
  121. *
  122. * @dev_len: length of dev_tx and dev_rx
  123. * @dev_tx: mapping between destination event line and io address
  124. * @dev_rx: mapping between source event line and io address
  125. * @memcpy: list of memcpy event lines
  126. * @memcpy_len: length of memcpy
  127. * @memcpy_conf_phy: default configuration of physical channel memcpy
  128. * @memcpy_conf_log: default configuration of logical channel memcpy
  129. * @disabled_channels: A vector, ending with -1, that marks physical channels
  130. * that are for different reasons not available for the driver.
  131. */
  132. struct stedma40_platform_data {
  133. u32 dev_len;
  134. const dma_addr_t *dev_tx;
  135. const dma_addr_t *dev_rx;
  136. int *memcpy;
  137. u32 memcpy_len;
  138. struct stedma40_chan_cfg *memcpy_conf_phy;
  139. struct stedma40_chan_cfg *memcpy_conf_log;
  140. int disabled_channels[STEDMA40_MAX_PHYS];
  141. };
  142. /**
  143. * stedma40_filter() - Provides stedma40_chan_cfg to the
  144. * ste_dma40 dma driver via the dmaengine framework.
  145. * does some checking of what's provided.
  146. *
  147. * Never directly called by client. It used by dmaengine.
  148. * @chan: dmaengine handle.
  149. * @data: Must be of type: struct stedma40_chan_cfg and is
  150. * the configuration of the framework.
  151. *
  152. *
  153. */
  154. bool stedma40_filter(struct dma_chan *chan, void *data);
  155. /**
  156. * stedma40_memcpy_sg() - extension of the dma framework, memcpy to/from
  157. * scattergatter lists.
  158. *
  159. * @chan: dmaengine handle
  160. * @sgl_dst: Destination scatter list
  161. * @sgl_src: Source scatter list
  162. * @sgl_len: The length of each scatterlist. Both lists must be of equal length
  163. * and each element must match the corresponding element in the other scatter
  164. * list.
  165. * @flags: is actually enum dma_ctrl_flags. See dmaengine.h
  166. */
  167. struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
  168. struct scatterlist *sgl_dst,
  169. struct scatterlist *sgl_src,
  170. unsigned int sgl_len,
  171. unsigned long flags);
  172. /**
  173. * stedma40_slave_mem() - Transfers a raw data buffer to or from a slave
  174. * (=device)
  175. *
  176. * @chan: dmaengine handle
  177. * @addr: source or destination physicall address.
  178. * @size: bytes to transfer
  179. * @direction: direction of transfer
  180. * @flags: is actually enum dma_ctrl_flags. See dmaengine.h
  181. */
  182. static inline struct
  183. dma_async_tx_descriptor *stedma40_slave_mem(struct dma_chan *chan,
  184. dma_addr_t addr,
  185. unsigned int size,
  186. enum dma_data_direction direction,
  187. unsigned long flags)
  188. {
  189. struct scatterlist sg;
  190. sg_init_table(&sg, 1);
  191. sg.dma_address = addr;
  192. sg.length = size;
  193. return chan->device->device_prep_slave_sg(chan, &sg, 1,
  194. direction, flags);
  195. }
  196. #endif