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/rmi/xls_ehci.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1998 The NetBSD Foundation, Inc.
    3  * All rights reserved.
    4  *
    5  * This code is derived from software contributed to The NetBSD Foundation
    6  * by Lennart Augustsson (augustss@carlstedt.se) at
    7  * Carlstedt Research & Technology.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  *
   18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   28  * POSSIBILITY OF SUCH DAMAGE.
   29  */
   30 
   31 #include <sys/cdefs.h>
   32 __FBSDID("$FreeBSD: releng/9.0/sys/mips/rmi/xls_ehci.c 220558 2011-04-12 07:49:11Z hselasky $");
   33 
   34 #include "opt_bus.h"
   35 
   36 #include <sys/stdint.h>
   37 #include <sys/stddef.h>
   38 #include <sys/param.h>
   39 #include <sys/queue.h>
   40 #include <sys/types.h>
   41 #include <sys/systm.h>
   42 #include <sys/kernel.h>
   43 #include <sys/bus.h>
   44 #include <sys/module.h>
   45 #include <sys/lock.h>
   46 #include <sys/mutex.h>
   47 #include <sys/condvar.h>
   48 #include <sys/sysctl.h>
   49 #include <sys/sx.h>
   50 #include <sys/unistd.h>
   51 #include <sys/callout.h>
   52 #include <sys/malloc.h>
   53 #include <sys/priv.h>
   54 
   55 #include <sys/rman.h>
   56 #include <machine/resource.h>
   57 
   58 #include <dev/usb/usb.h>
   59 #include <dev/usb/usbdi.h>
   60 
   61 #include <dev/usb/usb_core.h>
   62 #include <dev/usb/usb_busdma.h>
   63 #include <dev/usb/usb_process.h>
   64 #include <dev/usb/usb_util.h>
   65 
   66 #include <dev/usb/usb_controller.h>
   67 #include <dev/usb/usb_bus.h>
   68 #include <dev/usb/controller/ehci.h>
   69 #include <dev/usb/controller/ehcireg.h>
   70 #include <mips/rmi/pic.h>
   71 
   72 static int ehci_xls_attach(device_t self);
   73 static int ehci_xls_detach(device_t self);
   74 static int ehci_xls_shutdown(device_t self);
   75 static int ehci_xls_suspend(device_t self);
   76 static int ehci_xls_resume(device_t self);
   77 
   78 static int
   79 ehci_xls_suspend(device_t self)
   80 {
   81         ehci_softc_t *sc = device_get_softc(self);
   82         int err;
   83 
   84         err = bus_generic_suspend(self);
   85         if (err)
   86                 return (err);
   87         ehci_suspend(sc);
   88         return (0);
   89 }
   90 
   91 static int
   92 ehci_xls_resume(device_t self)
   93 {
   94         ehci_softc_t *sc = device_get_softc(self);
   95 
   96         ehci_resume(sc);
   97 
   98         bus_generic_resume(self);
   99 
  100         return (0);
  101 }
  102 
  103 static int
  104 ehci_xls_shutdown(device_t self)
  105 {
  106         ehci_softc_t *sc = device_get_softc(self);
  107         int err;
  108 
  109         err = bus_generic_shutdown(self);
  110         if (err)
  111                 return (err);
  112         ehci_shutdown(sc);
  113 
  114         return (0);
  115 }
  116 
  117 static const char *xlr_usb_dev_desc = "RMI XLR USB 2.0 controller";
  118 static const char *xlr_vendor_desc = "RMI Corp";
  119 
  120 static int
  121 ehci_xls_probe(device_t self)
  122 {
  123         /* TODO see if usb is enabled on the board */
  124         device_set_desc(self, xlr_usb_dev_desc);
  125         return BUS_PROBE_DEFAULT;
  126 }
  127 
  128 static int
  129 ehci_xls_attach(device_t self)
  130 {
  131         ehci_softc_t *sc = device_get_softc(self);
  132         int err;
  133         int rid;
  134 
  135         sc->sc_bus.parent = self;
  136         sc->sc_bus.devices = sc->sc_devices;
  137         sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
  138 
  139         /* get all DMA memory */
  140         if (usb_bus_mem_alloc_all(&sc->sc_bus,
  141             USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) {
  142                 return (ENOMEM);
  143         }
  144 
  145         rid = 0;
  146         sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid,
  147             RF_ACTIVE);
  148         if (!sc->sc_io_res) {
  149                 device_printf(self, "Could not map memory\n");
  150                 goto error;
  151         }
  152         sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
  153         sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
  154         printf("IO Resource tag %lx, hdl %lx, size %lx\n",
  155                (u_long)sc->sc_io_tag, (u_long)sc->sc_io_hdl, 
  156                (u_long)sc->sc_io_size);
  157 
  158         rid = 0;
  159         sc->sc_irq_res = bus_alloc_resource(self, SYS_RES_IRQ, &rid,
  160             PIC_USB_IRQ, PIC_USB_IRQ, 1, RF_SHAREABLE | RF_ACTIVE);
  161         if (sc->sc_irq_res == NULL) {
  162                 device_printf(self, "Could not allocate irq\n");
  163                 goto error;
  164         }
  165 
  166         sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
  167         if (!sc->sc_bus.bdev) {
  168                 device_printf(self, "Could not add USB device\n");
  169                 goto error;
  170         }
  171         device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
  172         device_set_desc(sc->sc_bus.bdev, xlr_usb_dev_desc);
  173 
  174         sprintf(sc->sc_vendor, xlr_vendor_desc);
  175 
  176         err = bus_setup_intr(self, sc->sc_irq_res,
  177             INTR_TYPE_BIO | INTR_MPSAFE, NULL,
  178             (driver_intr_t *) ehci_interrupt, sc, &sc->sc_intr_hdl);
  179         if (err) {
  180                 device_printf(self, "Could not setup irq, %d\n", err);
  181                 sc->sc_intr_hdl = NULL;
  182                 goto error;
  183         }
  184 
  185         err = ehci_init(sc);
  186         if (err) {
  187                 device_printf(self, "USB init failed err=%d\n", err);
  188                 goto error;
  189         }
  190 
  191         err = device_probe_and_attach(sc->sc_bus.bdev);
  192         if (err) {
  193                 device_printf(self, "USB probe and attach failed err=%d\n", err);
  194                 goto error;
  195         }
  196 
  197         return (0);
  198 
  199 error:
  200         ehci_xls_detach(self);
  201         return (ENXIO);
  202 }
  203 
  204 static int
  205 ehci_xls_detach(device_t self)
  206 {
  207         ehci_softc_t *sc = device_get_softc(self);
  208         device_t bdev;
  209         int err;
  210 
  211         if (sc->sc_bus.bdev) {
  212                 bdev = sc->sc_bus.bdev;
  213                 device_detach(bdev);
  214                 device_delete_child(self, bdev);
  215         }
  216         /* during module unload there are lots of children leftover */
  217         device_delete_all_children(self);
  218 
  219         if (sc->sc_irq_res && sc->sc_intr_hdl) {
  220                 ehci_detach(sc);
  221 
  222                 err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl);
  223                 if (err)
  224                         device_printf(self, "Could not tear down irq, %d\n",
  225                             err);
  226                 sc->sc_intr_hdl = 0;
  227         }
  228 
  229         if (sc->sc_irq_res) {
  230                 bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res);
  231                 sc->sc_irq_res = NULL;
  232         }
  233         if (sc->sc_io_res) {
  234                 bus_release_resource(self, SYS_RES_MEMORY, 0,
  235                     sc->sc_io_res);
  236                 sc->sc_io_res = NULL;
  237                 sc->sc_io_tag = 0;
  238                 sc->sc_io_hdl = 0;
  239         }
  240 
  241         usb_bus_mem_free_all(&sc->sc_bus, &ehci_iterate_hw_softc);
  242 
  243         return (0);
  244 }
  245 
  246 static device_method_t ehci_methods[] = {
  247         /* Device interface */
  248         DEVMETHOD(device_probe, ehci_xls_probe),
  249         DEVMETHOD(device_attach, ehci_xls_attach),
  250         DEVMETHOD(device_detach, ehci_xls_detach),
  251         DEVMETHOD(device_suspend, ehci_xls_suspend),
  252         DEVMETHOD(device_resume, ehci_xls_resume),
  253         DEVMETHOD(device_shutdown, ehci_xls_shutdown),
  254 
  255         /* Bus interface */
  256         DEVMETHOD(bus_print_child, bus_generic_print_child),
  257 
  258         {0, 0}
  259 };
  260 
  261 static driver_t ehci_driver = {
  262         "ehci",
  263         ehci_methods,
  264         sizeof(struct ehci_softc),
  265 };
  266 
  267 static devclass_t ehci_devclass;
  268 
  269 DRIVER_MODULE(ehci, iodi, ehci_driver, ehci_devclass, 0, 0);
  270 MODULE_DEPEND(ehci, usb, 1, 1, 1);

Cache object: 022a6c45c9b51597f1deff6ec9add0d5


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