xhci_acpi.c revision 1.3
1/* $NetBSD: xhci_acpi.c,v 1.3 2019/02/16 23:28:56 tron Exp $ */ 2 3/*- 4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jared McNeill <jmcneill@invisible.ca>. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.3 2019/02/16 23:28:56 tron Exp $"); 34 35#include <sys/param.h> 36#include <sys/bus.h> 37#include <sys/cpu.h> 38#include <sys/device.h> 39 40#include <dev/usb/usb.h> 41#include <dev/usb/usbdi.h> 42#include <dev/usb/usbdivar.h> 43#include <dev/usb/usb_mem.h> 44#include <dev/usb/xhcireg.h> 45#include <dev/usb/xhcivar.h> 46 47#include <dev/acpi/acpireg.h> 48#include <dev/acpi/acpivar.h> 49#include <dev/acpi/acpi_intr.h> 50#include <dev/acpi/acpi_usb.h> 51 52static const char * const compatible[] = { 53 "PNP0D10", /* XHCI-compliant USB controller without standard debug */ 54 "PNP0D15", /* XHCI-compliant USB controller with standard debug */ 55 NULL 56}; 57 58struct xhci_acpi_softc { 59 struct xhci_softc sc_xhci; 60 ACPI_HANDLE sc_handle; 61}; 62 63static int xhci_acpi_match(device_t, cfdata_t, void *); 64static void xhci_acpi_attach(device_t, device_t, void *); 65 66static void xhci_acpi_init(struct xhci_softc *); 67 68CFATTACH_DECL2_NEW(xhci_acpi, sizeof(struct xhci_acpi_softc), 69 xhci_acpi_match, xhci_acpi_attach, NULL, 70 xhci_activate, NULL, xhci_childdet); 71 72static int 73xhci_acpi_match(device_t parent, cfdata_t cf, void *aux) 74{ 75 struct acpi_attach_args *aa = aux; 76 77 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 78 return 0; 79 80 return acpi_match_hid(aa->aa_node->ad_devinfo, compatible); 81} 82 83static void 84xhci_acpi_attach(device_t parent, device_t self, void *aux) 85{ 86 struct xhci_acpi_softc * const asc = device_private(self); 87 struct xhci_softc * const sc = &asc->sc_xhci; 88 struct acpi_attach_args *aa = aux; 89 struct acpi_resources res; 90 struct acpi_mem *mem; 91 struct acpi_irq *irq; 92 ACPI_STATUS rv; 93 int error; 94 void *ih; 95 96 asc->sc_handle = aa->aa_node->ad_handle; 97 98 sc->sc_dev = self; 99 sc->sc_bus.ub_hcpriv = sc; 100 sc->sc_bus.ub_dmatag = aa->aa_dmat; 101 sc->sc_bus.ub_revision = USBREV_3_0; 102 sc->sc_quirks = 0; 103 sc->sc_vendor_init = xhci_acpi_init; 104 105 rv = acpi_resource_parse(sc->sc_dev, asc->sc_handle, "_CRS", 106 &res, &acpi_resource_parse_ops_default); 107 if (ACPI_FAILURE(rv)) 108 return; 109 110 mem = acpi_res_mem(&res, 0); 111 if (mem == NULL) { 112 aprint_error_dev(self, "couldn't find mem resource\n"); 113 goto done; 114 } 115 116 irq = acpi_res_irq(&res, 0); 117 if (irq == NULL) { 118 aprint_error_dev(self, "couldn't find irq resource\n"); 119 goto done; 120 } 121 122 sc->sc_ios = mem->ar_length; 123 sc->sc_iot = aa->aa_memt; 124 error = bus_space_map(sc->sc_iot, mem->ar_base, mem->ar_length, 0, &sc->sc_ioh); 125 if (error) { 126 aprint_error_dev(self, "couldn't map registers\n"); 127 return; 128 } 129 130 ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle, 131 IPL_USB, true, xhci_intr, sc, device_xname(self)); 132 if (ih == NULL) { 133 aprint_error_dev(self, "couldn't establish interrupt\n"); 134 return; 135 } 136 137 error = xhci_init(sc); 138 if (error) { 139 aprint_error_dev(self, "init failed, error = %d\n", error); 140 return; 141 } 142 143 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); 144 sc->sc_child2 = config_found(self, &sc->sc_bus2, usbctlprint); 145 146done: 147 acpi_resource_cleanup(&res); 148} 149 150static void 151xhci_acpi_init(struct xhci_softc *sc) 152{ 153 struct xhci_acpi_softc * const asc = (struct xhci_acpi_softc *)sc; 154 155 acpi_usb_post_reset(asc->sc_handle); 156} 157