1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
4  */
5 
6 #ifndef __VLYNQ_H__
7 #define __VLYNQ_H__
8 
9 #include <linux/device.h>
10 #include <linux/types.h>
11 
12 struct module;
13 
14 #define VLYNQ_NUM_IRQS 32
15 
16 struct vlynq_mapping {
17 	u32 size;
18 	u32 offset;
19 };
20 
21 enum vlynq_divisor {
22 	vlynq_div_auto = 0,
23 	vlynq_ldiv1,
24 	vlynq_ldiv2,
25 	vlynq_ldiv3,
26 	vlynq_ldiv4,
27 	vlynq_ldiv5,
28 	vlynq_ldiv6,
29 	vlynq_ldiv7,
30 	vlynq_ldiv8,
31 	vlynq_rdiv1,
32 	vlynq_rdiv2,
33 	vlynq_rdiv3,
34 	vlynq_rdiv4,
35 	vlynq_rdiv5,
36 	vlynq_rdiv6,
37 	vlynq_rdiv7,
38 	vlynq_rdiv8,
39 	vlynq_div_external
40 };
41 
42 struct vlynq_device_id {
43 	u32 id;
44 	enum vlynq_divisor divisor;
45 	unsigned long driver_data;
46 };
47 
48 struct vlynq_regs;
49 struct vlynq_device {
50 	u32 id, dev_id;
51 	int local_irq;
52 	int remote_irq;
53 	enum vlynq_divisor divisor;
54 	u32 regs_start, regs_end;
55 	u32 mem_start, mem_end;
56 	u32 irq_start, irq_end;
57 	int irq;
58 	int enabled;
59 	struct vlynq_regs *local;
60 	struct vlynq_regs *remote;
61 	struct device dev;
62 };
63 
64 struct vlynq_driver {
65 	char *name;
66 	struct vlynq_device_id *id_table;
67 	int (*probe)(struct vlynq_device *dev, struct vlynq_device_id *id);
68 	void (*remove)(struct vlynq_device *dev);
69 	struct device_driver driver;
70 };
71 
72 struct plat_vlynq_ops {
73 	int (*on)(struct vlynq_device *dev);
74 	void (*off)(struct vlynq_device *dev);
75 };
76 
to_vlynq_driver(struct device_driver * drv)77 static inline struct vlynq_driver *to_vlynq_driver(struct device_driver *drv)
78 {
79 	return container_of(drv, struct vlynq_driver, driver);
80 }
81 
to_vlynq_device(struct device * device)82 static inline struct vlynq_device *to_vlynq_device(struct device *device)
83 {
84 	return container_of(device, struct vlynq_device, dev);
85 }
86 
87 extern struct bus_type vlynq_bus_type;
88 
89 extern int __vlynq_register_driver(struct vlynq_driver *driver,
90 				   struct module *owner);
91 
vlynq_register_driver(struct vlynq_driver * driver)92 static inline int vlynq_register_driver(struct vlynq_driver *driver)
93 {
94 	return __vlynq_register_driver(driver, THIS_MODULE);
95 }
96 
vlynq_get_drvdata(struct vlynq_device * dev)97 static inline void *vlynq_get_drvdata(struct vlynq_device *dev)
98 {
99 	return dev_get_drvdata(&dev->dev);
100 }
101 
vlynq_set_drvdata(struct vlynq_device * dev,void * data)102 static inline void vlynq_set_drvdata(struct vlynq_device *dev, void *data)
103 {
104 	dev_set_drvdata(&dev->dev, data);
105 }
106 
vlynq_mem_start(struct vlynq_device * dev)107 static inline u32 vlynq_mem_start(struct vlynq_device *dev)
108 {
109 	return dev->mem_start;
110 }
111 
vlynq_mem_end(struct vlynq_device * dev)112 static inline u32 vlynq_mem_end(struct vlynq_device *dev)
113 {
114 	return dev->mem_end;
115 }
116 
vlynq_mem_len(struct vlynq_device * dev)117 static inline u32 vlynq_mem_len(struct vlynq_device *dev)
118 {
119 	return dev->mem_end - dev->mem_start + 1;
120 }
121 
vlynq_virq_to_irq(struct vlynq_device * dev,int virq)122 static inline int vlynq_virq_to_irq(struct vlynq_device *dev, int virq)
123 {
124 	int irq = dev->irq_start + virq;
125 	if ((irq < dev->irq_start) || (irq > dev->irq_end))
126 		return -EINVAL;
127 
128 	return irq;
129 }
130 
vlynq_irq_to_virq(struct vlynq_device * dev,int irq)131 static inline int vlynq_irq_to_virq(struct vlynq_device *dev, int irq)
132 {
133 	if ((irq < dev->irq_start) || (irq > dev->irq_end))
134 		return -EINVAL;
135 
136 	return irq - dev->irq_start;
137 }
138 
139 extern void vlynq_unregister_driver(struct vlynq_driver *driver);
140 extern int vlynq_enable_device(struct vlynq_device *dev);
141 extern void vlynq_disable_device(struct vlynq_device *dev);
142 extern int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
143 				   struct vlynq_mapping *mapping);
144 extern int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
145 				    struct vlynq_mapping *mapping);
146 extern int vlynq_set_local_irq(struct vlynq_device *dev, int virq);
147 extern int vlynq_set_remote_irq(struct vlynq_device *dev, int virq);
148 
149 #endif /* __VLYNQ_H__ */
150