dwc2.h revision 1.2.10.3 1 1.2.10.2 tls /* $NetBSD: dwc2.h,v 1.2.10.3 2017/12/03 11:38:01 jdolecek Exp $ */
2 1.2.10.2 tls
3 1.2.10.2 tls /*-
4 1.2.10.2 tls * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.2.10.2 tls * All rights reserved.
6 1.2.10.2 tls *
7 1.2.10.2 tls * This code is derived from software contributed to The NetBSD Foundation
8 1.2.10.2 tls * by Nick Hudson
9 1.2.10.2 tls *
10 1.2.10.2 tls * Redistribution and use in source and binary forms, with or without
11 1.2.10.2 tls * modification, are permitted provided that the following conditions
12 1.2.10.2 tls * are met:
13 1.2.10.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.2.10.2 tls * notice, this list of conditions and the following disclaimer.
15 1.2.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.10.2 tls * notice, this list of conditions and the following disclaimer in the
17 1.2.10.2 tls * documentation and/or other materials provided with the distribution.
18 1.2.10.2 tls *
19 1.2.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2.10.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2.10.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2.10.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2.10.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2.10.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2.10.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2.10.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2.10.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2.10.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2.10.2 tls * POSSIBILITY OF SUCH DAMAGE.
30 1.2.10.2 tls */
31 1.2.10.2 tls
32 1.2.10.2 tls #ifndef _EXTERNAL_BSD_DWC2_DWC2_H_
33 1.2.10.2 tls #define _EXTERNAL_BSD_DWC2_DWC2_H_
34 1.2.10.2 tls
35 1.2.10.2 tls #include <sys/param.h>
36 1.2.10.2 tls
37 1.2.10.2 tls #include <sys/callout.h>
38 1.2.10.3 jdolecek #include <sys/kernel.h>
39 1.2.10.3 jdolecek #include <sys/proc.h>
40 1.2.10.3 jdolecek #include <sys/workqueue.h>
41 1.2.10.2 tls
42 1.2.10.2 tls #include <linux/list.h>
43 1.2.10.3 jdolecek #include <linux/workqueue.h>
44 1.2.10.2 tls
45 1.2.10.3 jdolecek #include "opt_usb.h"
46 1.2.10.2 tls // #define VERBOSE_DEBUG
47 1.2.10.2 tls // #define DWC2_DUMP_FRREM
48 1.2.10.2 tls // #define CONFIG_USB_DWC2_TRACK_MISSED_SOFS
49 1.2.10.2 tls
50 1.2.10.3 jdolecek #define CONFIG_USB_DWC2_HOST 1
51 1.2.10.3 jdolecek #define CONFIG_USB_DWC2_DUAL_ROLE 0
52 1.2.10.3 jdolecek #define CONFIG_USB_DWC2_PERIPHERAL 0
53 1.2.10.3 jdolecek
54 1.2.10.2 tls typedef int irqreturn_t;
55 1.2.10.2 tls #define IRQ_NONE 0
56 1.2.10.2 tls #define IRQ_HANDLED 1
57 1.2.10.2 tls
58 1.2.10.2 tls #define u8 uint8_t
59 1.2.10.2 tls #define u16 uint16_t
60 1.2.10.2 tls #define s16 int16_t
61 1.2.10.2 tls #define u32 uint32_t
62 1.2.10.2 tls #define u64 uint64_t
63 1.2.10.2 tls
64 1.2.10.2 tls #define dma_addr_t bus_addr_t
65 1.2.10.2 tls
66 1.2.10.2 tls #define DWC2_READ_4(hsotg, reg) \
67 1.2.10.2 tls bus_space_read_4((hsotg)->hsotg_sc->sc_iot, (hsotg)->hsotg_sc->sc_ioh, (reg))
68 1.2.10.2 tls #define DWC2_WRITE_4(hsotg, reg, data) \
69 1.2.10.2 tls bus_space_write_4((hsotg)->hsotg_sc->sc_iot, (hsotg)->hsotg_sc->sc_ioh, (reg), (data));
70 1.2.10.2 tls
71 1.2.10.2 tls #ifdef DWC2_DEBUG
72 1.2.10.2 tls extern int dwc2debug;
73 1.2.10.2 tls #define WARN_ON(x) KASSERT(!(x))
74 1.2.10.2 tls
75 1.2.10.2 tls #define dev_info(d,fmt,...) do { \
76 1.2.10.2 tls printf("%s: " fmt, device_xname(d), \
77 1.2.10.2 tls ## __VA_ARGS__); \
78 1.2.10.2 tls } while (0)
79 1.2.10.2 tls #define dev_warn(d,fmt,...) do { \
80 1.2.10.2 tls printf("%s: " fmt, device_xname(d), \
81 1.2.10.2 tls ## __VA_ARGS__); \
82 1.2.10.2 tls } while (0)
83 1.2.10.2 tls #define dev_err(d,fmt,...) do { \
84 1.2.10.2 tls printf("%s: " fmt, device_xname(d), \
85 1.2.10.2 tls ## __VA_ARGS__); \
86 1.2.10.2 tls } while (0)
87 1.2.10.2 tls #define dev_dbg(d,fmt,...) do { \
88 1.2.10.2 tls if (dwc2debug >= 1) { \
89 1.2.10.2 tls printf("%s: " fmt, device_xname(d), \
90 1.2.10.2 tls ## __VA_ARGS__); \
91 1.2.10.2 tls } \
92 1.2.10.2 tls } while (0)
93 1.2.10.2 tls #define dev_vdbg(d,fmt,...) do { \
94 1.2.10.2 tls if (dwc2debug >= 2) { \
95 1.2.10.2 tls printf("%s: " fmt, device_xname(d), \
96 1.2.10.2 tls ## __VA_ARGS__); \
97 1.2.10.2 tls } \
98 1.2.10.2 tls } while (0)
99 1.2.10.2 tls #else
100 1.2.10.2 tls #define WARN_ON(x)
101 1.2.10.2 tls #define dev_info(...) do { } while (0)
102 1.2.10.2 tls #define dev_warn(...) do { } while (0)
103 1.2.10.2 tls #define dev_err(...) do { } while (0)
104 1.2.10.2 tls #define dev_dbg(...) do { } while (0)
105 1.2.10.2 tls #define dev_vdbg(...) do { } while (0)
106 1.2.10.2 tls #endif
107 1.2.10.2 tls
108 1.2.10.2 tls #define jiffies hardclock_ticks
109 1.2.10.2 tls #define msecs_to_jiffies mstohz
110 1.2.10.2 tls
111 1.2.10.2 tls #define gfp_t int
112 1.2.10.2 tls #define GFP_KERNEL KM_SLEEP
113 1.2.10.2 tls #define GFP_ATOMIC KM_NOSLEEP
114 1.2.10.2 tls
115 1.2.10.2 tls enum usb_otg_state {
116 1.2.10.2 tls OTG_STATE_RESERVED = 0,
117 1.2.10.2 tls
118 1.2.10.2 tls OTG_STATE_A_HOST,
119 1.2.10.2 tls OTG_STATE_A_PERIPHERAL,
120 1.2.10.2 tls OTG_STATE_A_SUSPEND,
121 1.2.10.2 tls OTG_STATE_B_HOST,
122 1.2.10.2 tls OTG_STATE_B_PERIPHERAL,
123 1.2.10.2 tls };
124 1.2.10.2 tls
125 1.2.10.2 tls #define usleep_range(l, u) do { DELAY(u); } while (0)
126 1.2.10.2 tls
127 1.2.10.2 tls #define spinlock_t kmutex_t
128 1.2.10.2 tls #define spin_lock_init(lock) mutex_init(lock, MUTEX_DEFAULT, IPL_VM)
129 1.2.10.2 tls #define spin_lock(l) do { mutex_spin_enter(l); } while (0)
130 1.2.10.2 tls #define spin_unlock(l) do { mutex_spin_exit(l); } while (0)
131 1.2.10.2 tls
132 1.2.10.2 tls #define spin_lock_irqsave(l, f) \
133 1.2.10.2 tls do { mutex_spin_enter(l); (void)(f); } while (0)
134 1.2.10.2 tls
135 1.2.10.2 tls #define spin_unlock_irqrestore(l, f) \
136 1.2.10.2 tls do { mutex_spin_exit(l); (void)(f); } while (0)
137 1.2.10.2 tls
138 1.2.10.2 tls #define IRQ_RETVAL(r) (r)
139 1.2.10.2 tls
140 1.2.10.2 tls #define USB_ENDPOINT_XFER_CONTROL UE_CONTROL /* 0 */
141 1.2.10.2 tls #define USB_ENDPOINT_XFER_ISOC UE_ISOCHRONOUS /* 1 */
142 1.2.10.2 tls #define USB_ENDPOINT_XFER_BULK UE_BULK /* 2 */
143 1.2.10.2 tls #define USB_ENDPOINT_XFER_INT UE_INTERRUPT /* 3 */
144 1.2.10.2 tls
145 1.2.10.2 tls #define USB_DIR_IN UE_DIR_IN
146 1.2.10.2 tls #define USB_DIR_OUT UE_DIR_OUT
147 1.2.10.2 tls
148 1.2.10.2 tls #define USB_PORT_FEAT_CONNECTION UHF_PORT_CONNECTION
149 1.2.10.2 tls #define USB_PORT_FEAT_ENABLE UHF_PORT_ENABLE
150 1.2.10.2 tls #define USB_PORT_FEAT_SUSPEND UHF_PORT_SUSPEND
151 1.2.10.2 tls #define USB_PORT_FEAT_OVER_CURRENT UHF_PORT_OVER_CURRENT
152 1.2.10.2 tls #define USB_PORT_FEAT_RESET UHF_PORT_RESET
153 1.2.10.2 tls // #define USB_PORT_FEAT_L1 5 /* L1 suspend */
154 1.2.10.2 tls #define USB_PORT_FEAT_POWER UHF_PORT_POWER
155 1.2.10.2 tls #define USB_PORT_FEAT_LOWSPEED UHF_PORT_LOW_SPEED
156 1.2.10.2 tls #define USB_PORT_FEAT_C_CONNECTION UHF_C_PORT_CONNECTION
157 1.2.10.2 tls #define USB_PORT_FEAT_C_ENABLE UHF_C_PORT_ENABLE
158 1.2.10.2 tls #define USB_PORT_FEAT_C_SUSPEND UHF_C_PORT_SUSPEND
159 1.2.10.2 tls #define USB_PORT_FEAT_C_OVER_CURRENT UHF_C_PORT_OVER_CURRENT
160 1.2.10.2 tls #define USB_PORT_FEAT_C_RESET UHF_C_PORT_RESET
161 1.2.10.2 tls #define USB_PORT_FEAT_TEST UHF_PORT_TEST
162 1.2.10.2 tls #define USB_PORT_FEAT_INDICATOR UHF_PORT_INDICATOR
163 1.2.10.2 tls #define USB_PORT_FEAT_C_PORT_L1 UHF_C_PORT_L1
164 1.2.10.2 tls
165 1.2.10.2 tls #define C_HUB_LOCAL_POWER UHF_C_HUB_LOCAL_POWER
166 1.2.10.2 tls #define C_HUB_OVER_CURRENT UHF_C_HUB_OVER_CURRENT
167 1.2.10.2 tls
168 1.2.10.2 tls #define USB_REQ_GET_STATUS UR_GET_STATUS
169 1.2.10.2 tls #define USB_REQ_CLEAR_FEATURE UR_CLEAR_FEATURE
170 1.2.10.2 tls #define USB_REQ_SET_FEATURE UR_SET_FEATURE
171 1.2.10.2 tls #define USB_REQ_GET_DESCRIPTOR UR_GET_DESCRIPTOR
172 1.2.10.2 tls
173 1.2.10.2 tls #define ClearHubFeature ((UT_WRITE_CLASS_DEVICE << 8) | USB_REQ_CLEAR_FEATURE)
174 1.2.10.2 tls #define ClearPortFeature ((UT_WRITE_CLASS_OTHER << 8) | USB_REQ_CLEAR_FEATURE)
175 1.2.10.2 tls #define GetHubDescriptor ((UT_READ_CLASS_DEVICE << 8) | USB_REQ_GET_DESCRIPTOR)
176 1.2.10.2 tls #define GetHubStatus ((UT_READ_CLASS_DEVICE << 8) | USB_REQ_GET_STATUS)
177 1.2.10.2 tls #define GetPortStatus ((UT_READ_CLASS_OTHER << 8) | USB_REQ_GET_STATUS)
178 1.2.10.2 tls #define SetHubFeature ((UT_WRITE_CLASS_DEVICE << 8) | USB_REQ_SET_FEATURE)
179 1.2.10.2 tls #define SetPortFeature ((UT_WRITE_CLASS_OTHER << 8) | USB_REQ_SET_FEATURE)
180 1.2.10.2 tls
181 1.2.10.2 tls #define USB_PORT_STAT_CONNECTION UPS_CURRENT_CONNECT_STATUS
182 1.2.10.2 tls #define USB_PORT_STAT_ENABLE UPS_PORT_ENABLED
183 1.2.10.2 tls #define USB_PORT_STAT_SUSPEND UPS_SUSPEND
184 1.2.10.2 tls #define USB_PORT_STAT_OVERCURRENT UPS_OVERCURRENT_INDICATOR
185 1.2.10.2 tls #define USB_PORT_STAT_RESET UPS_RESET
186 1.2.10.2 tls #define USB_PORT_STAT_L1 UPS_PORT_L1
187 1.2.10.2 tls #define USB_PORT_STAT_POWER UPS_PORT_POWER
188 1.2.10.2 tls #define USB_PORT_STAT_LOW_SPEED UPS_LOW_SPEED
189 1.2.10.2 tls #define USB_PORT_STAT_HIGH_SPEED UPS_HIGH_SPEED
190 1.2.10.2 tls #define USB_PORT_STAT_TEST UPS_PORT_TEST
191 1.2.10.2 tls #define USB_PORT_STAT_INDICATOR UPS_PORT_INDICATOR
192 1.2.10.2 tls
193 1.2.10.2 tls #define USB_PORT_STAT_C_CONNECTION UPS_C_CONNECT_STATUS
194 1.2.10.2 tls #define USB_PORT_STAT_C_ENABLE UPS_C_PORT_ENABLED
195 1.2.10.2 tls #define USB_PORT_STAT_C_SUSPEND UPS_C_SUSPEND
196 1.2.10.2 tls #define USB_PORT_STAT_C_OVERCURRENT UPS_C_OVERCURRENT_INDICATOR
197 1.2.10.2 tls #define USB_PORT_STAT_C_RESET UPS_C_PORT_RESET
198 1.2.10.2 tls #define USB_PORT_STAT_C_L1 UPS_C_PORT_L1
199 1.2.10.2 tls
200 1.2.10.3 jdolecek #define USB_DT_HUB UDESC_HUB
201 1.2.10.3 jdolecek
202 1.2.10.3 jdolecek /* See USB 2.0 spec Table 11-13, offset 3 */
203 1.2.10.3 jdolecek #define HUB_CHAR_LPSM UHD_PWR
204 1.2.10.3 jdolecek #define HUB_CHAR_COMMON_LPSM UHD_PWR_GANGED
205 1.2.10.3 jdolecek #define HUB_CHAR_INDV_PORT_LPSM UHD_PWR_INDIVIDUAL
206 1.2.10.3 jdolecek #define HUB_CHAR_NO_LPSM UHD_PWR_NO_SWITCH
207 1.2.10.3 jdolecek
208 1.2.10.3 jdolecek #define HUB_CHAR_COMPOUND UHD_COMPOUND
209 1.2.10.3 jdolecek
210 1.2.10.3 jdolecek #define HUB_CHAR_OCPM UHD_OC
211 1.2.10.3 jdolecek #define HUB_CHAR_COMMON_OCPM UHD_OC_GLOBAL
212 1.2.10.3 jdolecek #define HUB_CHAR_INDV_PORT_OCPM UHD_OC_INDIVIDUAL
213 1.2.10.3 jdolecek #define HUB_CHAR_NO_OCPM UHD_OC_NONE
214 1.2.10.3 jdolecek
215 1.2.10.3 jdolecek #define HUB_CHAR_TTTT UHD_TT_THINK
216 1.2.10.3 jdolecek #define HUB_CHAR_PORTIND UHD_PORT_IND
217 1.2.10.3 jdolecek
218 1.2.10.3 jdolecek enum usb_dr_mode {
219 1.2.10.3 jdolecek USB_DR_MODE_UNKNOWN,
220 1.2.10.3 jdolecek USB_DR_MODE_HOST,
221 1.2.10.3 jdolecek USB_DR_MODE_PERIPHERAL,
222 1.2.10.3 jdolecek USB_DR_MODE_OTG,
223 1.2.10.3 jdolecek };
224 1.2.10.3 jdolecek
225 1.2.10.3 jdolecek struct usb_phy;
226 1.2.10.3 jdolecek struct usb_hcd;
227 1.2.10.3 jdolecek
228 1.2.10.3 jdolecek static inline int
229 1.2.10.3 jdolecek usb_phy_set_suspend(struct usb_phy *x, int suspend)
230 1.2.10.2 tls {
231 1.2.10.3 jdolecek
232 1.2.10.3 jdolecek return 0;
233 1.2.10.2 tls }
234 1.2.10.2 tls
235 1.2.10.3 jdolecek static inline void
236 1.2.10.3 jdolecek usb_hcd_resume_root_hub(struct usb_hcd *hcd)
237 1.2.10.3 jdolecek {
238 1.2.10.2 tls
239 1.2.10.3 jdolecek return;
240 1.2.10.3 jdolecek }
241 1.2.10.2 tls
242 1.2.10.3 jdolecek static inline int
243 1.2.10.3 jdolecek usb_disabled(void)
244 1.2.10.3 jdolecek {
245 1.2.10.2 tls
246 1.2.10.3 jdolecek return 0;
247 1.2.10.3 jdolecek }
248 1.2.10.2 tls
249 1.2.10.3 jdolecek static inline void
250 1.2.10.3 jdolecek udelay(unsigned long usecs)
251 1.2.10.3 jdolecek {
252 1.2.10.3 jdolecek
253 1.2.10.3 jdolecek DELAY(usecs);
254 1.2.10.3 jdolecek }
255 1.2.10.2 tls
256 1.2.10.2 tls static inline void
257 1.2.10.3 jdolecek ndelay(unsigned long nsecs)
258 1.2.10.2 tls {
259 1.2.10.3 jdolecek
260 1.2.10.3 jdolecek DELAY(nsecs / 1000);
261 1.2.10.2 tls }
262 1.2.10.2 tls
263 1.2.10.2 tls static inline void
264 1.2.10.3 jdolecek msleep(unsigned int msec)
265 1.2.10.2 tls {
266 1.2.10.3 jdolecek if (cold ||
267 1.2.10.3 jdolecek ((hz < 1000) && (msec < (1000/hz))))
268 1.2.10.3 jdolecek udelay(msec * 1000);
269 1.2.10.3 jdolecek else
270 1.2.10.3 jdolecek (void)kpause("mdelay", false, mstohz(msec), NULL);
271 1.2.10.2 tls }
272 1.2.10.2 tls
273 1.2.10.3 jdolecek #define EREMOTEIO EIO
274 1.2.10.3 jdolecek #define ECOMM EIO
275 1.2.10.3 jdolecek #define ENOTSUPP ENOTSUP
276 1.2.10.3 jdolecek
277 1.2.10.3 jdolecek #define NS_TO_US(ns) ((ns + 500L) / 1000L)
278 1.2.10.3 jdolecek
279 1.2.10.3 jdolecek #define USB_RESUME_TIMEOUT 40 /* ms */
280 1.2.10.3 jdolecek
281 1.2.10.2 tls #endif
282