Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / drivers / usb / host / dwc_otg / dwc_otg_os_dep.h
1 #ifndef _DWC_OS_DEP_H_
2 #define _DWC_OS_DEP_H_
3
4 /**
5  * @file
6  *
7  * This file contains OS dependent structures.
8  *
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <linux/errno.h>
17 #include <linux/types.h>
18 #include <linux/slab.h>
19 #include <linux/list.h>
20 #include <linux/interrupt.h>
21 #include <linux/ctype.h>
22 #include <linux/string.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/jiffies.h>
25 #include <linux/delay.h>
26 #include <linux/timer.h>
27 #include <linux/workqueue.h>
28 #include <linux/stat.h>
29 #include <linux/pci.h>
30 #include <linux/compiler.h>
31
32 #include <linux/version.h>
33
34 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
35 # include <linux/irq.h>
36 #endif
37
38 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
39 # include <linux/usb/ch9.h>
40 #else
41 # include <linux/usb_ch9.h>
42 #endif
43
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
45 # include <linux/usb/gadget.h>
46 #else
47 # include <linux/usb_gadget.h>
48 #endif
49
50 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
51 # include <asm/irq.h>
52 #endif
53
54 #ifdef PCI_INTERFACE
55 # include <asm/io.h>
56 #endif
57
58 #ifdef LM_INTERFACE
59 # include <asm/unaligned.h>
60 # include <asm/sizes.h>
61 # include <asm/param.h>
62 # include <asm/io.h>
63 # if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
64 #  include <asm/arch/hardware.h>
65 #  include <asm/arch/lm.h>
66 #  include <asm/arch/irqs.h>
67 #  include <asm/arch/regs-irq.h>
68 # else
69 /* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
70    here we assume that the machine architecture provides definitions
71    in its own header
72 */
73 #  include <mach/lm.h>
74 #  include <mach/hardware.h>
75 # endif
76 #endif
77
78 #ifdef PLATFORM_INTERFACE
79 #include <linux/platform_device.h>
80 #ifdef CONFIG_ARM
81 #include <asm/mach/map.h>
82 #endif
83 #endif
84
85 /** The OS page size */
86 #define DWC_OS_PAGE_SIZE        PAGE_SIZE
87
88 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
89 typedef int gfp_t;
90 #endif
91
92 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
93 # define IRQF_SHARED SA_SHIRQ
94 #endif
95
96 typedef struct os_dependent {
97         /** Base address returned from ioremap() */
98         void *base;
99
100         /** Register offset for Diagnostic API */
101         uint32_t reg_offset;
102
103         /** Base address for MPHI peripheral */
104         void *mphi_base;
105
106         /** mphi_base actually points to the SWIRQ block */
107         bool use_swirq;
108
109         /** IRQ number (<0 if not valid) */
110         int irq_num;
111
112         /** FIQ number (<0 if not valid) */
113         int fiq_num;
114
115 #ifdef LM_INTERFACE
116         struct lm_device *lmdev;
117 #elif  defined(PCI_INTERFACE)
118         struct pci_dev *pcidev;
119
120         /** Start address of a PCI region */
121         resource_size_t rsrc_start;
122
123         /** Length address of a PCI region */
124         resource_size_t rsrc_len;
125 #elif  defined(PLATFORM_INTERFACE)
126         struct platform_device *platformdev;
127 #endif
128
129 } os_dependent_t;
130
131 #ifdef __cplusplus
132 }
133 #endif
134
135
136
137 /* Type for the our device on the chosen bus */
138 #if   defined(LM_INTERFACE)
139 typedef struct lm_device       dwc_bus_dev_t;
140 #elif defined(PCI_INTERFACE)
141 typedef struct pci_dev         dwc_bus_dev_t;
142 #elif defined(PLATFORM_INTERFACE)
143 typedef struct platform_device dwc_bus_dev_t;
144 #endif
145
146 /* Helper macro to retrieve drvdata from the device on the chosen bus */
147 #if    defined(LM_INTERFACE)
148 #define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
149 #elif  defined(PCI_INTERFACE)
150 #define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
151 #elif  defined(PLATFORM_INTERFACE)
152 #define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
153 #endif
154
155 /**
156  * Helper macro returning the otg_device structure of a given struct device
157  *
158  * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
159  */
160 #ifdef LM_INTERFACE
161 #define DWC_OTG_GETDRVDEV(_var, _dev) do { \
162                 struct lm_device *lm_dev = \
163                         container_of(_dev, struct lm_device, dev); \
164                 _var = lm_get_drvdata(lm_dev); \
165         } while (0)
166
167 #elif defined(PCI_INTERFACE)
168 #define DWC_OTG_GETDRVDEV(_var, _dev) do { \
169                 _var = dev_get_drvdata(_dev); \
170         } while (0)
171
172 #elif defined(PLATFORM_INTERFACE)
173 #define DWC_OTG_GETDRVDEV(_var, _dev) do { \
174                 struct platform_device *platform_dev = \
175                         container_of(_dev, struct platform_device, dev); \
176                 _var = platform_get_drvdata(platform_dev); \
177         } while (0)
178 #endif
179
180
181 /**
182  * Helper macro returning the struct dev of the given struct os_dependent
183  *
184  * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
185  */
186 #ifdef LM_INTERFACE
187 #define DWC_OTG_OS_GETDEV(_osdep) \
188         ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
189 #elif defined(PCI_INTERFACE)
190 #define DWC_OTG_OS_GETDEV(_osdep) \
191         ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
192 #elif defined(PLATFORM_INTERFACE)
193 #define DWC_OTG_OS_GETDEV(_osdep) \
194         ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
195 #endif
196
197
198
199
200 #endif /* _DWC_OS_DEP_H_ */