5a10856167
r261844, r261845, r261846, r262194, r262522, r262559 r258046: Fix a typo on a comment in ofw_bus_if.m, the default method will return -1 when a node doesn't exist. r258047: Move the KASSERT() check to the point before the increase of number of pins. r258050: Fix gpiobus to return BUS_PROBE_GENERIC insted of BUS_PROBE_SPECIFIC (0) so it can be overriden by its OFW/FDT version. Give a chance for GPIO devices that implement the device_identify method to attach. r259035: Remove unnecessary includes and an unused softc variable. While here apply two minor style(9) fixes. r259036: Move the GPIOBUS_SET_PINFLAGS(..., ..., pin, GPIO_PIN_OUTPUT) to led(4) control callback function. This makes gpioled(4) works even if the pin is accidentally set to an input. r259037: Fix the pin value reading on AM335x. Because of the inverted logic it was always returning '0' for all the reads, even for the outputs. It is now known to work with gpioiic(4) and gpioled(4). r261842: Add an OFW GPIO compatible bus. This allows the use of the DTS files to describe GPIO bindings in the system. Move the GPIOBUS lock macros to gpiobusvar.h as they are now shared between the OFW and the non OFW versions of GPIO bus. Export gpiobus_print_pins() so it can also be used on the OFW GPIO bus. r261843: Add OFW support to the in tree gpio compatible devices: gpioiic(4) and gpioled(4). Tested on RPi and BBB (using the hardware I2C controller and gpioiic(4) for the I2C tests). It was also verified for regressions on RSPRO (MIPS/ar71xx) used as reference for a non OFW-based system. Update the gpioled(4) and gpioiic(4) man pages with some details and examples about the FDT/OFW support. Some compatibility details pointed out by imp@ will follow in subsequent commits. r261844: Allow the use of OFW I2C bus together with iicbb(4) on OFW-based systems. This change makes ofw_iicbus attach to iicbb(4) controllers in addition to the already supported i2c host bridges (iichb). On iicbb(4) allow the direct access of the OFW parent node by its children, so they can be directly attached to iicbb(4) node on the DTS without the need of describing the i2c bus. r261845: Allow the use of the OFW GPIO bus for ti_gpio and bcm2835_gpio. With this change the gpio children can be described as directly connected to the GPIO controller without the need of describing the OFW GPIO bus itself on the DTS file. With this commit the OFW GPIO bus is fully functional on BBB and RPi. GPIO controllers which want to use the OFW GPIO bus will need similar changes. r261846: Make the gpioled(4) work out of the box on BBB. Add gpioled(4) to BEAGLEBONE kernel and add the description of the four on-board leds of beaglebone-black to its DTS file. r262194: Remove an unnecessary header. r262522: Fix make depend for iicbus. r262559: Inspired by r262522, fix make depend. This fixes the build of gpio modules.
191 lines
5.4 KiB
C
191 lines
5.4 KiB
C
/*-
|
|
* Copyright (c) 2009, Nathan Whitehorn <nwhitehorn@FreeBSD.org>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice unmodified, this list of conditions, and the following
|
|
* disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/bus.h>
|
|
#include <sys/kernel.h>
|
|
#include <sys/libkern.h>
|
|
#include <sys/lock.h>
|
|
#include <sys/module.h>
|
|
#include <sys/mutex.h>
|
|
|
|
#include <dev/iicbus/iicbus.h>
|
|
#include <dev/iicbus/iiconf.h>
|
|
#include <dev/ofw/ofw_bus.h>
|
|
#include <dev/ofw/ofw_bus_subr.h>
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
#include "iicbus_if.h"
|
|
|
|
/* Methods */
|
|
static device_probe_t ofw_iicbus_probe;
|
|
static device_attach_t ofw_iicbus_attach;
|
|
static device_t ofw_iicbus_add_child(device_t dev, u_int order,
|
|
const char *name, int unit);
|
|
static const struct ofw_bus_devinfo *ofw_iicbus_get_devinfo(device_t bus,
|
|
device_t dev);
|
|
|
|
static device_method_t ofw_iicbus_methods[] = {
|
|
/* Device interface */
|
|
DEVMETHOD(device_probe, ofw_iicbus_probe),
|
|
DEVMETHOD(device_attach, ofw_iicbus_attach),
|
|
|
|
/* Bus interface */
|
|
DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
|
|
DEVMETHOD(bus_add_child, ofw_iicbus_add_child),
|
|
|
|
/* ofw_bus interface */
|
|
DEVMETHOD(ofw_bus_get_devinfo, ofw_iicbus_get_devinfo),
|
|
DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),
|
|
DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),
|
|
DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
|
|
DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
|
|
DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
|
|
|
|
DEVMETHOD_END
|
|
};
|
|
|
|
struct ofw_iicbus_devinfo {
|
|
struct iicbus_ivar opd_dinfo;
|
|
struct ofw_bus_devinfo opd_obdinfo;
|
|
};
|
|
|
|
static devclass_t ofwiicbus_devclass;
|
|
|
|
DEFINE_CLASS_1(iicbus, ofw_iicbus_driver, ofw_iicbus_methods,
|
|
sizeof(struct iicbus_softc), iicbus_driver);
|
|
DRIVER_MODULE(ofw_iicbus, iicbb, ofw_iicbus_driver, ofwiicbus_devclass, 0, 0);
|
|
DRIVER_MODULE(ofw_iicbus, iichb, ofw_iicbus_driver, ofwiicbus_devclass, 0, 0);
|
|
MODULE_VERSION(ofw_iicbus, 1);
|
|
MODULE_DEPEND(ofw_iicbus, iicbus, 1, 1, 1);
|
|
|
|
static int
|
|
ofw_iicbus_probe(device_t dev)
|
|
{
|
|
|
|
if (ofw_bus_get_node(dev) == -1)
|
|
return (ENXIO);
|
|
device_set_desc(dev, "OFW I2C bus");
|
|
|
|
return (0);
|
|
}
|
|
|
|
static int
|
|
ofw_iicbus_attach(device_t dev)
|
|
{
|
|
struct iicbus_softc *sc = IICBUS_SOFTC(dev);
|
|
struct ofw_iicbus_devinfo *dinfo;
|
|
phandle_t child;
|
|
pcell_t paddr;
|
|
device_t childdev;
|
|
|
|
sc->dev = dev;
|
|
mtx_init(&sc->lock, "iicbus", NULL, MTX_DEF);
|
|
iicbus_reset(dev, IIC_FASTEST, 0, NULL);
|
|
|
|
bus_generic_probe(dev);
|
|
bus_enumerate_hinted_children(dev);
|
|
|
|
/*
|
|
* Attach those children represented in the device tree.
|
|
*/
|
|
for (child = OF_child(ofw_bus_get_node(dev)); child != 0;
|
|
child = OF_peer(child)) {
|
|
/*
|
|
* Try to get the I2C address first from the i2c-address
|
|
* property, then try the reg property. It moves around
|
|
* on different systems.
|
|
*/
|
|
if (OF_getencprop(child, "i2c-address", &paddr,
|
|
sizeof(paddr)) == -1)
|
|
if (OF_getencprop(child, "reg", &paddr,
|
|
sizeof(paddr)) == -1)
|
|
continue;
|
|
|
|
/*
|
|
* Now set up the I2C and OFW bus layer devinfo and add it
|
|
* to the bus.
|
|
*/
|
|
dinfo = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF,
|
|
M_NOWAIT | M_ZERO);
|
|
if (dinfo == NULL)
|
|
continue;
|
|
dinfo->opd_dinfo.addr = paddr;
|
|
if (ofw_bus_gen_setup_devinfo(&dinfo->opd_obdinfo, child) !=
|
|
0) {
|
|
free(dinfo, M_DEVBUF);
|
|
continue;
|
|
}
|
|
childdev = device_add_child(dev, NULL, -1);
|
|
device_set_ivars(childdev, dinfo);
|
|
}
|
|
|
|
return (bus_generic_attach(dev));
|
|
}
|
|
|
|
static device_t
|
|
ofw_iicbus_add_child(device_t dev, u_int order, const char *name, int unit)
|
|
{
|
|
device_t child;
|
|
struct ofw_iicbus_devinfo *devi;
|
|
|
|
child = device_add_child_ordered(dev, order, name, unit);
|
|
if (child == NULL)
|
|
return (child);
|
|
devi = malloc(sizeof(struct ofw_iicbus_devinfo), M_DEVBUF,
|
|
M_NOWAIT | M_ZERO);
|
|
if (devi == NULL) {
|
|
device_delete_child(dev, child);
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* NULL all the OFW-related parts of the ivars for non-OFW
|
|
* children.
|
|
*/
|
|
devi->opd_obdinfo.obd_node = -1;
|
|
devi->opd_obdinfo.obd_name = NULL;
|
|
devi->opd_obdinfo.obd_compat = NULL;
|
|
devi->opd_obdinfo.obd_type = NULL;
|
|
devi->opd_obdinfo.obd_model = NULL;
|
|
|
|
device_set_ivars(child, devi);
|
|
|
|
return (child);
|
|
}
|
|
|
|
static const struct ofw_bus_devinfo *
|
|
ofw_iicbus_get_devinfo(device_t bus, device_t dev)
|
|
{
|
|
struct ofw_iicbus_devinfo *dinfo;
|
|
|
|
dinfo = device_get_ivars(dev);
|
|
return (&dinfo->opd_obdinfo);
|
|
}
|