netwalker_usb.c revision 1.1.6.2 1 1.1.6.2 rmind /*
2 1.1.6.2 rmind * Copyright (c) 2010 Genetec Corporation. All rights reserved.
3 1.1.6.2 rmind * Written by Hiroyuki Bessho for Genetec Corporation.
4 1.1.6.2 rmind *
5 1.1.6.2 rmind * Redistribution and use in source and binary forms, with or without
6 1.1.6.2 rmind * modification, are permitted provided that the following conditions
7 1.1.6.2 rmind * are met:
8 1.1.6.2 rmind * 1. Redistributions of source code must retain the above copyright
9 1.1.6.2 rmind * notice, this list of conditions and the following disclaimer.
10 1.1.6.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
11 1.1.6.2 rmind * notice, this list of conditions and the following disclaimer in the
12 1.1.6.2 rmind * documentation and/or other materials provided with the distribution.
13 1.1.6.2 rmind *
14 1.1.6.2 rmind * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
15 1.1.6.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16 1.1.6.2 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 1.1.6.2 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
18 1.1.6.2 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 1.1.6.2 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 1.1.6.2 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 1.1.6.2 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 1.1.6.2 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 1.1.6.2 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 1.1.6.2 rmind * POSSIBILITY OF SUCH DAMAGE.
25 1.1.6.2 rmind *
26 1.1.6.2 rmind */
27 1.1.6.2 rmind #include <sys/cdefs.h>
28 1.1.6.2 rmind __KERNEL_RCSID(0, "$NetBSD: netwalker_usb.c,v 1.1.6.2 2011/03/05 20:50:08 rmind Exp $");
29 1.1.6.2 rmind
30 1.1.6.2 rmind #include <sys/param.h>
31 1.1.6.2 rmind #include <sys/systm.h>
32 1.1.6.2 rmind #include <sys/conf.h>
33 1.1.6.2 rmind #include <sys/kernel.h>
34 1.1.6.2 rmind #include <sys/device.h>
35 1.1.6.2 rmind #include <sys/intr.h>
36 1.1.6.2 rmind #include <sys/bus.h>
37 1.1.6.2 rmind
38 1.1.6.2 rmind #include <dev/usb/usb.h>
39 1.1.6.2 rmind #include <dev/usb/usbdi.h>
40 1.1.6.2 rmind #include <dev/usb/usbdivar.h>
41 1.1.6.2 rmind #include <dev/usb/usb_mem.h>
42 1.1.6.2 rmind
43 1.1.6.2 rmind #include <dev/usb/ehcireg.h>
44 1.1.6.2 rmind #include <dev/usb/ehcivar.h>
45 1.1.6.2 rmind
46 1.1.6.2 rmind #include <arm/imx/imx51reg.h>
47 1.1.6.2 rmind #include <arm/imx/imx51var.h>
48 1.1.6.2 rmind #include <arm/imx/imxusbreg.h>
49 1.1.6.2 rmind #include <arm/imx/imxusbvar.h>
50 1.1.6.2 rmind #include <arm/imx/imx51_iomuxreg.h>
51 1.1.6.2 rmind #include <arm/imx/imxgpiovar.h>
52 1.1.6.2 rmind #include "locators.h"
53 1.1.6.2 rmind
54 1.1.6.2 rmind
55 1.1.6.2 rmind struct netwalker_usbc_softc {
56 1.1.6.2 rmind struct imxusbc_softc sc_imxusbc;
57 1.1.6.2 rmind };
58 1.1.6.2 rmind
59 1.1.6.2 rmind
60 1.1.6.2 rmind static int imxusbc_match(device_t, cfdata_t, void *);
61 1.1.6.2 rmind static void imxusbc_attach(device_t, device_t, void *);
62 1.1.6.2 rmind static void netwalker_usb_init(struct imxehci_softc *);
63 1.1.6.2 rmind
64 1.1.6.2 rmind static void init_otg(struct imxehci_softc *);
65 1.1.6.2 rmind static void init_h1(struct imxehci_softc *);
66 1.1.6.2 rmind
67 1.1.6.2 rmind extern const struct iomux_conf iomux_usb1_config[];
68 1.1.6.2 rmind
69 1.1.6.2 rmind /* attach structures */
70 1.1.6.2 rmind CFATTACH_DECL_NEW(imxusbc_axi, sizeof(struct netwalker_usbc_softc),
71 1.1.6.2 rmind imxusbc_match, imxusbc_attach, NULL, NULL);
72 1.1.6.2 rmind
73 1.1.6.2 rmind static int
74 1.1.6.2 rmind imxusbc_match(device_t parent, cfdata_t cf, void *aux)
75 1.1.6.2 rmind {
76 1.1.6.2 rmind struct axi_attach_args *aa = aux;
77 1.1.6.2 rmind
78 1.1.6.2 rmind printf("%s\n", __func__);
79 1.1.6.2 rmind
80 1.1.6.2 rmind if (aa->aa_addr == USBOH3_BASE)
81 1.1.6.2 rmind return 1;
82 1.1.6.2 rmind return 0;
83 1.1.6.2 rmind }
84 1.1.6.2 rmind
85 1.1.6.2 rmind static void
86 1.1.6.2 rmind imxusbc_attach(device_t parent, device_t self, void *aux)
87 1.1.6.2 rmind {
88 1.1.6.2 rmind struct axi_attach_args *aa = aux;
89 1.1.6.2 rmind struct imxusbc_softc *sc = device_private(self);
90 1.1.6.2 rmind
91 1.1.6.2 rmind sc->sc_init_md_hook = netwalker_usb_init;
92 1.1.6.2 rmind sc->sc_setup_md_hook = NULL;
93 1.1.6.2 rmind
94 1.1.6.2 rmind imxusbc_attach_common(parent, self, aa->aa_iot);
95 1.1.6.2 rmind
96 1.1.6.2 rmind }
97 1.1.6.2 rmind
98 1.1.6.2 rmind static void
99 1.1.6.2 rmind netwalker_usb_init(struct imxehci_softc *sc)
100 1.1.6.2 rmind {
101 1.1.6.2 rmind switch (sc->sc_unit) {
102 1.1.6.2 rmind case 0: /* OTG controller */
103 1.1.6.2 rmind init_otg(sc);
104 1.1.6.2 rmind break;
105 1.1.6.2 rmind case 1: /* EHCI Host 1 */
106 1.1.6.2 rmind init_h1(sc);
107 1.1.6.2 rmind break;
108 1.1.6.2 rmind default:
109 1.1.6.2 rmind aprint_error_dev(sc->sc_hsc.sc_dev, "unit %d not supprted\n",
110 1.1.6.2 rmind sc->sc_unit);
111 1.1.6.2 rmind }
112 1.1.6.2 rmind }
113 1.1.6.2 rmind
114 1.1.6.2 rmind static void
115 1.1.6.2 rmind init_otg(struct imxehci_softc *sc)
116 1.1.6.2 rmind {
117 1.1.6.2 rmind struct imxusbc_softc *usbc = sc->sc_usbc;
118 1.1.6.2 rmind uint32_t reg;
119 1.1.6.2 rmind
120 1.1.6.2 rmind sc->sc_iftype = IMXUSBC_IF_UTMI;
121 1.1.6.2 rmind
122 1.1.6.2 rmind imxehci_reset(sc);
123 1.1.6.2 rmind
124 1.1.6.2 rmind reg = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh, USBOH3_PHYCTRL0);
125 1.1.6.2 rmind reg |= PHYCTRL0_OTG_OVER_CUR_DIS;
126 1.1.6.2 rmind bus_space_write_4(usbc->sc_iot, usbc->sc_ioh, USBOH3_PHYCTRL0, reg);
127 1.1.6.2 rmind
128 1.1.6.2 rmind reg = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh, USBOH3_USBCTRL);
129 1.1.6.2 rmind reg &= ~(USBCTRL_OWIR|USBCTRL_OPM);
130 1.1.6.2 rmind bus_space_write_4(usbc->sc_iot, usbc->sc_ioh, USBOH3_USBCTRL, reg);
131 1.1.6.2 rmind
132 1.1.6.2 rmind reg = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh, USBOH3_PHYCTRL1);
133 1.1.6.2 rmind reg = (reg & ~PHYCTRL1_PLLDIVVALUE_MASK) | PHYCTRL1_PLLDIVVALUE_24MHZ;
134 1.1.6.2 rmind bus_space_write_4(usbc->sc_iot, usbc->sc_ioh, USBOH3_PHYCTRL1, reg);
135 1.1.6.2 rmind }
136 1.1.6.2 rmind
137 1.1.6.2 rmind
138 1.1.6.2 rmind
139 1.1.6.2 rmind
140 1.1.6.2 rmind static void
141 1.1.6.2 rmind init_h1(struct imxehci_softc *sc)
142 1.1.6.2 rmind {
143 1.1.6.2 rmind struct imxusbc_softc *usbc = sc->sc_usbc;
144 1.1.6.2 rmind uint32_t reg;
145 1.1.6.2 rmind
146 1.1.6.2 rmind /* output HIGH to USBH1_STP */
147 1.1.6.2 rmind gpio_data_write(GPIO_NO(1,27), 1);
148 1.1.6.2 rmind gpio_set_direction(GPIO_NO(1, 27), GPIO_DIR_OUT);
149 1.1.6.2 rmind
150 1.1.6.2 rmind iomux_mux_config(iomux_usb1_config);
151 1.1.6.2 rmind
152 1.1.6.2 rmind delay(100 * 1000);
153 1.1.6.2 rmind
154 1.1.6.2 rmind /* XXX enable USB clock */
155 1.1.6.2 rmind
156 1.1.6.2 rmind imxehci_reset(sc);
157 1.1.6.2 rmind
158 1.1.6.2 rmind /* select external clock for Host 1 */
159 1.1.6.2 rmind reg = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh,
160 1.1.6.2 rmind USBOH3_USBCTRL1);
161 1.1.6.2 rmind reg |= USBCTRL1_UH1_EXT_CLK_EN;
162 1.1.6.2 rmind bus_space_write_4(usbc->sc_iot, usbc->sc_ioh,
163 1.1.6.2 rmind USBOH3_USBCTRL1, reg);
164 1.1.6.2 rmind
165 1.1.6.2 rmind
166 1.1.6.2 rmind /* select ULPI interface for Host 1 */
167 1.1.6.2 rmind sc->sc_iftype = IMXUSBC_IF_ULPI;
168 1.1.6.2 rmind
169 1.1.6.2 rmind reg = bus_space_read_4(usbc->sc_iot, usbc->sc_ioh,
170 1.1.6.2 rmind USBOH3_USBCTRL);
171 1.1.6.2 rmind reg &= ~(USBCTRL_H1PM);
172 1.1.6.2 rmind reg |= USBCTRL_H1UIE|USBCTRL_H1WIE;
173 1.1.6.2 rmind bus_space_write_4(usbc->sc_iot, usbc->sc_ioh,
174 1.1.6.2 rmind USBOH3_USBCTRL, reg);
175 1.1.6.2 rmind
176 1.1.6.2 rmind iomux_set_function(MUX_PIN_USBH1_STP, IOMUX_CONFIG_ALT0);
177 1.1.6.2 rmind
178 1.1.6.2 rmind
179 1.1.6.2 rmind /* HUB RESET release */
180 1.1.6.2 rmind gpio_data_write(GPIO_NO(1, 7), 1);
181 1.1.6.2 rmind gpio_set_direction(GPIO_NO(1, 7), GPIO_DIR_OUT);
182 1.1.6.2 rmind
183 1.1.6.2 rmind
184 1.1.6.2 rmind /* Drive 26M_OSC_EN line high 3_1 */
185 1.1.6.2 rmind gpio_data_write(GPIO_NO(3, 1), 1);
186 1.1.6.2 rmind gpio_set_direction(GPIO_NO(3, 1), GPIO_DIR_OUT);
187 1.1.6.2 rmind
188 1.1.6.2 rmind /* Drive USB_CLK_EN_B line low 2_1 */
189 1.1.6.2 rmind gpio_data_write(GPIO_NO(2, 1), 0);
190 1.1.6.2 rmind gpio_set_direction(GPIO_NO(2, 1), GPIO_DIR_IN);
191 1.1.6.2 rmind
192 1.1.6.2 rmind /* MX51_PIN_EIM_D21 - De-assert USB PHY RESETB */
193 1.1.6.2 rmind delay(10 * 1000);
194 1.1.6.2 rmind gpio_data_write(GPIO_NO(2, 5), 1);
195 1.1.6.2 rmind gpio_set_direction(GPIO_NO(2, 5), GPIO_DIR_OUT);
196 1.1.6.2 rmind iomux_set_function(MUX_PIN_EIM_D21, IOMUX_CONFIG_ALT1);
197 1.1.6.2 rmind delay(5 * 1000);
198 1.1.6.2 rmind }
199 1.1.6.2 rmind
200 1.1.6.2 rmind /*
201 1.1.6.2 rmind * IOMUX setting for USB Host1
202 1.1.6.2 rmind * taken from Linux driver
203 1.1.6.2 rmind */
204 1.1.6.2 rmind const struct iomux_conf iomux_usb1_config[] = {
205 1.1.6.2 rmind
206 1.1.6.2 rmind {
207 1.1.6.2 rmind /* Initially setup this pin for GPIO, and change to
208 1.1.6.2 rmind * USBH1_STP later */
209 1.1.6.2 rmind .pin = MUX_PIN_USBH1_STP,
210 1.1.6.2 rmind .mux = IOMUX_CONFIG_ALT2,
211 1.1.6.2 rmind .pad = (PAD_CTL_SRE | PAD_CTL_DSE_HIGH |
212 1.1.6.2 rmind PAD_CTL_KEEPER | PAD_CTL_HYS)
213 1.1.6.2 rmind },
214 1.1.6.2 rmind
215 1.1.6.2 rmind {
216 1.1.6.2 rmind /* Clock */
217 1.1.6.2 rmind .pin = MUX_PIN_USBH1_CLK,
218 1.1.6.2 rmind .mux = IOMUX_CONFIG_ALT0,
219 1.1.6.2 rmind .pad = (PAD_CTL_SRE | PAD_CTL_DSE_HIGH |
220 1.1.6.2 rmind PAD_CTL_KEEPER | PAD_CTL_HYS)
221 1.1.6.2 rmind },
222 1.1.6.2 rmind {
223 1.1.6.2 rmind /* DIR */
224 1.1.6.2 rmind .pin = MUX_PIN_USBH1_DIR,
225 1.1.6.2 rmind .mux = IOMUX_CONFIG_ALT0,
226 1.1.6.2 rmind .pad = (PAD_CTL_SRE | PAD_CTL_DSE_HIGH |
227 1.1.6.2 rmind PAD_CTL_KEEPER | PAD_CTL_HYS)
228 1.1.6.2 rmind },
229 1.1.6.2 rmind
230 1.1.6.2 rmind {
231 1.1.6.2 rmind /* NXT */
232 1.1.6.2 rmind .pin = MUX_PIN_USBH1_NXT,
233 1.1.6.2 rmind .mux = IOMUX_CONFIG_ALT0,
234 1.1.6.2 rmind .pad = (PAD_CTL_SRE | PAD_CTL_DSE_HIGH |
235 1.1.6.2 rmind PAD_CTL_KEEPER | PAD_CTL_HYS)
236 1.1.6.2 rmind },
237 1.1.6.2 rmind
238 1.1.6.2 rmind #define USBH1_DATA_CONFIG(n) \
239 1.1.6.2 rmind { \
240 1.1.6.2 rmind /* DATA n */ \
241 1.1.6.2 rmind .pin = __CONCAT(MUX_PIN_USBH1_DATA,n), \
242 1.1.6.2 rmind .mux = IOMUX_CONFIG_ALT0, \
243 1.1.6.2 rmind .pad = (PAD_CTL_SRE | PAD_CTL_DSE_HIGH | \
244 1.1.6.2 rmind PAD_CTL_KEEPER | PAD_CTL_PUS_100K_PU | \
245 1.1.6.2 rmind PAD_CTL_HYS), \
246 1.1.6.2 rmind /* XXX: what does 100K_PU with KEEPER ? */ \
247 1.1.6.2 rmind }
248 1.1.6.2 rmind
249 1.1.6.2 rmind USBH1_DATA_CONFIG(0),
250 1.1.6.2 rmind USBH1_DATA_CONFIG(1),
251 1.1.6.2 rmind USBH1_DATA_CONFIG(2),
252 1.1.6.2 rmind USBH1_DATA_CONFIG(3),
253 1.1.6.2 rmind USBH1_DATA_CONFIG(4),
254 1.1.6.2 rmind USBH1_DATA_CONFIG(5),
255 1.1.6.2 rmind USBH1_DATA_CONFIG(6),
256 1.1.6.2 rmind USBH1_DATA_CONFIG(7),
257 1.1.6.2 rmind
258 1.1.6.2 rmind {
259 1.1.6.2 rmind /* USB_CLK_EN_B GPIO2[1]*/
260 1.1.6.2 rmind .pin = MUX_PIN_EIM_D17,
261 1.1.6.2 rmind .mux = IOMUX_CONFIG_ALT1,
262 1.1.6.2 rmind .pad = (PAD_CTL_DSE_HIGH | PAD_CTL_PKE | PAD_CTL_SRE),
263 1.1.6.2 rmind },
264 1.1.6.2 rmind
265 1.1.6.2 rmind {
266 1.1.6.2 rmind /* USB PHY RESETB */
267 1.1.6.2 rmind .pin = MUX_PIN_EIM_D21,
268 1.1.6.2 rmind .mux = IOMUX_CONFIG_ALT1,
269 1.1.6.2 rmind .pad = (PAD_CTL_DSE_HIGH | PAD_CTL_KEEPER |
270 1.1.6.2 rmind PAD_CTL_PUS_100K_PU | PAD_CTL_SRE)
271 1.1.6.2 rmind },
272 1.1.6.2 rmind {
273 1.1.6.2 rmind /* USB HUB RESET */
274 1.1.6.2 rmind .pin = MUX_PIN_GPIO1_7,
275 1.1.6.2 rmind .mux = IOMUX_CONFIG_ALT0,
276 1.1.6.2 rmind .pad = (PAD_CTL_DSE_HIGH | PAD_CTL_SRE),
277 1.1.6.2 rmind },
278 1.1.6.2 rmind
279 1.1.6.2 rmind /* end of table */
280 1.1.6.2 rmind {.pin = IOMUX_CONF_EOT}
281 1.1.6.2 rmind };
282