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