source: rtems-libbsd/rtemsbsd/sys/dev/usb/controller/dwc_otg_nexus.c @ 3c967ca

55-freebsd-126-freebsd-12
Last change on this file since 3c967ca was 3c967ca, checked in by Sebastian Huber <sebastian.huber@…>, on 06/08/17 at 11:15:12

Use <sys/lock.h> provided by Newlib

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*-
2 * Copyright (c) 2012 Hans Petter Selasky.
3 * Copyright (c) 2015 embedded brains GmbH.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <machine/rtems-bsd-kernel-space.h>
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD$");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/bus.h>
36#include <sys/condvar.h>
37#include <sys/kernel.h>
38#include <sys/lock.h>
39#include <sys/malloc.h>
40#include <sys/module.h>
41#include <sys/mutex.h>
42#include <sys/rman.h>
43
44#include <dev/usb/usb.h>
45#include <dev/usb/usbdi.h>
46
47#include <dev/usb/usb_core.h>
48#include <dev/usb/usb_busdma.h>
49#include <dev/usb/usb_process.h>
50#include <dev/usb/usb_util.h>
51
52#include <dev/usb/usb_controller.h>
53#include <dev/usb/usb_bus.h>
54
55#include <dev/usb/controller/dwc_otg.h>
56
57static device_probe_t dwc_otg_probe;
58static device_detach_t dwc_otg_detach;
59
60static int
61dwc_otg_probe(device_t dev)
62{
63
64        device_set_desc(dev, "DWC OTG 2.0 integrated USB controller");
65
66        return (BUS_PROBE_DEFAULT);
67}
68
69int
70dwc_otg_attach(device_t dev)
71{
72        struct dwc_otg_softc *sc = device_get_softc(dev);
73        char usb_mode[24];
74        int err;
75        int rid;
76
77        /* initialise some bus fields */
78        sc->sc_bus.parent = dev;
79        sc->sc_bus.devices = sc->sc_devices;
80        sc->sc_bus.devices_max = DWC_OTG_MAX_DEVICES;
81        sc->sc_bus.dma_bits = 32;
82
83        /* force USB host mode */
84        sc->sc_mode = DWC_MODE_HOST;
85
86        /* get all DMA memory */
87        if (usb_bus_mem_alloc_all(&sc->sc_bus,
88            USB_GET_DMA_TAG(dev), NULL)) {
89                return (ENOMEM);
90        }
91        rid = 0;
92        sc->sc_io_res =
93            bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
94
95        if (!(sc->sc_io_res)) {
96                err = ENOMEM;
97                goto error;
98        }
99        sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
100        sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
101        sc->sc_io_size = rman_get_size(sc->sc_io_res);
102
103        rid = 0;
104        sc->sc_irq_res =
105            bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
106        if (sc->sc_irq_res == NULL)
107                goto error;
108
109        sc->sc_bus.bdev = device_add_child(dev, "usbus", -1);
110        if (sc->sc_bus.bdev == NULL)
111                goto error;
112
113        device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
114
115        err = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_TTY | INTR_MPSAFE,
116            &dwc_otg_filter_interrupt, &dwc_otg_interrupt, sc, &sc->sc_intr_hdl);
117        if (err) {
118                sc->sc_intr_hdl = NULL;
119                goto error;
120        }
121        err = dwc_otg_init(sc);
122        if (err == 0) {
123                err = device_probe_and_attach(sc->sc_bus.bdev);
124        }
125        if (err)
126                goto error;
127
128
129        return (0);
130
131error:
132        return (ENXIO);
133}
134
135
136static device_method_t dwc_otg_methods[] = {
137        /* Device interface */
138        DEVMETHOD(device_probe, dwc_otg_probe),
139        DEVMETHOD(device_attach, dwc_otg_attach),
140        DEVMETHOD(device_suspend, bus_generic_suspend),
141        DEVMETHOD(device_resume, bus_generic_resume),
142        DEVMETHOD(device_shutdown, bus_generic_shutdown),
143
144        DEVMETHOD_END
145};
146
147driver_t dwc_otg_driver = {
148        .name = "dwcotg",
149        .methods = dwc_otg_methods,
150        .size = sizeof(struct dwc_otg_softc),
151};
152
153static devclass_t dwc_otg_devclass;
154
155DRIVER_MODULE(dwcotg, nexus, dwc_otg_driver, dwc_otg_devclass, 0, 0);
156MODULE_DEPEND(dwcotg, usb, 1, 1, 1);
Note: See TracBrowser for help on using the repository browser.