1/* $NetBSD: zynq7000_usb.c,v 1.3 2022/10/25 22:52:48 jmcneill Exp $ */ 2/*- 3 * Copyright (c) 2015 Genetec Corporation. All rights reserved. 4 * Written by Hashimoto Kenichi for Genetec Corporation. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> 29__KERNEL_RCSID(0, "$NetBSD: zynq7000_usb.c,v 1.3 2022/10/25 22:52:48 jmcneill Exp $"); 30 31#include "opt_soc.h" 32 33#include <sys/param.h> 34#include <sys/bus.h> 35#include <sys/conf.h> 36#include <sys/device.h> 37#include <sys/intr.h> 38#include <sys/kernel.h> 39#include <sys/systm.h> 40 41#include <dev/usb/usb.h> 42#include <dev/usb/usbdi.h> 43#include <dev/usb/usbdivar.h> 44#include <dev/usb/usb_mem.h> 45 46#include <dev/usb/ehcireg.h> 47#include <dev/usb/ehcivar.h> 48 49#include <arm/xilinx/zynq_usbvar.h> 50#include <arm/xilinx/zynq_usbreg.h> 51 52#include <dev/fdt/fdtvar.h> 53 54static const struct device_compatible_entry compat_data[] = { 55 { .compat = "xlnx,zynq-usb-2.20a" }, 56 DEVICE_COMPAT_EOL 57}; 58 59static int zynqusb_match(device_t, struct cfdata *, void *); 60static void zynqusb_attach(device_t, device_t, void *); 61 62/* attach structures */ 63CFATTACH_DECL_NEW(zynqusb, sizeof(struct zynqehci_softc), 64 zynqusb_match, zynqusb_attach, NULL, NULL); 65 66static int 67zynqusb_match(device_t parent, struct cfdata *cf, void *aux) 68{ 69 struct fdt_attach_args * const faa = aux; 70 71 return of_compatible_match(faa->faa_phandle, compat_data); 72} 73 74static void 75zynqusb_attach(device_t parent, device_t self, void *aux) 76{ 77 struct fdt_attach_args * faa = aux; 78 char intrstr[128]; 79 const int phandle = faa->faa_phandle; 80 struct zynqehci_softc *sc = device_private(self); 81 ehci_softc_t *hsc = &sc->sc_hsc; 82 bus_addr_t addr; 83 bus_size_t size; 84 85 if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { 86 aprint_error(": couldn't get registers\n"); 87 return; 88 } 89 90 if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) { 91 aprint_error(": failed to decode interrupt\n"); 92 return; 93 } 94 95 if (fdtbus_intr_establish(phandle, 0, IPL_USB, IST_LEVEL, ehci_intr, 96 hsc) == NULL) { 97 aprint_error("failed to establish interrupt on %s\n", 98 intrstr); 99 return; 100 } 101 102 zynqusb_attach_common(parent, self, faa->faa_bst, faa->faa_dmat, 103 addr, size, 0, ZYNQUSBC_IF_ULPI, ZYNQUSB_HOST); 104 aprint_normal_dev(self, "interrupting on %s\n", intrstr); 105} 106