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