0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef SHDMA_BASE_H
0014 #define SHDMA_BASE_H
0015
0016 #include <linux/dmaengine.h>
0017 #include <linux/interrupt.h>
0018 #include <linux/list.h>
0019 #include <linux/types.h>
0020
0021
0022
0023
0024
0025
0026
0027
0028 enum shdma_pm_state {
0029 SHDMA_PM_ESTABLISHED,
0030 SHDMA_PM_BUSY,
0031 SHDMA_PM_PENDING,
0032 };
0033
0034 struct device;
0035
0036
0037
0038
0039
0040
0041
0042 struct shdma_slave {
0043 int slave_id;
0044 };
0045
0046 struct shdma_desc {
0047 struct list_head node;
0048 struct dma_async_tx_descriptor async_tx;
0049 enum dma_transfer_direction direction;
0050 size_t partial;
0051 dma_cookie_t cookie;
0052 int chunks;
0053 int mark;
0054 bool cyclic;
0055 };
0056
0057 struct shdma_chan {
0058 spinlock_t chan_lock;
0059 struct list_head ld_queue;
0060 struct list_head ld_free;
0061 struct dma_chan dma_chan;
0062 struct device *dev;
0063 void *desc;
0064 int desc_num;
0065 size_t max_xfer_len;
0066 int id;
0067 int irq;
0068 int slave_id;
0069 int real_slave_id;
0070 int hw_req;
0071
0072 enum shdma_pm_state pm_state;
0073 };
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 struct shdma_ops {
0092 bool (*desc_completed)(struct shdma_chan *, struct shdma_desc *);
0093 void (*halt_channel)(struct shdma_chan *);
0094 bool (*channel_busy)(struct shdma_chan *);
0095 dma_addr_t (*slave_addr)(struct shdma_chan *);
0096 int (*desc_setup)(struct shdma_chan *, struct shdma_desc *,
0097 dma_addr_t, dma_addr_t, size_t *);
0098 int (*set_slave)(struct shdma_chan *, int, dma_addr_t, bool);
0099 void (*setup_xfer)(struct shdma_chan *, int);
0100 void (*start_xfer)(struct shdma_chan *, struct shdma_desc *);
0101 struct shdma_desc *(*embedded_desc)(void *, int);
0102 bool (*chan_irq)(struct shdma_chan *, int);
0103 size_t (*get_partial)(struct shdma_chan *, struct shdma_desc *);
0104 };
0105
0106 struct shdma_dev {
0107 struct dma_device dma_dev;
0108 struct shdma_chan **schan;
0109 const struct shdma_ops *ops;
0110 size_t desc_size;
0111 };
0112
0113 #define shdma_for_each_chan(c, d, i) for (i = 0, c = (d)->schan[0]; \
0114 i < (d)->dma_dev.chancnt; c = (d)->schan[++i])
0115
0116 int shdma_request_irq(struct shdma_chan *, int,
0117 unsigned long, const char *);
0118 bool shdma_reset(struct shdma_dev *sdev);
0119 void shdma_chan_probe(struct shdma_dev *sdev,
0120 struct shdma_chan *schan, int id);
0121 void shdma_chan_remove(struct shdma_chan *schan);
0122 int shdma_init(struct device *dev, struct shdma_dev *sdev,
0123 int chan_num);
0124 void shdma_cleanup(struct shdma_dev *sdev);
0125 #if IS_ENABLED(CONFIG_SH_DMAE_BASE)
0126 bool shdma_chan_filter(struct dma_chan *chan, void *arg);
0127 #else
0128 static inline bool shdma_chan_filter(struct dma_chan *chan, void *arg)
0129 {
0130 return false;
0131 }
0132 #endif
0133
0134 #endif