xref: /linux/arch/sh/include/asm/dma.h (revision 63307d015b91e626c97bb82e88054af3d0b74643)
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * include/asm-sh/dma.h
4  *
5  * Copyright (C) 2003, 2004  Paul Mundt
6  */
7 #ifndef __ASM_SH_DMA_H
8 #define __ASM_SH_DMA_H
9 #ifdef __KERNEL__
10 
11 #include <linux/spinlock.h>
12 #include <linux/wait.h>
13 #include <linux/sched.h>
14 #include <linux/device.h>
15 #include <asm-generic/dma.h>
16 
17 /*
18  * Read and write modes can mean drastically different things depending on the
19  * channel configuration. Consult your DMAC documentation and module
20  * implementation for further clues.
21  */
22 #define DMA_MODE_READ		0x00
23 #define DMA_MODE_WRITE		0x01
24 #define DMA_MODE_MASK		0x01
25 
26 #define DMA_AUTOINIT		0x10
27 
28 /*
29  * DMAC (dma_info) flags
30  */
31 enum {
32 	DMAC_CHANNELS_CONFIGURED	= 0x01,
33 	DMAC_CHANNELS_TEI_CAPABLE	= 0x02,	/* Transfer end interrupt */
34 };
35 
36 /*
37  * DMA channel capabilities / flags
38  */
39 enum {
40 	DMA_CONFIGURED			= 0x01,
41 
42 	/*
43 	 * Transfer end interrupt, inherited from DMAC.
44 	 * wait_queue used in dma_wait_for_completion.
45 	 */
46 	DMA_TEI_CAPABLE			= 0x02,
47 };
48 
49 extern spinlock_t dma_spin_lock;
50 
51 struct dma_channel;
52 
53 struct dma_ops {
54 	int (*request)(struct dma_channel *chan);
55 	void (*free)(struct dma_channel *chan);
56 
57 	int (*get_residue)(struct dma_channel *chan);
58 	int (*xfer)(struct dma_channel *chan);
59 	int (*configure)(struct dma_channel *chan, unsigned long flags);
60 	int (*extend)(struct dma_channel *chan, unsigned long op, void *param);
61 };
62 
63 struct dma_channel {
64 	char dev_id[16];		/* unique name per DMAC of channel */
65 
66 	unsigned int chan;		/* DMAC channel number */
67 	unsigned int vchan;		/* Virtual channel number */
68 
69 	unsigned int mode;
70 	unsigned int count;
71 
72 	unsigned long sar;
73 	unsigned long dar;
74 
75 	const char **caps;
76 
77 	unsigned long flags;
78 	atomic_t busy;
79 
80 	wait_queue_head_t wait_queue;
81 
82 	struct device dev;
83 	void *priv_data;
84 };
85 
86 struct dma_info {
87 	struct platform_device *pdev;
88 
89 	const char *name;
90 	unsigned int nr_channels;
91 	unsigned long flags;
92 
93 	struct dma_ops *ops;
94 	struct dma_channel *channels;
95 
96 	struct list_head list;
97 	int first_channel_nr;
98 	int first_vchannel_nr;
99 };
100 
101 struct dma_chan_caps {
102 	int ch_num;
103 	const char **caplist;
104 };
105 
106 #define to_dma_channel(channel) container_of(channel, struct dma_channel, dev)
107 
108 /* arch/sh/drivers/dma/dma-api.c */
109 extern int dma_xfer(unsigned int chan, unsigned long from,
110 		    unsigned long to, size_t size, unsigned int mode);
111 
112 #define dma_write(chan, from, to, size)	\
113 	dma_xfer(chan, from, to, size, DMA_MODE_WRITE)
114 #define dma_write_page(chan, from, to)	\
115 	dma_write(chan, from, to, PAGE_SIZE)
116 
117 #define dma_read(chan, from, to, size)	\
118 	dma_xfer(chan, from, to, size, DMA_MODE_READ)
119 #define dma_read_page(chan, from, to)	\
120 	dma_read(chan, from, to, PAGE_SIZE)
121 
122 extern int request_dma_bycap(const char **dmac, const char **caps,
123 			     const char *dev_id);
124 extern int get_dma_residue(unsigned int chan);
125 extern struct dma_info *get_dma_info(unsigned int chan);
126 extern struct dma_channel *get_dma_channel(unsigned int chan);
127 extern void dma_wait_for_completion(unsigned int chan);
128 extern void dma_configure_channel(unsigned int chan, unsigned long flags);
129 
130 extern int register_dmac(struct dma_info *info);
131 extern void unregister_dmac(struct dma_info *info);
132 extern struct dma_info *get_dma_info_by_name(const char *dmac_name);
133 
134 extern int dma_extend(unsigned int chan, unsigned long op, void *param);
135 extern int register_chan_caps(const char *dmac, struct dma_chan_caps *capslist);
136 
137 /* arch/sh/drivers/dma/dma-sysfs.c */
138 extern int dma_create_sysfs_files(struct dma_channel *, struct dma_info *);
139 extern void dma_remove_sysfs_files(struct dma_channel *, struct dma_info *);
140 
141 #ifdef CONFIG_PCI
142 extern int isa_dma_bridge_buggy;
143 #else
144 #define isa_dma_bridge_buggy	(0)
145 #endif
146 
147 #endif /* __KERNEL__ */
148 #endif /* __ASM_SH_DMA_H */
149