2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004 Marius Strobl, Joerg Wunsch
6 * derived from sys/i386/isa/pcf.c which is:
8 * Copyright (c) 1998 Nicolas Souchu, Marc Bouget
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
36 * Device specific driver for the EBus i2c devices found on some sun4u
37 * systems. On systems not having a boot-bus controller the i2c devices
40 * Known onboard slave devices on the primary bus are:
43 * 0x40 PCF8574 I/O fan status (CPU fans 1+2)
44 * 0x9e PCF8591 A/D temperature (CPU + hotspot)
47 * 0x70 PCF8574 I/O fan status (fans 1-4)
48 * 0x78 PCF8574 I/O fan fail interrupt
49 * 0x9a PCF8591 A/D voltage (CPU core)
50 * 0x9c PCF8591 A/D temperature (hotspots 1+2, aux. analog 1+2)
51 * 0x9e PCF8591 A/D temperature (CPUs 1-4)
54 * 0x70 PCF8574 I/O reserved for factory use
55 * 0x9e PCF8591 A/D temperature (CPU)
58 * 0x70 PCF8574 I/O reserved for factory use
59 * 0x72 PCF8574 I/O geographic address + power supply status lines
60 * 0x9e PCF8591 A/D temperature (CPU)
61 * 0xa0 AT24C01A hostid
63 * For AXmp, CP1400 and CP1500 these are described in more detail in:
64 * http://www.sun.com/oem/products/manuals/805-7581-04.pdf
68 #include <sys/param.h>
71 #include <sys/kernel.h>
72 #include <sys/module.h>
73 #include <sys/mutex.h>
74 #include <sys/resource.h>
75 #include <sys/systm.h>
77 #include <dev/ofw/ofw_bus.h>
78 #include <dev/ofw/openfirm.h>
80 #include <machine/bus.h>
81 #include <machine/resource.h>
85 #include <dev/iicbus/iiconf.h>
86 #include <dev/pcf/pcfvar.h>
87 #include "iicbus_if.h"
89 #define PCF_NAME "pcf"
91 static int pcf_ebus_probe(device_t);
92 static int pcf_ebus_attach(device_t);
93 static int pcf_ebus_detach(device_t);
95 static device_method_t pcf_ebus_methods[] = {
96 /* device interface */
97 DEVMETHOD(device_probe, pcf_ebus_probe),
98 DEVMETHOD(device_attach, pcf_ebus_attach),
99 DEVMETHOD(device_detach, pcf_ebus_detach),
101 /* iicbus interface */
102 DEVMETHOD(iicbus_callback, iicbus_null_callback),
103 DEVMETHOD(iicbus_repeated_start, pcf_repeated_start),
104 DEVMETHOD(iicbus_start, pcf_start),
105 DEVMETHOD(iicbus_stop, pcf_stop),
106 DEVMETHOD(iicbus_write, pcf_write),
107 DEVMETHOD(iicbus_read, pcf_read),
108 DEVMETHOD(iicbus_reset, pcf_rst_card),
112 static devclass_t pcf_ebus_devclass;
114 static driver_t pcf_ebus_driver = {
117 sizeof(struct pcf_softc),
121 pcf_ebus_probe(device_t dev)
126 * We must not attach to this i2c device if this is a system with
127 * a boot-bus controller. Additionally testing the compatibility
128 * property will hopefully take care of this.
130 if (strcmp("i2c", ofw_bus_get_name(dev)) == 0) {
131 compat = ofw_bus_get_compat(dev);
132 if (compat != NULL && strcmp("i2cpcf,8584", compat) == 0) {
133 device_set_desc(dev, "PCF8584 I2C bus controller");
141 pcf_ebus_attach(device_t dev)
143 struct pcf_softc *sc;
148 sc = DEVTOSOFTC(dev);
149 mtx_init(&sc->pcf_lock, device_get_nameunit(dev), "pcf", MTX_DEF);
151 /* get OFW node of the pcf */
152 if ((node = ofw_bus_get_node(dev)) == -1) {
153 device_printf(dev, "cannot get OFW node\n");
157 /* IO port is mandatory */
158 sc->res_ioport = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
159 &sc->rid_ioport, RF_ACTIVE);
160 if (sc->res_ioport == 0) {
161 device_printf(dev, "cannot reserve I/O port range\n");
165 sc->pcf_flags = device_get_flags(dev);
168 * XXX use poll-mode property?
170 if (!(sc->pcf_flags & IIC_POLLED)) {
171 sc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
172 &sc->rid_irq, RF_ACTIVE);
173 if (sc->res_irq == 0) {
174 device_printf(dev, "can't reserve irq, polled mode.\n");
175 sc->pcf_flags |= IIC_POLLED;
180 * XXX on AXmp there's probably a second IRQ which is the fan fail
181 * interrupt genererated by the PCF8574 at 0x78.
184 /* get address of the pcf */
185 if (OF_getprop(node, "own-address", &own_addr, sizeof(own_addr)) ==
187 device_printf(dev, "cannot get own address\n");
191 device_printf(dev, "PCF8584 address: 0x%08llx\n", (unsigned
195 pcf_rst_card(dev, IIC_FASTEST, own_addr, NULL);
198 rv = bus_setup_intr(dev, sc->res_irq,
199 INTR_TYPE_NET /* | INTR_ENTROPY */, NULL, pcf_intr, sc,
202 device_printf(dev, "could not setup IRQ\n");
207 if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL)
208 device_printf(dev, "could not allocate iicbus instance\n");
210 /* probe and attach the iicbus */
211 bus_generic_attach(dev);
216 if (sc->res_irq != 0) {
217 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq,
220 if (sc->res_ioport != 0) {
221 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid_ioport,
224 mtx_destroy(&sc->pcf_lock);
229 pcf_ebus_detach(device_t dev)
231 struct pcf_softc *sc;
234 sc = DEVTOSOFTC(dev);
236 if ((rv = bus_generic_detach(dev)) != 0)
239 if ((rv = device_delete_child(dev, sc->iicbus)) != 0)
242 if (sc->res_irq != 0) {
243 bus_teardown_intr(dev, sc->res_irq,
245 bus_release_resource(dev, SYS_RES_IRQ, sc->rid_irq,
249 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid_ioport,
251 mtx_destroy(&sc->pcf_lock);
256 DRIVER_MODULE(pcf_ebus, ebus, pcf_ebus_driver, pcf_ebus_devclass, 0, 0);