bcm2835_dwctwo.c revision 1.1.10.3 1 /* $NetBSD: bcm2835_dwctwo.c,v 1.1.10.3 2017/12/03 11:35:52 jdolecek Exp $ */
2
3 /*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nick Hudson
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: bcm2835_dwctwo.c,v 1.1.10.3 2017/12/03 11:35:52 jdolecek Exp $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/mutex.h>
39 #include <sys/bus.h>
40 #include <sys/workqueue.h>
41
42 #include <arm/broadcom/bcm2835reg.h>
43 #include <arm/broadcom/bcm_amba.h>
44
45 #include <dev/usb/usb.h>
46 #include <dev/usb/usbdi.h>
47 #include <dev/usb/usbdivar.h>
48 #include <dev/usb/usb_mem.h>
49
50 #include <dwc2/dwc2var.h>
51
52 #include <dwc2/dwc2.h>
53 #include "dwc2_core.h"
54
55 struct bcmdwc2_softc {
56 struct dwc2_softc sc_dwc2;
57
58 void *sc_ih;
59 };
60
61 static struct dwc2_core_params bcmdwc2_params = {
62 .otg_cap = 0, /* HNP/SRP capable */
63 .otg_ver = 0, /* 1.3 */
64 .dma_enable = 1,
65 .dma_desc_enable = 0,
66 .speed = 0, /* High Speed */
67 .enable_dynamic_fifo = 1,
68 .en_multiple_tx_fifo = 1,
69 .host_rx_fifo_size = 774, /* 774 DWORDs */
70 .host_nperio_tx_fifo_size = 256, /* 256 DWORDs */
71 .host_perio_tx_fifo_size = 512, /* 512 DWORDs */
72 .max_transfer_size = 65535,
73 .max_packet_count = 511,
74 .host_channels = 8,
75 .phy_type = 1, /* UTMI */
76 .phy_utmi_width = 8, /* 8 bits */
77 .phy_ulpi_ddr = 0, /* Single */
78 .phy_ulpi_ext_vbus = 0,
79 .i2c_enable = 0,
80 .ulpi_fs_ls = 0,
81 .host_support_fs_ls_low_power = 0,
82 .host_ls_low_power_phy_clk = 0, /* 48 MHz */
83 .ts_dline = 0,
84 .reload_ctl = 0,
85 .ahbcfg = 0x10,
86 .uframe_sched = 1,
87 .external_id_pin_ctl = -1,
88 .hibernation = -1,
89 };
90
91 static int bcmdwc2_match(device_t, struct cfdata *, void *);
92 static void bcmdwc2_attach(device_t, device_t, void *);
93 static void bcmdwc2_deferred(device_t);
94
95 CFATTACH_DECL_NEW(bcmdwctwo, sizeof(struct bcmdwc2_softc),
96 bcmdwc2_match, bcmdwc2_attach, NULL, NULL);
97
98 /* ARGSUSED */
99 static int
100 bcmdwc2_match(device_t parent, struct cfdata *match, void *aux)
101 {
102 struct amba_attach_args *aaa = aux;
103
104 if (strcmp(aaa->aaa_name, "dwctwo") != 0)
105 return 0;
106
107 return 1;
108 }
109
110 /* ARGSUSED */
111 static void
112 bcmdwc2_attach(device_t parent, device_t self, void *aux)
113 {
114 struct bcmdwc2_softc *sc = device_private(self);
115 struct amba_attach_args *aaa = aux;
116 int error;
117
118 sc->sc_dwc2.sc_dev = self;
119
120 sc->sc_dwc2.sc_iot = aaa->aaa_iot;
121 sc->sc_dwc2.sc_bus.ub_dmatag = aaa->aaa_dmat;
122 sc->sc_dwc2.sc_params = &bcmdwc2_params;
123
124 error = bus_space_map(aaa->aaa_iot, aaa->aaa_addr, aaa->aaa_size, 0,
125 &sc->sc_dwc2.sc_ioh);
126 if (error) {
127 aprint_error_dev(self,
128 "can't map registers for %s: %d\n", aaa->aaa_name, error);
129 return;
130 }
131
132 aprint_naive(": USB controller\n");
133 aprint_normal(": USB controller\n");
134
135 sc->sc_ih = intr_establish(aaa->aaa_intr, IPL_VM,
136 IST_LEVEL | IST_MPSAFE, dwc2_intr, &sc->sc_dwc2);
137
138 if (sc->sc_ih == NULL) {
139 aprint_error_dev(self, "failed to establish interrupt %d\n",
140 aaa->aaa_intr);
141 goto fail;
142 }
143 config_defer(self, bcmdwc2_deferred);
144
145 return;
146
147 fail:
148 if (sc->sc_ih) {
149 intr_disestablish(sc->sc_ih);
150 sc->sc_ih = NULL;
151 }
152 bus_space_unmap(sc->sc_dwc2.sc_iot, sc->sc_dwc2.sc_ioh, aaa->aaa_size);
153 }
154
155 static void
156 bcmdwc2_deferred(device_t self)
157 {
158 struct bcmdwc2_softc *sc = device_private(self);
159 int error;
160
161 error = dwc2_init(&sc->sc_dwc2);
162 if (error != 0) {
163 aprint_error_dev(self, "couldn't initialize host, error=%d\n",
164 error);
165 return;
166 }
167 sc->sc_dwc2.sc_child = config_found(sc->sc_dwc2.sc_dev,
168 &sc->sc_dwc2.sc_bus, usbctlprint);
169 }
170