sunxi_musb.c revision 1.7 1 1.7 thorpej /* $NetBSD: sunxi_musb.c,v 1.7 2021/01/18 02:35:49 thorpej Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include <sys/cdefs.h>
30 1.7 thorpej __KERNEL_RCSID(0, "$NetBSD: sunxi_musb.c,v 1.7 2021/01/18 02:35:49 thorpej Exp $");
31 1.1 jmcneill
32 1.1 jmcneill #include <sys/param.h>
33 1.1 jmcneill #include <sys/bus.h>
34 1.1 jmcneill #include <sys/device.h>
35 1.1 jmcneill #include <sys/intr.h>
36 1.1 jmcneill #include <sys/systm.h>
37 1.1 jmcneill #include <sys/kernel.h>
38 1.1 jmcneill #include <sys/pool.h>
39 1.1 jmcneill
40 1.1 jmcneill #include <dev/usb/usb.h>
41 1.1 jmcneill #include <dev/usb/usbdi.h>
42 1.1 jmcneill #include <dev/usb/usbdivar.h>
43 1.1 jmcneill #include <dev/usb/motgvar.h>
44 1.2 jmcneill #include <dev/usb/motgreg.h>
45 1.1 jmcneill
46 1.1 jmcneill #include <dev/fdt/fdtvar.h>
47 1.1 jmcneill
48 1.2 jmcneill #include <machine/bus_defs.h>
49 1.2 jmcneill
50 1.1 jmcneill #define MUSB2_REG_AWIN_VEND0 0x43
51 1.1 jmcneill
52 1.1 jmcneill static int sunxi_musb_match(device_t, cfdata_t, void *);
53 1.1 jmcneill static void sunxi_musb_attach(device_t, device_t, void *);
54 1.1 jmcneill
55 1.2 jmcneill struct sunxi_musb_softc {
56 1.2 jmcneill struct motg_softc sc_otg;
57 1.2 jmcneill struct bus_space sc_bs;
58 1.2 jmcneill };
59 1.2 jmcneill
60 1.2 jmcneill CFATTACH_DECL_NEW(sunxi_musb, sizeof(struct sunxi_musb_softc),
61 1.1 jmcneill sunxi_musb_match, sunxi_musb_attach, NULL, NULL);
62 1.1 jmcneill
63 1.7 thorpej static const struct device_compatible_entry compat_data[] = {
64 1.7 thorpej { .compat = "allwinner,sun4i-a10-musb", .value = 5 },
65 1.7 thorpej { .compat = "allwinner,sun6i-a13-musb", .value = 5 },
66 1.7 thorpej { .compat = "allwinner,sun8i-h3-musb", .value = 4 },
67 1.7 thorpej { .compat = "allwinner,sun8i-a33-musb", .value = 5 },
68 1.7 thorpej
69 1.7 thorpej { 0 }
70 1.1 jmcneill };
71 1.1 jmcneill
72 1.2 jmcneill #define REMAPFLAG 0x8000
73 1.2 jmcneill #define REGDECL(a, b) [(a)] = ((b) | REMAPFLAG)
74 1.2 jmcneill
75 1.2 jmcneill /* Allwinner USB DRD register mappings */
76 1.2 jmcneill static const uint16_t sunxi_musb_regmap[] = {
77 1.2 jmcneill REGDECL(MUSB2_REG_EPFIFO(0), 0x0000),
78 1.2 jmcneill REGDECL(MUSB2_REG_EPFIFO(1), 0x0004),
79 1.2 jmcneill REGDECL(MUSB2_REG_EPFIFO(2), 0x0008),
80 1.2 jmcneill REGDECL(MUSB2_REG_EPFIFO(3), 0x000c),
81 1.2 jmcneill REGDECL(MUSB2_REG_EPFIFO(4), 0x0010),
82 1.2 jmcneill REGDECL(MUSB2_REG_EPFIFO(5), 0x0014),
83 1.2 jmcneill REGDECL(MUSB2_REG_POWER, 0x0040),
84 1.2 jmcneill REGDECL(MUSB2_REG_DEVCTL, 0x0041),
85 1.2 jmcneill REGDECL(MUSB2_REG_EPINDEX, 0x0042),
86 1.2 jmcneill REGDECL(MUSB2_REG_AWIN_VEND0, 0x0043),
87 1.2 jmcneill REGDECL(MUSB2_REG_INTTX, 0x0044),
88 1.2 jmcneill REGDECL(MUSB2_REG_INTRX, 0x0046),
89 1.2 jmcneill REGDECL(MUSB2_REG_INTTXE, 0x0048),
90 1.2 jmcneill REGDECL(MUSB2_REG_INTRXE, 0x004a),
91 1.2 jmcneill REGDECL(MUSB2_REG_INTUSB, 0x004c),
92 1.2 jmcneill REGDECL(MUSB2_REG_INTUSBE, 0x0050),
93 1.2 jmcneill REGDECL(MUSB2_REG_FRAME, 0x0054),
94 1.2 jmcneill REGDECL(MUSB2_REG_TESTMODE, 0x007c),
95 1.2 jmcneill REGDECL(MUSB2_REG_TXMAXP, 0x0080),
96 1.2 jmcneill REGDECL(MUSB2_REG_TXCSRL, 0x0082),
97 1.2 jmcneill REGDECL(MUSB2_REG_TXCSRH, 0x0083),
98 1.2 jmcneill REGDECL(MUSB2_REG_RXMAXP, 0x0084),
99 1.2 jmcneill REGDECL(MUSB2_REG_RXCSRL, 0x0086),
100 1.2 jmcneill REGDECL(MUSB2_REG_RXCSRH, 0x0087),
101 1.2 jmcneill REGDECL(MUSB2_REG_RXCOUNT, 0x0088),
102 1.2 jmcneill REGDECL(MUSB2_REG_TXTI, 0x008c),
103 1.2 jmcneill REGDECL(MUSB2_REG_TXNAKLIMIT, 0x008d),
104 1.2 jmcneill REGDECL(MUSB2_REG_RXNAKLIMIT, 0x008d),
105 1.2 jmcneill REGDECL(MUSB2_REG_RXTI, 0x008e),
106 1.2 jmcneill REGDECL(MUSB2_REG_TXFIFOSZ, 0x0090),
107 1.2 jmcneill REGDECL(MUSB2_REG_TXFIFOADD, 0x0092),
108 1.2 jmcneill REGDECL(MUSB2_REG_RXFIFOSZ, 0x0094),
109 1.2 jmcneill REGDECL(MUSB2_REG_RXFIFOADD, 0x0096),
110 1.2 jmcneill REGDECL(MUSB2_REG_FADDR, 0x0098),
111 1.2 jmcneill REGDECL(MUSB2_REG_TXFADDR(0), 0x0098),
112 1.2 jmcneill REGDECL(MUSB2_REG_TXHADDR(0), 0x009a),
113 1.2 jmcneill REGDECL(MUSB2_REG_TXHUBPORT(0), 0x009b),
114 1.2 jmcneill REGDECL(MUSB2_REG_RXFADDR(0), 0x009c),
115 1.2 jmcneill REGDECL(MUSB2_REG_RXHADDR(0), 0x009e),
116 1.2 jmcneill REGDECL(MUSB2_REG_RXHUBPORT(0), 0x009f),
117 1.2 jmcneill REGDECL(MUSB2_REG_TXFADDR(1), 0x0098),
118 1.2 jmcneill REGDECL(MUSB2_REG_TXHADDR(1), 0x009a),
119 1.2 jmcneill REGDECL(MUSB2_REG_TXHUBPORT(1), 0x009b),
120 1.2 jmcneill REGDECL(MUSB2_REG_RXFADDR(1), 0x009c),
121 1.2 jmcneill REGDECL(MUSB2_REG_RXHADDR(1), 0x009e),
122 1.2 jmcneill REGDECL(MUSB2_REG_RXHUBPORT(1), 0x009f),
123 1.2 jmcneill REGDECL(MUSB2_REG_TXFADDR(2), 0x0098),
124 1.2 jmcneill REGDECL(MUSB2_REG_TXHADDR(2), 0x009a),
125 1.2 jmcneill REGDECL(MUSB2_REG_TXHUBPORT(2), 0x009b),
126 1.2 jmcneill REGDECL(MUSB2_REG_RXFADDR(2), 0x009c),
127 1.2 jmcneill REGDECL(MUSB2_REG_RXHADDR(2), 0x009e),
128 1.2 jmcneill REGDECL(MUSB2_REG_RXHUBPORT(2), 0x009f),
129 1.2 jmcneill REGDECL(MUSB2_REG_TXFADDR(3), 0x0098),
130 1.2 jmcneill REGDECL(MUSB2_REG_TXHADDR(3), 0x009a),
131 1.2 jmcneill REGDECL(MUSB2_REG_TXHUBPORT(3), 0x009b),
132 1.2 jmcneill REGDECL(MUSB2_REG_RXFADDR(3), 0x009c),
133 1.2 jmcneill REGDECL(MUSB2_REG_RXHADDR(3), 0x009e),
134 1.2 jmcneill REGDECL(MUSB2_REG_RXHUBPORT(3), 0x009f),
135 1.2 jmcneill REGDECL(MUSB2_REG_TXFADDR(4), 0x0098),
136 1.2 jmcneill REGDECL(MUSB2_REG_TXHADDR(4), 0x009a),
137 1.2 jmcneill REGDECL(MUSB2_REG_TXHUBPORT(4), 0x009b),
138 1.2 jmcneill REGDECL(MUSB2_REG_RXFADDR(4), 0x009c),
139 1.2 jmcneill REGDECL(MUSB2_REG_RXHADDR(4), 0x009e),
140 1.2 jmcneill REGDECL(MUSB2_REG_RXHUBPORT(4), 0x009f),
141 1.2 jmcneill REGDECL(MUSB2_REG_TXFADDR(5), 0x0098),
142 1.2 jmcneill REGDECL(MUSB2_REG_TXHADDR(5), 0x009a),
143 1.2 jmcneill REGDECL(MUSB2_REG_TXHUBPORT(5), 0x009b),
144 1.2 jmcneill REGDECL(MUSB2_REG_RXFADDR(5), 0x009c),
145 1.2 jmcneill REGDECL(MUSB2_REG_RXHADDR(5), 0x009e),
146 1.2 jmcneill REGDECL(MUSB2_REG_RXHUBPORT(5), 0x009f),
147 1.2 jmcneill REGDECL(MUSB2_REG_CONFDATA, 0x00c0),
148 1.2 jmcneill };
149 1.2 jmcneill
150 1.2 jmcneill static bus_size_t
151 1.2 jmcneill sunxi_musb_reg(bus_size_t o)
152 1.2 jmcneill {
153 1.2 jmcneill bus_size_t v;
154 1.2 jmcneill
155 1.2 jmcneill if (o >= __arraycount(sunxi_musb_regmap))
156 1.2 jmcneill return o;
157 1.2 jmcneill
158 1.2 jmcneill v = sunxi_musb_regmap[o];
159 1.2 jmcneill KASSERTMSG((v & REMAPFLAG) != 0, "%s: reg %#lx not in regmap",
160 1.2 jmcneill __func__, o);
161 1.2 jmcneill
162 1.2 jmcneill return v & ~REMAPFLAG;
163 1.2 jmcneill }
164 1.2 jmcneill
165 1.2 jmcneill static int
166 1.2 jmcneill sunxi_musb_filt(bus_size_t o)
167 1.2 jmcneill {
168 1.2 jmcneill switch (o) {
169 1.2 jmcneill case MUSB2_REG_MISC:
170 1.2 jmcneill case MUSB2_REG_RXDBDIS:
171 1.2 jmcneill case MUSB2_REG_TXDBDIS:
172 1.2 jmcneill return 1;
173 1.2 jmcneill default:
174 1.2 jmcneill return 0;
175 1.2 jmcneill }
176 1.2 jmcneill }
177 1.2 jmcneill
178 1.2 jmcneill static uint8_t
179 1.2 jmcneill sunxi_musb_bs_r_1(void *t, bus_space_handle_t h, bus_size_t o)
180 1.2 jmcneill {
181 1.2 jmcneill switch (o) {
182 1.2 jmcneill case MUSB2_REG_HWVERS:
183 1.2 jmcneill return 0; /* no known equivalent */
184 1.2 jmcneill }
185 1.2 jmcneill
186 1.3 jmcneill return bus_space_read_1((bus_space_tag_t)t, h, sunxi_musb_reg(o));
187 1.2 jmcneill }
188 1.2 jmcneill
189 1.2 jmcneill static uint16_t
190 1.2 jmcneill sunxi_musb_bs_r_2(void *t, bus_space_handle_t h, bus_size_t o)
191 1.2 jmcneill {
192 1.3 jmcneill return bus_space_read_2((bus_space_tag_t)t, h, sunxi_musb_reg(o));
193 1.2 jmcneill }
194 1.2 jmcneill
195 1.2 jmcneill static void
196 1.2 jmcneill sunxi_musb_bs_w_1(void *t, bus_space_handle_t h, bus_size_t o,
197 1.2 jmcneill uint8_t v)
198 1.2 jmcneill {
199 1.2 jmcneill if (sunxi_musb_filt(o) != 0)
200 1.2 jmcneill return;
201 1.2 jmcneill
202 1.3 jmcneill bus_space_write_1((bus_space_tag_t)t, h, sunxi_musb_reg(o), v);
203 1.2 jmcneill }
204 1.2 jmcneill
205 1.2 jmcneill static void
206 1.2 jmcneill sunxi_musb_bs_w_2(void *t, bus_space_handle_t h, bus_size_t o,
207 1.2 jmcneill uint16_t v)
208 1.2 jmcneill {
209 1.2 jmcneill if (sunxi_musb_filt(o) != 0)
210 1.2 jmcneill return;
211 1.2 jmcneill
212 1.3 jmcneill bus_space_write_2((bus_space_tag_t)t, h, sunxi_musb_reg(o), v);
213 1.2 jmcneill }
214 1.2 jmcneill
215 1.2 jmcneill static void
216 1.2 jmcneill sunxi_musb_bs_rm_1(void *t, bus_space_handle_t h, bus_size_t o,
217 1.2 jmcneill uint8_t *d, bus_size_t c)
218 1.2 jmcneill {
219 1.3 jmcneill bus_space_read_multi_1((bus_space_tag_t)t, h, sunxi_musb_reg(o), d, c);
220 1.2 jmcneill }
221 1.2 jmcneill
222 1.2 jmcneill static void
223 1.2 jmcneill sunxi_musb_bs_rm_4(void *t, bus_space_handle_t h, bus_size_t o,
224 1.2 jmcneill uint32_t *d, bus_size_t c)
225 1.2 jmcneill {
226 1.3 jmcneill bus_space_read_multi_4((bus_space_tag_t)t, h, sunxi_musb_reg(o), d, c);
227 1.2 jmcneill }
228 1.2 jmcneill
229 1.2 jmcneill static void
230 1.2 jmcneill sunxi_musb_bs_wm_1(void *t, bus_space_handle_t h, bus_size_t o,
231 1.2 jmcneill const uint8_t *d, bus_size_t c)
232 1.2 jmcneill {
233 1.2 jmcneill if (sunxi_musb_filt(o) != 0)
234 1.2 jmcneill return;
235 1.2 jmcneill
236 1.3 jmcneill bus_space_write_multi_1((bus_space_tag_t)t, h, sunxi_musb_reg(o), d, c);
237 1.2 jmcneill }
238 1.2 jmcneill
239 1.2 jmcneill static void
240 1.2 jmcneill sunxi_musb_bs_wm_4(void *t, bus_space_handle_t h, bus_size_t o,
241 1.2 jmcneill const uint32_t *d, bus_size_t c)
242 1.2 jmcneill {
243 1.2 jmcneill if (sunxi_musb_filt(o) != 0)
244 1.2 jmcneill return;
245 1.2 jmcneill
246 1.3 jmcneill bus_space_write_multi_4((bus_space_tag_t)t, h, sunxi_musb_reg(o), d, c);
247 1.2 jmcneill }
248 1.2 jmcneill
249 1.2 jmcneill static void
250 1.2 jmcneill sunxi_musb_bs_barrier(void *t, bus_space_handle_t h, bus_size_t o,
251 1.2 jmcneill bus_size_t l, int f)
252 1.2 jmcneill {
253 1.3 jmcneill bus_space_barrier((bus_space_tag_t)t, h, o, l, f);
254 1.2 jmcneill }
255 1.2 jmcneill
256 1.1 jmcneill static int
257 1.1 jmcneill sunxi_musb_intr(void *priv)
258 1.1 jmcneill {
259 1.1 jmcneill struct motg_softc * const sc = priv;
260 1.1 jmcneill uint16_t inttx, intrx;
261 1.1 jmcneill uint8_t intusb;
262 1.1 jmcneill
263 1.1 jmcneill mutex_enter(&sc->sc_intr_lock);
264 1.1 jmcneill
265 1.1 jmcneill intusb = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MUSB2_REG_INTUSB);
266 1.1 jmcneill inttx = bus_space_read_2(sc->sc_iot, sc->sc_ioh, MUSB2_REG_INTTX);
267 1.1 jmcneill intrx = bus_space_read_2(sc->sc_iot, sc->sc_ioh, MUSB2_REG_INTRX);
268 1.1 jmcneill if (!intusb && !inttx && !intrx) {
269 1.1 jmcneill mutex_exit(&sc->sc_intr_lock);
270 1.1 jmcneill return 0;
271 1.1 jmcneill }
272 1.1 jmcneill
273 1.1 jmcneill if (intusb)
274 1.1 jmcneill bus_space_write_1(sc->sc_iot, sc->sc_ioh, MUSB2_REG_INTUSB, intusb);
275 1.1 jmcneill if (inttx)
276 1.1 jmcneill bus_space_write_2(sc->sc_iot, sc->sc_ioh, MUSB2_REG_INTTX, inttx);
277 1.1 jmcneill if (intrx)
278 1.1 jmcneill bus_space_write_2(sc->sc_iot, sc->sc_ioh, MUSB2_REG_INTRX, intrx);
279 1.1 jmcneill
280 1.1 jmcneill motg_intr(sc, intrx, inttx, intusb);
281 1.1 jmcneill
282 1.1 jmcneill mutex_exit(&sc->sc_intr_lock);
283 1.1 jmcneill
284 1.1 jmcneill return 1;
285 1.1 jmcneill }
286 1.1 jmcneill
287 1.1 jmcneill static void
288 1.1 jmcneill sunxi_musb_poll(void *priv)
289 1.1 jmcneill {
290 1.1 jmcneill sunxi_musb_intr(priv);
291 1.1 jmcneill }
292 1.1 jmcneill
293 1.1 jmcneill static int
294 1.1 jmcneill sunxi_musb_match(device_t parent, cfdata_t cf, void *aux)
295 1.1 jmcneill {
296 1.1 jmcneill struct fdt_attach_args * const faa = aux;
297 1.1 jmcneill
298 1.1 jmcneill return of_match_compat_data(faa->faa_phandle, compat_data);
299 1.1 jmcneill }
300 1.1 jmcneill
301 1.1 jmcneill static void
302 1.1 jmcneill sunxi_musb_attach(device_t parent, device_t self, void *aux)
303 1.1 jmcneill {
304 1.2 jmcneill struct sunxi_musb_softc * const msc = device_private(self);
305 1.2 jmcneill struct motg_softc * const sc = &msc->sc_otg;
306 1.1 jmcneill struct fdt_attach_args * const faa = aux;
307 1.1 jmcneill const int phandle = faa->faa_phandle;
308 1.1 jmcneill struct fdtbus_reset *rst;
309 1.1 jmcneill struct fdtbus_phy *phy;
310 1.1 jmcneill struct clk *clk;
311 1.1 jmcneill char intrstr[128];
312 1.1 jmcneill const char *dr_mode;
313 1.1 jmcneill bus_addr_t addr;
314 1.1 jmcneill bus_size_t size;
315 1.1 jmcneill void *ih;
316 1.1 jmcneill u_int n;
317 1.1 jmcneill
318 1.1 jmcneill /* Only "host" mode is supported */
319 1.1 jmcneill dr_mode = fdtbus_get_string(phandle, "dr_mode");
320 1.1 jmcneill if (dr_mode == NULL || strcmp(dr_mode, "host") != 0) {
321 1.1 jmcneill aprint_normal(": '%s' mode not supported\n", dr_mode);
322 1.1 jmcneill return;
323 1.1 jmcneill }
324 1.1 jmcneill
325 1.1 jmcneill if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
326 1.1 jmcneill aprint_error(": couldn't get registers\n");
327 1.1 jmcneill return;
328 1.1 jmcneill }
329 1.1 jmcneill
330 1.1 jmcneill /* Enable clocks */
331 1.1 jmcneill for (n = 0; (clk = fdtbus_clock_get_index(phandle, n)) != NULL; n++)
332 1.1 jmcneill if (clk_enable(clk) != 0) {
333 1.1 jmcneill aprint_error(": couldn't enable clock #%d\n", n);
334 1.1 jmcneill return;
335 1.1 jmcneill }
336 1.1 jmcneill /* De-assert resets */
337 1.1 jmcneill for (n = 0; (rst = fdtbus_reset_get_index(phandle, n)) != NULL; n++)
338 1.1 jmcneill if (fdtbus_reset_deassert(rst) != 0) {
339 1.1 jmcneill aprint_error(": couldn't de-assert reset #%d\n", n);
340 1.1 jmcneill return;
341 1.1 jmcneill }
342 1.1 jmcneill
343 1.1 jmcneill /* Enable optional phy */
344 1.1 jmcneill phy = fdtbus_phy_get(phandle, "usb");
345 1.1 jmcneill if (phy && fdtbus_phy_enable(phy, true) != 0) {
346 1.1 jmcneill aprint_error(": couldn't enable phy\n");
347 1.1 jmcneill return;
348 1.1 jmcneill }
349 1.1 jmcneill
350 1.2 jmcneill /* Create custom bus space tag for remapping registers */
351 1.2 jmcneill msc->sc_bs.bs_cookie = faa->faa_bst;
352 1.2 jmcneill msc->sc_bs.bs_r_1 = sunxi_musb_bs_r_1;
353 1.2 jmcneill msc->sc_bs.bs_r_2 = sunxi_musb_bs_r_2;
354 1.2 jmcneill msc->sc_bs.bs_w_1 = sunxi_musb_bs_w_1;
355 1.2 jmcneill msc->sc_bs.bs_w_2 = sunxi_musb_bs_w_2;
356 1.2 jmcneill msc->sc_bs.bs_rm_1 = sunxi_musb_bs_rm_1;
357 1.2 jmcneill msc->sc_bs.bs_rm_4 = sunxi_musb_bs_rm_4;
358 1.2 jmcneill msc->sc_bs.bs_wm_1 = sunxi_musb_bs_wm_1;
359 1.2 jmcneill msc->sc_bs.bs_wm_4 = sunxi_musb_bs_wm_4;
360 1.2 jmcneill msc->sc_bs.bs_barrier = sunxi_musb_bs_barrier;
361 1.2 jmcneill
362 1.1 jmcneill sc->sc_dev = self;
363 1.1 jmcneill sc->sc_bus.ub_hcpriv = sc;
364 1.1 jmcneill sc->sc_bus.ub_dmatag = faa->faa_dmat;
365 1.1 jmcneill sc->sc_size = size;
366 1.2 jmcneill sc->sc_iot = &msc->sc_bs;
367 1.2 jmcneill if (bus_space_map(faa->faa_bst, addr, size, 0, &sc->sc_ioh) != 0) {
368 1.1 jmcneill aprint_error(": couldn't map registers\n");
369 1.1 jmcneill return;
370 1.1 jmcneill }
371 1.1 jmcneill sc->sc_intr_poll = sunxi_musb_poll;
372 1.1 jmcneill sc->sc_intr_poll_arg = sc;
373 1.1 jmcneill sc->sc_mode = MOTG_MODE_HOST;
374 1.7 thorpej sc->sc_ep_max = of_search_compatible(phandle, compat_data)->value;
375 1.1 jmcneill sc->sc_ep_fifosize = 512;
376 1.1 jmcneill
377 1.1 jmcneill aprint_naive("\n");
378 1.1 jmcneill aprint_normal(": USB OTG\n");
379 1.1 jmcneill
380 1.1 jmcneill if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
381 1.1 jmcneill aprint_error_dev(self, "failed to decode interrupt\n");
382 1.1 jmcneill return;
383 1.1 jmcneill }
384 1.1 jmcneill
385 1.6 jmcneill ih = fdtbus_intr_establish_xname(phandle, 0, IPL_USB, FDT_INTR_MPSAFE,
386 1.6 jmcneill sunxi_musb_intr, sc, device_xname(self));
387 1.1 jmcneill if (ih == NULL) {
388 1.1 jmcneill aprint_error_dev(self, "couldn't establish interrupt on %s\n",
389 1.1 jmcneill intrstr);
390 1.1 jmcneill return;
391 1.1 jmcneill }
392 1.1 jmcneill aprint_normal_dev(self, "interrupting on %s\n", intrstr);
393 1.1 jmcneill
394 1.1 jmcneill bus_space_write_1(sc->sc_iot, sc->sc_ioh, MUSB2_REG_AWIN_VEND0, 0);
395 1.1 jmcneill
396 1.1 jmcneill motg_init(sc);
397 1.1 jmcneill }
398