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/dev/pcf/envctrl.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) 2004 Joerg Wunsch
    3  *
    4  * derived from sys/i386/isa/pcf.c which is:
    5  *
    6  * Copyright (c) 1998 Nicolas Souchu, Marc Bouget
    7  * All rights reserved.
    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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   28  * SUCH DAMAGE.
   29  */
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD: src/sys/dev/pcf/envctrl.c,v 1.4 2004/08/12 17:41:30 marius Exp $");
   32 
   33 /*
   34  * Device specific driver for the SUNW,envctrl device found on some
   35  * UltraSPARC Sun systems.  This device is a Philips PCF8584 sitting
   36  * on the Ebus2.
   37  */
   38 
   39 #include <sys/param.h>
   40 #include <sys/systm.h>
   41 #include <sys/bus.h>
   42 #include <sys/conf.h>
   43 #include <sys/kernel.h>
   44 #include <sys/malloc.h>
   45 #include <sys/module.h>
   46 #include <sys/resource.h>
   47 #include <sys/uio.h>
   48 
   49 #include <dev/ofw/ofw_bus.h>
   50 
   51 #include <machine/bus.h>
   52 #include <machine/resource.h>
   53 
   54 #include <sys/rman.h>
   55 
   56 #include <dev/iicbus/iiconf.h>
   57 #include <dev/pcf/pcfvar.h>
   58 #include "iicbus_if.h"
   59 
   60 #undef PCF_DEFAULT_ADDR
   61 #define PCF_DEFAULT_ADDR        0x55 /* SUNW,pcf default */
   62 
   63 static int envctrl_probe(device_t);
   64 static int envctrl_attach(device_t);
   65 static int envctrl_detach(device_t);
   66 
   67 static device_method_t envctrl_methods[] = {
   68         /* device interface */
   69         DEVMETHOD(device_probe,         envctrl_probe),
   70         DEVMETHOD(device_attach,        envctrl_attach),
   71         DEVMETHOD(device_detach,        envctrl_detach),
   72 
   73         /* iicbus interface */
   74         DEVMETHOD(iicbus_callback,      iicbus_null_callback),
   75         DEVMETHOD(iicbus_repeated_start, pcf_repeated_start),
   76         DEVMETHOD(iicbus_start,         pcf_start),
   77         DEVMETHOD(iicbus_stop,          pcf_stop),
   78         DEVMETHOD(iicbus_write,         pcf_write),
   79         DEVMETHOD(iicbus_read,          pcf_read),
   80         DEVMETHOD(iicbus_reset,         pcf_rst_card),
   81         { 0, 0 }
   82 };
   83 
   84 static devclass_t envctrl_devclass;
   85 
   86 static driver_t envctrl_driver = {
   87         "envctrl",
   88         envctrl_methods,
   89         sizeof(struct pcf_softc),
   90 };
   91 
   92 static int
   93 envctrl_probe(device_t dev)
   94 {
   95 
   96         if (strcmp("SUNW,envctrl", ofw_bus_get_name(dev)) == 0) {
   97                 device_set_desc(dev, "EBus SUNW,envctrl");
   98                 return (0);
   99         }
  100         return (ENXIO);
  101 }
  102 
  103 static int
  104 envctrl_attach(device_t dev)
  105 {
  106         struct pcf_softc *sc;
  107         int rv = ENXIO;
  108 
  109         sc = DEVTOSOFTC(dev);
  110         bzero(sc, sizeof(struct pcf_softc));
  111 
  112         /* IO port is mandatory */
  113         sc->res_ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
  114                                                 &sc->rid_ioport, RF_ACTIVE);
  115         if (sc->res_ioport == 0) {
  116                 device_printf(dev, "cannot reserve I/O port range\n");
  117                 goto error;
  118         }
  119         sc->bt_ioport = rman_get_bustag(sc->res_ioport);
  120         sc->bh_ioport = rman_get_bushandle(sc->res_ioport);
  121 
  122         sc->pcf_flags = device_get_flags(dev);
  123 
  124         if (!(sc->pcf_flags & IIC_POLLED)) {
  125                 sc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->rid_irq,
  126                                                      RF_ACTIVE);
  127                 if (sc->res_irq == 0) {
  128                         device_printf(dev, "can't reserve irq, polled mode.\n");
  129                         sc->pcf_flags |= IIC_POLLED;
  130                 }
  131         }
  132 
  133         /* reset the chip */
  134         pcf_rst_card(dev, IIC_FASTEST, PCF_DEFAULT_ADDR, NULL);
  135 
  136         rv = BUS_SETUP_INTR(device_get_parent(dev), dev, sc->res_irq,
  137                             INTR_TYPE_NET /* | INTR_ENTROPY */,
  138                             pcf_intr, sc, &sc->intr_cookie);
  139         if (rv) {
  140                 device_printf(dev, "could not setup IRQ\n");
  141                 goto error;
  142         }
  143 
  144         if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL)
  145                 device_printf(dev, "could not allocate iicbus instance\n");
  146 
  147         /* probe and attach the iicbus */
  148         bus_generic_attach(dev);
  149 
  150         return (0);
  151 
  152 error:
  153         if (sc->res_irq != 0) {
  154                 bus_deactivate_resource(dev, SYS_RES_IRQ, sc->rid_irq,
  155                                         sc->res_irq);
  156                 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq,
  157                                      sc->res_irq);
  158         }
  159         if (sc->res_ioport != 0) {
  160                 bus_deactivate_resource(dev, SYS_RES_IOPORT, sc->rid_ioport,
  161                                         sc->res_ioport);
  162                 bus_release_resource(dev, SYS_RES_IOPORT, sc->rid_ioport,
  163                                      sc->res_ioport);
  164         }
  165         return (rv);
  166 }
  167 
  168 static int
  169 envctrl_detach(device_t dev)
  170 {
  171         struct pcf_softc *sc;
  172         int rv;
  173 
  174         sc = DEVTOSOFTC(dev);
  175 
  176         if ((rv = bus_generic_detach(dev)) != 0)
  177                 return (rv);
  178 
  179         if ((rv = device_delete_child(dev, sc->iicbus)) != 0)
  180                 return (rv);
  181 
  182         if (sc->res_irq != 0) {
  183                 BUS_TEARDOWN_INTR(device_get_parent(dev), dev, sc->res_irq,
  184                                   sc->intr_cookie);
  185                 bus_deactivate_resource(dev, SYS_RES_IRQ, sc->rid_irq, sc->res_irq);
  186                 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq, sc->res_irq);
  187         }
  188 
  189         bus_deactivate_resource(dev, SYS_RES_IOPORT, sc->rid_ioport, sc->res_ioport);
  190         bus_release_resource(dev, SYS_RES_IOPORT, sc->rid_ioport, sc->res_ioport);
  191 
  192         return (0);
  193 }
  194 
  195 DRIVER_MODULE(envctrl, ebus, envctrl_driver, envctrl_devclass, 0, 0);
  196 MODULE_DEPEND(envctrl, iicbus, PCF_MINVER, PCF_PREFVER, PCF_MAXVER);
  197 MODULE_VERSION(envctrl, PCF_MODVER);

Cache object: ac08b8339c660eeac1acb56228760fc3


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