2 * Copyright (c) 2004 Marius Strobl, Joerg Wunsch
4 * derived from sys/i386/isa/pcf.c which is:
6 * Copyright (c) 1998 Nicolas Souchu, Marc Bouget
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
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
38 * Known onboard slave devices on the primary bus are:
41 * 0x40 PCF8574 I/O fan status (CPU fans 1+2)
42 * 0x9e PCF8591 A/D temperature (CPU + hotspot)
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)
52 * 0x70 PCF8574 I/O reserved for factory use
53 * 0x9e PCF8591 A/D temperature (CPU)
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
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
66 #include <sys/param.h>
69 #include <sys/kernel.h>
70 #include <sys/module.h>
71 #include <sys/mutex.h>
72 #include <sys/resource.h>
73 #include <sys/systm.h>
75 #include <dev/ofw/ofw_bus.h>
76 #include <dev/ofw/openfirm.h>
78 #include <machine/bus.h>
79 #include <machine/resource.h>
83 #include <dev/iicbus/iiconf.h>
84 #include <dev/pcf/pcfvar.h>
85 #include "iicbus_if.h"
87 #define PCF_NAME "pcf"
89 static int pcf_ebus_probe(device_t);
90 static int pcf_ebus_attach(device_t);
91 static int pcf_ebus_detach(device_t);
93 static device_method_t pcf_ebus_methods[] = {
94 /* device interface */
95 DEVMETHOD(device_probe, pcf_ebus_probe),
96 DEVMETHOD(device_attach, pcf_ebus_attach),
97 DEVMETHOD(device_detach, pcf_ebus_detach),
99 /* iicbus interface */
100 DEVMETHOD(iicbus_callback, iicbus_null_callback),
101 DEVMETHOD(iicbus_repeated_start, pcf_repeated_start),
102 DEVMETHOD(iicbus_start, pcf_start),
103 DEVMETHOD(iicbus_stop, pcf_stop),
104 DEVMETHOD(iicbus_write, pcf_write),
105 DEVMETHOD(iicbus_read, pcf_read),
106 DEVMETHOD(iicbus_reset, pcf_rst_card),
110 static devclass_t pcf_ebus_devclass;
112 static driver_t pcf_ebus_driver = {
115 sizeof(struct pcf_softc),
119 pcf_ebus_probe(device_t dev)
124 * We must not attach to this i2c device if this is a system with
125 * a boot-bus controller. Additionally testing the compatibility
126 * property will hopefully take care of this.
128 if (strcmp("i2c", ofw_bus_get_name(dev)) == 0) {
129 compat = ofw_bus_get_compat(dev);
130 if (compat != NULL && strcmp("i2cpcf,8584", compat) == 0) {
131 device_set_desc(dev, "PCF8584 I2C bus controller");
139 pcf_ebus_attach(device_t dev)
141 struct pcf_softc *sc;
146 sc = DEVTOSOFTC(dev);
147 mtx_init(&sc->pcf_lock, device_get_nameunit(dev), "pcf", MTX_DEF);
149 /* get OFW node of the pcf */
150 if ((node = ofw_bus_get_node(dev)) == -1) {
151 device_printf(dev, "cannot get OFW node\n");
155 /* IO port is mandatory */
156 sc->res_ioport = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
157 &sc->rid_ioport, RF_ACTIVE);
158 if (sc->res_ioport == 0) {
159 device_printf(dev, "cannot reserve I/O port range\n");
163 sc->pcf_flags = device_get_flags(dev);
166 * XXX use poll-mode property?
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;
178 * XXX on AXmp there's probably a second IRQ which is the fan fail
179 * interrupt genererated by the PCF8574 at 0x78.
182 /* get address of the pcf */
183 if (OF_getprop(node, "own-address", &own_addr, sizeof(own_addr)) ==
185 device_printf(dev, "cannot get own address\n");
189 device_printf(dev, "PCF8584 address: 0x%08llx\n", (unsigned
193 pcf_rst_card(dev, IIC_FASTEST, own_addr, NULL);
196 rv = bus_setup_intr(dev, sc->res_irq,
197 INTR_TYPE_NET /* | INTR_ENTROPY */, NULL, pcf_intr, sc,
200 device_printf(dev, "could not setup IRQ\n");
205 if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL)
206 device_printf(dev, "could not allocate iicbus instance\n");
208 /* probe and attach the iicbus */
209 bus_generic_attach(dev);
214 if (sc->res_irq != 0) {
215 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq,
218 if (sc->res_ioport != 0) {
219 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid_ioport,
222 mtx_destroy(&sc->pcf_lock);
227 pcf_ebus_detach(device_t dev)
229 struct pcf_softc *sc;
232 sc = DEVTOSOFTC(dev);
234 if ((rv = bus_generic_detach(dev)) != 0)
237 if ((rv = device_delete_child(dev, sc->iicbus)) != 0)
240 if (sc->res_irq != 0) {
241 bus_teardown_intr(dev, sc->res_irq,
243 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq,
247 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid_ioport,
249 mtx_destroy(&sc->pcf_lock);
254 DRIVER_MODULE(pcf_ebus, ebus, pcf_ebus_driver, pcf_ebus_devclass, 0, 0);