pl08x.h 7.4 KB

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