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