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

Cache object: 0d8bcf14404df4979014a7995e5d1252


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