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_ehci.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) 2008 Sam Leffler.  All rights reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  *
   13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   23  */
   24 
   25 /*
   26  * AR71XX attachment driver for the USB Enhanced Host Controller.
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __FBSDID("$FreeBSD: stable/8/sys/mips/atheros/ar71xx_ehci.c 308404 2016-11-07 09:27:05Z hselasky $");
   31 
   32 #include "opt_bus.h"
   33 
   34 #include <sys/param.h>
   35 #include <sys/systm.h>
   36 #include <sys/bus.h>
   37 #include <sys/rman.h>
   38 #include <sys/condvar.h>
   39 #include <sys/kernel.h>
   40 #include <sys/module.h>
   41 
   42 #include <machine/bus.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 #include <dev/usb/controller/ehci.h>
   55 #include <dev/usb/controller/ehcireg.h>
   56 
   57 #include <mips/atheros/ar71xx_bus_space_reversed.h>
   58 
   59 #define EHCI_HC_DEVSTR          "AR71XX Integrated USB 2.0 controller"
   60 
   61 struct ar71xx_ehci_softc {
   62         ehci_softc_t            base;   /* storage for EHCI code */
   63 };
   64 
   65 static device_attach_t ar71xx_ehci_attach;
   66 static device_detach_t ar71xx_ehci_detach;
   67 
   68 bs_r_1_proto(reversed);
   69 bs_w_1_proto(reversed);
   70 
   71 static int
   72 ar71xx_ehci_probe(device_t self)
   73 {
   74 
   75         device_set_desc(self, EHCI_HC_DEVSTR);
   76 
   77         return (BUS_PROBE_DEFAULT);
   78 }
   79 
   80 static int
   81 ar71xx_ehci_attach(device_t self)
   82 {
   83         struct ar71xx_ehci_softc *isc = device_get_softc(self);
   84         ehci_softc_t *sc = &isc->base;
   85         int err;
   86         int rid;
   87 
   88         /* initialise some bus fields */
   89         sc->sc_bus.parent = self;
   90         sc->sc_bus.devices = sc->sc_devices;
   91         sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
   92 
   93         /* get all DMA memory */
   94         if (usb_bus_mem_alloc_all(&sc->sc_bus,
   95             USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) {
   96                 return (ENOMEM);
   97         }
   98 
   99         sc->sc_bus.usbrev = USB_REV_2_0;
  100 
  101         /* NB: hints fix the memory location and irq */
  102 
  103         rid = 0;
  104         sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid, RF_ACTIVE);
  105         if (!sc->sc_io_res) {
  106                 device_printf(self, "Could not map memory\n");
  107                 goto error;
  108         }
  109 
  110         /*
  111          * Craft special resource for bus space ops that handle
  112          * byte-alignment of non-word addresses.  
  113          */
  114         sc->sc_io_tag = ar71xx_bus_space_reversed;
  115         sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
  116         sc->sc_io_size = rman_get_size(sc->sc_io_res);
  117 
  118         rid = 0;
  119         sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid,
  120             RF_ACTIVE);
  121         if (sc->sc_irq_res == NULL) {
  122                 device_printf(self, "Could not allocate irq\n");
  123                 goto error;
  124         }
  125         sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
  126         if (!sc->sc_bus.bdev) {
  127                 device_printf(self, "Could not add USB device\n");
  128                 goto error;
  129         }
  130         device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
  131         device_set_desc(sc->sc_bus.bdev, EHCI_HC_DEVSTR);
  132 
  133         sprintf(sc->sc_vendor, "Atheros");
  134 
  135 
  136         err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
  137             NULL, (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl);
  138         if (err) {
  139                 device_printf(self, "Could not setup irq, %d\n", err);
  140                 sc->sc_intr_hdl = NULL;
  141                 goto error;
  142         }
  143 
  144         /*
  145          * Arrange to force Host mode, select big-endian byte alignment,
  146          * and arrange to not terminate reset operations (the adapter
  147          * will ignore it if we do but might as well save a reg write).
  148          * Also, the controller has an embedded Transaction Translator
  149          * which means port speed must be read from the Port Status
  150          * register following a port enable.
  151          */
  152         sc->sc_flags = EHCI_SCFLG_SETMODE;
  153         (void) ehci_reset(sc);
  154 
  155         err = ehci_init(sc);
  156         if (!err) {
  157                 err = device_probe_and_attach(sc->sc_bus.bdev);
  158         }
  159         if (err) {
  160                 device_printf(self, "USB init failed err=%d\n", err);
  161                 goto error;
  162         }
  163         return (0);
  164 
  165 error:
  166         ar71xx_ehci_detach(self);
  167         return (ENXIO);
  168 }
  169 
  170 static int
  171 ar71xx_ehci_detach(device_t self)
  172 {
  173         struct ar71xx_ehci_softc *isc = device_get_softc(self);
  174         ehci_softc_t *sc = &isc->base;
  175         int err;
  176 
  177         /* during module unload there are lots of children leftover */
  178         device_delete_all_children(self);
  179 
  180         if (sc->sc_irq_res && sc->sc_intr_hdl) {
  181                 /*
  182                  * only call ehci_detach() after ehci_init()
  183                  */
  184                 ehci_detach(sc);
  185 
  186                 err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl);
  187 
  188                 if (err)
  189                         /* XXX or should we panic? */
  190                         device_printf(self, "Could not tear down irq, %d\n",
  191                             err);
  192                 sc->sc_intr_hdl = NULL;
  193         }
  194 
  195         if (sc->sc_irq_res) {
  196                 bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res);
  197                 sc->sc_irq_res = NULL;
  198         }
  199         if (sc->sc_io_res) {
  200                 bus_release_resource(self, SYS_RES_MEMORY, 0,
  201                     sc->sc_io_res);
  202                 sc->sc_io_res = NULL;
  203         }
  204         usb_bus_mem_free_all(&sc->sc_bus, &ehci_iterate_hw_softc);
  205 
  206         return (0);
  207 }
  208 
  209 static device_method_t ehci_methods[] = {
  210         /* Device interface */
  211         DEVMETHOD(device_probe, ar71xx_ehci_probe),
  212         DEVMETHOD(device_attach, ar71xx_ehci_attach),
  213         DEVMETHOD(device_detach, ar71xx_ehci_detach),
  214         DEVMETHOD(device_suspend, bus_generic_suspend),
  215         DEVMETHOD(device_resume, bus_generic_resume),
  216         DEVMETHOD(device_shutdown, bus_generic_shutdown),
  217 
  218         DEVMETHOD_END
  219 };
  220 
  221 static driver_t ehci_driver = {
  222         .name = "ehci",
  223         .methods = ehci_methods,
  224         .size = sizeof(struct ar71xx_ehci_softc),
  225 };
  226 
  227 static devclass_t ehci_devclass;
  228 
  229 DRIVER_MODULE(ehci, nexus, ehci_driver, ehci_devclass, 0, 0);
  230 MODULE_DEPEND(ehci, usb, 1, 1, 1);

Cache object: 77744c836d7571f9fdbe398427355be2


[ 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.