Deleted Added
full compact
exynos5_ehci.c (266332) exynos5_ehci.c (266341)
1/*-
2 * Copyright (c) 2013 Ruslan Bukin <br@bsdpad.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2013 Ruslan Bukin <br@bsdpad.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/10/sys/arm/samsung/exynos/exynos5_ehci.c 266332 2014-05-17 17:54:38Z ian $");
28__FBSDID("$FreeBSD: stable/10/sys/arm/samsung/exynos/exynos5_ehci.c 266341 2014-05-17 19:37:04Z ian $");
29
30#include "opt_bus.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/bus.h>
37#include <sys/condvar.h>
38#include <sys/rman.h>
29
30#include "opt_bus.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/bus.h>
37#include <sys/condvar.h>
38#include <sys/rman.h>
39#include <sys/gpio.h>
39
40#include <dev/ofw/ofw_bus.h>
41#include <dev/ofw/ofw_bus_subr.h>
42
43#include <dev/usb/usb.h>
44#include <dev/usb/usbdi.h>
45#include <dev/usb/usb_busdma.h>
46#include <dev/usb/usb_process.h>
47#include <dev/usb/usb_controller.h>
48#include <dev/usb/usb_bus.h>
49#include <dev/usb/controller/ehci.h>
50#include <dev/usb/controller/ehcireg.h>
51
52#include <dev/fdt/fdt_common.h>
53
54#include <machine/bus.h>
55#include <machine/resource.h>
56
40
41#include <dev/ofw/ofw_bus.h>
42#include <dev/ofw/ofw_bus_subr.h>
43
44#include <dev/usb/usb.h>
45#include <dev/usb/usbdi.h>
46#include <dev/usb/usb_busdma.h>
47#include <dev/usb/usb_process.h>
48#include <dev/usb/usb_controller.h>
49#include <dev/usb/usb_bus.h>
50#include <dev/usb/controller/ehci.h>
51#include <dev/usb/controller/ehcireg.h>
52
53#include <dev/fdt/fdt_common.h>
54
55#include <machine/bus.h>
56#include <machine/resource.h>
57
58#include "gpio_if.h"
59
57#include "opt_platform.h"
58
59/* GPIO control */
60#include "opt_platform.h"
61
62/* GPIO control */
60#define GPIO_CON(x, v) ((v) << ((x) * 4))
61#define GPIO_MASK 0xf
62#define GPIO_OUTPUT 1
63#define GPIO_INPUT 0
63#define GPIO_OUTPUT 1
64#define GPIO_INPUT 0
64#define GPX3CON 0x0
65#define GPX3DAT 0x4
66#define PIN_USB 5
65#define PIN_USB 161
67
68/* PWR control */
69#define EXYNOS5_PWR_USBHOST_PHY 0x708
70#define PHY_POWER_ON 1
71#define PHY_POWER_OFF 0
72
73/* SYSREG */
74#define EXYNOS5_SYSREG_USB2_PHY 0x0
75#define USB2_MODE_HOST 0x1
76
77/* USB HOST */
78#define HOST_CTRL_CLK_24MHZ (5 << 16)
79#define HOST_CTRL_CLK_MASK (7 << 16)
80#define HOST_CTRL_SIDDQ (1 << 6)
81#define HOST_CTRL_SLEEP (1 << 5)
82#define HOST_CTRL_SUSPEND (1 << 4)
83#define HOST_CTRL_RESET_LINK (1 << 1)
84#define HOST_CTRL_RESET_PHY (1 << 0)
85#define HOST_CTRL_RESET_PHY_ALL (1U << 31)
86
87/* Forward declarations */
88static int exynos_ehci_attach(device_t dev);
89static int exynos_ehci_detach(device_t dev);
90static int exynos_ehci_probe(device_t dev);
91
92struct exynos_ehci_softc {
66
67/* PWR control */
68#define EXYNOS5_PWR_USBHOST_PHY 0x708
69#define PHY_POWER_ON 1
70#define PHY_POWER_OFF 0
71
72/* SYSREG */
73#define EXYNOS5_SYSREG_USB2_PHY 0x0
74#define USB2_MODE_HOST 0x1
75
76/* USB HOST */
77#define HOST_CTRL_CLK_24MHZ (5 << 16)
78#define HOST_CTRL_CLK_MASK (7 << 16)
79#define HOST_CTRL_SIDDQ (1 << 6)
80#define HOST_CTRL_SLEEP (1 << 5)
81#define HOST_CTRL_SUSPEND (1 << 4)
82#define HOST_CTRL_RESET_LINK (1 << 1)
83#define HOST_CTRL_RESET_PHY (1 << 0)
84#define HOST_CTRL_RESET_PHY_ALL (1U << 31)
85
86/* Forward declarations */
87static int exynos_ehci_attach(device_t dev);
88static int exynos_ehci_detach(device_t dev);
89static int exynos_ehci_probe(device_t dev);
90
91struct exynos_ehci_softc {
92 device_t dev;
93 ehci_softc_t base;
93 ehci_softc_t base;
94 struct resource *res[6];
94 struct resource *res[5];
95 bus_space_tag_t host_bst;
96 bus_space_tag_t pwr_bst;
97 bus_space_tag_t sysreg_bst;
95 bus_space_tag_t host_bst;
96 bus_space_tag_t pwr_bst;
97 bus_space_tag_t sysreg_bst;
98 bus_space_tag_t gpio_bst;
99 bus_space_handle_t host_bsh;
100 bus_space_handle_t pwr_bsh;
101 bus_space_handle_t sysreg_bsh;
98 bus_space_handle_t host_bsh;
99 bus_space_handle_t pwr_bsh;
100 bus_space_handle_t sysreg_bsh;
102 bus_space_handle_t gpio_bsh;
103
104};
105
106static struct resource_spec exynos_ehci_spec[] = {
107 { SYS_RES_MEMORY, 0, RF_ACTIVE },
108 { SYS_RES_MEMORY, 1, RF_ACTIVE },
109 { SYS_RES_MEMORY, 2, RF_ACTIVE },
110 { SYS_RES_MEMORY, 3, RF_ACTIVE },
101
102};
103
104static struct resource_spec exynos_ehci_spec[] = {
105 { SYS_RES_MEMORY, 0, RF_ACTIVE },
106 { SYS_RES_MEMORY, 1, RF_ACTIVE },
107 { SYS_RES_MEMORY, 2, RF_ACTIVE },
108 { SYS_RES_MEMORY, 3, RF_ACTIVE },
111 { SYS_RES_MEMORY, 4, RF_ACTIVE },
112 { SYS_RES_IRQ, 0, RF_ACTIVE },
113 { -1, 0 }
114};
115
116static device_method_t ehci_methods[] = {
117 /* Device interface */
118 DEVMETHOD(device_probe, exynos_ehci_probe),
119 DEVMETHOD(device_attach, exynos_ehci_attach),
120 DEVMETHOD(device_detach, exynos_ehci_detach),
121 DEVMETHOD(device_suspend, bus_generic_suspend),
122 DEVMETHOD(device_resume, bus_generic_resume),
123 DEVMETHOD(device_shutdown, bus_generic_shutdown),
124
125 /* Bus interface */
126 DEVMETHOD(bus_print_child, bus_generic_print_child),
127
128 { 0, 0 }
129};
130
131/* kobj_class definition */
132static driver_t ehci_driver = {
133 "ehci",
134 ehci_methods,
135 sizeof(ehci_softc_t)
136};
137
138static devclass_t ehci_devclass;
139
140DRIVER_MODULE(ehci, simplebus, ehci_driver, ehci_devclass, 0, 0);
141MODULE_DEPEND(ehci, usb, 1, 1, 1);
142
143/*
144 * Public methods
145 */
146static int
147exynos_ehci_probe(device_t dev)
148{
149
150 if (!ofw_bus_status_okay(dev))
151 return (ENXIO);
152
153 if (ofw_bus_is_compatible(dev, "exynos,usb-ehci") == 0)
154 return (ENXIO);
155
156 device_set_desc(dev, "Exynos integrated USB controller");
157 return (BUS_PROBE_DEFAULT);
158}
159
160static int
161gpio_ctrl(struct exynos_ehci_softc *esc, int dir, int power)
162{
109 { SYS_RES_IRQ, 0, RF_ACTIVE },
110 { -1, 0 }
111};
112
113static device_method_t ehci_methods[] = {
114 /* Device interface */
115 DEVMETHOD(device_probe, exynos_ehci_probe),
116 DEVMETHOD(device_attach, exynos_ehci_attach),
117 DEVMETHOD(device_detach, exynos_ehci_detach),
118 DEVMETHOD(device_suspend, bus_generic_suspend),
119 DEVMETHOD(device_resume, bus_generic_resume),
120 DEVMETHOD(device_shutdown, bus_generic_shutdown),
121
122 /* Bus interface */
123 DEVMETHOD(bus_print_child, bus_generic_print_child),
124
125 { 0, 0 }
126};
127
128/* kobj_class definition */
129static driver_t ehci_driver = {
130 "ehci",
131 ehci_methods,
132 sizeof(ehci_softc_t)
133};
134
135static devclass_t ehci_devclass;
136
137DRIVER_MODULE(ehci, simplebus, ehci_driver, ehci_devclass, 0, 0);
138MODULE_DEPEND(ehci, usb, 1, 1, 1);
139
140/*
141 * Public methods
142 */
143static int
144exynos_ehci_probe(device_t dev)
145{
146
147 if (!ofw_bus_status_okay(dev))
148 return (ENXIO);
149
150 if (ofw_bus_is_compatible(dev, "exynos,usb-ehci") == 0)
151 return (ENXIO);
152
153 device_set_desc(dev, "Exynos integrated USB controller");
154 return (BUS_PROBE_DEFAULT);
155}
156
157static int
158gpio_ctrl(struct exynos_ehci_softc *esc, int dir, int power)
159{
163 int reg;
160 device_t gpio_dev;
164
161
165 /* Power control */
166 reg = bus_space_read_4(esc->gpio_bst, esc->gpio_bsh, GPX3DAT);
167 reg &= ~(1 << PIN_USB);
168 reg |= (power << PIN_USB);
169 bus_space_write_4(esc->gpio_bst, esc->gpio_bsh, GPX3DAT, reg);
162 /* Get the GPIO device, we need this to give power to USB */
163 gpio_dev = devclass_get_device(devclass_find("gpio"), 0);
164 if (gpio_dev == NULL) {
165 device_printf(esc->dev, "cant find gpio_dev\n");
166 return (1);
167 }
170
168
171 /* Input/Output control */
172 reg = bus_space_read_4(esc->gpio_bst, esc->gpio_bsh, GPX3CON);
173 reg &= ~GPIO_CON(PIN_USB, GPIO_MASK);
174 reg |= GPIO_CON(PIN_USB, dir);
175 bus_space_write_4(esc->gpio_bst, esc->gpio_bsh, GPX3CON, reg);
169 if (power)
170 GPIO_PIN_SET(gpio_dev, PIN_USB, GPIO_PIN_HIGH);
171 else
172 GPIO_PIN_SET(gpio_dev, PIN_USB, GPIO_PIN_LOW);
176
173
174 if (dir)
175 GPIO_PIN_SETFLAGS(gpio_dev, PIN_USB, GPIO_PIN_OUTPUT);
176 else
177 GPIO_PIN_SETFLAGS(gpio_dev, PIN_USB, GPIO_PIN_INPUT);
178
177 return (0);
178}
179
180static int
181phy_init(struct exynos_ehci_softc *esc)
182{
183 int reg;
184
185 gpio_ctrl(esc, GPIO_INPUT, 1);
186
187 /* set USB HOST mode */
188 bus_space_write_4(esc->sysreg_bst, esc->sysreg_bsh,
189 EXYNOS5_SYSREG_USB2_PHY, USB2_MODE_HOST);
190
191 /* Power ON phy */
192 bus_space_write_4(esc->pwr_bst, esc->pwr_bsh,
193 EXYNOS5_PWR_USBHOST_PHY, PHY_POWER_ON);
194
195 reg = bus_space_read_4(esc->host_bst, esc->host_bsh, 0x0);
196 reg &= ~(HOST_CTRL_CLK_MASK |
197 HOST_CTRL_RESET_PHY |
198 HOST_CTRL_RESET_PHY_ALL |
199 HOST_CTRL_SIDDQ |
200 HOST_CTRL_SUSPEND |
201 HOST_CTRL_SLEEP);
202
203 reg |= (HOST_CTRL_CLK_24MHZ |
204 HOST_CTRL_RESET_LINK);
205 bus_space_write_4(esc->host_bst, esc->host_bsh, 0x0, reg);
206
207 DELAY(10);
208
209 reg = bus_space_read_4(esc->host_bst, esc->host_bsh, 0x0);
210 reg &= ~(HOST_CTRL_RESET_LINK);
211 bus_space_write_4(esc->host_bst, esc->host_bsh, 0x0, reg);
212
213 gpio_ctrl(esc, GPIO_OUTPUT, 1);
214
215 return (0);
216}
217
218static int
219exynos_ehci_attach(device_t dev)
220{
221 struct exynos_ehci_softc *esc;
222 ehci_softc_t *sc;
223 bus_space_handle_t bsh;
224 int err;
225
226 esc = device_get_softc(dev);
179 return (0);
180}
181
182static int
183phy_init(struct exynos_ehci_softc *esc)
184{
185 int reg;
186
187 gpio_ctrl(esc, GPIO_INPUT, 1);
188
189 /* set USB HOST mode */
190 bus_space_write_4(esc->sysreg_bst, esc->sysreg_bsh,
191 EXYNOS5_SYSREG_USB2_PHY, USB2_MODE_HOST);
192
193 /* Power ON phy */
194 bus_space_write_4(esc->pwr_bst, esc->pwr_bsh,
195 EXYNOS5_PWR_USBHOST_PHY, PHY_POWER_ON);
196
197 reg = bus_space_read_4(esc->host_bst, esc->host_bsh, 0x0);
198 reg &= ~(HOST_CTRL_CLK_MASK |
199 HOST_CTRL_RESET_PHY |
200 HOST_CTRL_RESET_PHY_ALL |
201 HOST_CTRL_SIDDQ |
202 HOST_CTRL_SUSPEND |
203 HOST_CTRL_SLEEP);
204
205 reg |= (HOST_CTRL_CLK_24MHZ |
206 HOST_CTRL_RESET_LINK);
207 bus_space_write_4(esc->host_bst, esc->host_bsh, 0x0, reg);
208
209 DELAY(10);
210
211 reg = bus_space_read_4(esc->host_bst, esc->host_bsh, 0x0);
212 reg &= ~(HOST_CTRL_RESET_LINK);
213 bus_space_write_4(esc->host_bst, esc->host_bsh, 0x0, reg);
214
215 gpio_ctrl(esc, GPIO_OUTPUT, 1);
216
217 return (0);
218}
219
220static int
221exynos_ehci_attach(device_t dev)
222{
223 struct exynos_ehci_softc *esc;
224 ehci_softc_t *sc;
225 bus_space_handle_t bsh;
226 int err;
227
228 esc = device_get_softc(dev);
229 esc->dev = dev;
227 sc = &esc->base;
228 sc->sc_bus.parent = dev;
229 sc->sc_bus.devices = sc->sc_devices;
230 sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
231
232 if (bus_alloc_resources(dev, exynos_ehci_spec, esc->res)) {
233 device_printf(dev, "could not allocate resources\n");
234 return (ENXIO);
235 }
236
237 /* EHCI registers */
238 sc->sc_io_tag = rman_get_bustag(esc->res[0]);
239 bsh = rman_get_bushandle(esc->res[0]);
240 sc->sc_io_size = rman_get_size(esc->res[0]);
241
242 /* EHCI HOST ctrl registers */
243 esc->host_bst = rman_get_bustag(esc->res[1]);
244 esc->host_bsh = rman_get_bushandle(esc->res[1]);
245
246 /* PWR registers */
247 esc->pwr_bst = rman_get_bustag(esc->res[2]);
248 esc->pwr_bsh = rman_get_bushandle(esc->res[2]);
249
250 /* SYSREG */
251 esc->sysreg_bst = rman_get_bustag(esc->res[3]);
252 esc->sysreg_bsh = rman_get_bushandle(esc->res[3]);
253
230 sc = &esc->base;
231 sc->sc_bus.parent = dev;
232 sc->sc_bus.devices = sc->sc_devices;
233 sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
234
235 if (bus_alloc_resources(dev, exynos_ehci_spec, esc->res)) {
236 device_printf(dev, "could not allocate resources\n");
237 return (ENXIO);
238 }
239
240 /* EHCI registers */
241 sc->sc_io_tag = rman_get_bustag(esc->res[0]);
242 bsh = rman_get_bushandle(esc->res[0]);
243 sc->sc_io_size = rman_get_size(esc->res[0]);
244
245 /* EHCI HOST ctrl registers */
246 esc->host_bst = rman_get_bustag(esc->res[1]);
247 esc->host_bsh = rman_get_bushandle(esc->res[1]);
248
249 /* PWR registers */
250 esc->pwr_bst = rman_get_bustag(esc->res[2]);
251 esc->pwr_bsh = rman_get_bushandle(esc->res[2]);
252
253 /* SYSREG */
254 esc->sysreg_bst = rman_get_bustag(esc->res[3]);
255 esc->sysreg_bsh = rman_get_bushandle(esc->res[3]);
256
254 /* GPIO */
255 esc->gpio_bst = rman_get_bustag(esc->res[4]);
256 esc->gpio_bsh = rman_get_bushandle(esc->res[4]);
257
258 /* get all DMA memory */
259 if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(dev),
260 &ehci_iterate_hw_softc))
261 return (ENXIO);
262
263 /*
264 * Set handle to USB related registers subregion used by
265 * generic EHCI driver.
266 */
267 err = bus_space_subregion(sc->sc_io_tag, bsh, 0x0,
268 sc->sc_io_size, &sc->sc_io_hdl);
269 if (err != 0)
270 return (ENXIO);
271
272 phy_init(esc);
273
274 /* Setup interrupt handler */
257 /* get all DMA memory */
258 if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(dev),
259 &ehci_iterate_hw_softc))
260 return (ENXIO);
261
262 /*
263 * Set handle to USB related registers subregion used by
264 * generic EHCI driver.
265 */
266 err = bus_space_subregion(sc->sc_io_tag, bsh, 0x0,
267 sc->sc_io_size, &sc->sc_io_hdl);
268 if (err != 0)
269 return (ENXIO);
270
271 phy_init(esc);
272
273 /* Setup interrupt handler */
275 err = bus_setup_intr(dev, esc->res[5], INTR_TYPE_BIO | INTR_MPSAFE,
274 err = bus_setup_intr(dev, esc->res[4], INTR_TYPE_BIO | INTR_MPSAFE,
276 NULL, (driver_intr_t *)ehci_interrupt, sc,
277 &sc->sc_intr_hdl);
278 if (err) {
279 device_printf(dev, "Could not setup irq, "
280 "%d\n", err);
281 return (1);
282 }
283
284 /* Add USB device */
285 sc->sc_bus.bdev = device_add_child(dev, "usbus", -1);
286 if (!sc->sc_bus.bdev) {
287 device_printf(dev, "Could not add USB device\n");
275 NULL, (driver_intr_t *)ehci_interrupt, sc,
276 &sc->sc_intr_hdl);
277 if (err) {
278 device_printf(dev, "Could not setup irq, "
279 "%d\n", err);
280 return (1);
281 }
282
283 /* Add USB device */
284 sc->sc_bus.bdev = device_add_child(dev, "usbus", -1);
285 if (!sc->sc_bus.bdev) {
286 device_printf(dev, "Could not add USB device\n");
288 err = bus_teardown_intr(dev, esc->res[5],
287 err = bus_teardown_intr(dev, esc->res[4],
289 sc->sc_intr_hdl);
290 if (err)
291 device_printf(dev, "Could not tear down irq,"
292 " %d\n", err);
293 return (1);
294 }
295 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
296
297 strlcpy(sc->sc_vendor, "Samsung", sizeof(sc->sc_vendor));
298
299 err = ehci_init(sc);
300 if (!err) {
301 sc->sc_flags |= EHCI_SCFLG_DONEINIT;
302 err = device_probe_and_attach(sc->sc_bus.bdev);
303 } else {
304 device_printf(dev, "USB init failed err=%d\n", err);
305
306 device_delete_child(dev, sc->sc_bus.bdev);
307 sc->sc_bus.bdev = NULL;
308
288 sc->sc_intr_hdl);
289 if (err)
290 device_printf(dev, "Could not tear down irq,"
291 " %d\n", err);
292 return (1);
293 }
294 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
295
296 strlcpy(sc->sc_vendor, "Samsung", sizeof(sc->sc_vendor));
297
298 err = ehci_init(sc);
299 if (!err) {
300 sc->sc_flags |= EHCI_SCFLG_DONEINIT;
301 err = device_probe_and_attach(sc->sc_bus.bdev);
302 } else {
303 device_printf(dev, "USB init failed err=%d\n", err);
304
305 device_delete_child(dev, sc->sc_bus.bdev);
306 sc->sc_bus.bdev = NULL;
307
309 err = bus_teardown_intr(dev, esc->res[5],
308 err = bus_teardown_intr(dev, esc->res[4],
310 sc->sc_intr_hdl);
311 if (err)
312 device_printf(dev, "Could not tear down irq,"
313 " %d\n", err);
314 return (1);
315 }
316 return (0);
317}
318
319static int
320exynos_ehci_detach(device_t dev)
321{
322 struct exynos_ehci_softc *esc;
323 ehci_softc_t *sc;
324 int err;
325
326 esc = device_get_softc(dev);
327 sc = &esc->base;
328
329 if (sc->sc_flags & EHCI_SCFLG_DONEINIT)
330 return (0);
331
332 /*
333 * only call ehci_detach() after ehci_init()
334 */
335 if (sc->sc_flags & EHCI_SCFLG_DONEINIT) {
336 ehci_detach(sc);
337 sc->sc_flags &= ~EHCI_SCFLG_DONEINIT;
338 }
339
340 /*
341 * Disable interrupts that might have been switched on in
342 * ehci_init.
343 */
344 if (sc->sc_io_tag && sc->sc_io_hdl)
345 bus_space_write_4(sc->sc_io_tag, sc->sc_io_hdl,
346 EHCI_USBINTR, 0);
347
309 sc->sc_intr_hdl);
310 if (err)
311 device_printf(dev, "Could not tear down irq,"
312 " %d\n", err);
313 return (1);
314 }
315 return (0);
316}
317
318static int
319exynos_ehci_detach(device_t dev)
320{
321 struct exynos_ehci_softc *esc;
322 ehci_softc_t *sc;
323 int err;
324
325 esc = device_get_softc(dev);
326 sc = &esc->base;
327
328 if (sc->sc_flags & EHCI_SCFLG_DONEINIT)
329 return (0);
330
331 /*
332 * only call ehci_detach() after ehci_init()
333 */
334 if (sc->sc_flags & EHCI_SCFLG_DONEINIT) {
335 ehci_detach(sc);
336 sc->sc_flags &= ~EHCI_SCFLG_DONEINIT;
337 }
338
339 /*
340 * Disable interrupts that might have been switched on in
341 * ehci_init.
342 */
343 if (sc->sc_io_tag && sc->sc_io_hdl)
344 bus_space_write_4(sc->sc_io_tag, sc->sc_io_hdl,
345 EHCI_USBINTR, 0);
346
348 if (esc->res[5] && sc->sc_intr_hdl) {
349 err = bus_teardown_intr(dev, esc->res[5],
347 if (esc->res[4] && sc->sc_intr_hdl) {
348 err = bus_teardown_intr(dev, esc->res[4],
350 sc->sc_intr_hdl);
351 if (err) {
352 device_printf(dev, "Could not tear down irq,"
353 " %d\n", err);
354 return (err);
355 }
356 sc->sc_intr_hdl = NULL;
357 }
358
359 if (sc->sc_bus.bdev) {
360 device_delete_child(dev, sc->sc_bus.bdev);
361 sc->sc_bus.bdev = NULL;
362 }
363
364 /* During module unload there are lots of children leftover */
365 device_delete_children(dev);
366
367 bus_release_resources(dev, exynos_ehci_spec, esc->res);
368
369 return (0);
370}
349 sc->sc_intr_hdl);
350 if (err) {
351 device_printf(dev, "Could not tear down irq,"
352 " %d\n", err);
353 return (err);
354 }
355 sc->sc_intr_hdl = NULL;
356 }
357
358 if (sc->sc_bus.bdev) {
359 device_delete_child(dev, sc->sc_bus.bdev);
360 sc->sc_bus.bdev = NULL;
361 }
362
363 /* During module unload there are lots of children leftover */
364 device_delete_children(dev);
365
366 bus_release_resources(dev, exynos_ehci_spec, esc->res);
367
368 return (0);
369}