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-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) 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: stable/8/sys/mips/rmi/xls_ehci.c 308404 2016-11-07 09:27:05Z hselasky $");
   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/module.h>
   52 #include <sys/lock.h>
   53 #include <sys/mutex.h>
   54 #include <sys/condvar.h>
   55 #include <sys/sysctl.h>
   56 #include <sys/sx.h>
   57 #include <sys/unistd.h>
   58 #include <sys/callout.h>
   59 #include <sys/malloc.h>
   60 #include <sys/priv.h>
   61 
   62 #include <sys/rman.h>
   63 #include <machine/resource.h>
   64 
   65 #include <dev/usb/usb.h>
   66 #include <dev/usb/usbdi.h>
   67 
   68 #include <dev/usb/usb_core.h>
   69 #include <dev/usb/usb_busdma.h>
   70 #include <dev/usb/usb_process.h>
   71 #include <dev/usb/usb_util.h>
   72 
   73 #include <dev/usb/usb_controller.h>
   74 #include <dev/usb/usb_bus.h>
   75 #include <dev/usb/controller/ehci.h>
   76 #include <dev/usb/controller/ehcireg.h>
   77 #include <mips/rmi/pic.h>
   78 
   79 static device_attach_t ehci_xls_attach;
   80 static device_detach_t ehci_xls_detach;
   81 
   82 static const char *xlr_usb_dev_desc = "RMI XLR USB 2.0 controller";
   83 static const char *xlr_vendor_desc = "RMI Corp";
   84 
   85 static int
   86 ehci_xls_probe(device_t self)
   87 {
   88         /* TODO see if usb is enabled on the board */
   89         device_set_desc(self, xlr_usb_dev_desc);
   90         return BUS_PROBE_DEFAULT;
   91 }
   92 
   93 static int
   94 ehci_xls_attach(device_t self)
   95 {
   96         ehci_softc_t *sc = device_get_softc(self);
   97         int err;
   98         int rid;
   99 
  100         sc->sc_bus.parent = self;
  101         sc->sc_bus.devices = sc->sc_devices;
  102         sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
  103 
  104         /* get all DMA memory */
  105         if (usb_bus_mem_alloc_all(&sc->sc_bus,
  106             USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) {
  107                 return (ENOMEM);
  108         }
  109 
  110         rid = 0;
  111         sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid,
  112             RF_ACTIVE);
  113         if (!sc->sc_io_res) {
  114                 device_printf(self, "Could not map memory\n");
  115                 goto error;
  116         }
  117         sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
  118         sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
  119         printf("IO Resource tag %lx, hdl %lx, size %lx\n",
  120                (u_long)sc->sc_io_tag, (u_long)sc->sc_io_hdl, 
  121                (u_long)sc->sc_io_size);
  122 
  123         rid = 0;
  124         sc->sc_irq_res = bus_alloc_resource(self, SYS_RES_IRQ, &rid,
  125             PIC_USB_IRQ, PIC_USB_IRQ, 1, RF_SHAREABLE | RF_ACTIVE);
  126         if (sc->sc_irq_res == NULL) {
  127                 device_printf(self, "Could not allocate irq\n");
  128                 goto error;
  129         }
  130 
  131         sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
  132         if (!sc->sc_bus.bdev) {
  133                 device_printf(self, "Could not add USB device\n");
  134                 goto error;
  135         }
  136         device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
  137         device_set_desc(sc->sc_bus.bdev, xlr_usb_dev_desc);
  138 
  139         sprintf(sc->sc_vendor, xlr_vendor_desc);
  140 
  141         err = bus_setup_intr(self, sc->sc_irq_res,
  142             INTR_TYPE_BIO | INTR_MPSAFE, NULL,
  143             (driver_intr_t *) ehci_interrupt, sc, &sc->sc_intr_hdl);
  144         if (err) {
  145                 device_printf(self, "Could not setup irq, %d\n", err);
  146                 sc->sc_intr_hdl = NULL;
  147                 goto error;
  148         }
  149 
  150         err = ehci_init(sc);
  151         if (err) {
  152                 device_printf(self, "USB init failed err=%d\n", err);
  153                 goto error;
  154         }
  155 
  156         err = device_probe_and_attach(sc->sc_bus.bdev);
  157         if (err) {
  158                 device_printf(self, "USB probe and attach failed err=%d\n", err);
  159                 goto error;
  160         }
  161 
  162         return (0);
  163 
  164 error:
  165         ehci_xls_detach(self);
  166         return (ENXIO);
  167 }
  168 
  169 static int
  170 ehci_xls_detach(device_t self)
  171 {
  172         ehci_softc_t *sc = device_get_softc(self);
  173         int err;
  174 
  175         /* during module unload there are lots of children leftover */
  176         device_delete_all_children(self);
  177 
  178         if (sc->sc_irq_res && sc->sc_intr_hdl) {
  179                 ehci_detach(sc);
  180 
  181                 err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl);
  182                 if (err)
  183                         device_printf(self, "Could not tear down irq, %d\n",
  184                             err);
  185                 sc->sc_intr_hdl = 0;
  186         }
  187 
  188         if (sc->sc_irq_res) {
  189                 bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res);
  190                 sc->sc_irq_res = NULL;
  191         }
  192         if (sc->sc_io_res) {
  193                 bus_release_resource(self, SYS_RES_MEMORY, 0,
  194                     sc->sc_io_res);
  195                 sc->sc_io_res = NULL;
  196                 sc->sc_io_tag = 0;
  197                 sc->sc_io_hdl = 0;
  198         }
  199 
  200         usb_bus_mem_free_all(&sc->sc_bus, &ehci_iterate_hw_softc);
  201 
  202         return (0);
  203 }
  204 
  205 static device_method_t ehci_methods[] = {
  206         /* Device interface */
  207         DEVMETHOD(device_probe, ehci_xls_probe),
  208         DEVMETHOD(device_attach, ehci_xls_attach),
  209         DEVMETHOD(device_detach, ehci_xls_detach),
  210         DEVMETHOD(device_suspend, bus_generic_suspend),
  211         DEVMETHOD(device_resume, bus_generic_resume),
  212         DEVMETHOD(device_shutdown, bus_generic_shutdown),
  213 
  214         DEVMETHOD_END
  215 };
  216 
  217 static driver_t ehci_driver = {
  218         .name = "ehci",
  219         .methods = ehci_methods,
  220         .size = sizeof(struct ehci_softc),
  221 };
  222 
  223 static devclass_t ehci_devclass;
  224 
  225 DRIVER_MODULE(ehci, iodi, ehci_driver, ehci_devclass, 0, 0);
  226 MODULE_DEPEND(ehci, usb, 1, 1, 1);

Cache object: 153e6f082f7eaca3ebae6441e3d62952


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