pl08x.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * linux/amba/pl08x.h - ARM PrimeCell DMA Controller driver
  3. *
  4. * Copyright (C) 2005 ARM Ltd
  5. * Copyright (C) 2010 ST-Ericsson SA
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * pl08x information required by platform code
  12. *
  13. * Please credit ARM.com
  14. * Documentation: ARM DDI 0196D
  15. */
  16. #ifndef AMBA_PL08X_H
  17. #define AMBA_PL08X_H
  18. /* We need sizes of structs from this header */
  19. #include <linux/dmaengine.h>
  20. #include <linux/interrupt.h>
  21. struct pl08x_lli;
  22. struct pl08x_driver_data;
  23. /* Bitmasks for selecting AHB ports for DMA transfers */
  24. enum {
  25. PL08X_AHB1 = (1 << 0),
  26. PL08X_AHB2 = (1 << 1)
  27. };
  28. /**
  29. * struct pl08x_channel_data - data structure to pass info between
  30. * platform and PL08x driver regarding channel configuration
  31. * @bus_id: name of this device channel, not just a device name since
  32. * devices may have more than one channel e.g. "foo_tx"
  33. * @min_signal: the minimum DMA signal number to be muxed in for this
  34. * channel (for platforms supporting muxed signals). If you have
  35. * static assignments, make sure this is set to the assigned signal
  36. * number, PL08x have 16 possible signals in number 0 thru 15 so
  37. * when these are not enough they often get muxed (in hardware)
  38. * disabling simultaneous use of the same channel for two devices.
  39. * @max_signal: the maximum DMA signal number to be muxed in for
  40. * the channel. Set to the same as min_signal for
  41. * devices with static assignments
  42. * @muxval: a number usually used to poke into some mux regiser to
  43. * mux in the signal to this channel
  44. * @cctl_opt: default options for the channel control register
  45. * @addr: source/target address in physical memory for this DMA channel,
  46. * can be the address of a FIFO register for burst requests for example.
  47. * This can be left undefined if the PrimeCell API is used for configuring
  48. * this.
  49. * @circular_buffer: whether the buffer passed in is circular and
  50. * shall simply be looped round round (like a record baby round
  51. * round round round)
  52. * @single: the device connected to this channel will request single DMA
  53. * transfers, not bursts. (Bursts are default.)
  54. * @periph_buses: the device connected to this channel is accessible via
  55. * these buses (use PL08X_AHB1 | PL08X_AHB2).
  56. */
  57. struct pl08x_channel_data {
  58. char *bus_id;
  59. int min_signal;
  60. int max_signal;
  61. u32 muxval;
  62. u32 cctl;
  63. dma_addr_t addr;
  64. bool circular_buffer;
  65. bool single;
  66. u8 periph_buses;
  67. };
  68. /**
  69. * Struct pl08x_bus_data - information of source or destination
  70. * busses for a transfer
  71. * @addr: current address
  72. * @maxwidth: the maximum width of a transfer on this bus
  73. * @buswidth: the width of this bus in bytes: 1, 2 or 4
  74. */
  75. struct pl08x_bus_data {
  76. dma_addr_t addr;
  77. u8 maxwidth;
  78. u8 buswidth;
  79. };
  80. /**
  81. * struct pl08x_phy_chan - holder for the physical channels
  82. * @id: physical index to this channel
  83. * @lock: a lock to use when altering an instance of this struct
  84. * @signal: the physical signal (aka channel) serving this physical channel
  85. * right now
  86. * @serving: the virtual channel currently being served by this physical
  87. * channel
  88. */
  89. struct pl08x_phy_chan {
  90. unsigned int id;
  91. void __iomem *base;
  92. spinlock_t lock;
  93. int signal;
  94. struct pl08x_dma_chan *serving;
  95. };
  96. /**
  97. * struct pl08x_sg - structure containing data per sg
  98. * @src_addr: src address of sg
  99. * @dst_addr: dst address of sg
  100. * @len: transfer len in bytes
  101. * @node: node for txd's dsg_list
  102. */
  103. struct pl08x_sg {
  104. dma_addr_t src_addr;
  105. dma_addr_t dst_addr;
  106. size_t len;
  107. struct list_head node;
  108. };
  109. /**
  110. * struct pl08x_txd - wrapper for struct dma_async_tx_descriptor
  111. * @tx: async tx descriptor
  112. * @node: node for txd list for channels
  113. * @dsg_list: list of children sg's
  114. * @direction: direction of transfer
  115. * @llis_bus: DMA memory address (physical) start for the LLIs
  116. * @llis_va: virtual memory address start for the LLIs
  117. * @cctl: control reg values for current txd
  118. * @ccfg: config reg values for current txd
  119. */
  120. struct pl08x_txd {
  121. struct dma_async_tx_descriptor tx;
  122. struct list_head node;
  123. struct list_head dsg_list;
  124. enum dma_transfer_direction direction;
  125. dma_addr_t llis_bus;
  126. struct pl08x_lli *llis_va;
  127. /* Default cctl value for LLIs */
  128. u32 cctl;
  129. /*
  130. * Settings to be put into the physical channel when we
  131. * trigger this txd. Other registers are in llis_va[0].
  132. */
  133. u32 ccfg;
  134. };
  135. /**
  136. * struct pl08x_dma_chan_state - holds the PL08x specific virtual channel
  137. * states
  138. * @PL08X_CHAN_IDLE: the channel is idle
  139. * @PL08X_CHAN_RUNNING: the channel has allocated a physical transport
  140. * channel and is running a transfer on it
  141. * @PL08X_CHAN_PAUSED: the channel has allocated a physical transport
  142. * channel, but the transfer is currently paused
  143. * @PL08X_CHAN_WAITING: the channel is waiting for a physical transport
  144. * channel to become available (only pertains to memcpy channels)
  145. */
  146. enum pl08x_dma_chan_state {
  147. PL08X_CHAN_IDLE,
  148. PL08X_CHAN_RUNNING,
  149. PL08X_CHAN_PAUSED,
  150. PL08X_CHAN_WAITING,
  151. };
  152. /**
  153. * struct pl08x_dma_chan - this structure wraps a DMA ENGINE channel
  154. * @chan: wrappped abstract channel
  155. * @phychan: the physical channel utilized by this channel, if there is one
  156. * @phychan_hold: if non-zero, hold on to the physical channel even if we
  157. * have no pending entries
  158. * @tasklet: tasklet scheduled by the IRQ to handle actual work etc
  159. * @name: name of channel
  160. * @cd: channel platform data
  161. * @runtime_addr: address for RX/TX according to the runtime config
  162. * @runtime_direction: current direction of this channel according to
  163. * runtime config
  164. * @lc: last completed transaction on this channel
  165. * @pend_list: queued transactions pending on this channel
  166. * @at: active transaction on this channel
  167. * @lock: a lock for this channel data
  168. * @host: a pointer to the host (internal use)
  169. * @state: whether the channel is idle, paused, running etc
  170. * @slave: whether this channel is a device (slave) or for memcpy
  171. * @device_fc: Flow Controller Settings for ccfg register. Only valid for slave
  172. * channels. Fill with 'true' if peripheral should be flow controller. Direction
  173. * will be selected at Runtime.
  174. * @waiting: a TX descriptor on this channel which is waiting for a physical
  175. * channel to become available
  176. */
  177. struct pl08x_dma_chan {
  178. struct dma_chan chan;
  179. struct pl08x_phy_chan *phychan;
  180. int phychan_hold;
  181. struct tasklet_struct tasklet;
  182. char *name;
  183. const struct pl08x_channel_data *cd;
  184. dma_addr_t src_addr;
  185. dma_addr_t dst_addr;
  186. u32 src_cctl;
  187. u32 dst_cctl;
  188. enum dma_transfer_direction runtime_direction;
  189. dma_cookie_t lc;
  190. struct list_head pend_list;
  191. struct pl08x_txd *at;
  192. spinlock_t lock;
  193. struct pl08x_driver_data *host;
  194. enum pl08x_dma_chan_state state;
  195. bool slave;
  196. bool device_fc;
  197. struct pl08x_txd *waiting;
  198. };
  199. /**
  200. * struct pl08x_platform_data - the platform configuration for the PL08x
  201. * PrimeCells.
  202. * @slave_channels: the channels defined for the different devices on the
  203. * platform, all inclusive, including multiplexed channels. The available
  204. * physical channels will be multiplexed around these signals as they are
  205. * requested, just enumerate all possible channels.
  206. * @get_signal: request a physical signal to be used for a DMA transfer
  207. * immediately: if there is some multiplexing or similar blocking the use
  208. * of the channel the transfer can be denied by returning less than zero,
  209. * else it returns the allocated signal number
  210. * @put_signal: indicate to the platform that this physical signal is not
  211. * running any DMA transfer and multiplexing can be recycled
  212. * @lli_buses: buses which LLIs can be fetched from: PL08X_AHB1 | PL08X_AHB2
  213. * @mem_buses: buses which memory can be accessed from: PL08X_AHB1 | PL08X_AHB2
  214. */
  215. struct pl08x_platform_data {
  216. const struct pl08x_channel_data *slave_channels;
  217. unsigned int num_slave_channels;
  218. struct pl08x_channel_data memcpy_channel;
  219. int (*get_signal)(struct pl08x_dma_chan *);
  220. void (*put_signal)(struct pl08x_dma_chan *);
  221. u8 lli_buses;
  222. u8 mem_buses;
  223. };
  224. #ifdef CONFIG_AMBA_PL08X
  225. bool pl08x_filter_id(struct dma_chan *chan, void *chan_id);
  226. #else
  227. static inline bool pl08x_filter_id(struct dma_chan *chan, void *chan_id)
  228. {
  229. return false;
  230. }
  231. #endif
  232. #endif /* AMBA_PL08X_H */