From owner-svn-src-all@FreeBSD.ORG Thu May 15 01:27:58 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8D83923D; Thu, 15 May 2014 01:27:58 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 765FF210E; Thu, 15 May 2014 01:27:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4F1Rwwi072887; Thu, 15 May 2014 01:27:58 GMT (envelope-from loos@svn.freebsd.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4F1Rsbx072863; Thu, 15 May 2014 01:27:54 GMT (envelope-from loos@svn.freebsd.org) Message-Id: <201405150127.s4F1Rsbx072863@svn.freebsd.org> From: Luiz Otavio O Souza Date: Thu, 15 May 2014 01:27:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r266105 - in stable/10: share/man/man4 sys/arm/broadcom/bcm2835 sys/arm/conf sys/arm/ti sys/boot/fdt/dts sys/conf sys/dev/gpio sys/dev/iicbus sys/dev/ofw sys/modules/gpio/gpiobus sys/mo... X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 May 2014 01:27:58 -0000 Author: loos Date: Thu May 15 01:27:53 2014 New Revision: 266105 URL: http://svnweb.freebsd.org/changeset/base/266105 Log: MFC r258046, r258047, r258050, r259035, r259036, r259037, r261842, r261843, 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. Added: stable/10/sys/dev/gpio/ofw_gpiobus.c - copied, changed from r261842, head/sys/dev/gpio/ofw_gpiobus.c Modified: stable/10/share/man/man4/gpioiic.4 stable/10/share/man/man4/gpioled.4 stable/10/sys/arm/broadcom/bcm2835/bcm2835_gpio.c stable/10/sys/arm/conf/BEAGLEBONE stable/10/sys/arm/ti/ti_gpio.c stable/10/sys/boot/fdt/dts/beaglebone-black.dts stable/10/sys/boot/fdt/dts/bindings-gpio.txt stable/10/sys/conf/files stable/10/sys/dev/gpio/gpiobus.c stable/10/sys/dev/gpio/gpiobusvar.h stable/10/sys/dev/gpio/gpioiic.c stable/10/sys/dev/gpio/gpioled.c stable/10/sys/dev/iicbus/iicbb.c stable/10/sys/dev/ofw/ofw_bus_if.m stable/10/sys/dev/ofw/ofw_iicbus.c stable/10/sys/modules/gpio/gpiobus/Makefile stable/10/sys/modules/gpio/gpioiic/Makefile stable/10/sys/modules/gpio/gpioled/Makefile stable/10/sys/modules/i2c/iicbb/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/share/man/man4/gpioiic.4 ============================================================================== --- stable/10/share/man/man4/gpioiic.4 Thu May 15 01:27:24 2014 (r266104) +++ stable/10/share/man/man4/gpioiic.4 Thu May 15 01:27:53 2014 (r266105) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 5, 2013 +.Dd February 13, 2014 .Dt GPIOIIC 4 .Os .Sh NAME @@ -65,7 +65,7 @@ This is a bitmask of the pins on the that are to be used for SCLOCK and SDATA from the GPIO IIC bit-banging bus. To configure pin 0 and 7, use the bitmask of -10000001 and convert it to a hexadecimal value of 0x0081. +0b10000001 and convert it to a hexadecimal value of 0x0081. Please note that this mask should only ever have two bits set (any others bits - i.e., pins - will be ignored). .It Va hint.gpioiic.%d.scl @@ -73,13 +73,77 @@ Indicates which bit in the .Va hint.gpioiic.%d.pins should be used as the SCLOCK source. +Optional, defaults to 0. .It Va hint.gpioiic.%d.sda Indicates which bit in the .Va hint.gpioiic.%d.pins should be used as the SDATA source. +Optional, defaults to 1. +.El +.Pp +On a +.Xr FDT 4 +based system, like +.Li ARM , the dts part for a +.Nm gpioiic +device usually looks like: +.Bd -literal +gpio: gpio { + + gpio-controller; + ... + + gpioiic0 { + compatible = "gpioiic"; + /* + * Attach to GPIO pins 21 and 22. Set them + * initially as inputs. + */ + gpios = <&gpio 21 1 0 + &gpio 22 1 0>; + scl = <0>; /* GPIO pin 21 - optional */ + sda = <1>; /* GPIO pin 22 - optional */ + + /* This is an example of a gpioiic child. */ + gpioiic-child0 { + compatible = "lm75"; + i2c-address = <0x4f>; + }; + }; +}; +.Ed +.Pp +Where: +.Bl -tag -width ".Va compatible" +.It Va compatible +Should always be set to "gpioiic". +.It Va gpios +The +.Va gpios +property indicates which GPIO pins should be used for SCLOCK and SDATA +on the GPIO IIC bit-banging bus. +For more details about the +.Va gpios +property, please consult +.Pa /usr/src/sys/boot/fdt/dts/bindings-gpio.txt . +.It Va scl +The +.Va scl +option indicates which bit in the +.Va gpios +should be used as the SCLOCK source. +Optional, defaults to 0. +.It Va sda +The +.Va sda +option indicates which bit in the +.Va gpios +should be used as the SDATA source. +Optional, defaults to 1. .El .Sh SEE ALSO +.Xr fdt 4 , .Xr gpio 4 , .Xr gpioled 4 , .Xr iic 4 , Modified: stable/10/share/man/man4/gpioled.4 ============================================================================== --- stable/10/share/man/man4/gpioled.4 Thu May 15 01:27:24 2014 (r266104) +++ stable/10/share/man/man4/gpioled.4 Thu May 15 01:27:53 2014 (r266105) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 5, 2013 +.Dd February 13, 2014 .Dt GPIOLED 4 .Os .Sh NAME @@ -68,7 +68,75 @@ Which pin on the GPIO interface to map t Please note that this mask should only ever have one bit set (any others bits - i.e., pins - will be ignored). .El +.Pp +On a +.Xr FDT 4 +based system, like +.Li ARM , the dts part for a +.Nm gpioled +device usually looks like: +.Bd -literal +gpio: gpio { + + gpio-controller; + ... + + led0 { + compatible = "gpioled"; + gpios = <&gpio 16 2 0>; /* GPIO pin 16. */ + name = "ok"; + }; + + led1 { + compatible = "gpioled"; + gpios = <&gpio 17 2 0>; /* GPIO pin 17. */ + name = "user-led1"; + }; +}; +.Ed +.Pp +And optionally, you can choose combine all the leds under a single +.Dq gpio-leds +compatible node: +.Bd -literal +simplebus0 { + + ... + + leds { + compatible = "gpio-leds"; + + led0 { + gpios = <&gpio 16 2 0>; + name = "ok" + }; + + led1 { + gpios = <&gpio 17 2 0>; + name = "user-led1" + }; + }; +}; +.Ed +.Pp +Both methods are equally supported and it is possible to have the leds +defined with any sort of mix between the methods. +The only restriction is that a GPIO pin cannot be mapped by two different +(gpio)leds. +.Pp +For more details about the +.Va gpios +property, please consult +.Pa /usr/src/sys/boot/fdt/dts/bindings-gpio.txt . +.Pp +The property +.Va name +is the arbitrary name of device in +.Pa /dev/led/ +to create for +.Xr led 4 . .Sh SEE ALSO +.Xr fdt 4 , .Xr gpio 4 , .Xr led 4 , .Xr gpioiic 4 Modified: stable/10/sys/arm/broadcom/bcm2835/bcm2835_gpio.c ============================================================================== --- stable/10/sys/arm/broadcom/bcm2835/bcm2835_gpio.c Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/arm/broadcom/bcm2835/bcm2835_gpio.c Thu May 15 01:27:53 2014 (r266105) @@ -762,6 +762,14 @@ bcm_gpio_detach(device_t dev) return (EBUSY); } +static phandle_t +bcm_gpio_get_node(device_t bus, device_t dev) +{ + + /* We only have one child, the GPIO bus, which needs our own node. */ + return (ofw_bus_get_node(bus)); +} + static device_method_t bcm_gpio_methods[] = { /* Device interface */ DEVMETHOD(device_probe, bcm_gpio_probe), @@ -778,6 +786,9 @@ static device_method_t bcm_gpio_methods[ DEVMETHOD(gpio_pin_set, bcm_gpio_pin_set), DEVMETHOD(gpio_pin_toggle, bcm_gpio_pin_toggle), + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_node, bcm_gpio_get_node), + DEVMETHOD_END }; Modified: stable/10/sys/arm/conf/BEAGLEBONE ============================================================================== --- stable/10/sys/arm/conf/BEAGLEBONE Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/arm/conf/BEAGLEBONE Thu May 15 01:27:53 2014 (r266105) @@ -101,6 +101,7 @@ device am335x_pmic # AM335x Power Mana # GPIO device gpio +device gpioled # USB support device usb Modified: stable/10/sys/arm/ti/ti_gpio.c ============================================================================== --- stable/10/sys/arm/ti/ti_gpio.c Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/arm/ti/ti_gpio.c Thu May 15 01:27:53 2014 (r266105) @@ -543,9 +543,9 @@ ti_gpio_pin_get(device_t dev, uint32_t p /* Read the value on the pin */ if (val & mask) - *value = (ti_gpio_read_4(sc, bank, TI_GPIO_DATAOUT) & mask) ? 1 : 0; - else *value = (ti_gpio_read_4(sc, bank, TI_GPIO_DATAIN) & mask) ? 1 : 0; + else + *value = (ti_gpio_read_4(sc, bank, TI_GPIO_DATAOUT) & mask) ? 1 : 0; TI_GPIO_UNLOCK(sc); @@ -788,6 +788,14 @@ ti_gpio_detach(device_t dev) return(0); } +static phandle_t +ti_gpio_get_node(device_t bus, device_t dev) +{ + + /* We only have one child, the GPIO bus, which needs our own node. */ + return (ofw_bus_get_node(bus)); +} + static device_method_t ti_gpio_methods[] = { DEVMETHOD(device_probe, ti_gpio_probe), DEVMETHOD(device_attach, ti_gpio_attach), @@ -802,6 +810,10 @@ static device_method_t ti_gpio_methods[] DEVMETHOD(gpio_pin_get, ti_gpio_pin_get), DEVMETHOD(gpio_pin_set, ti_gpio_pin_set), DEVMETHOD(gpio_pin_toggle, ti_gpio_pin_toggle), + + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_node, ti_gpio_get_node), + {0, 0}, }; Modified: stable/10/sys/boot/fdt/dts/beaglebone-black.dts ============================================================================== --- stable/10/sys/boot/fdt/dts/beaglebone-black.dts Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/boot/fdt/dts/beaglebone-black.dts Thu May 15 01:27:53 2014 (r266105) @@ -153,6 +153,30 @@ } }; + leds { + compatible = "gpio-leds"; + + led1 { + gpios = <&GPIO 53 2 0>; + name = "led1"; + }; + + led2 { + gpios = <&GPIO 54 2 0>; + name = "led2"; + }; + + led3 { + gpios = <&GPIO 55 2 0>; + name = "led3"; + }; + + led4 { + gpios = <&GPIO 56 2 0>; + name = "led4"; + }; + }; + chosen { stdin = "uart0"; stdout = "uart0"; Modified: stable/10/sys/boot/fdt/dts/bindings-gpio.txt ============================================================================== --- stable/10/sys/boot/fdt/dts/bindings-gpio.txt Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/boot/fdt/dts/bindings-gpio.txt Thu May 15 01:27:53 2014 (r266105) @@ -82,7 +82,7 @@ dir: flags: 0x0000---- IN_NONE - 0x0001---- IN_POL_LOW Polarity low (inverted input value. + 0x0001---- IN_POL_LOW Polarity low (active-low). 0x0002---- IN_IRQ_EDGE Interrupt, edge triggered. 0x0004---- IN_IRQ_LEVEL Interrupt, level triggered. Modified: stable/10/sys/conf/files ============================================================================== --- stable/10/sys/conf/files Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/conf/files Thu May 15 01:27:53 2014 (r266105) @@ -1439,6 +1439,7 @@ dev/gpio/gpioiic.c optional gpioiic dev/gpio/gpioled.c optional gpioled dev/gpio/gpio_if.m optional gpio dev/gpio/gpiobus_if.m optional gpio +dev/gpio/ofw_gpiobus.c optional fdt gpio dev/hatm/if_hatm.c optional hatm pci dev/hatm/if_hatm_intr.c optional hatm pci dev/hatm/if_hatm_ioctl.c optional hatm pci Modified: stable/10/sys/dev/gpio/gpiobus.c ============================================================================== --- stable/10/sys/dev/gpio/gpiobus.c Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/dev/gpio/gpiobus.c Thu May 15 01:27:53 2014 (r266105) @@ -46,7 +46,6 @@ __FBSDID("$FreeBSD$"); #include "gpio_if.h" #include "gpiobus_if.h" -static void gpiobus_print_pins(struct gpiobus_ivar *); static int gpiobus_parse_pins(struct gpiobus_softc *, device_t, int); static int gpiobus_probe(device_t); static int gpiobus_attach(device_t); @@ -73,17 +72,7 @@ static int gpiobus_pin_set(device_t, dev static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*); static int gpiobus_pin_toggle(device_t, device_t, uint32_t); -#define GPIOBUS_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) -#define GPIOBUS_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) -#define GPIOBUS_LOCK_INIT(_sc) \ - mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_dev), \ - "gpiobus", MTX_DEF) -#define GPIOBUS_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); -#define GPIOBUS_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED); -#define GPIOBUS_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED); - - -static void +void gpiobus_print_pins(struct gpiobus_ivar *devi) { int range_start, range_stop, need_coma; @@ -175,7 +164,8 @@ static int gpiobus_probe(device_t dev) { device_set_desc(dev, "GPIO bus"); - return (0); + + return (BUS_PROBE_GENERIC); } static int @@ -190,13 +180,13 @@ gpiobus_attach(device_t dev) if (res) return (ENXIO); + KASSERT(sc->sc_npins != 0, ("GPIO device with no pins")); + /* * Increase to get number of pins */ sc->sc_npins++; - KASSERT(sc->sc_npins != 0, ("GPIO device with no pins")); - sc->sc_pins_mapped = malloc(sizeof(int) * sc->sc_npins, M_DEVBUF, M_NOWAIT | M_ZERO); @@ -209,7 +199,9 @@ gpiobus_attach(device_t dev) /* * Get parent's pins and mark them as unmapped */ + bus_generic_probe(dev); bus_enumerate_hinted_children(dev); + return (bus_generic_attach(dev)); } Modified: stable/10/sys/dev/gpio/gpiobusvar.h ============================================================================== --- stable/10/sys/dev/gpio/gpiobusvar.h Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/dev/gpio/gpiobusvar.h Thu May 15 01:27:53 2014 (r266105) @@ -30,12 +30,25 @@ #ifndef __GPIOBUS_H__ #define __GPIOBUS_H__ +#include "opt_platform.h" + #include #include #include -#define GPIOBUS_IVAR(d) (struct gpiobus_ivar *) device_get_ivars(d) -#define GPIOBUS_SOFTC(d) (struct gpiobus_softc *) device_get_softc(d) +#ifdef FDT +#include +#endif + +#define GPIOBUS_IVAR(d) (struct gpiobus_ivar *) device_get_ivars(d) +#define GPIOBUS_SOFTC(d) (struct gpiobus_softc *) device_get_softc(d) +#define GPIOBUS_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) +#define GPIOBUS_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) +#define GPIOBUS_LOCK_INIT(_sc) mtx_init(&_sc->sc_mtx, \ + device_get_nameunit(_sc->sc_dev), "gpiobus", MTX_DEF) +#define GPIOBUS_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx) +#define GPIOBUS_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED) +#define GPIOBUS_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED) struct gpiobus_softc { @@ -54,4 +67,11 @@ struct gpiobus_ivar uint32_t *pins; /* pins map */ }; +void gpiobus_print_pins(struct gpiobus_ivar *); +#ifdef FDT +device_t ofw_gpiobus_add_fdt_child(device_t, phandle_t); +#endif + +extern driver_t gpiobus_driver; + #endif /* __GPIOBUS_H__ */ Modified: stable/10/sys/dev/gpio/gpioiic.c ============================================================================== --- stable/10/sys/dev/gpio/gpioiic.c Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/dev/gpio/gpioiic.c Thu May 15 01:27:53 2014 (r266105) @@ -28,21 +28,24 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_platform.h" + #include #include -#include #include #include #include -#include -#include -#include #include -#include #include #include "gpiobus_if.h" +#ifdef FDT +#include +#include +#include +#endif + #include #include @@ -55,7 +58,6 @@ struct gpioiic_softc { device_t sc_dev; device_t sc_busdev; - struct cdev *sc_leddev; int scl_pin; int sda_pin; }; @@ -77,7 +79,12 @@ static int gpioiic_probe(device_t dev) { +#ifdef FDT + if (!ofw_bus_is_compatible(dev, "gpioiic")) + return (ENXIO); +#endif device_set_desc(dev, "GPIO I2C bit-banging driver"); + return (0); } @@ -86,6 +93,10 @@ gpioiic_attach(device_t dev) { struct gpioiic_softc *sc = device_get_softc(dev); device_t bitbang; +#ifdef FDT + phandle_t node; + pcell_t pin; +#endif sc->sc_dev = dev; sc->sc_busdev = device_get_parent(dev); @@ -96,6 +107,15 @@ gpioiic_attach(device_t dev) device_get_unit(dev), "sda", &sc->sda_pin)) sc->sda_pin = SDA_PIN_DEFAULT; +#ifdef FDT + if ((node = ofw_bus_get_node(dev)) == -1) + return (ENXIO); + if (OF_getencprop(node, "scl", &pin, sizeof(pin)) > 0) + sc->scl_pin = (int)pin; + if (OF_getencprop(node, "sda", &pin, sizeof(pin)) > 0) + sc->sda_pin = (int)pin; +#endif + /* add generic bit-banging code */ bitbang = device_add_child(dev, "iicbb", -1); device_probe_and_attach(bitbang); @@ -139,7 +159,7 @@ gpioiic_callback(device_t dev, int index error = EINVAL; } - return(error); + return (error); } static void @@ -214,6 +234,16 @@ gpioiic_reset(device_t dev, u_char speed return (IIC_ENOADDR); } +#ifdef FDT +static phandle_t +gpioiic_get_node(device_t bus, device_t dev) +{ + + /* We only have one child, the iicbb, which needs our own node. */ + return (ofw_bus_get_node(bus)); +} +#endif + static devclass_t gpioiic_devclass; static device_method_t gpioiic_methods[] = { @@ -230,6 +260,11 @@ static device_method_t gpioiic_methods[] DEVMETHOD(iicbb_getscl, gpioiic_getscl), DEVMETHOD(iicbb_reset, gpioiic_reset), +#ifdef FDT + /* OFW bus interface */ + DEVMETHOD(ofw_bus_get_node, gpioiic_get_node), +#endif + { 0, 0 } }; Modified: stable/10/sys/dev/gpio/gpioled.c ============================================================================== --- stable/10/sys/dev/gpio/gpioled.c Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/dev/gpio/gpioled.c Thu May 15 01:27:53 2014 (r266105) @@ -27,6 +27,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_platform.h" + #include #include #include @@ -39,6 +41,12 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef FDT +#include +#include +#include +#endif + #include #include #include "gpiobus_if.h" @@ -75,6 +83,8 @@ gpioled_control(void *priv, int onoff) GPIOLED_LOCK(sc); GPIOBUS_LOCK_BUS(sc->sc_busdev); GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev); + GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, + GPIO_PIN_OUTPUT); GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, onoff ? GPIO_PIN_HIGH : GPIO_PIN_LOW); GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); @@ -82,10 +92,65 @@ gpioled_control(void *priv, int onoff) GPIOLED_UNLOCK(sc); } +#ifdef FDT +static void +gpioled_identify(driver_t *driver, device_t bus) +{ + phandle_t child, leds, root; + + root = OF_finddevice("/"); + if (root == 0) + return; + leds = fdt_find_compatible(root, "gpio-leds", 1); + if (leds == 0) + return; + + /* Traverse the 'gpio-leds' node and add its children. */ + for (child = OF_child(leds); child != 0; child = OF_peer(child)) + if (ofw_gpiobus_add_fdt_child(bus, child) == NULL) + continue; +} +#endif + static int gpioled_probe(device_t dev) { +#ifdef FDT + int match; + phandle_t node; + char *compat; + + /* + * We can match against our own node compatible string and also against + * our parent node compatible string. The first is normally used to + * describe leds on a gpiobus and the later when there is a common node + * compatible with 'gpio-leds' which is used to concentrate all the + * leds nodes on the dts. + */ + match = 0; + if (ofw_bus_is_compatible(dev, "gpioled")) + match = 1; + + if (match == 0) { + if ((node = ofw_bus_get_node(dev)) == -1) + return (ENXIO); + if ((node = OF_parent(node)) == -1) + return (ENXIO); + if (OF_getprop_alloc(node, "compatible", 1, + (void **)&compat) == -1) + return (ENXIO); + + if (strcasecmp(compat, "gpio-leds") == 0) + match = 1; + + free(compat, M_OFWPROP); + } + + if (match == 0) + return (ENXIO); +#endif device_set_desc(dev, "GPIO led"); + return (0); } @@ -93,21 +158,35 @@ static int gpioled_attach(device_t dev) { struct gpioled_softc *sc; +#ifdef FDT + phandle_t node; + char *name; +#else const char *name; +#endif sc = device_get_softc(dev); sc->sc_dev = dev; sc->sc_busdev = device_get_parent(dev); GPIOLED_LOCK_INIT(sc); +#ifdef FDT + name = NULL; + if ((node = ofw_bus_get_node(dev)) == -1) + return (ENXIO); + if (OF_getprop_alloc(node, "label", 1, (void **)&name) == -1) + OF_getprop_alloc(node, "name", 1, (void **)&name); +#else if (resource_string_value(device_get_name(dev), device_get_unit(dev), "name", &name)) name = NULL; - - GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, - GPIO_PIN_OUTPUT); +#endif sc->sc_leddev = led_create(gpioled_control, sc, name ? name : device_get_nameunit(dev)); +#ifdef FDT + if (name != NULL) + free(name, M_OFWPROP); +#endif return (0); } @@ -130,6 +209,9 @@ static devclass_t gpioled_devclass; static device_method_t gpioled_methods[] = { /* Device interface */ +#ifdef FDT + DEVMETHOD(device_identify, gpioled_identify), +#endif DEVMETHOD(device_probe, gpioled_probe), DEVMETHOD(device_attach, gpioled_attach), DEVMETHOD(device_detach, gpioled_detach), Copied and modified: stable/10/sys/dev/gpio/ofw_gpiobus.c (from r261842, head/sys/dev/gpio/ofw_gpiobus.c) ============================================================================== --- head/sys/dev/gpio/ofw_gpiobus.c Thu Feb 13 17:08:29 2014 (r261842, copy source) +++ stable/10/sys/dev/gpio/ofw_gpiobus.c Thu May 15 01:27:53 2014 (r266105) @@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include Modified: stable/10/sys/dev/iicbus/iicbb.c ============================================================================== --- stable/10/sys/dev/iicbus/iicbb.c Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/dev/iicbus/iicbb.c Thu May 15 01:27:53 2014 (r266105) @@ -43,6 +43,8 @@ __FBSDID("$FreeBSD$"); * */ +#include "opt_platform.h" + #include #include #include @@ -50,6 +52,11 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef FDT +#include +#include +#include +#endif #include #include @@ -77,6 +84,9 @@ static int iicbb_write(device_t, const c static int iicbb_read(device_t, char *, int, int *, int, int); static int iicbb_reset(device_t, u_char, u_char, u_char *); static int iicbb_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs); +#ifdef FDT +static phandle_t iicbb_get_node(device_t, device_t); +#endif static device_method_t iicbb_methods[] = { /* device interface */ @@ -98,6 +108,11 @@ static device_method_t iicbb_methods[] = DEVMETHOD(iicbus_reset, iicbb_reset), DEVMETHOD(iicbus_transfer, iicbb_transfer), +#ifdef FDT + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_node, iicbb_get_node), +#endif + { 0, 0 } }; @@ -154,6 +169,16 @@ iicbb_detach(device_t dev) return (0); } +#ifdef FDT +static phandle_t +iicbb_get_node(device_t bus, device_t dev) +{ + + /* We only have one child, the I2C bus, which needs our own node. */ + return (ofw_bus_get_node(bus)); +} +#endif + static void iicbb_child_detached( device_t dev, device_t child ) { Modified: stable/10/sys/dev/ofw/ofw_bus_if.m ============================================================================== --- stable/10/sys/dev/ofw/ofw_bus_if.m Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/dev/ofw/ofw_bus_if.m Thu May 15 01:27:53 2014 (r266105) @@ -158,7 +158,7 @@ METHOD const char * get_name { } DEFAULT ofw_bus_default_get_name; # Get the firmware node for the device dev on the bus. The default method will -# return 0, which signals that there is no such node. +# return -1, which signals that there is no such node. METHOD phandle_t get_node { device_t bus; device_t dev; Modified: stable/10/sys/dev/ofw/ofw_iicbus.c ============================================================================== --- stable/10/sys/dev/ofw/ofw_iicbus.c Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/dev/ofw/ofw_iicbus.c Thu May 15 01:27:53 2014 (r266105) @@ -80,6 +80,7 @@ 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); Modified: stable/10/sys/modules/gpio/gpiobus/Makefile ============================================================================== --- stable/10/sys/modules/gpio/gpiobus/Makefile Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/modules/gpio/gpiobus/Makefile Thu May 15 01:27:53 2014 (r266105) @@ -33,7 +33,7 @@ KMOD= gpiobus SRCS= gpiobus.c -SRCS+= device_if.h bus_if.h gpio_if.h gpiobus_if.h +SRCS+= device_if.h bus_if.h gpio_if.h gpiobus_if.h opt_platform.h CFLAGS+= -I. -I${.CURDIR}/../../../dev/gpio/ Modified: stable/10/sys/modules/gpio/gpioiic/Makefile ============================================================================== --- stable/10/sys/modules/gpio/gpioiic/Makefile Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/modules/gpio/gpioiic/Makefile Thu May 15 01:27:53 2014 (r266105) @@ -34,6 +34,7 @@ KMOD= gpioiic SRCS= gpioiic.c SRCS+= device_if.h bus_if.h gpio_if.h gpiobus_if.h iicbus_if.h iicbb_if.h +SRCS+= opt_platform.h CFLAGS+= -I. -I${.CURDIR}/../../../dev/gpio/ Modified: stable/10/sys/modules/gpio/gpioled/Makefile ============================================================================== --- stable/10/sys/modules/gpio/gpioled/Makefile Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/modules/gpio/gpioled/Makefile Thu May 15 01:27:53 2014 (r266105) @@ -33,7 +33,7 @@ KMOD= gpioled SRCS= gpioled.c -SRCS+= device_if.h bus_if.h gpio_if.h gpiobus_if.h +SRCS+= device_if.h bus_if.h gpio_if.h gpiobus_if.h opt_platform.h CFLAGS+= -I. -I${.CURDIR}/../../../dev/gpio/ Modified: stable/10/sys/modules/i2c/iicbb/Makefile ============================================================================== --- stable/10/sys/modules/i2c/iicbb/Makefile Thu May 15 01:27:24 2014 (r266104) +++ stable/10/sys/modules/i2c/iicbb/Makefile Thu May 15 01:27:53 2014 (r266105) @@ -3,6 +3,6 @@ .PATH: ${.CURDIR}/../../../dev/iicbus KMOD = iicbb SRCS = device_if.h bus_if.h iicbus_if.h \ - iicbb_if.h iicbb_if.c iicbb.c + iicbb_if.h iicbb_if.c iicbb.c opt_platform.h .include