On Sat, Jul 16, 2016 at 04:07:23PM +1000, Jonathan Gray wrote:
> prcm and omgpio have to attach early so we can't easily test
> against the right fdt node without searching the entire
> tree.  The following uses the compatible property of the root
> node to decide how to set the function pointers instead of
> board ids.
> 
> The beaglebone specific pad configuration in omgpio_pin_ctl()
> stays as that really is board specific.

Specific pins are board specific but the function call is soc
specific.  So here is an updated diff to add a soc specific
callback.

Removing board_id use in intc included below as well.

Index: intc.c
===================================================================
RCS file: /cvs/src/sys/arch/armv7/omap/intc.c,v
retrieving revision 1.4
diff -u -p -r1.4 intc.c
--- intc.c      31 Jan 2016 00:14:50 -0000      1.4
+++ intc.c      16 Jul 2016 06:50:17 -0000
@@ -23,6 +23,9 @@
 #include <sys/evcount.h>
 #include <machine/bus.h>
 #include <armv7/armv7/armv7var.h>
+
+#include <dev/ofw/fdt.h>
+
 #include "intc.h"
 
 #define INTC_NUM_IRQ intc_nirq
@@ -116,6 +119,11 @@ intc_attach(struct device *parent, struc
        struct armv7_attach_args *aa = args;
        int i;
        u_int32_t rev;
+       void *node;
+
+       node = fdt_find_node("/");
+       if (node == NULL)
+               panic("%s: could not get fdt root node", __func__);
 
        intc_iot = aa->aa_iot;
        if (bus_space_map(intc_iot, aa->aa_dev->mem[0].addr,
@@ -137,14 +145,10 @@ intc_attach(struct device *parent, struc
        bus_space_write_4(intc_iot, intc_ioh, INTC_SYSCONFIG,
            INTC_SYSCONFIG_AUTOIDLE);
 
-       switch (board_id) {
-       case BOARD_ID_AM335X_BEAGLEBONE:
+       if (fdt_is_compatible(node, "ti,am33xx"))
                intc_nirq = 128;
-               break;
-       default:
+       else
                intc_nirq = 96;
-               break;
-       }
 
        /* mask all interrupts */
        for (i = 0; i < INTC_NUM_BANKS; i++)
Index: prcm.c
===================================================================
RCS file: /cvs/src/sys/arch/armv7/omap/prcm.c,v
retrieving revision 1.9
diff -u -p -r1.9 prcm.c
--- prcm.c      8 May 2014 21:17:01 -0000       1.9
+++ prcm.c      16 Jul 2016 06:50:17 -0000
@@ -65,6 +65,8 @@
 #include <armv7/omap/omap3_prcmreg.h>
 #include <armv7/omap/omap4_prcmreg.h>
 
+#include <dev/ofw/fdt.h>
+
 #define PRCM_REVISION          0x0800
 #define PRCM_SYSCONFIG         0x0810
 
@@ -120,29 +122,32 @@ prcm_attach(struct device *parent, struc
        struct armv7_attach_args *aa = args;
        struct prcm_softc *sc = (struct prcm_softc *) self;
        u_int32_t reg;
+       void *node;
 
        sc->sc_iot = aa->aa_iot;
 
-       switch (board_id) {
-       case BOARD_ID_AM335X_BEAGLEBONE:
+       node = fdt_find_node("/");
+       if (node == NULL)
+               panic("%s: could not get fdt root node",
+                   sc->sc_dev.dv_xname);
+
+       if (fdt_is_compatible(node, "ti,am33xx")) {
                sc->sc_setup = NULL;
                sc->sc_enablemodule = prcm_am335x_enablemodule;
                sc->sc_setclock = prcm_am335x_setclock;
-               break;
-       case BOARD_ID_OMAP3_BEAGLE:
-       case BOARD_ID_OMAP3_OVERO:
+       } else if (fdt_is_compatible(node, "ti,omap3")) {
                sc->sc_setup = prcm_v3_setup;
                sc->sc_enablemodule = prcm_v3_enablemodule;
                sc->sc_setclock = prcm_v3_setclock;
-               break;
-       case BOARD_ID_OMAP4_PANDA:
+       } else if (fdt_is_compatible(node, "ti,omap4")) {
                sc->sc_setup = NULL;
                sc->sc_enablemodule = prcm_v4_enablemodule;
                sc->sc_setclock = NULL;
                sc->cm1_avail = 1;
                sc->cm2_avail = 1;
-               break;
-       }
+       } else
+               panic("%s: could not find a compatible soc",
+                   sc->sc_dev.dv_xname);
 
        if (bus_space_map(sc->sc_iot, aa->aa_dev->mem[0].addr,
            aa->aa_dev->mem[0].size, 0, &sc->sc_prcm))
Index: omgpio.c
===================================================================
RCS file: /cvs/src/sys/arch/armv7/omap/omgpio.c,v
retrieving revision 1.6
diff -u -p -r1.6 omgpio.c
--- omgpio.c    31 Jan 2016 00:14:50 -0000      1.6
+++ omgpio.c    16 Jul 2016 06:50:17 -0000
@@ -35,6 +35,8 @@
 #include <armv7/omap/sitara_cm.h>
 #include <armv7/omap/omgpiovar.h>
 
+#include <dev/ofw/fdt.h>
+
 #include "gpio.h"
 
 /* OMAP3 registers */
@@ -179,6 +181,7 @@ struct omgpio_softc {
        struct gpio_chipset_tag sc_gpio_gc;
        gpio_pin_t              sc_gpio_pins[GPIO_NUM_PINS];
        struct omgpio_regs      sc_regs;
+       int                     (*sc_padconf_set_gpioflags)(uint32_t, uint32_t);
 };
 
 #define GPIO_PIN_TO_INST(x)    ((x) >> 5)
@@ -189,7 +192,6 @@ 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 *);
@@ -198,7 +200,7 @@ int omgpio_pin_dir_read(struct omgpio_so
 void omgpio_pin_dir_write(struct omgpio_softc *, unsigned int, unsigned int);
 
 struct cfattach omgpio_ca = {
-       sizeof (struct omgpio_softc), omgpio_match, omgpio_attach
+       sizeof (struct omgpio_softc), NULL, omgpio_attach
 };
 
 struct cfdriver omgpio_cd = {
@@ -223,21 +225,6 @@ omgpio_write4(struct omgpio_softc *sc, u
        bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val));
 }
 
-int
-omgpio_match(struct device *parent, void *v, void *aux)
-{
-       switch (board_id) {
-       case BOARD_ID_OMAP3_BEAGLE:
-       case BOARD_ID_OMAP3_OVERO:
-       case BOARD_ID_AM335X_BEAGLEBONE:
-       case BOARD_ID_OMAP4_PANDA:
-               break; /* continue trying */
-       default:
-               return 0; /* unknown */
-       }
-       return (1);
-}
-
 void
 omgpio_attach(struct device *parent, struct device *self, void *args)
 {
@@ -246,6 +233,12 @@ omgpio_attach(struct device *parent, str
        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);
 
        prcm_enablemodule(PRCM_GPIO0 + aa->aa_dev->unit);
 
@@ -254,9 +247,8 @@ omgpio_attach(struct device *parent, str
            aa->aa_dev->mem[0].size, 0, &sc->sc_ioh))
                panic("%s: bus_space_map failed!", DEVNAME(sc));
 
-       switch (board_id) {
-       case BOARD_ID_OMAP3_BEAGLE:
-       case BOARD_ID_OMAP3_OVERO:
+       if (fdt_is_compatible(node, "ti,omap3")) {
+               sc->sc_padconf_set_gpioflags = NULL;
                sc->sc_regs.revision = GPIO3_REVISION;
                sc->sc_regs.sysconfig = GPIO3_SYSCONFIG;
                sc->sc_regs.irqstatus_raw0 = -1;
@@ -285,8 +277,8 @@ omgpio_attach(struct device *parent, str
                sc->sc_regs.setwkupena = GPIO3_SETWKUENA;
                sc->sc_regs.cleardataout = GPIO3_CLEARDATAOUT;
                sc->sc_regs.setdataout = GPIO3_SETDATAOUT;
-               break;
-       case BOARD_ID_OMAP4_PANDA:
+       } else if (fdt_is_compatible(node, "ti,omap4")) {
+               sc->sc_padconf_set_gpioflags = NULL;
                sc->sc_regs.revision = GPIO4_REVISION;
                sc->sc_regs.sysconfig = GPIO4_SYSCONFIG;
                sc->sc_regs.irqstatus_raw0 = GPIO4_IRQSTATUS_RAW_0;
@@ -315,8 +307,8 @@ omgpio_attach(struct device *parent, str
                sc->sc_regs.setwkupena = GPIO4_SETWKUENA;
                sc->sc_regs.cleardataout = GPIO4_CLEARDATAOUT;
                sc->sc_regs.setdataout = GPIO4_SETDATAOUT;
-               break;
-       case BOARD_ID_AM335X_BEAGLEBONE:
+       } 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;
@@ -345,8 +337,9 @@ omgpio_attach(struct device *parent, str
                sc->sc_regs.setwkupena = -1;
                sc->sc_regs.cleardataout = GPIO_AM335X_CLEARDATAOUT;
                sc->sc_regs.setdataout = GPIO_AM335X_SETDATAOUT;
-               break;
-       }
+       } else
+               panic("%s: could not find a compatible soc",
+                   sc->sc_dev.dv_xname);
 
        rev = READ4(sc, sc->sc_regs.revision);
 
@@ -469,8 +462,8 @@ omgpio_pin_ctl(void *arg, int pin, int f
        else if (flags & GPIO_PIN_OUTPUT)
                omgpio_pin_dir_write(sc, pin, OMGPIO_DIR_OUT);
 
-       if (board_id == BOARD_ID_AM335X_BEAGLEBONE)
-               sitara_cm_padconf_set_gpioflags(
+       if (sc->sc_padconf_set_gpioflags)
+               sc->sc_padconf_set_gpioflags(
                    sc->sc_dev.dv_unit * GPIO_NUM_PINS + pin, flags);
 }
 

Reply via email to