From 6e0cf5844d3ca47735b64e098a714f5c1c9b1aaf Mon Sep 17 00:00:00 2001 From: jsg Date: Thu, 11 Aug 2016 04:33:06 +0000 Subject: [PATCH] Dynamically attach omgpio(4) using the FDT. am335x has a compatible string of "ti,omap4-gpio" and has the same offsets as omap4, so combine the omap4 and am335x cases when setting up function pointers. --- share/man/man4/man4.armv7/omap.4 | 6 +- share/man/man4/man4.armv7/omgpio.4 | 6 +- sys/arch/armv7/conf/GENERIC | 4 +- sys/arch/armv7/conf/RAMDISK | 4 +- sys/arch/armv7/omap/files.omap | 4 +- sys/arch/armv7/omap/omap.c | 18 +---- sys/arch/armv7/omap/omgpio.c | 115 ++++++++++++++--------------- 7 files changed, 68 insertions(+), 89 deletions(-) diff --git a/share/man/man4/man4.armv7/omap.4 b/share/man/man4/man4.armv7/omap.4 index 735bc146159..731d027b944 100644 --- a/share/man/man4/man4.armv7/omap.4 +++ b/share/man/man4/man4.armv7/omap.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: omap.4,v 1.5 2016/08/06 10:07:45 jsg Exp $ +.\" $OpenBSD: omap.4,v 1.6 2016/08/11 04:33:06 jsg Exp $ .\" Copyright (c) 2014 Sylvestre Gallon .\" .\" Permission to use, copy, modify, and distribute this software for any @@ -13,7 +13,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: August 6 2016 $ +.Dd $Mdocdate: August 11 2016 $ .Dt OMAP 4 armv7 .Os .Sh NAME @@ -38,8 +38,6 @@ Texas Instruments dual mode timer device Texas Instruments enhanced DMA device .It Xr gptimer 4 Texas Instruments general purpose timer device -.It Xr omgpio 4 -omap3, omap4 and am335x GPIO controller .It Xr prcm 4 Texas Instruments power, reset and clock management device .It Xr sitaracm 4 diff --git a/share/man/man4/man4.armv7/omgpio.4 b/share/man/man4/man4.armv7/omgpio.4 index 8b099f59d98..0098b03b7e7 100644 --- a/share/man/man4/man4.armv7/omgpio.4 +++ b/share/man/man4/man4.armv7/omgpio.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: omgpio.4,v 1.2 2014/05/01 13:26:34 jasper Exp $ +.\" $OpenBSD: omgpio.4,v 1.3 2016/08/11 04:33:06 jsg Exp $ .\" .\" Copyright (c) 2013 Raphael Graf .\" @@ -14,14 +14,14 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 1 2014 $ +.Dd $Mdocdate: August 11 2016 $ .Dt OMGPIO 4 armv7 .Os .Sh NAME .Nm omgpio .Nd omap3, omap4 and am335x GPIO controller .Sh SYNOPSIS -.Cd "omgpio* at omap?" +.Cd "omgpio* at fdt?" .Cd "gpio* at omgpio?" .Sh DESCRIPTION The diff --git a/sys/arch/armv7/conf/GENERIC b/sys/arch/armv7/conf/GENERIC index c47dedd88f2..5bf8ee162f7 100644 --- a/sys/arch/armv7/conf/GENERIC +++ b/sys/arch/armv7/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.44 2016/08/11 01:53:18 jsg Exp $ +# $OpenBSD: GENERIC,v 1.45 2016/08/11 04:33:06 jsg Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -66,7 +66,7 @@ intc* at fdt? # OMAP3 interrupt controller prcm* at omap? # power/clock controller sitaracm* at omap? # sitara control module omdog* at fdt? # watchdog timer -omgpio* at omap? # user-visible GPIO pins? +omgpio* at fdt? # user-visible GPIO pins? gpio* at omgpio? tiiic* at fdt? iic* at tiiic? diff --git a/sys/arch/armv7/conf/RAMDISK b/sys/arch/armv7/conf/RAMDISK index dbbf6f320b7..cfffe718334 100644 --- a/sys/arch/armv7/conf/RAMDISK +++ b/sys/arch/armv7/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.41 2016/08/11 01:53:18 jsg Exp $ +# $OpenBSD: RAMDISK,v 1.42 2016/08/11 04:33:06 jsg Exp $ machine armv7 arm @@ -65,7 +65,7 @@ intc* at fdt? # OMAP3 interrupt controller prcm* at omap? # power/clock controller sitaracm* at omap? # sitara control module omdog* at fdt? # watchdog timer -omgpio* at omap? # user-visible GPIO pins? +omgpio* at fdt? # user-visible GPIO pins? gpio* at omgpio? tiiic* at fdt? iic* at tiiic? diff --git a/sys/arch/armv7/omap/files.omap b/sys/arch/armv7/omap/files.omap index 5b8fd67fb81..295d9ead933 100644 --- a/sys/arch/armv7/omap/files.omap +++ b/sys/arch/armv7/omap/files.omap @@ -1,4 +1,4 @@ -# $OpenBSD: files.omap,v 1.15 2016/08/11 01:53:18 jsg Exp $ +# $OpenBSD: files.omap,v 1.16 2016/08/11 04:33:06 jsg Exp $ define omap {} device omap: omap @@ -27,7 +27,7 @@ file arch/armv7/omap/am335x_cm_padconf.c sitaracm file arch/armv7/omap/sitara_cm.c sitaracm device omgpio: gpiobus -attach omgpio at omap +attach omgpio at fdt file arch/armv7/omap/omgpio.c omgpio device tiiic: i2cbus diff --git a/sys/arch/armv7/omap/omap.c b/sys/arch/armv7/omap/omap.c index 33259159267..435d6921e37 100644 --- a/sys/arch/armv7/omap/omap.c +++ b/sys/arch/armv7/omap/omap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: omap.c,v 1.18 2016/08/11 01:53:18 jsg Exp $ */ +/* $OpenBSD: omap.c,v 1.19 2016/08/11 04:33:06 jsg Exp $ */ /* * Copyright (c) 2005,2008 Dale Rahn * @@ -42,12 +42,6 @@ struct board_dev omap3_dev[] = { { "prcm", 0 }, { "gptimer", 0 }, { "gptimer", 1 }, - { "omgpio", 0 }, - { "omgpio", 1 }, - { "omgpio", 2 }, - { "omgpio", 3 }, - { "omgpio", 4 }, - { "omgpio", 5 }, { NULL, 0 } }; @@ -57,22 +51,12 @@ struct board_dev am33xx_dev[] = { { "edma", 0 }, { "dmtimer", 0 }, { "dmtimer", 1 }, - { "omgpio", 0 }, - { "omgpio", 1 }, - { "omgpio", 2 }, - { "omgpio", 3 }, { NULL, 0 } }; struct board_dev omap4_dev[] = { { "omapid", 0 }, { "prcm", 0 }, - { "omgpio", 0 }, - { "omgpio", 1 }, - { "omgpio", 2 }, - { "omgpio", 3 }, - { "omgpio", 4 }, - { "omgpio", 5 }, { NULL, 0 } }; diff --git a/sys/arch/armv7/omap/omgpio.c b/sys/arch/armv7/omap/omgpio.c index c964553093f..a4a80323c77 100644 --- a/sys/arch/armv7/omap/omgpio.c +++ b/sys/arch/armv7/omap/omgpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: omgpio.c,v 1.8 2016/08/06 18:21:34 patrick Exp $ */ +/* $OpenBSD: omgpio.c,v 1.9 2016/08/11 04:33:06 jsg Exp $ */ /* * Copyright (c) 2007,2009 Dale Rahn * @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -36,6 +37,7 @@ #include #include +#include #include "gpio.h" @@ -175,7 +177,7 @@ struct omgpio_softc { void *sc_ih_l; int sc_max_il; int sc_min_il; - int sc_irq; + int sc_node; struct intrhand *sc_handlers[GPIO_NUM_PINS]; int sc_omap_ver; struct gpio_chipset_tag sc_gpio_gc; @@ -192,6 +194,7 @@ struct omgpio_softc { u_int32_t omgpio_read4(struct omgpio_softc *, u_int32_t); void omgpio_write4(struct omgpio_softc *, u_int32_t, u_int32_t); +int omgpio_match(struct device *, void *, void *); void omgpio_attach(struct device *, struct device *, void *); void omgpio_recalc_interrupts(struct omgpio_softc *); int omgpio_irq(void *); @@ -200,13 +203,19 @@ int omgpio_pin_dir_read(struct omgpio_softc *, unsigned int); void omgpio_pin_dir_write(struct omgpio_softc *, unsigned int, unsigned int); struct cfattach omgpio_ca = { - sizeof (struct omgpio_softc), NULL, omgpio_attach + sizeof (struct omgpio_softc), omgpio_match, omgpio_attach }; struct cfdriver omgpio_cd = { NULL, "omgpio", DV_DULL }; +const char *omgpio_compatible[] = { + "ti,omap3-gpio", + "ti,omap4-gpio", + NULL +}; + u_int32_t omgpio_read4(struct omgpio_softc *sc, u_int32_t reg) { @@ -225,29 +234,49 @@ omgpio_write4(struct omgpio_softc *sc, u_int32_t reg, u_int32_t val) bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val)); } +int +omgpio_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + int i; + + for (i = 0; omgpio_compatible[i] != NULL; i++) { + if (OF_is_compatible(faa->fa_node, omgpio_compatible[i])) + return 1; + } + return 0; +} + void -omgpio_attach(struct device *parent, struct device *self, void *args) +omgpio_attach(struct device *parent, struct device *self, void *aux) { - struct armv7_attach_args *aa = args; + struct fdt_attach_args *faa = aux; struct omgpio_softc *sc = (struct omgpio_softc *) self; struct gpiobus_attach_args gba; u_int32_t rev; - int i; - void *node; - - node = fdt_find_node("/"); - if (node == NULL) - panic("%s: could not get fdt root node", - sc->sc_dev.dv_xname); + int i, len, unit; + char hwmods[64]; + + if (faa->fa_nreg < 1) + return; + + unit = 0; + if ((len = OF_getprop(faa->fa_node, "ti,hwmods", hwmods, + sizeof(hwmods))) == 6) { + if ((strncmp(hwmods, "gpio", 4) == 0) && + (hwmods[4] > '0') && (hwmods[4] <= '9')) + unit = hwmods[4] - '1'; + } - prcm_enablemodule(PRCM_GPIO0 + aa->aa_dev->unit); + prcm_enablemodule(PRCM_GPIO0 + unit); - sc->sc_iot = aa->aa_iot; - if (bus_space_map(sc->sc_iot, aa->aa_dev->mem[0].addr, - aa->aa_dev->mem[0].size, 0, &sc->sc_ioh)) + sc->sc_node = faa->fa_node; + sc->sc_iot = faa->fa_iot; + if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, + faa->fa_reg[0].size, 0, &sc->sc_ioh)) panic("%s: bus_space_map failed!", DEVNAME(sc)); - if (fdt_is_compatible(node, "ti,omap3")) { + if (OF_is_compatible(faa->fa_node, "ti,omap3-gpio")) { sc->sc_padconf_set_gpioflags = NULL; sc->sc_regs.revision = GPIO3_REVISION; sc->sc_regs.sysconfig = GPIO3_SYSCONFIG; @@ -277,7 +306,7 @@ omgpio_attach(struct device *parent, struct device *self, void *args) sc->sc_regs.setwkupena = GPIO3_SETWKUENA; sc->sc_regs.cleardataout = GPIO3_CLEARDATAOUT; sc->sc_regs.setdataout = GPIO3_SETDATAOUT; - } else if (fdt_is_compatible(node, "ti,omap4")) { + } else if (OF_is_compatible(faa->fa_node, "ti,omap4-gpio")) { sc->sc_padconf_set_gpioflags = NULL; sc->sc_regs.revision = GPIO4_REVISION; sc->sc_regs.sysconfig = GPIO4_SYSCONFIG; @@ -292,7 +321,7 @@ omgpio_attach(struct device *parent, struct device *self, void *args) sc->sc_regs.irqwaken0 = GPIO4_IRQWAKEN_0; sc->sc_regs.irqwaken1 = GPIO4_IRQWAKEN_1; sc->sc_regs.sysstatus = GPIO4_SYSSTATUS; - sc->sc_regs.wakeupenable = GPIO4_WAKEUPENABLE; + sc->sc_regs.wakeupenable = -1; sc->sc_regs.ctrl = GPIO4_CTRL; sc->sc_regs.oe = GPIO4_OE; sc->sc_regs.datain = GPIO4_DATAIN; @@ -303,40 +332,10 @@ omgpio_attach(struct device *parent, struct device *self, void *args) sc->sc_regs.fallingdetect = GPIO4_FALLINGDETECT; sc->sc_regs.debounceenable = GPIO4_DEBOUNCENABLE; sc->sc_regs.debouncingtime = GPIO4_DEBOUNCINGTIME; - sc->sc_regs.clearwkupena = GPIO4_CLEARWKUPENA; - sc->sc_regs.setwkupena = GPIO4_SETWKUENA; - sc->sc_regs.cleardataout = GPIO4_CLEARDATAOUT; - sc->sc_regs.setdataout = GPIO4_SETDATAOUT; - } else if (fdt_is_compatible(node, "ti,am33xx")) { - sc->sc_padconf_set_gpioflags = sitara_cm_padconf_set_gpioflags; - sc->sc_regs.revision = GPIO_AM335X_REVISION; - sc->sc_regs.sysconfig = GPIO_AM335X_SYSCONFIG; - sc->sc_regs.irqstatus_raw0 = GPIO_AM335X_IRQSTATUS_RAW_0; - sc->sc_regs.irqstatus_raw1 = GPIO_AM335X_IRQSTATUS_RAW_1; - sc->sc_regs.irqstatus0 = GPIO_AM335X_IRQSTATUS_0; - sc->sc_regs.irqstatus1 = GPIO_AM335X_IRQSTATUS_1; - sc->sc_regs.irqstatus_set0 = GPIO_AM335X_IRQSTATUS_SET_0; - sc->sc_regs.irqstatus_set1 = GPIO_AM335X_IRQSTATUS_SET_1; - sc->sc_regs.irqstatus_clear0 = GPIO_AM335X_IRQSTATUS_CLR_0; - sc->sc_regs.irqstatus_clear1 = GPIO_AM335X_IRQSTATUS_CLR_1; - sc->sc_regs.irqwaken0 = GPIO_AM335X_IRQWAKEN_0; - sc->sc_regs.irqwaken1 = GPIO_AM335X_IRQWAKEN_1; - sc->sc_regs.sysstatus = GPIO_AM335X_SYSSTATUS; - sc->sc_regs.wakeupenable = -1; - sc->sc_regs.ctrl = GPIO_AM335X_CTRL; - sc->sc_regs.oe = GPIO_AM335X_OE; - sc->sc_regs.datain = GPIO_AM335X_DATAIN; - sc->sc_regs.dataout = GPIO_AM335X_DATAOUT; - sc->sc_regs.leveldetect0 = GPIO_AM335X_LEVELDETECT0; - sc->sc_regs.leveldetect1 = GPIO_AM335X_LEVELDETECT1; - sc->sc_regs.risingdetect = GPIO_AM335X_RISINGDETECT; - sc->sc_regs.fallingdetect = GPIO_AM335X_FALLINGDETECT; - sc->sc_regs.debounceenable = GPIO_AM335X_DEBOUNCENABLE; - sc->sc_regs.debouncingtime = GPIO_AM335X_DEBOUNCINGTIME; sc->sc_regs.clearwkupena = -1; sc->sc_regs.setwkupena = -1; - sc->sc_regs.cleardataout = GPIO_AM335X_CLEARDATAOUT; - sc->sc_regs.setdataout = GPIO_AM335X_SETDATAOUT; + sc->sc_regs.cleardataout = GPIO4_CLEARDATAOUT; + sc->sc_regs.setdataout = GPIO4_SETDATAOUT; } else panic("%s: could not find a compatible soc", sc->sc_dev.dv_xname); @@ -345,8 +344,6 @@ omgpio_attach(struct device *parent, struct device *self, void *args) printf(": rev %d.%d\n", rev >> 4 & 0xf, rev & 0xf); - sc->sc_irq = aa->aa_dev->irq[0]; - WRITE4(sc, sc->sc_regs.irqstatus_clear0, ~0); WRITE4(sc, sc->sc_regs.irqstatus_clear1, ~0); @@ -722,18 +719,18 @@ omgpio_recalc_interrupts(struct omgpio_softc *sc) #if 0 if ((max == IPL_NONE || max != sc->sc_max_il) && sc->sc_ih_h != NULL) - arm_intr_disestablish(sc->sc_ih_h); + arm_intr_disestablish_fdt(sc->sc_ih_h); if (max != IPL_NONE && max != sc->sc_max_il) { - sc->sc_ih_h = arm_intr_establish(sc->sc_irq, max, omgpio_irq, + sc->sc_ih_h = arm_intr_establish_fdt(sc->sc_node, max, omgpio_irq, sc, NULL); } #else if (sc->sc_ih_h != NULL) - arm_intr_disestablish(sc->sc_ih_h); + arm_intr_disestablish_fdt(sc->sc_ih_h); if (max != IPL_NONE) { - sc->sc_ih_h = arm_intr_establish(sc->sc_irq, max, omgpio_irq, + sc->sc_ih_h = arm_intr_establish_fdt(sc->sc_node, max, omgpio_irq, sc, NULL); } #endif @@ -741,10 +738,10 @@ omgpio_recalc_interrupts(struct omgpio_softc *sc) sc->sc_max_il = max; if (sc->sc_ih_l != NULL) - arm_intr_disestablish(sc->sc_ih_l); + arm_intr_disestablish_fdt(sc->sc_ih_l); if (max != min) { - sc->sc_ih_h = arm_intr_establish(sc->sc_irq, min, + sc->sc_ih_h = arm_intr_establish_fdt(sc->sc_node, min, omgpio_irq_dummy, sc, NULL); } sc->sc_min_il = min; -- 2.20.1