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