xref: /netbsd/sys/dev/fdt/dwc3_fdt.c (revision b9d37795)
1*b9d37795Sskrll /* $NetBSD: dwc3_fdt.c,v 1.20 2022/06/12 08:04:07 skrll Exp $ */
2b79ff4f5Sjmcneill 
3b79ff4f5Sjmcneill /*-
4b79ff4f5Sjmcneill  * Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca>
5b79ff4f5Sjmcneill  * All rights reserved.
6b79ff4f5Sjmcneill  *
7b79ff4f5Sjmcneill  * Redistribution and use in source and binary forms, with or without
8b79ff4f5Sjmcneill  * modification, are permitted provided that the following conditions
9b79ff4f5Sjmcneill  * are met:
10b79ff4f5Sjmcneill  * 1. Redistributions of source code must retain the above copyright
11b79ff4f5Sjmcneill  *    notice, this list of conditions and the following disclaimer.
12b79ff4f5Sjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
13b79ff4f5Sjmcneill  *    notice, this list of conditions and the following disclaimer in the
14b79ff4f5Sjmcneill  *    documentation and/or other materials provided with the distribution.
15b79ff4f5Sjmcneill  *
16b79ff4f5Sjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17b79ff4f5Sjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18b79ff4f5Sjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19b79ff4f5Sjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20b79ff4f5Sjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21b79ff4f5Sjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22b79ff4f5Sjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23b79ff4f5Sjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24b79ff4f5Sjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b79ff4f5Sjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b79ff4f5Sjmcneill  * SUCH DAMAGE.
27b79ff4f5Sjmcneill  */
28b79ff4f5Sjmcneill 
29b79ff4f5Sjmcneill #include <sys/cdefs.h>
30*b9d37795Sskrll __KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.20 2022/06/12 08:04:07 skrll Exp $");
31b79ff4f5Sjmcneill 
32b79ff4f5Sjmcneill #include <sys/param.h>
33b79ff4f5Sjmcneill #include <sys/bus.h>
34b79ff4f5Sjmcneill #include <sys/device.h>
35b79ff4f5Sjmcneill #include <sys/intr.h>
36b79ff4f5Sjmcneill #include <sys/systm.h>
37b79ff4f5Sjmcneill #include <sys/kernel.h>
38b79ff4f5Sjmcneill 
39b79ff4f5Sjmcneill #include <dev/usb/usb.h>
40b79ff4f5Sjmcneill #include <dev/usb/usbdi.h>
41b79ff4f5Sjmcneill #include <dev/usb/usbdivar.h>
42b79ff4f5Sjmcneill #include <dev/usb/usb_mem.h>
43b79ff4f5Sjmcneill #include <dev/usb/xhcireg.h>
44b79ff4f5Sjmcneill #include <dev/usb/xhcivar.h>
45b79ff4f5Sjmcneill 
46b79ff4f5Sjmcneill #include <dev/fdt/fdtvar.h>
47b79ff4f5Sjmcneill 
48b79ff4f5Sjmcneill #define	DWC3_GCTL			0xc110
49b79ff4f5Sjmcneill #define	 GCTL_PRTCAP			__BITS(13,12)
50b79ff4f5Sjmcneill #define	  GCTL_PRTCAP_HOST		1
51b79ff4f5Sjmcneill #define	  GCTL_PRTCAP_DEVICE		2
52b79ff4f5Sjmcneill #define	  GCTL_PRTCAP_OTG		3
53b79ff4f5Sjmcneill #define	 GCTL_CORESOFTRESET		__BIT(11)
54b79ff4f5Sjmcneill 
5578cf5234Sjmcneill #define	DWC3_GUCTL1			0xc11c
5678cf5234Sjmcneill #define	 GUCTL1_TX_IPGAP_LINECHECK_DIS	__BIT(28)
5778cf5234Sjmcneill 
580d187490Sjmcneill #define	DWC3_SNPSID			0xc120
590d187490Sjmcneill #define	 DWC3_SNPSID_REV		__BITS(15,0)
600d187490Sjmcneill 
61b79ff4f5Sjmcneill #define	DWC3_GUSB2PHYCFG(n)		(0xc200 + ((n) * 4))
62b79ff4f5Sjmcneill #define	 GUSB2PHYCFG_PHYSOFTRST		__BIT(31)
6352c669e6Sjmcneill #define	 GUSB2PHYCFG_U2_FREECLK_EXISTS	__BIT(30)
6452c669e6Sjmcneill #define	 GUSB2PHYCFG_USBTRDTIM		__BITS(13,10)
6552c669e6Sjmcneill #define	 GUSB2PHYCFG_SUSPHY		__BIT(6)
6652c669e6Sjmcneill #define	 GUSB2PHYCFG_PHYIF		__BIT(3)
6752c669e6Sjmcneill #define	 GUSB2PHYCFG_ENBLSLPM		__BIT(0)
68b79ff4f5Sjmcneill 
69b79ff4f5Sjmcneill #define	DWC3_GUSB3PIPECTL(n)		(0xc2c0 + ((n) * 4))
70b79ff4f5Sjmcneill #define	 GUSB3PIPECTL_PHYSOFTRST	__BIT(31)
710d187490Sjmcneill #define	 GUSB3PIPECTL_UX_EXIT_PX	__BIT(27)
722f104affSjmcneill #define	 GUSB3PIPECTL_DEPOCHANGE	__BIT(18)
730d187490Sjmcneill #define	 GUSB3PIPECTL_SUSPHY		__BIT(17)
74b79ff4f5Sjmcneill 
7552c669e6Sjmcneill #define	DWC3_DCFG			0xc700
7652c669e6Sjmcneill #define	 DCFG_SPEED			__BITS(2,0)
7752c669e6Sjmcneill #define	  DCFG_SPEED_HS			0
7852c669e6Sjmcneill #define	  DCFG_SPEED_FS			1
7952c669e6Sjmcneill #define	  DCFG_SPEED_LS			2
8052c669e6Sjmcneill #define	  DCFG_SPEED_SS			4
8152c669e6Sjmcneill #define	  DCFG_SPEED_SS_PLUS		5
8252c669e6Sjmcneill 
83b79ff4f5Sjmcneill static int	dwc3_fdt_match(device_t, cfdata_t, void *);
84b79ff4f5Sjmcneill static void	dwc3_fdt_attach(device_t, device_t, void *);
85b79ff4f5Sjmcneill 
86b79ff4f5Sjmcneill CFATTACH_DECL2_NEW(dwc3_fdt, sizeof(struct xhci_softc),
87b79ff4f5Sjmcneill 	dwc3_fdt_match, dwc3_fdt_attach, NULL,
88b79ff4f5Sjmcneill 	xhci_activate, NULL, xhci_childdet);
89b79ff4f5Sjmcneill 
90b79ff4f5Sjmcneill #define	RD4(sc, reg)				\
91b79ff4f5Sjmcneill 	bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg))
92b79ff4f5Sjmcneill #define	WR4(sc, reg, val)			\
93b79ff4f5Sjmcneill 	bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
94b79ff4f5Sjmcneill #define	SET4(sc, reg, mask)			\
95b79ff4f5Sjmcneill 	WR4((sc), (reg), RD4((sc), (reg)) | (mask))
96b79ff4f5Sjmcneill #define	CLR4(sc, reg, mask)			\
97b79ff4f5Sjmcneill 	WR4((sc), (reg), RD4((sc), (reg)) & ~(mask))
98b79ff4f5Sjmcneill 
99b79ff4f5Sjmcneill static void
dwc3_fdt_soft_reset(struct xhci_softc * sc)100b79ff4f5Sjmcneill dwc3_fdt_soft_reset(struct xhci_softc *sc)
101b79ff4f5Sjmcneill {
102b79ff4f5Sjmcneill 	/* Put core in reset */
103b79ff4f5Sjmcneill 	SET4(sc, DWC3_GCTL, GCTL_CORESOFTRESET);
104b79ff4f5Sjmcneill 
105b79ff4f5Sjmcneill 	/* Assert USB3 PHY reset */
106b79ff4f5Sjmcneill 	SET4(sc, DWC3_GUSB3PIPECTL(0), GUSB3PIPECTL_PHYSOFTRST);
107b79ff4f5Sjmcneill 
108b79ff4f5Sjmcneill 	/* Assert USB2 PHY reset */
109b79ff4f5Sjmcneill 	SET4(sc, DWC3_GUSB2PHYCFG(0), GUSB2PHYCFG_PHYSOFTRST);
110b79ff4f5Sjmcneill 
111b79ff4f5Sjmcneill 	delay(100000);
112b79ff4f5Sjmcneill 
113b79ff4f5Sjmcneill 	/* Clear USB3 PHY reset */
114b79ff4f5Sjmcneill 	CLR4(sc, DWC3_GUSB3PIPECTL(0), GUSB3PIPECTL_PHYSOFTRST);
115b79ff4f5Sjmcneill 
116b79ff4f5Sjmcneill 	/* Clear USB2 PHY reset */
117b79ff4f5Sjmcneill 	CLR4(sc, DWC3_GUSB2PHYCFG(0), GUSB2PHYCFG_PHYSOFTRST);
118b79ff4f5Sjmcneill 
119b79ff4f5Sjmcneill 	delay(100000);
120b79ff4f5Sjmcneill 
121b79ff4f5Sjmcneill 	/* Take core out of reset */
122b79ff4f5Sjmcneill 	CLR4(sc, DWC3_GCTL, GCTL_CORESOFTRESET);
123b79ff4f5Sjmcneill }
124b79ff4f5Sjmcneill 
125b79ff4f5Sjmcneill static void
dwc3_fdt_enable_phy(struct xhci_softc * sc,const int phandle,u_int rev)12678cf5234Sjmcneill dwc3_fdt_enable_phy(struct xhci_softc *sc, const int phandle, u_int rev)
12752c669e6Sjmcneill {
1282f104affSjmcneill 	const char *max_speed, *phy_type;
12952c669e6Sjmcneill 	u_int phyif_utmi_bits;
13052c669e6Sjmcneill 	uint32_t val;
13152c669e6Sjmcneill 
13252c669e6Sjmcneill 	val = RD4(sc, DWC3_GUSB2PHYCFG(0));
1332f104affSjmcneill 	if (of_getprop_uint32(phandle, "snps,phyif-utmi-bits", &phyif_utmi_bits) != 0) {
1342f104affSjmcneill 		phy_type = fdtbus_get_string(phandle, "phy_type");
1352f104affSjmcneill 		if (phy_type && strcmp(phy_type, "utmi_wide") == 0)
1362f104affSjmcneill 			phyif_utmi_bits = 16;
1372f104affSjmcneill 		else if (phy_type && strcmp(phy_type, "utmi") == 0)
1382f104affSjmcneill 			phyif_utmi_bits = 8;
1392f104affSjmcneill 		else
1402f104affSjmcneill 			phyif_utmi_bits = 0;
1412f104affSjmcneill 	}
14252c669e6Sjmcneill 	if (phyif_utmi_bits == 16) {
14352c669e6Sjmcneill 		val |= GUSB2PHYCFG_PHYIF;
14452c669e6Sjmcneill 		val &= ~GUSB2PHYCFG_USBTRDTIM;
14552c669e6Sjmcneill 		val |= __SHIFTIN(5, GUSB2PHYCFG_USBTRDTIM);
14652c669e6Sjmcneill 	} else if (phyif_utmi_bits == 8) {
14752c669e6Sjmcneill 		val &= ~GUSB2PHYCFG_PHYIF;
14852c669e6Sjmcneill 		val &= ~GUSB2PHYCFG_USBTRDTIM;
14952c669e6Sjmcneill 		val |= __SHIFTIN(9, GUSB2PHYCFG_USBTRDTIM);
15052c669e6Sjmcneill 	}
1512f104affSjmcneill 	if (of_hasprop(phandle, "snps,dis-enblslpm-quirk") ||
1522f104affSjmcneill 	    of_hasprop(phandle, "snps,dis_enblslpm_quirk"))
15352c669e6Sjmcneill 		val &= ~GUSB2PHYCFG_ENBLSLPM;
15452c669e6Sjmcneill 	if (of_hasprop(phandle, "snps,dis-u2-freeclk-exists-quirk"))
15552c669e6Sjmcneill 		val &= ~GUSB2PHYCFG_U2_FREECLK_EXISTS;
156b5db38d4Sjmcneill 	if (of_hasprop(phandle, "snps,dis_u2_susphy_quirk"))
15752c669e6Sjmcneill 		val &= ~GUSB2PHYCFG_SUSPHY;
15852c669e6Sjmcneill 	WR4(sc, DWC3_GUSB2PHYCFG(0), val);
15952c669e6Sjmcneill 
1600d187490Sjmcneill 	val = RD4(sc, DWC3_GUSB3PIPECTL(0));
1610d187490Sjmcneill 	val &= ~GUSB3PIPECTL_UX_EXIT_PX;
1620d187490Sjmcneill 	if (of_hasprop(phandle, "snps,dis_u3_susphy_quirk"))
1630d187490Sjmcneill 		val &= ~GUSB3PIPECTL_SUSPHY;
1642f104affSjmcneill 	if (of_hasprop(phandle, "snps,dis-del-phy-power-chg-quirk"))
1652f104affSjmcneill 		val &= ~GUSB3PIPECTL_DEPOCHANGE;
1660d187490Sjmcneill 	WR4(sc, DWC3_GUSB3PIPECTL(0), val);
1670d187490Sjmcneill 
16878cf5234Sjmcneill 	if (rev >= 0x250a) {
16978cf5234Sjmcneill 		val = RD4(sc, DWC3_GUCTL1);
17078cf5234Sjmcneill 		if (of_hasprop(phandle, "snps,dis-tx-ipgap-linecheck-quirk"))
17178cf5234Sjmcneill 			val |= GUCTL1_TX_IPGAP_LINECHECK_DIS;
17278cf5234Sjmcneill 		WR4(sc, DWC3_GUCTL1, val);
17378cf5234Sjmcneill 	}
17478cf5234Sjmcneill 
17552c669e6Sjmcneill 	max_speed = fdtbus_get_string(phandle, "maximum-speed");
17652c669e6Sjmcneill 	if (max_speed == NULL)
17752c669e6Sjmcneill 		max_speed = "super-speed";
17852c669e6Sjmcneill 
17952c669e6Sjmcneill 	val = RD4(sc, DWC3_DCFG);
18052c669e6Sjmcneill 	val &= ~DCFG_SPEED;
18152c669e6Sjmcneill 	if (strcmp(max_speed, "low-speed") == 0)
18252c669e6Sjmcneill 		val |= __SHIFTIN(DCFG_SPEED_LS, DCFG_SPEED);
18352c669e6Sjmcneill 	else if (strcmp(max_speed, "full-speed") == 0)
18452c669e6Sjmcneill 		val |= __SHIFTIN(DCFG_SPEED_FS, DCFG_SPEED);
18552c669e6Sjmcneill 	else if (strcmp(max_speed, "high-speed") == 0)
18652c669e6Sjmcneill 		val |= __SHIFTIN(DCFG_SPEED_HS, DCFG_SPEED);
18752c669e6Sjmcneill 	else if (strcmp(max_speed, "super-speed") == 0)
18852c669e6Sjmcneill 		val |= __SHIFTIN(DCFG_SPEED_SS, DCFG_SPEED);
18952c669e6Sjmcneill 	else
19052c669e6Sjmcneill 		val |= __SHIFTIN(DCFG_SPEED_SS, DCFG_SPEED);	/* default to super speed */
19152c669e6Sjmcneill 	WR4(sc, DWC3_DCFG, val);
19252c669e6Sjmcneill }
19352c669e6Sjmcneill 
19452c669e6Sjmcneill static void
dwc3_fdt_set_mode(struct xhci_softc * sc,u_int mode)195b79ff4f5Sjmcneill dwc3_fdt_set_mode(struct xhci_softc *sc, u_int mode)
196b79ff4f5Sjmcneill {
197b79ff4f5Sjmcneill 	uint32_t val;
198b79ff4f5Sjmcneill 
199b79ff4f5Sjmcneill 	val = RD4(sc, DWC3_GCTL);
200b79ff4f5Sjmcneill 	val &= ~GCTL_PRTCAP;
201b79ff4f5Sjmcneill 	val |= __SHIFTIN(mode, GCTL_PRTCAP);
202b79ff4f5Sjmcneill 	WR4(sc, DWC3_GCTL, val);
203b79ff4f5Sjmcneill }
204b79ff4f5Sjmcneill 
2058e90f9edSthorpej static const struct device_compatible_entry compat_data[] = {
2067dd2d4e8Sjmcneill 	{ .compat = "allwinner,sun50i-h6-dwc3" },
2077dd2d4e8Sjmcneill 	{ .compat = "amlogic,meson-gxl-dwc3" },
2087dd2d4e8Sjmcneill 	{ .compat = "fsl,imx8mq-dwc3" },
2097dd2d4e8Sjmcneill 	{ .compat = "rockchip,rk3328-dwc3" },
2107dd2d4e8Sjmcneill 	{ .compat = "rockchip,rk3399-dwc3" },
2117dd2d4e8Sjmcneill 	{ .compat = "samsung,exynos5250-dwusb3" },
2127dd2d4e8Sjmcneill 	{ .compat = "snps,dwc3" },
2137dd2d4e8Sjmcneill 	DEVICE_COMPAT_EOL
2147dd2d4e8Sjmcneill };
2157dd2d4e8Sjmcneill 
2167dd2d4e8Sjmcneill static const struct device_compatible_entry compat_data_dwc3[] = {
2177dd2d4e8Sjmcneill 	{ .compat = "snps,dwc3" },
2188e90f9edSthorpej 	DEVICE_COMPAT_EOL
2198e90f9edSthorpej };
2208e90f9edSthorpej 
221b79ff4f5Sjmcneill static int
dwc3_fdt_match(device_t parent,cfdata_t cf,void * aux)222b79ff4f5Sjmcneill dwc3_fdt_match(device_t parent, cfdata_t cf, void *aux)
223b79ff4f5Sjmcneill {
224b79ff4f5Sjmcneill 	struct fdt_attach_args * const faa = aux;
225b79ff4f5Sjmcneill 
2268e90f9edSthorpej 	return of_compatible_match(faa->faa_phandle, compat_data);
227b79ff4f5Sjmcneill }
228b79ff4f5Sjmcneill 
229b79ff4f5Sjmcneill static void
dwc3_fdt_attach(device_t parent,device_t self,void * aux)230b79ff4f5Sjmcneill dwc3_fdt_attach(device_t parent, device_t self, void *aux)
231b79ff4f5Sjmcneill {
232b79ff4f5Sjmcneill 	struct xhci_softc * const sc = device_private(self);
233b79ff4f5Sjmcneill 	struct fdt_attach_args * const faa = aux;
234b79ff4f5Sjmcneill 	const int phandle = faa->faa_phandle;
235b79ff4f5Sjmcneill 	struct fdtbus_reset *rst;
236b79ff4f5Sjmcneill 	struct fdtbus_phy *phy;
237b79ff4f5Sjmcneill 	struct clk *clk;
238b79ff4f5Sjmcneill 	char intrstr[128];
239b79ff4f5Sjmcneill 	bus_addr_t addr;
240b79ff4f5Sjmcneill 	bus_size_t size;
2419c398a26Sjmcneill 	int error, dwc3_phandle;
242b79ff4f5Sjmcneill 	void *ih;
243b79ff4f5Sjmcneill 	u_int n;
244b79ff4f5Sjmcneill 
245b79ff4f5Sjmcneill 	/* Find dwc3 sub-node */
2467dd2d4e8Sjmcneill 	if (of_compatible_lookup(phandle, compat_data_dwc3) == NULL) {
24706633d80Sjmcneill 		dwc3_phandle = of_find_bycompat(phandle, "snps,dwc3");
24806633d80Sjmcneill 		if (dwc3_phandle <= 0) {
2499c398a26Sjmcneill 			dwc3_phandle = of_find_firstchild_byname(phandle, "dwc3");
25006633d80Sjmcneill 		}
2518e90f9edSthorpej 	} else {
2528e90f9edSthorpej 		dwc3_phandle = phandle;
2539c398a26Sjmcneill 	}
254b79ff4f5Sjmcneill 	if (dwc3_phandle <= 0) {
255b79ff4f5Sjmcneill 		aprint_error(": couldn't find dwc3 child node\n");
256b79ff4f5Sjmcneill 		return;
257b79ff4f5Sjmcneill 	}
258b79ff4f5Sjmcneill 
259*b9d37795Sskrll 	/*
260*b9d37795Sskrll 	 * Only host mode is supported, but this includes otg devices
261*b9d37795Sskrll 	 * that have 'usb-role-switch' and 'role-switch-default-mode' of
262*b9d37795Sskrll 	 * 'host'
263*b9d37795Sskrll 	 */
264b79ff4f5Sjmcneill 	const char *dr_mode = fdtbus_get_string(dwc3_phandle, "dr_mode");
265*b9d37795Sskrll 	if (dr_mode == NULL || strcmp(dr_mode, "otg") == 0) {
266*b9d37795Sskrll 		bool ok = false;
267*b9d37795Sskrll 		if (of_hasprop(dwc3_phandle, "usb-role-switch")) {
268*b9d37795Sskrll 			const char *rsdm = fdtbus_get_string(dwc3_phandle,
269*b9d37795Sskrll 			    "role-switch-default-mode");
270*b9d37795Sskrll 			if (rsdm != NULL && strcmp(rsdm, "host") == 0)
271*b9d37795Sskrll 				ok = true;
272*b9d37795Sskrll 
273*b9d37795Sskrll 			if (!ok) {
274*b9d37795Sskrll 				aprint_error(": host is not default mode\n");
275*b9d37795Sskrll 				return;
276*b9d37795Sskrll 			}
277*b9d37795Sskrll 		}
278*b9d37795Sskrll 		if (!ok) {
279*b9d37795Sskrll 			aprint_error(": cannot switch 'otg' mode to host\n");
280*b9d37795Sskrll 			return;
281*b9d37795Sskrll 		}
282*b9d37795Sskrll 	} else if (strcmp(dr_mode, "host") != 0) {
283b79ff4f5Sjmcneill 		aprint_error(": '%s' not supported\n", dr_mode);
284b79ff4f5Sjmcneill 		return;
285b79ff4f5Sjmcneill 	}
286b79ff4f5Sjmcneill 
287b79ff4f5Sjmcneill 	/* Enable clocks */
2889c398a26Sjmcneill 	fdtbus_clock_assign(phandle);
289b79ff4f5Sjmcneill 	for (n = 0; (clk = fdtbus_clock_get_index(phandle, n)) != NULL; n++)
290b79ff4f5Sjmcneill 		if (clk_enable(clk) != 0) {
291b79ff4f5Sjmcneill 			aprint_error(": couldn't enable clock #%d\n", n);
292b79ff4f5Sjmcneill 			return;
293b79ff4f5Sjmcneill 		}
294b79ff4f5Sjmcneill 	/* De-assert resets */
295b79ff4f5Sjmcneill 	for (n = 0; (rst = fdtbus_reset_get_index(phandle, n)) != NULL; n++)
296b79ff4f5Sjmcneill 		if (fdtbus_reset_deassert(rst) != 0) {
297b79ff4f5Sjmcneill 			aprint_error(": couldn't de-assert reset #%d\n", n);
298b79ff4f5Sjmcneill 			return;
299b79ff4f5Sjmcneill 		}
300b79ff4f5Sjmcneill 
301b79ff4f5Sjmcneill 	/* Get resources */
302b79ff4f5Sjmcneill 	if (fdtbus_get_reg(dwc3_phandle, 0, &addr, &size) != 0) {
303b79ff4f5Sjmcneill 		aprint_error(": couldn't get registers\n");
304b79ff4f5Sjmcneill 		return;
305b79ff4f5Sjmcneill 	}
306b79ff4f5Sjmcneill 
307b79ff4f5Sjmcneill 	sc->sc_dev = self;
308b79ff4f5Sjmcneill 	sc->sc_bus.ub_hcpriv = sc;
309b79ff4f5Sjmcneill 	sc->sc_bus.ub_dmatag = faa->faa_dmat;
310d75e36aeSjmcneill 	sc->sc_ios = size;
311b79ff4f5Sjmcneill 	sc->sc_iot = faa->faa_bst;
312b79ff4f5Sjmcneill 	if (bus_space_map(sc->sc_iot, addr, size, 0, &sc->sc_ioh) != 0) {
313b79ff4f5Sjmcneill 		aprint_error(": couldn't map registers\n");
314b79ff4f5Sjmcneill 		return;
315b79ff4f5Sjmcneill 	}
316b79ff4f5Sjmcneill 
317b79ff4f5Sjmcneill 	aprint_naive("\n");
3180d187490Sjmcneill 	aprint_normal(": DesignWare USB3 XHCI");
3190d187490Sjmcneill 	const uint32_t snpsid = RD4(sc, DWC3_SNPSID);
3200d187490Sjmcneill 	const u_int rev = __SHIFTOUT(snpsid, DWC3_SNPSID_REV);
3210d187490Sjmcneill 	aprint_normal(" (rev. %d.%03x)\n", rev >> 12, rev & 0xfff);
322b79ff4f5Sjmcneill 
3230d187490Sjmcneill 	/* Enable PHY devices */
324b08b2911Sjmcneill 	for (n = 0; (phy = fdtbus_phy_get_index(dwc3_phandle, n)) != NULL; n++) {
325b08b2911Sjmcneill 		if (fdtbus_phy_enable(phy, true) != 0)
326b08b2911Sjmcneill 			aprint_error_dev(self, "couldn't enable phy #%d\n", n);
327b08b2911Sjmcneill 	}
32852c669e6Sjmcneill 
329b79ff4f5Sjmcneill 	dwc3_fdt_soft_reset(sc);
33078cf5234Sjmcneill 	dwc3_fdt_enable_phy(sc, dwc3_phandle, rev);
331b79ff4f5Sjmcneill 	dwc3_fdt_set_mode(sc, GCTL_PRTCAP_HOST);
332b79ff4f5Sjmcneill 
333b79ff4f5Sjmcneill 	if (!fdtbus_intr_str(dwc3_phandle, 0, intrstr, sizeof(intrstr))) {
334b79ff4f5Sjmcneill 		aprint_error_dev(self, "failed to decode interrupt\n");
335b79ff4f5Sjmcneill 		return;
336b79ff4f5Sjmcneill 	}
337b79ff4f5Sjmcneill 
338a8436a52Sryo 	ih = fdtbus_intr_establish_xname(dwc3_phandle, 0, IPL_USB,
339a8436a52Sryo 	    FDT_INTR_MPSAFE, xhci_intr, sc, device_xname(self));
340b79ff4f5Sjmcneill 	if (ih == NULL) {
341b79ff4f5Sjmcneill 		aprint_error_dev(self, "couldn't establish interrupt on %s\n",
342b79ff4f5Sjmcneill 		    intrstr);
343b79ff4f5Sjmcneill 		return;
344b79ff4f5Sjmcneill 	}
345b79ff4f5Sjmcneill 	aprint_normal_dev(self, "interrupting on %s\n", intrstr);
346b79ff4f5Sjmcneill 
3472ca0fd1fSmsaitoh 	sc->sc_bus.ub_revision = USBREV_3_0;
348b79ff4f5Sjmcneill 	error = xhci_init(sc);
349b79ff4f5Sjmcneill 	if (error) {
350b79ff4f5Sjmcneill 		aprint_error_dev(self, "init failed, error = %d\n", error);
351b79ff4f5Sjmcneill 		return;
352b79ff4f5Sjmcneill 	}
353b79ff4f5Sjmcneill 
354beecddb6Sthorpej 	sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint, CFARGS_NONE);
3553bee0c11Sthorpej 	sc->sc_child2 = config_found(self, &sc->sc_bus2, usbctlprint,
356beecddb6Sthorpej 	    CFARGS_NONE);
357b79ff4f5Sjmcneill }
358