> Date: Sat, 16 Jul 2016 16:07:23 +1000
> From: Jonathan Gray <[email protected]>
> 
> 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.

Untimately seraching the tree is what we may end up doing.

> The beaglebone specific pad configuration in omgpio_pin_ctl()
> stays as that really is board specific.

For now, I think this is an improvement.

ok kettenis@

> 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:05:44 -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:05:44 -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 */
> @@ -189,7 +191,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 +199,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 +224,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 +232,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 +246,7 @@ 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_regs.revision = GPIO3_REVISION;
>               sc->sc_regs.sysconfig = GPIO3_SYSCONFIG;
>               sc->sc_regs.irqstatus_raw0 = -1;
> @@ -285,8 +275,7 @@ 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_regs.revision = GPIO4_REVISION;
>               sc->sc_regs.sysconfig = GPIO4_SYSCONFIG;
>               sc->sc_regs.irqstatus_raw0 = GPIO4_IRQSTATUS_RAW_0;
> @@ -315,8 +304,7 @@ 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_regs.revision = GPIO_AM335X_REVISION;
>               sc->sc_regs.sysconfig = GPIO_AM335X_SYSCONFIG;
>               sc->sc_regs.irqstatus_raw0 = GPIO_AM335X_IRQSTATUS_RAW_0;
> @@ -345,8 +333,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);
>  
> 
> 

Reply via email to