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/pcf_ebus.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 Marius Strobl, 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/pcf_ebus.c,v 1.3 2004/08/12 17:41:30 marius Exp $");
   32 
   33 /*
   34  * Device specific driver for the EBus i2c devices found on some sun4u
   35  * systems. On systems not having a boot-bus controller the i2c devices
   36  * are PCF8584.
   37  *
   38  * Known onboard slave devices on the primary bus are:
   39  *
   40  * AXe:
   41  *      0x40    PCF8574 I/O     fan status (CPU fans 1+2)
   42  *      0x9e    PCF8591 A/D     temperature (CPU + hotspot)
   43  *
   44  * AXmp:
   45  *      0x70    PCF8574 I/O     fan status (fans 1-4)
   46  *      0x78    PCF8574 I/O     fan fail interrupt
   47  *      0x9a    PCF8591 A/D     voltage (CPU core)
   48  *      0x9c    PCF8591 A/D     temperature (hotspots 1+2, aux. analog 1+2)
   49  *      0x9e    PCF8591 A/D     temperature (CPUs 1-4)
   50  *
   51  * CP1400:
   52  *      0x70    PCF8574 I/O     reserved for factory use
   53  *      0x9e    PCF8591 A/D     temperature (CPU)
   54  *
   55  * CP1500:
   56  *      0x70    PCF8574 I/O     reserved for factory use
   57  *      0x72    PCF8574 I/O     geographic address + power supply status lines
   58  *      0x9e    PCF8591 A/D     temperature (CPU)
   59  *      0xa0    AT24C01A        hostid
   60  *
   61  * For AXmp, CP1400 and CP1500 these are described in more detail in:
   62  * http://www.sun.com/oem/products/manuals/805-7581-04.pdf
   63  *
   64  */
   65 
   66 #include <sys/param.h>
   67 #include <sys/systm.h>
   68 #include <sys/bus.h>
   69 #include <sys/kernel.h>
   70 #include <sys/module.h>
   71 #include <sys/resource.h>
   72 
   73 #include <dev/ofw/ofw_bus.h>
   74 #include <dev/ofw/openfirm.h>
   75 
   76 #include <machine/bus.h>
   77 #include <machine/resource.h>
   78 
   79 #include <sys/rman.h>
   80 
   81 #include <dev/iicbus/iiconf.h>
   82 #include <dev/pcf/pcfvar.h>
   83 #include "iicbus_if.h"
   84 
   85 #define PCF_NAME        "pcf"
   86 
   87 static int pcf_ebus_probe(device_t);
   88 static int pcf_ebus_attach(device_t);
   89 static int pcf_ebus_detach(device_t);
   90 
   91 static device_method_t pcf_ebus_methods[] = {
   92         /* device interface */
   93         DEVMETHOD(device_probe,         pcf_ebus_probe),
   94         DEVMETHOD(device_attach,        pcf_ebus_attach),
   95         DEVMETHOD(device_detach,        pcf_ebus_detach),
   96 
   97         /* iicbus interface */
   98         DEVMETHOD(iicbus_callback,      iicbus_null_callback),
   99         DEVMETHOD(iicbus_repeated_start, pcf_repeated_start),
  100         DEVMETHOD(iicbus_start,         pcf_start),
  101         DEVMETHOD(iicbus_stop,          pcf_stop),
  102         DEVMETHOD(iicbus_write,         pcf_write),
  103         DEVMETHOD(iicbus_read,          pcf_read),
  104         DEVMETHOD(iicbus_reset,         pcf_rst_card),
  105         { 0, 0 }
  106 };
  107 
  108 static devclass_t pcf_ebus_devclass;
  109 
  110 static driver_t pcf_ebus_driver = {
  111         PCF_NAME,
  112         pcf_ebus_methods,
  113         sizeof(struct pcf_softc),
  114 };
  115 
  116 static int
  117 pcf_ebus_probe(device_t dev)
  118 {
  119         const char *compat;
  120 
  121         /*
  122          * We must not attach to this i2c device if this is a system with
  123          * a boot-bus controller. Additionally testing the compatibility
  124          * property will hopefully take care of this.
  125          */
  126         if (strcmp("i2c", ofw_bus_get_name(dev)) == 0) {
  127                 compat = ofw_bus_get_compat(dev);
  128                 if (compat != NULL && strcmp("i2cpcf,8584", compat) == 0) {
  129                         device_set_desc(dev, "PCF8584 I2C bus controller");
  130                         return (0);
  131                 }
  132         }
  133         return (ENXIO);
  134 }
  135 
  136 static int
  137 pcf_ebus_attach(device_t dev)
  138 {
  139         struct pcf_softc *sc;
  140         int rv = ENXIO;
  141         phandle_t node;
  142         uint64_t own_addr;
  143 
  144         sc = DEVTOSOFTC(dev);
  145         bzero(sc, sizeof(struct pcf_softc));
  146 
  147         /* get OFW node of the pcf */
  148         if ((node = ofw_bus_get_node(dev)) <= 0) {
  149                 device_printf(dev, "cannot get OFW node\n");
  150                 goto error;
  151         }
  152 
  153         /* IO port is mandatory */
  154         sc->res_ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
  155             &sc->rid_ioport, RF_ACTIVE);
  156         if (sc->res_ioport == 0) {
  157                 device_printf(dev, "cannot reserve I/O port range\n");
  158                 goto error;
  159         }
  160         sc->bt_ioport = rman_get_bustag(sc->res_ioport);
  161         sc->bh_ioport = rman_get_bushandle(sc->res_ioport);
  162 
  163         sc->pcf_flags = device_get_flags(dev);
  164 
  165         /*
  166          * XXX use poll-mode property?
  167          */
  168         if (!(sc->pcf_flags & IIC_POLLED)) {
  169                 sc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
  170                     &sc->rid_irq, RF_ACTIVE);
  171                 if (sc->res_irq == 0) {
  172                         device_printf(dev, "can't reserve irq, polled mode.\n");
  173                         sc->pcf_flags |= IIC_POLLED;
  174                 }
  175         }
  176 
  177         /*
  178          * XXX on AXmp there's probably a second IRQ which is the fan fail
  179          *     interrupt genererated by the PCF8574 at 0x78.
  180          */
  181 
  182         /* get address of the pcf */
  183         if (OF_getprop(node, "own-address", &own_addr, sizeof(own_addr)) ==
  184             -1) {
  185                 device_printf(dev, "cannot get own address\n");
  186                 goto error;
  187         }
  188         if (bootverbose)
  189                 device_printf(dev, "PCF8584 address: 0x%08llx\n", (unsigned
  190                     long long)own_addr);
  191 
  192         /* reset the chip */
  193         pcf_rst_card(dev, IIC_FASTEST, own_addr, NULL);
  194 
  195         if (sc->res_irq) {
  196                 rv = BUS_SETUP_INTR(device_get_parent(dev), dev, sc->res_irq,
  197                     INTR_TYPE_NET /* | INTR_ENTROPY */, pcf_intr, sc,
  198                     &sc->intr_cookie);
  199                 if (rv) {
  200                         device_printf(dev, "could not setup IRQ\n");
  201                         goto error;
  202                 }
  203         }
  204 
  205         if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL)
  206                 device_printf(dev, "could not allocate iicbus instance\n");
  207 
  208         /* probe and attach the iicbus */
  209         bus_generic_attach(dev);
  210 
  211         return (0);
  212 
  213 error:
  214         if (sc->res_irq != 0) {
  215                 bus_deactivate_resource(dev, SYS_RES_IRQ, sc->rid_irq,
  216                     sc->res_irq);
  217                 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq,
  218                     sc->res_irq);
  219         }
  220         if (sc->res_ioport != 0) {
  221                 bus_deactivate_resource(dev, SYS_RES_IOPORT, sc->rid_ioport,
  222                     sc->res_ioport);
  223                 bus_release_resource(dev, SYS_RES_IOPORT, sc->rid_ioport,
  224                     sc->res_ioport);
  225         }
  226         return (rv);
  227 }
  228 
  229 static int
  230 pcf_ebus_detach(device_t dev)
  231 {
  232         struct pcf_softc *sc;
  233         int rv;
  234 
  235         sc = DEVTOSOFTC(dev);
  236 
  237         if ((rv = bus_generic_detach(dev)) != 0)
  238                 return (rv);
  239 
  240         if ((rv = device_delete_child(dev, sc->iicbus)) != 0)
  241                 return (rv);
  242 
  243         if (sc->res_irq != 0) {
  244                 BUS_TEARDOWN_INTR(device_get_parent(dev), dev, sc->res_irq,
  245                     sc->intr_cookie);
  246                 bus_deactivate_resource(dev, SYS_RES_IRQ, sc->rid_irq,
  247                     sc->res_irq);
  248                 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq,
  249                     sc->res_irq);
  250         }
  251 
  252         bus_deactivate_resource(dev, SYS_RES_IOPORT, sc->rid_ioport,
  253             sc->res_ioport);
  254         bus_release_resource(dev, SYS_RES_IOPORT, sc->rid_ioport,
  255             sc->res_ioport);
  256 
  257         return (0);
  258 }
  259 
  260 DRIVER_MODULE(pcf_ebus, ebus, pcf_ebus_driver, pcf_ebus_devclass, 0, 0);
  261 MODULE_DEPEND(pcf_ebus, iicbus, PCF_MINVER, PCF_PREFVER, PCF_MAXVER);
  262 MODULE_VERSION(pcf_ebus, PCF_MODVER);

Cache object: a9bde6b6c790bac564409fdc21f79cf2


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