> Date: Sat, 16 Jul 2016 15:16:40 +1000
> From: Jonathan Gray <[email protected]>
> 
> Following on from kettenis' pinctrl changes in imx here is a diff to
> pull the pad configuration data from fdt for am335x.
> 
> Initially I had this as a different driver that attached to the pinmux
> child of the scm node in the fdt but that prevented the manual table
> driven gpio pad configuration.  So this adds the pinmux offset (0x800)
> to the SCM base addr when using the register values from fdt.

Looks good to me.

> Index: omap/if_cpsw.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/armv7/omap/if_cpsw.c,v
> retrieving revision 1.36
> diff -u -p -r1.36 if_cpsw.c
> --- omap/if_cpsw.c    9 Jul 2016 04:25:44 -0000       1.36
> +++ omap/if_cpsw.c    16 Jul 2016 04:55:41 -0000
> @@ -84,6 +84,7 @@
>  
>  #include <arch/armv7/armv7/armv7var.h>
>  #include <arch/armv7/omap/if_cpswreg.h>
> +#include <arch/armv7/omap/sitara_cm.h>
>  
>  #include <dev/ofw/openfirm.h>
>  
> @@ -334,9 +335,11 @@ cpsw_attach(struct device *parent, struc
>       struct ifnet * const ifp = &ac->ac_if;
>       u_int32_t idver;
>       int error;
> +     int node;
>       u_int i;
>       uint32_t intr[4];
>       uint32_t memsize;
> +     char name[32];
>  
>       if (faa->fa_nreg < 2 || (faa->fa_nintr != 4 && faa->fa_nintr != 12))
>               return;
> @@ -354,6 +357,19 @@ cpsw_attach(struct device *parent, struc
>        * we map a size that is a superset of both
>        */
>       memsize = 0x4000;
> +
> +     sitara_cm_pinctrlbyname(faa->fa_node, "default");
> +
> +     for (node = OF_child(faa->fa_node); node; node = OF_peer(node)) {
> +             memset(name, 0, sizeof(name));
> +
> +             if (OF_getprop(node, "compatible", name, sizeof(name)) == -1)
> +                     continue;
> +
> +             if (strcmp(name, "ti,davinci_mdio") != 0)
> +                     continue;
> +             sitara_cm_pinctrlbyname(node, "default");
> +     }
>  
>       timeout_set(&sc->sc_tick, cpsw_tick, sc);
>  
> Index: omap/omap_com.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/armv7/omap/omap_com.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 omap_com.c
> --- omap/omap_com.c   19 Jun 2016 14:38:13 -0000      1.5
> +++ omap/omap_com.c   16 Jul 2016 04:55:42 -0000
> @@ -51,6 +51,7 @@
>  
>  #include <armv7/armv7/armv7var.h>
>  #include <armv7/armv7/armv7_machdep.h>
> +#include <armv7/omap/sitara_cm.h>
>  
>  #include <dev/ofw/fdt.h>
>  #include <dev/ofw/openfirm.h>
> @@ -121,6 +122,8 @@ omapuart_attach(struct device *parent, s
>               printf("%s: bus_space_map failed\n", __func__);
>               return;
>       }
> +
> +     sitara_cm_pinctrlbyname(faa->fa_node, "default");
>  
>       com_attach_subr(sc);
>  
> Index: omap/ommmc.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/armv7/omap/ommmc.c,v
> retrieving revision 1.25
> diff -u -p -r1.25 ommmc.c
> --- omap/ommmc.c      15 Jul 2016 22:28:25 -0000      1.25
> +++ omap/ommmc.c      16 Jul 2016 04:55:42 -0000
> @@ -34,6 +34,7 @@
>  
>  #include <armv7/armv7/armv7var.h>
>  #include <armv7/omap/prcmvar.h>
> +#include <armv7/omap/sitara_cm.h>
>  
>  #include <dev/ofw/openfirm.h>
>  
> @@ -333,6 +334,8 @@ ommmc_attach(struct device *parent, stru
>               panic("%s: bus_space_map failed!", __func__);
>  
>       printf("\n");
> +
> +     sitara_cm_pinctrlbyname(faa->fa_node, "default");
>  
>       /* Enable ICLKEN, FCLKEN? */
>       prcm_enablemodule(PRCM_MMC0 + unit);
> Index: omap/sitara_cm.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/armv7/omap/sitara_cm.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 sitara_cm.c
> --- omap/sitara_cm.c  6 Nov 2013 19:03:07 -0000       1.2
> +++ omap/sitara_cm.c  16 Jul 2016 04:55:42 -0000
> @@ -52,6 +52,7 @@
>  #include <sys/param.h>
>  #include <sys/systm.h>
>  #include <sys/kernel.h>
> +#include <sys/malloc.h>
>  #include <sys/device.h>
>  #include <sys/conf.h>
>  #include <sys/proc.h>
> @@ -61,7 +62,10 @@
>  #include <armv7/omap/sitara_cm.h>
>  #include <armv7/omap/sitara_cmreg.h>
>  
> +#include <dev/ofw/openfirm.h>
> +
>  void sitara_cm_attach(struct device *parent, struct device *self, void *aux);
> +int sitara_cm_pinctrl(uint32_t);
>  
>  struct sitara_cm_softc {
>          struct device                sc_dev;
> @@ -391,4 +395,95 @@ sitara_cm_attach(struct device *parent, 
>               panic("sitara_cm_attach: read revision");
>       printf(": control module, rev %d.%d\n",
>           SCM_REVISION_MAJOR(rev), SCM_REVISION_MINOR(rev));
> +}
> +
> +int
> +sitara_cm_pinctrlbyid(int node, int id)
> +{
> +     char pinctrl[32];
> +     uint32_t *phandles;
> +     int len, i;
> +
> +     if (!sitara_cm_sc)
> +             return -1;
> +
> +     snprintf(pinctrl, sizeof(pinctrl), "pinctrl-%d", id);
> +     len = OF_getproplen(node, pinctrl);
> +     if (len <= 0)
> +             return -1;
> +
> +     phandles = malloc(len, M_TEMP, M_WAITOK);
> +     OF_getpropintarray(node, pinctrl, phandles, len);
> +     for (i = 0; i < len / sizeof(uint32_t); i++)
> +             sitara_cm_pinctrl(phandles[i]);
> +     free(phandles, M_TEMP, len);
> +     return 0;
> +}
> +
> +int
> +sitara_cm_pinctrlbyname(int node, const char *config)
> +{
> +     char *names;
> +     char *name;
> +     char *end;
> +     int id = 0;
> +     int len;
> +
> +     if (!sitara_cm_sc)
> +             return -1;
> +
> +     len = OF_getproplen(node, "pinctrl-names");
> +     if (len <= 0)
> +             printf("no pinctrl-names\n");
> +
> +     names = malloc(len, M_TEMP, M_WAITOK);
> +     OF_getprop(node, "pinctrl-names", names, len);
> +     end = names + len;
> +     name = names;
> +     while (name < end) {
> +             if (strcmp(name, config) == 0) {
> +                     free(names, M_TEMP, len);
> +                     return sitara_cm_pinctrlbyid(node, id);
> +             }
> +             name += strlen(name) + 1;
> +             id++;
> +     }
> +     free(names, M_TEMP, len);
> +     return -1;
> +}
> +
> +int
> +sitara_cm_pinctrl(uint32_t phandle)
> +{
> +     struct sitara_cm_softc *sc = sitara_cm_sc;
> +     uint32_t *pins;
> +     int npins;
> +     int node;
> +     int len;
> +     int i, j;
> +
> +     if (sc == NULL)
> +             return -1;
> +
> +     node = OF_getnodebyphandle(phandle);
> +     if (node == 0)
> +             return -1;
> +
> +     len = OF_getproplen(node, "pinctrl-single,pins");
> +     if (len <= 0)
> +             return -1;
> +
> +     pins = malloc(len, M_TEMP, M_WAITOK);
> +     OF_getpropintarray(node, "pinctrl-single,pins", pins, len);
> +     npins = len / (2 * sizeof(uint32_t));
> +
> +     for (i = 0, j = 0; i < npins; i++, j += 2) {
> +             uint32_t conf_reg = SCM_PINMUX + pins[2 * i + 0];
> +             uint32_t conf_val = pins[2 * i + 1];
> +
> +             bus_space_write_4(sc->sc_iot, sc->sc_ioh, conf_reg, conf_val);
> +     }
> +
> +     free(pins, M_TEMP, len);
> +     return 0;
>  }
> Index: omap/sitara_cm.h
> ===================================================================
> RCS file: /cvs/src/sys/arch/armv7/omap/sitara_cm.h,v
> retrieving revision 1.1
> diff -u -p -r1.1 sitara_cm.h
> --- omap/sitara_cm.h  4 Sep 2013 14:38:32 -0000       1.1
> +++ omap/sitara_cm.h  16 Jul 2016 04:55:42 -0000
> @@ -74,5 +74,7 @@ int sitara_cm_padconf_set_gpioflags(uint
>  void sitara_cm_padconf_get_gpioflags(uint32_t gpio, uint32_t *flags);
>  int sitara_cm_reg_read_4(uint32_t reg, uint32_t *val);
>  int sitara_cm_reg_write_4(uint32_t reg, uint32_t val);
> +int sitara_cm_pinctrlbyid(int node, int id);
> +int sitara_cm_pinctrlbyname(int node, const char *);
>  
>  #endif /* _OMAP_SCM_H_ */
> Index: omap/sitara_cmreg.h
> ===================================================================
> RCS file: /cvs/src/sys/arch/armv7/omap/sitara_cmreg.h,v
> retrieving revision 1.1
> diff -u -p -r1.1 sitara_cmreg.h
> --- omap/sitara_cmreg.h       4 Sep 2013 14:38:32 -0000       1.1
> +++ omap/sitara_cmreg.h       16 Jul 2016 04:55:42 -0000
> @@ -40,6 +40,8 @@
>  #define SCM_REVISION_CUSTOM(x)       (((x) & 0x000000c0) >>  6)
>  #define SCM_REVISION_MINOR(x)        (((x) & 0x0000001f) >>  0)
>  
> +#define SCM_PINMUX           0x800
> +
>  #define OMAP2SCM_MAC_ID0_LO  0x630
>  #define OMAP2SCM_MAC_ID0_HI  0x634
>  
> Index: omap/ti_iic.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/armv7/omap/ti_iic.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 ti_iic.c
> --- omap/ti_iic.c     26 Jun 2016 07:25:05 -0000      1.5
> +++ omap/ti_iic.c     16 Jul 2016 04:55:42 -0000
> @@ -65,9 +65,8 @@
>  
>  #include <armv7/armv7/armv7var.h>
>  #include <armv7/omap/prcmvar.h>
> -#include <armv7/omap/sitara_cm.h>
> -#include <armv7/omap/sitara_cmreg.h>
>  #include <armv7/omap/ti_iicreg.h>
> +#include <armv7/omap/sitara_cm.h>
>  
>  #include <dev/ofw/openfirm.h>
>  
> @@ -165,16 +164,8 @@ ti_iic_attach(struct device *parent, str
>       struct fdt_attach_args *faa = aux;
>       struct i2cbus_attach_args iba;
>       uint16_t rev;
> -     const char *mode;
> -     u_int state;
>       int irq, unit, len;
> -     char buf[20];
>       char hwmods[128];
> -     char *pin;
> -     /* BBB specific pin names */
> -     char *pins[6] = {"I2C0_SDA", "I2C0_SCL",
> -                     "SPIO_D1", "SPI0_CS0",
> -                     "UART1_CTSn", "UART1_RTSn"};
>  
>       if (faa->fa_nreg != 2 || (faa->fa_nintr != 1 && faa->fa_nintr != 3))
>               return;
> @@ -203,34 +194,12 @@ ti_iic_attach(struct device *parent, str
>           faa->fa_reg[1], 0, &sc->sc_ioh))
>               panic("%s: bus_space_map failed!", DEVNAME(sc));
>  
> +     sitara_cm_pinctrlbyname(faa->fa_node, "default");
> +
>       sc->sc_ih = arm_intr_establish(irq, IPL_NET,
>           ti_iic_intr, sc, DEVNAME(sc));
>  
>       prcm_enablemodule(PRCM_I2C0 + unit);
> -
> -     if (board_id == BOARD_ID_AM335X_BEAGLEBONE) {
> -             pin = pins[unit * 2];
> -             snprintf(buf, sizeof buf, "I2C%d_SDA", unit);
> -             if (sitara_cm_padconf_set(pin, buf,
> -                 (0x01 << 4) | (0x01 << 5) | (0x01 << 6)) != 0) {
> -                     printf(": can't switch %s pad\n", buf);
> -                     return;
> -             }
> -             if (sitara_cm_padconf_get(pin, &mode, &state) == 0) {
> -                     printf(": %s state %d ", mode, state);
> -             }
> -
> -             pin = pins[unit * 2 + 1];
> -             snprintf(buf, sizeof buf, "I2C%d_SCL", unit);
> -             if (sitara_cm_padconf_set(pin, buf,
> -                 (0x01 << 4) | (0x01 << 5) | (0x01 << 6)) != 0) {
> -                     printf(": can't switch %s pad\n", buf);
> -                     return;
> -             }
> -             if (sitara_cm_padconf_get(pin, &mode, &state) == 0) {
> -                     printf(": %s state %d ", mode, state);
> -             }
> -     }
>  
>       rev = I2C_READ_REG(sc, AM335X_I2C_REVNB_LO);
>       printf(" rev %d.%d\n",
> 
> 

Reply via email to