xref: /linux/include/linux/of_dma.h (revision 5ea5880764cbb164afb17a62e76ca75dc371409d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * OF helpers for DMA request / controller
4  *
5  * Based on of_gpio.h
6  *
7  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
8  */
9 
10 #ifndef __LINUX_OF_DMA_H
11 #define __LINUX_OF_DMA_H
12 
13 #include <linux/of.h>
14 #include <linux/dmaengine.h>
15 
16 struct device_node;
17 
18 struct of_dma {
19 	struct list_head	of_dma_controllers;
20 	struct device_node	*of_node;
21 	struct dma_chan		*(*of_dma_xlate)
22 				(struct of_phandle_args *, struct of_dma *);
23 	void			*(*of_dma_route_allocate)
24 				(struct of_phandle_args *, struct of_dma *);
25 	struct dma_router	*dma_router;
26 	void			*of_dma_data;
27 };
28 
29 struct of_dma_filter_info {
30 	dma_cap_mask_t	dma_cap;
31 	dma_filter_fn	filter_fn;
32 };
33 
34 #ifdef CONFIG_DMA_OF
35 extern int of_dma_controller_register(struct device_node *np,
36 		struct dma_chan *(*of_dma_xlate)
37 		(struct of_phandle_args *, struct of_dma *),
38 		void *data);
39 extern void of_dma_controller_free(struct device_node *np);
40 
41 static void __of_dma_controller_free(void *np)
42 {
43 	of_dma_controller_free(np);
44 }
45 
46 static inline int
47 devm_of_dma_controller_register(struct device *dev, struct device_node *np,
48 				struct dma_chan *(*of_dma_xlate)
49 				(struct of_phandle_args *, struct of_dma *),
50 				void *data)
51 {
52 	int ret;
53 
54 	ret = of_dma_controller_register(np, of_dma_xlate, data);
55 	if (ret)
56 		return ret;
57 
58 	return devm_add_action_or_reset(dev, __of_dma_controller_free, np);
59 }
60 
61 extern int of_dma_router_register(struct device_node *np,
62 		void *(*of_dma_route_allocate)
63 		(struct of_phandle_args *, struct of_dma *),
64 		struct dma_router *dma_router);
65 #define of_dma_router_free of_dma_controller_free
66 
67 extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
68 						     const char *name);
69 extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
70 		struct of_dma *ofdma);
71 extern struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec,
72 		struct of_dma *ofdma);
73 
74 #else
75 static inline int of_dma_controller_register(struct device_node *np,
76 		struct dma_chan *(*of_dma_xlate)
77 		(struct of_phandle_args *, struct of_dma *),
78 		void *data)
79 {
80 	return -ENODEV;
81 }
82 
83 static inline void of_dma_controller_free(struct device_node *np)
84 {
85 }
86 
87 static inline int
88 devm_of_dma_controller_register(struct device *dev, struct device_node *np,
89 				struct dma_chan *(*of_dma_xlate)
90 				(struct of_phandle_args *, struct of_dma *),
91 				void *data)
92 {
93 	return -ENODEV;
94 }
95 
96 static inline int of_dma_router_register(struct device_node *np,
97 		void *(*of_dma_route_allocate)
98 		(struct of_phandle_args *, struct of_dma *),
99 		struct dma_router *dma_router)
100 {
101 	return -ENODEV;
102 }
103 
104 #define of_dma_router_free of_dma_controller_free
105 
106 static inline struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
107 						     const char *name)
108 {
109 	return ERR_PTR(-ENODEV);
110 }
111 
112 static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
113 		struct of_dma *ofdma)
114 {
115 	return NULL;
116 }
117 
118 #define of_dma_xlate_by_chan_id NULL
119 
120 #endif
121 
122 #endif /* __LINUX_OF_DMA_H */
123