1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2019 Emmanuel Vadot <[email protected]> 5 * Copyright (c) 2021-2022 Bjoern A. Zeeb <[email protected]> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 #include <sys/cdefs.h> 32 __FBSDID("$FreeBSD$"); 33 34 #include "opt_platform.h" 35 #include "opt_acpi.h" 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/bus.h> 40 #include <sys/rman.h> 41 #include <sys/condvar.h> 42 #include <sys/kernel.h> 43 #include <sys/module.h> 44 #ifdef FDT 45 #include <sys/gpio.h> 46 #endif 47 48 #include <machine/bus.h> 49 50 #include <dev/usb/usb.h> 51 #include <dev/usb/usbdi.h> 52 53 #include <dev/usb/usb_core.h> 54 #include <dev/usb/usb_busdma.h> 55 #include <dev/usb/usb_process.h> 56 57 #include <dev/usb/usb_controller.h> 58 #include <dev/usb/usb_bus.h> 59 #include <dev/usb/controller/xhci.h> 60 #include <dev/usb/controller/dwc3.h> 61 62 #ifdef FDT 63 #include <dev/fdt/simplebus.h> 64 65 #include <dev/fdt/fdt_common.h> 66 #include <dev/ofw/ofw_bus.h> 67 #include <dev/ofw/ofw_bus_subr.h> 68 #include <dev/ofw/ofw_subr.h> 69 70 #include <dev/extres/clk/clk.h> 71 #include <dev/extres/phy/phy_usb.h> 72 #endif 73 74 #ifdef DEV_ACPI 75 #include <contrib/dev/acpica/include/acpi.h> 76 #include <contrib/dev/acpica/include/accommon.h> 77 #include <dev/acpica/acpivar.h> 78 #endif 79 80 #include "generic_xhci.h" 81 82 struct snps_dwc3_softc { 83 struct xhci_softc sc; 84 device_t dev; 85 struct resource * mem_res; 86 bus_space_tag_t bst; 87 bus_space_handle_t bsh; 88 uint32_t snpsid; 89 uint32_t snpsversion; 90 uint32_t snpsrevision; 91 uint32_t snpsversion_type; 92 #ifdef FDT 93 clk_t clk_ref; 94 clk_t clk_suspend; 95 clk_t clk_bus; 96 #endif 97 }; 98 99 #define DWC3_WRITE(_sc, _off, _val) \ 100 bus_space_write_4(_sc->bst, _sc->bsh, _off, _val) 101 #define DWC3_READ(_sc, _off) \ 102 bus_space_read_4(_sc->bst, _sc->bsh, _off) 103 104 #define IS_DMA_32B 1 105 106 static int 107 snps_dwc3_attach_xhci(device_t dev) 108 { 109 struct snps_dwc3_softc *snps_sc = device_get_softc(dev); 110 struct xhci_softc *sc = &snps_sc->sc; 111 int err = 0, rid = 0; 112 113 sc->sc_io_res = snps_sc->mem_res; 114 sc->sc_io_tag = snps_sc->bst; 115 sc->sc_io_hdl = snps_sc->bsh; 116 sc->sc_io_size = rman_get_size(snps_sc->mem_res); 117 118 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 119 RF_SHAREABLE | RF_ACTIVE); 120 if (sc->sc_irq_res == NULL) { 121 device_printf(dev, "Failed to allocate IRQ\n"); 122 return (ENXIO); 123 } 124 125 sc->sc_bus.bdev = device_add_child(dev, "usbus", -1); 126 if (sc->sc_bus.bdev == NULL) { 127 device_printf(dev, "Failed to add USB device\n"); 128 return (ENXIO); 129 } 130 131 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); 132 133 sprintf(sc->sc_vendor, "Synopsys"); 134 device_set_desc(sc->sc_bus.bdev, "Synopsys"); 135 136 err = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, 137 NULL, (driver_intr_t *)xhci_interrupt, sc, &sc->sc_intr_hdl); 138 if (err != 0) { 139 device_printf(dev, "Failed to setup IRQ, %d\n", err); 140 sc->sc_intr_hdl = NULL; 141 return (err); 142 } 143 144 err = xhci_init(sc, dev, IS_DMA_32B); 145 if (err != 0) { 146 device_printf(dev, "Failed to init XHCI, with error %d\n", err); 147 return (ENXIO); 148 } 149 150 err = xhci_start_controller(sc); 151 if (err != 0) { 152 device_printf(dev, "Failed to start XHCI controller, with error %d\n", err); 153 return (ENXIO); 154 } 155 156 device_printf(sc->sc_bus.bdev, "trying to attach\n"); 157 err = device_probe_and_attach(sc->sc_bus.bdev); 158 if (err != 0) { 159 device_printf(dev, "Failed to initialize USB, with error %d\n", err); 160 return (ENXIO); 161 } 162 163 return (0); 164 } 165 166 #ifdef DWC3_DEBUG 167 static void 168 snsp_dwc3_dump_regs(struct snps_dwc3_softc *sc, const char *msg) 169 { 170 struct xhci_softc *xsc; 171 uint32_t reg; 172 173 if (!bootverbose) 174 return; 175 176 device_printf(sc->dev, "%s: %s:\n", __func__, msg ? msg : ""); 177 178 reg = DWC3_READ(sc, DWC3_GCTL); 179 device_printf(sc->dev, "GCTL: %#012x\n", reg); 180 reg = DWC3_READ(sc, DWC3_GUCTL); 181 device_printf(sc->dev, "GUCTL: %#012x\n", reg); 182 reg = DWC3_READ(sc, DWC3_GUCTL1); 183 device_printf(sc->dev, "GUCTL1: %#012x\n", reg); 184 reg = DWC3_READ(sc, DWC3_GUSB2PHYCFG0); 185 device_printf(sc->dev, "GUSB2PHYCFG0: %#012x\n", reg); 186 reg = DWC3_READ(sc, DWC3_GUSB3PIPECTL0); 187 device_printf(sc->dev, "GUSB3PIPECTL0: %#012x\n", reg); 188 reg = DWC3_READ(sc, DWC3_DCFG); 189 device_printf(sc->dev, "DCFG: %#012x\n", reg); 190 191 xsc = &sc->sc; 192 device_printf(sc->dev, "xhci quirks: %#012x\n", xsc->sc_quirks); 193 } 194 195 static void 196 snps_dwc3_dump_ctrlparams(struct snps_dwc3_softc *sc) 197 { 198 const bus_size_t offs[] = { 199 DWC3_GHWPARAMS0, DWC3_GHWPARAMS1, DWC3_GHWPARAMS2, DWC3_GHWPARAMS3, 200 DWC3_GHWPARAMS4, DWC3_GHWPARAMS5, DWC3_GHWPARAMS6, DWC3_GHWPARAMS7, 201 DWC3_GHWPARAMS8, 202 }; 203 uint32_t reg; 204 int i; 205 206 for (i = 0; i < nitems(offs); i++) { 207 reg = DWC3_READ(sc, offs[i]); 208 if (bootverbose) 209 device_printf(sc->dev, "hwparams[%d]: %#012x\n", i, reg); 210 } 211 } 212 #endif 213 214 static void 215 snps_dwc3_reset(struct snps_dwc3_softc *sc) 216 { 217 uint32_t gctl, ghwp0, phy2, phy3; 218 219 ghwp0 = DWC3_READ(sc, DWC3_GHWPARAMS0); 220 221 gctl = DWC3_READ(sc, DWC3_GCTL); 222 gctl |= DWC3_GCTL_CORESOFTRESET; 223 DWC3_WRITE(sc, DWC3_GCTL, gctl); 224 225 phy2 = DWC3_READ(sc, DWC3_GUSB2PHYCFG0); 226 phy2 |= DWC3_GUSB2PHYCFG0_PHYSOFTRST; 227 if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) == 228 DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE) 229 phy2 &= ~DWC3_GUSB2PHYCFG0_SUSPENDUSB20; 230 DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, phy2); 231 232 phy3 = DWC3_READ(sc, DWC3_GUSB3PIPECTL0); 233 phy3 |= DWC3_GUSB3PIPECTL0_PHYSOFTRST; 234 if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) == 235 DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE) 236 phy3 &= ~DWC3_GUSB3PIPECTL0_SUSPENDUSB3; 237 DWC3_WRITE(sc, DWC3_GUSB3PIPECTL0, phy3); 238 239 DELAY(1000); 240 241 phy2 &= ~DWC3_GUSB2PHYCFG0_PHYSOFTRST; 242 DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, phy2); 243 244 phy3 &= ~DWC3_GUSB3PIPECTL0_PHYSOFTRST; 245 DWC3_WRITE(sc, DWC3_GUSB3PIPECTL0, phy3); 246 247 gctl &= ~DWC3_GCTL_CORESOFTRESET; 248 DWC3_WRITE(sc, DWC3_GCTL, gctl); 249 250 } 251 252 static void 253 snps_dwc3_configure_host(struct snps_dwc3_softc *sc) 254 { 255 uint32_t reg; 256 257 reg = DWC3_READ(sc, DWC3_GCTL); 258 reg &= ~DWC3_GCTL_PRTCAPDIR_MASK; 259 reg |= DWC3_GCTL_PRTCAPDIR_HOST; 260 DWC3_WRITE(sc, DWC3_GCTL, reg); 261 262 /* 263 * Enable the Host IN Auto Retry feature, making the 264 * host respond with a non-terminating retry ACK. 265 * XXX If we ever support more than host mode this needs a dr_mode check. 266 */ 267 reg = DWC3_READ(sc, DWC3_GUCTL); 268 reg |= DWC3_GUCTL_HOST_AUTO_RETRY; 269 DWC3_WRITE(sc, DWC3_GUCTL, reg); 270 } 271 272 #ifdef FDT 273 static void 274 snps_dwc3_configure_phy(struct snps_dwc3_softc *sc, phandle_t node) 275 { 276 char *phy_type; 277 uint32_t reg; 278 int nphy_types; 279 280 phy_type = NULL; 281 nphy_types = OF_getprop_alloc(node, "phy_type", (void **)&phy_type); 282 if (nphy_types <= 0) 283 return; 284 285 reg = DWC3_READ(sc, DWC3_GUSB2PHYCFG0); 286 if (strncmp(phy_type, "utmi_wide", 9) == 0) { 287 reg &= ~(DWC3_GUSB2PHYCFG0_PHYIF | DWC3_GUSB2PHYCFG0_USBTRDTIM(0xf)); 288 reg |= DWC3_GUSB2PHYCFG0_PHYIF | 289 DWC3_GUSB2PHYCFG0_USBTRDTIM(DWC3_GUSB2PHYCFG0_USBTRDTIM_16BITS); 290 } else { 291 reg &= ~(DWC3_GUSB2PHYCFG0_PHYIF | DWC3_GUSB2PHYCFG0_USBTRDTIM(0xf)); 292 reg |= DWC3_GUSB2PHYCFG0_PHYIF | 293 DWC3_GUSB2PHYCFG0_USBTRDTIM(DWC3_GUSB2PHYCFG0_USBTRDTIM_8BITS); 294 } 295 DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, reg); 296 OF_prop_free(phy_type); 297 } 298 #endif 299 300 static void 301 snps_dwc3_do_quirks(struct snps_dwc3_softc *sc) 302 { 303 struct xhci_softc *xsc; 304 uint32_t ghwp0, reg; 305 306 ghwp0 = DWC3_READ(sc, DWC3_GHWPARAMS0); 307 reg = DWC3_READ(sc, DWC3_GUSB2PHYCFG0); 308 if (device_has_property(sc->dev, "snps,dis-u2-freeclk-exists-quirk")) 309 reg &= ~DWC3_GUSB2PHYCFG0_U2_FREECLK_EXISTS; 310 else 311 reg |= DWC3_GUSB2PHYCFG0_U2_FREECLK_EXISTS; 312 if (device_has_property(sc->dev, "snps,dis_u2_susphy_quirk")) 313 reg &= ~DWC3_GUSB2PHYCFG0_SUSPENDUSB20; 314 else if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) == 315 DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE) 316 reg |= DWC3_GUSB2PHYCFG0_SUSPENDUSB20; 317 if (device_has_property(sc->dev, "snps,dis_enblslpm_quirk")) 318 reg &= ~DWC3_GUSB2PHYCFG0_ENBLSLPM; 319 else 320 reg |= DWC3_GUSB2PHYCFG0_ENBLSLPM; 321 DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, reg); 322 323 reg = DWC3_READ(sc, DWC3_GUCTL1); 324 if (device_has_property(sc->dev, "snps,dis-tx-ipgap-linecheck-quirk")) 325 reg |= DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS; 326 DWC3_WRITE(sc, DWC3_GUCTL1, reg); 327 328 reg = DWC3_READ(sc, DWC3_GUSB3PIPECTL0); 329 if (device_has_property(sc->dev, "snps,dis-del-phy-power-chg-quirk")) 330 reg &= ~DWC3_GUSB3PIPECTL0_DELAYP1TRANS; 331 if (device_has_property(sc->dev, "snps,dis_rxdet_inp3_quirk")) 332 reg |= DWC3_GUSB3PIPECTL0_DISRXDETINP3; 333 if (device_has_property(sc->dev, "snps,dis_u3_susphy_quirk")) 334 reg &= ~DWC3_GUSB3PIPECTL0_SUSPENDUSB3; 335 else if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) == 336 DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE) 337 reg |= DWC3_GUSB3PIPECTL0_SUSPENDUSB3; 338 DWC3_WRITE(sc, DWC3_GUSB3PIPECTL0, reg); 339 340 /* Port Disable does not work on <= 3.00a. Disable PORT_PED. */ 341 if ((sc->snpsid & 0xffff) <= 0x300a) { 342 xsc = &sc->sc; 343 xsc->sc_quirks |= XHCI_QUIRK_DISABLE_PORT_PED; 344 } 345 } 346 347 static int 348 snps_dwc3_probe_common(device_t dev) 349 { 350 char dr_mode[16] = { 0 }; 351 ssize_t s; 352 353 s = device_get_property(dev, "dr_mode", dr_mode, sizeof(dr_mode), 354 DEVICE_PROP_BUFFER); 355 if (s == -1) { 356 device_printf(dev, "Cannot determine dr_mode\n"); 357 return (ENXIO); 358 } 359 if (strcmp(dr_mode, "host") != 0) { 360 device_printf(dev, 361 "Found dr_mode '%s' but only 'host' supported. s=%zd\n", 362 dr_mode, s); 363 return (ENXIO); 364 } 365 366 device_set_desc(dev, "Synopsys Designware DWC3"); 367 return (BUS_PROBE_DEFAULT); 368 } 369 370 static int 371 snps_dwc3_common_attach(device_t dev, bool is_fdt) 372 { 373 struct snps_dwc3_softc *sc; 374 #ifdef FDT 375 phandle_t node; 376 phy_t usb2_phy, usb3_phy; 377 uint32_t reg; 378 #endif 379 int error, rid; 380 381 sc = device_get_softc(dev); 382 sc->dev = dev; 383 384 rid = 0; 385 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 386 RF_ACTIVE); 387 if (sc->mem_res == NULL) { 388 device_printf(dev, "Failed to map memory\n"); 389 return (ENXIO); 390 } 391 sc->bst = rman_get_bustag(sc->mem_res); 392 sc->bsh = rman_get_bushandle(sc->mem_res); 393 394 sc->snpsid = DWC3_READ(sc, DWC3_GSNPSID); 395 sc->snpsversion = DWC3_VERSION(sc->snpsid); 396 sc->snpsrevision = DWC3_REVISION(sc->snpsid); 397 if (sc->snpsversion == DWC3_1_IP_ID || 398 sc->snpsversion == DWC3_2_IP_ID) { 399 sc->snpsrevision = DWC3_READ(sc, DWC3_1_VER_NUMBER); 400 sc->snpsversion_type = DWC3_READ(sc, DWC3_1_VER_TYPE); 401 } 402 if (bootverbose) { 403 switch (sc->snpsversion) { 404 case DWC3_IP_ID: 405 device_printf(sc->dev, "SNPS Version: DWC3 (%x %x)\n", 406 sc->snpsversion, sc->snpsrevision); 407 break; 408 case DWC3_1_IP_ID: 409 device_printf(sc->dev, "SNPS Version: DWC3.1 (%x %x %x)\n", 410 sc->snpsversion, sc->snpsrevision, 411 sc->snpsversion_type); 412 break; 413 case DWC3_2_IP_ID: 414 device_printf(sc->dev, "SNPS Version: DWC3.2 (%x %x %x)\n", 415 sc->snpsversion, sc->snpsrevision, 416 sc->snpsversion_type); 417 break; 418 } 419 } 420 #ifdef DWC3_DEBUG 421 snps_dwc3_dump_ctrlparams(sc); 422 #endif 423 424 #ifdef FDT 425 if (!is_fdt) 426 goto skip_phys; 427 428 node = ofw_bus_get_node(dev); 429 430 /* Get the clocks if any */ 431 if (ofw_bus_is_compatible(dev, "rockchip,rk3328-dwc3") == 1) { 432 if (clk_get_by_ofw_name(dev, node, "ref_clk", &sc->clk_ref) != 0) 433 device_printf(dev, "Cannot get ref_clk\n"); 434 if (clk_get_by_ofw_name(dev, node, "suspend_clk", &sc->clk_suspend) != 0) 435 device_printf(dev, "Cannot get suspend_clk\n"); 436 if (clk_get_by_ofw_name(dev, node, "bus_clk", &sc->clk_bus) != 0) 437 device_printf(dev, "Cannot get bus_clk\n"); 438 } 439 440 if (sc->clk_ref != NULL) { 441 if (clk_enable(sc->clk_ref) != 0) 442 device_printf(dev, "Cannot enable ref_clk\n"); 443 } 444 if (sc->clk_suspend != NULL) { 445 if (clk_enable(sc->clk_suspend) != 0) 446 device_printf(dev, "Cannot enable suspend_clk\n"); 447 } 448 if (sc->clk_bus != NULL) { 449 if (clk_enable(sc->clk_bus) != 0) 450 device_printf(dev, "Cannot enable bus_clk\n"); 451 } 452 453 /* Get the phys */ 454 usb2_phy = usb3_phy = NULL; 455 error = phy_get_by_ofw_name(dev, node, "usb2-phy", &usb2_phy); 456 if (error == 0 && usb2_phy != NULL) 457 phy_enable(usb2_phy); 458 error = phy_get_by_ofw_name(dev, node, "usb3-phy", &usb3_phy); 459 if (error == 0 && usb3_phy != NULL) 460 phy_enable(usb3_phy); 461 if (sc->snpsversion == DWC3_IP_ID) { 462 if (sc->snpsrevision >= 0x290A) { 463 uint32_t hwparams3; 464 465 hwparams3 = DWC3_READ(sc, DWC3_GHWPARAMS3); 466 if (DWC3_HWPARAMS3_SSPHY(hwparams3) == DWC3_HWPARAMS3_SSPHY_DISABLE) { 467 reg = DWC3_READ(sc, DWC3_GUCTL1); 468 if (bootverbose) 469 device_printf(dev, "Forcing USB2 clock only\n"); 470 reg |= DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK; 471 DWC3_WRITE(sc, DWC3_GUCTL1, reg); 472 } 473 } 474 } 475 snps_dwc3_configure_phy(sc, node); 476 skip_phys: 477 #endif 478 479 snps_dwc3_reset(sc); 480 snps_dwc3_configure_host(sc); 481 snps_dwc3_do_quirks(sc); 482 483 #ifdef DWC3_DEBUG 484 snsp_dwc3_dump_regs(sc, "Pre XHCI init"); 485 #endif 486 error = snps_dwc3_attach_xhci(dev); 487 #ifdef DWC3_DEBUG 488 snsp_dwc3_dump_regs(sc, "Post XHCI init"); 489 #endif 490 491 #ifdef FDT 492 if (error) { 493 if (sc->clk_ref != NULL) 494 clk_disable(sc->clk_ref); 495 if (sc->clk_suspend != NULL) 496 clk_disable(sc->clk_suspend); 497 if (sc->clk_bus != NULL) 498 clk_disable(sc->clk_bus); 499 } 500 #endif 501 return (error); 502 } 503 504 #ifdef FDT 505 static struct ofw_compat_data compat_data[] = { 506 { "snps,dwc3", 1 }, 507 { NULL, 0 } 508 }; 509 510 static int 511 snps_dwc3_fdt_probe(device_t dev) 512 { 513 514 if (!ofw_bus_status_okay(dev)) 515 return (ENXIO); 516 517 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) 518 return (ENXIO); 519 520 return (snps_dwc3_probe_common(dev)); 521 } 522 523 static int 524 snps_dwc3_fdt_attach(device_t dev) 525 { 526 527 return (snps_dwc3_common_attach(dev, true)); 528 } 529 530 static device_method_t snps_dwc3_fdt_methods[] = { 531 /* Device interface */ 532 DEVMETHOD(device_probe, snps_dwc3_fdt_probe), 533 DEVMETHOD(device_attach, snps_dwc3_fdt_attach), 534 535 DEVMETHOD_END 536 }; 537 538 DEFINE_CLASS_1(snps_dwc3_fdt, snps_dwc3_fdt_driver, snps_dwc3_fdt_methods, 539 sizeof(struct snps_dwc3_softc), generic_xhci_driver); 540 541 DRIVER_MODULE(snps_dwc3_fdt, simplebus, snps_dwc3_fdt_driver, 0, 0); 542 MODULE_DEPEND(snps_dwc3_fdt, xhci, 1, 1, 1); 543 #endif 544 545 #ifdef DEV_ACPI 546 static char *dwc3_acpi_ids[] = { 547 "808622B7", /* This was an Intel PCI Vendor/Device ID used. */ 548 "PNP0D10", /* The generic XHCI PNP ID needing extra probe checks. */ 549 NULL 550 }; 551 552 static int 553 snps_dwc3_acpi_probe(device_t dev) 554 { 555 char *match; 556 int error; 557 558 if (acpi_disabled("snps_dwc3")) 559 return (ENXIO); 560 561 error = ACPI_ID_PROBE(device_get_parent(dev), dev, dwc3_acpi_ids, &match); 562 if (error > 0) 563 return (ENXIO); 564 565 /* 566 * If we found the Generic XHCI PNP ID we can only attach if we have 567 * some other means to identify the device as dwc3. 568 */ 569 if (strcmp(match, "PNP0D10") == 0) { 570 /* This is needed in SolidRun's HoneyComb. */ 571 if (device_has_property(dev, "snps,dis_rxdet_inp3_quirk")) 572 goto is_dwc3; 573 574 return (ENXIO); 575 } 576 577 is_dwc3: 578 return (snps_dwc3_probe_common(dev)); 579 } 580 581 static int 582 snps_dwc3_acpi_attach(device_t dev) 583 { 584 585 return (snps_dwc3_common_attach(dev, false)); 586 } 587 588 static device_method_t snps_dwc3_acpi_methods[] = { 589 /* Device interface */ 590 DEVMETHOD(device_probe, snps_dwc3_acpi_probe), 591 DEVMETHOD(device_attach, snps_dwc3_acpi_attach), 592 593 DEVMETHOD_END 594 }; 595 596 DEFINE_CLASS_1(snps_dwc3_acpi, snps_dwc3_acpi_driver, snps_dwc3_acpi_methods, 597 sizeof(struct snps_dwc3_softc), generic_xhci_driver); 598 599 DRIVER_MODULE(snps_dwc3_acpi, acpi, snps_dwc3_acpi_driver, 0, 0); 600 MODULE_DEPEND(snps_dwc3_acpi, usb, 1, 1, 1); 601 #endif 602