The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/mips/atheros/ar71xx_ohci.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
    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 unmodified, this list of conditions, and the following
   10  *    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 <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: stable/8/sys/mips/atheros/ar71xx_ohci.c 308404 2016-11-07 09:27:05Z hselasky $");
   30 
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/bus.h>
   34 #include <sys/rman.h>
   35 #include <sys/condvar.h>
   36 #include <sys/kernel.h>
   37 #include <sys/module.h>
   38 
   39 #include <dev/usb/usb.h>
   40 #include <dev/usb/usbdi.h>
   41 
   42 #include <dev/usb/usb_core.h>
   43 #include <dev/usb/usb_busdma.h>
   44 #include <dev/usb/usb_process.h>
   45 #include <dev/usb/usb_util.h>
   46 
   47 #include <dev/usb/usb_controller.h>
   48 #include <dev/usb/usb_bus.h>
   49 #include <dev/usb/controller/ohci.h>
   50 #include <dev/usb/controller/ohcireg.h>
   51 
   52 #include <sys/rman.h>
   53 
   54 static int ar71xx_ohci_attach(device_t dev);
   55 static int ar71xx_ohci_detach(device_t dev);
   56 static int ar71xx_ohci_probe(device_t dev);
   57 
   58 struct ar71xx_ohci_softc
   59 {
   60         struct ohci_softc sc_ohci;
   61 };
   62 
   63 static int
   64 ar71xx_ohci_probe(device_t dev)
   65 {
   66         device_set_desc(dev, "AR71XX integrated OHCI controller");
   67         return (BUS_PROBE_DEFAULT);
   68 }
   69 
   70 static int
   71 ar71xx_ohci_attach(device_t dev)
   72 {
   73         struct ar71xx_ohci_softc *sc = device_get_softc(dev);
   74         int err;
   75         int rid;
   76 
   77         /* initialise some bus fields */
   78         sc->sc_ohci.sc_bus.parent = dev;
   79         sc->sc_ohci.sc_bus.devices = sc->sc_ohci.sc_devices;
   80         sc->sc_ohci.sc_bus.devices_max = OHCI_MAX_DEVICES;
   81 
   82         /* get all DMA memory */
   83         if (usb_bus_mem_alloc_all(&sc->sc_ohci.sc_bus,
   84             USB_GET_DMA_TAG(dev), &ohci_iterate_hw_softc)) {
   85                 return (ENOMEM);
   86         }
   87 
   88         sc->sc_ohci.sc_dev = dev;
   89 
   90         rid = 0;
   91         sc->sc_ohci.sc_io_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
   92             RF_ACTIVE);
   93         if (sc->sc_ohci.sc_io_res == NULL) {
   94                 err = ENOMEM;
   95                 goto error;
   96         }
   97         sc->sc_ohci.sc_io_tag = rman_get_bustag(sc->sc_ohci.sc_io_res);
   98         sc->sc_ohci.sc_io_hdl = rman_get_bushandle(sc->sc_ohci.sc_io_res);
   99         sc->sc_ohci.sc_io_size = rman_get_size(sc->sc_ohci.sc_io_res);
  100 
  101         rid = 0;
  102         sc->sc_ohci.sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
  103             RF_ACTIVE);
  104         if (sc->sc_ohci.sc_irq_res == NULL) {
  105                 err = ENOMEM;
  106                 goto error;
  107         }
  108         sc->sc_ohci.sc_bus.bdev = device_add_child(dev, "usbus", -1);
  109         if (sc->sc_ohci.sc_bus.bdev == NULL) {
  110                 err = ENOMEM;
  111                 goto error;
  112         }
  113         device_set_ivars(sc->sc_ohci.sc_bus.bdev, &sc->sc_ohci.sc_bus);
  114 
  115         err = bus_setup_intr(dev, sc->sc_ohci.sc_irq_res, 
  116             INTR_TYPE_BIO | INTR_MPSAFE, NULL, 
  117             (driver_intr_t *)ohci_interrupt, sc, &sc->sc_ohci.sc_intr_hdl);
  118         if (err) {
  119                 err = ENXIO;
  120                 goto error;
  121         }
  122 
  123         strlcpy(sc->sc_ohci.sc_vendor, "Atheros", sizeof(sc->sc_ohci.sc_vendor));
  124 
  125         bus_space_write_4(sc->sc_ohci.sc_io_tag, sc->sc_ohci.sc_io_hdl, OHCI_CONTROL, 0);
  126 
  127         err = ohci_init(&sc->sc_ohci);
  128         if (!err)
  129                 err = device_probe_and_attach(sc->sc_ohci.sc_bus.bdev);
  130 
  131         if (err)
  132                 goto error;
  133         return (0);
  134 
  135 error:
  136         if (err) {
  137                 ar71xx_ohci_detach(dev);
  138                 return (err);
  139         }
  140         return (err);
  141 }
  142 
  143 static int
  144 ar71xx_ohci_detach(device_t dev)
  145 {
  146         struct ar71xx_ohci_softc *sc = device_get_softc(dev);
  147 
  148         /* during module unload there are lots of children leftover */
  149         device_delete_all_children(dev);
  150 
  151         /*
  152          * Put the controller into reset, then disable clocks and do
  153          * the MI tear down.  We have to disable the clocks/hardware
  154          * after we do the rest of the teardown.  We also disable the
  155          * clocks in the opposite order we acquire them, but that
  156          * doesn't seem to be absolutely necessary.  We free up the
  157          * clocks after we disable them, so the system could, in
  158          * theory, reuse them.
  159          */
  160         bus_space_write_4(sc->sc_ohci.sc_io_tag, sc->sc_ohci.sc_io_hdl,
  161             OHCI_CONTROL, 0);
  162 
  163         if (sc->sc_ohci.sc_intr_hdl) {
  164                 bus_teardown_intr(dev, sc->sc_ohci.sc_irq_res, sc->sc_ohci.sc_intr_hdl);
  165                 sc->sc_ohci.sc_intr_hdl = NULL;
  166         }
  167 
  168         if (sc->sc_ohci.sc_irq_res && sc->sc_ohci.sc_intr_hdl) {
  169                 /*
  170                  * only call ohci_detach() after ohci_init()
  171                  */
  172                 ohci_detach(&sc->sc_ohci);
  173 
  174                 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_ohci.sc_irq_res);
  175                 sc->sc_ohci.sc_irq_res = NULL;
  176         }
  177         if (sc->sc_ohci.sc_io_res) {
  178                 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_ohci.sc_io_res);
  179                 sc->sc_ohci.sc_io_res = NULL;
  180                 sc->sc_ohci.sc_io_tag = 0;
  181                 sc->sc_ohci.sc_io_hdl = 0;
  182         }
  183         usb_bus_mem_free_all(&sc->sc_ohci.sc_bus, &ohci_iterate_hw_softc);
  184 
  185         return (0);
  186 }
  187 
  188 static device_method_t ohci_methods[] = {
  189         /* Device interface */
  190         DEVMETHOD(device_probe, ar71xx_ohci_probe),
  191         DEVMETHOD(device_attach, ar71xx_ohci_attach),
  192         DEVMETHOD(device_detach, ar71xx_ohci_detach),
  193         DEVMETHOD(device_suspend, bus_generic_suspend),
  194         DEVMETHOD(device_resume, bus_generic_resume),
  195         DEVMETHOD(device_shutdown, bus_generic_shutdown),
  196 
  197         DEVMETHOD_END
  198 };
  199 
  200 static driver_t ohci_driver = {
  201         .name = "ohci",
  202         .methods = ohci_methods,
  203         .size = sizeof(struct ar71xx_ohci_softc),
  204 };
  205 
  206 static devclass_t ohci_devclass;
  207 
  208 DRIVER_MODULE(ohci, apb, ohci_driver, ohci_devclass, 0, 0);

Cache object: 157d435542498b16f9fda4c3cc931a38


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.