bcm2835_dwctwo.c revision 1.1.10.2 1 1.1.10.2 tls /* $NetBSD: bcm2835_dwctwo.c,v 1.1.10.2 2014/08/20 00:02:45 tls Exp $ */
2 1.1.10.2 tls
3 1.1.10.2 tls /*-
4 1.1.10.2 tls * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.1.10.2 tls * All rights reserved.
6 1.1.10.2 tls *
7 1.1.10.2 tls * This code is derived from software contributed to The NetBSD Foundation
8 1.1.10.2 tls * by Nick Hudson
9 1.1.10.2 tls *
10 1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
11 1.1.10.2 tls * modification, are permitted provided that the following conditions
12 1.1.10.2 tls * are met:
13 1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
15 1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
17 1.1.10.2 tls * documentation and/or other materials provided with the distribution.
18 1.1.10.2 tls *
19 1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.10.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.10.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.10.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.10.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.10.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.10.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.10.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.10.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.10.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.10.2 tls * POSSIBILITY OF SUCH DAMAGE.
30 1.1.10.2 tls */
31 1.1.10.2 tls
32 1.1.10.2 tls #include <sys/cdefs.h>
33 1.1.10.2 tls __KERNEL_RCSID(0, "$NetBSD: bcm2835_dwctwo.c,v 1.1.10.2 2014/08/20 00:02:45 tls Exp $");
34 1.1.10.2 tls
35 1.1.10.2 tls #include <sys/param.h>
36 1.1.10.2 tls #include <sys/systm.h>
37 1.1.10.2 tls #include <sys/device.h>
38 1.1.10.2 tls #include <sys/mutex.h>
39 1.1.10.2 tls #include <sys/bus.h>
40 1.1.10.2 tls #include <sys/workqueue.h>
41 1.1.10.2 tls
42 1.1.10.2 tls #include <arm/broadcom/bcm2835reg.h>
43 1.1.10.2 tls #include <arm/broadcom/bcm_amba.h>
44 1.1.10.2 tls
45 1.1.10.2 tls #include <dev/usb/usb.h>
46 1.1.10.2 tls #include <dev/usb/usbdi.h>
47 1.1.10.2 tls #include <dev/usb/usbdivar.h>
48 1.1.10.2 tls #include <dev/usb/usb_mem.h>
49 1.1.10.2 tls
50 1.1.10.2 tls #include <dwc2/dwc2var.h>
51 1.1.10.2 tls
52 1.1.10.2 tls #include <dwc2/dwc2.h>
53 1.1.10.2 tls #include "dwc2_core.h"
54 1.1.10.2 tls
55 1.1.10.2 tls struct bcmdwc2_softc {
56 1.1.10.2 tls struct dwc2_softc sc_dwc2;
57 1.1.10.2 tls
58 1.1.10.2 tls void *sc_ih;
59 1.1.10.2 tls };
60 1.1.10.2 tls
61 1.1.10.2 tls static struct dwc2_core_params bcmdwc2_params = {
62 1.1.10.2 tls .otg_cap = 0, /* HNP/SRP capable */
63 1.1.10.2 tls .otg_ver = 0, /* 1.3 */
64 1.1.10.2 tls .dma_enable = 1,
65 1.1.10.2 tls .dma_desc_enable = 0,
66 1.1.10.2 tls .speed = 0, /* High Speed */
67 1.1.10.2 tls .enable_dynamic_fifo = 1,
68 1.1.10.2 tls .en_multiple_tx_fifo = 1,
69 1.1.10.2 tls .host_rx_fifo_size = 774, /* 774 DWORDs */
70 1.1.10.2 tls .host_nperio_tx_fifo_size = 256, /* 256 DWORDs */
71 1.1.10.2 tls .host_perio_tx_fifo_size = 512, /* 512 DWORDs */
72 1.1.10.2 tls .max_transfer_size = 65535,
73 1.1.10.2 tls .max_packet_count = 511,
74 1.1.10.2 tls .host_channels = 8,
75 1.1.10.2 tls .phy_type = 1, /* UTMI */
76 1.1.10.2 tls .phy_utmi_width = 8, /* 8 bits */
77 1.1.10.2 tls .phy_ulpi_ddr = 0, /* Single */
78 1.1.10.2 tls .phy_ulpi_ext_vbus = 0,
79 1.1.10.2 tls .i2c_enable = 0,
80 1.1.10.2 tls .ulpi_fs_ls = 0,
81 1.1.10.2 tls .host_support_fs_ls_low_power = 0,
82 1.1.10.2 tls .host_ls_low_power_phy_clk = 0, /* 48 MHz */
83 1.1.10.2 tls .ts_dline = 0,
84 1.1.10.2 tls .reload_ctl = 0,
85 1.1.10.2 tls .ahbcfg = 0x10,
86 1.1.10.2 tls .uframe_sched = 1,
87 1.1.10.2 tls };
88 1.1.10.2 tls
89 1.1.10.2 tls static int bcmdwc2_match(device_t, struct cfdata *, void *);
90 1.1.10.2 tls static void bcmdwc2_attach(device_t, device_t, void *);
91 1.1.10.2 tls static void bcmdwc2_deferred(device_t);
92 1.1.10.2 tls
93 1.1.10.2 tls CFATTACH_DECL_NEW(bcmdwctwo, sizeof(struct bcmdwc2_softc),
94 1.1.10.2 tls bcmdwc2_match, bcmdwc2_attach, NULL, NULL);
95 1.1.10.2 tls
96 1.1.10.2 tls /* ARGSUSED */
97 1.1.10.2 tls static int
98 1.1.10.2 tls bcmdwc2_match(device_t parent, struct cfdata *match, void *aux)
99 1.1.10.2 tls {
100 1.1.10.2 tls struct amba_attach_args *aaa = aux;
101 1.1.10.2 tls
102 1.1.10.2 tls if (strcmp(aaa->aaa_name, "dwctwo") != 0)
103 1.1.10.2 tls return 0;
104 1.1.10.2 tls
105 1.1.10.2 tls return 1;
106 1.1.10.2 tls }
107 1.1.10.2 tls
108 1.1.10.2 tls /* ARGSUSED */
109 1.1.10.2 tls static void
110 1.1.10.2 tls bcmdwc2_attach(device_t parent, device_t self, void *aux)
111 1.1.10.2 tls {
112 1.1.10.2 tls struct bcmdwc2_softc *sc = device_private(self);
113 1.1.10.2 tls struct amba_attach_args *aaa = aux;
114 1.1.10.2 tls int error;
115 1.1.10.2 tls
116 1.1.10.2 tls sc->sc_dwc2.sc_dev = self;
117 1.1.10.2 tls
118 1.1.10.2 tls sc->sc_dwc2.sc_iot = aaa->aaa_iot;
119 1.1.10.2 tls sc->sc_dwc2.sc_bus.dmatag = aaa->aaa_dmat;
120 1.1.10.2 tls sc->sc_dwc2.sc_params = &bcmdwc2_params;
121 1.1.10.2 tls
122 1.1.10.2 tls error = bus_space_map(aaa->aaa_iot, aaa->aaa_addr, aaa->aaa_size, 0,
123 1.1.10.2 tls &sc->sc_dwc2.sc_ioh);
124 1.1.10.2 tls if (error) {
125 1.1.10.2 tls aprint_error_dev(self,
126 1.1.10.2 tls "can't map registers for %s: %d\n", aaa->aaa_name, error);
127 1.1.10.2 tls return;
128 1.1.10.2 tls }
129 1.1.10.2 tls
130 1.1.10.2 tls aprint_naive(": USB controller\n");
131 1.1.10.2 tls aprint_normal(": USB controller\n");
132 1.1.10.2 tls
133 1.1.10.2 tls sc->sc_ih = bcm2835_intr_establish(aaa->aaa_intr, IPL_USB,
134 1.1.10.2 tls dwc2_intr, &sc->sc_dwc2);
135 1.1.10.2 tls
136 1.1.10.2 tls if (sc->sc_ih == NULL) {
137 1.1.10.2 tls aprint_error_dev(self, "failed to establish interrupt %d\n",
138 1.1.10.2 tls aaa->aaa_intr);
139 1.1.10.2 tls goto fail;
140 1.1.10.2 tls }
141 1.1.10.2 tls config_defer(self, bcmdwc2_deferred);
142 1.1.10.2 tls
143 1.1.10.2 tls return;
144 1.1.10.2 tls
145 1.1.10.2 tls fail:
146 1.1.10.2 tls if (sc->sc_ih) {
147 1.1.10.2 tls intr_disestablish(sc->sc_ih);
148 1.1.10.2 tls sc->sc_ih = NULL;
149 1.1.10.2 tls }
150 1.1.10.2 tls bus_space_unmap(sc->sc_dwc2.sc_iot, sc->sc_dwc2.sc_ioh, aaa->aaa_size);
151 1.1.10.2 tls }
152 1.1.10.2 tls
153 1.1.10.2 tls static void
154 1.1.10.2 tls bcmdwc2_deferred(device_t self)
155 1.1.10.2 tls {
156 1.1.10.2 tls struct bcmdwc2_softc *sc = device_private(self);
157 1.1.10.2 tls int error;
158 1.1.10.2 tls
159 1.1.10.2 tls error = dwc2_init(&sc->sc_dwc2);
160 1.1.10.2 tls if (error != 0) {
161 1.1.10.2 tls aprint_error_dev(self, "couldn't initialize host, error=%d\n",
162 1.1.10.2 tls error);
163 1.1.10.2 tls return;
164 1.1.10.2 tls }
165 1.1.10.2 tls sc->sc_dwc2.sc_child = config_found(sc->sc_dwc2.sc_dev,
166 1.1.10.2 tls &sc->sc_dwc2.sc_bus, usbctlprint);
167 1.1.10.2 tls }
168