1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef SHDMA_BASE_H
17#define SHDMA_BASE_H
18
19#include <linux/dmaengine.h>
20#include <linux/interrupt.h>
21#include <linux/list.h>
22#include <linux/types.h>
23
24
25
26
27
28
29
30
31enum shdma_pm_state {
32 SHDMA_PM_ESTABLISHED,
33 SHDMA_PM_BUSY,
34 SHDMA_PM_PENDING,
35};
36
37struct device;
38
39
40
41
42
43
44
45struct shdma_slave {
46 int slave_id;
47};
48
49struct shdma_desc {
50 struct list_head node;
51 struct dma_async_tx_descriptor async_tx;
52 enum dma_transfer_direction direction;
53 size_t partial;
54 dma_cookie_t cookie;
55 int chunks;
56 int mark;
57 bool cyclic;
58};
59
60struct shdma_chan {
61 spinlock_t chan_lock;
62 struct list_head ld_queue;
63 struct list_head ld_free;
64 struct dma_chan dma_chan;
65 struct device *dev;
66 void *desc;
67 int desc_num;
68 size_t max_xfer_len;
69 int id;
70 int irq;
71 int slave_id;
72 int real_slave_id;
73 int hw_req;
74
75 enum shdma_pm_state pm_state;
76};
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94struct shdma_ops {
95 bool (*desc_completed)(struct shdma_chan *, struct shdma_desc *);
96 void (*halt_channel)(struct shdma_chan *);
97 bool (*channel_busy)(struct shdma_chan *);
98 dma_addr_t (*slave_addr)(struct shdma_chan *);
99 int (*desc_setup)(struct shdma_chan *, struct shdma_desc *,
100 dma_addr_t, dma_addr_t, size_t *);
101 int (*set_slave)(struct shdma_chan *, int, dma_addr_t, bool);
102 void (*setup_xfer)(struct shdma_chan *, int);
103 void (*start_xfer)(struct shdma_chan *, struct shdma_desc *);
104 struct shdma_desc *(*embedded_desc)(void *, int);
105 bool (*chan_irq)(struct shdma_chan *, int);
106 size_t (*get_partial)(struct shdma_chan *, struct shdma_desc *);
107};
108
109struct shdma_dev {
110 struct dma_device dma_dev;
111 struct shdma_chan **schan;
112 const struct shdma_ops *ops;
113 size_t desc_size;
114};
115
116#define shdma_for_each_chan(c, d, i) for (i = 0, c = (d)->schan[0]; \
117 i < (d)->dma_dev.chancnt; c = (d)->schan[++i])
118
119int shdma_request_irq(struct shdma_chan *, int,
120 unsigned long, const char *);
121bool shdma_reset(struct shdma_dev *sdev);
122void shdma_chan_probe(struct shdma_dev *sdev,
123 struct shdma_chan *schan, int id);
124void shdma_chan_remove(struct shdma_chan *schan);
125int shdma_init(struct device *dev, struct shdma_dev *sdev,
126 int chan_num);
127void shdma_cleanup(struct shdma_dev *sdev);
128#if IS_ENABLED(CONFIG_SH_DMAE_BASE)
129bool shdma_chan_filter(struct dma_chan *chan, void *arg);
130#else
131static inline bool shdma_chan_filter(struct dma_chan *chan, void *arg)
132{
133 return false;
134}
135#endif
136
137#endif
138