diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2016-07-17 02:45:06 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2016-07-17 02:45:06 +0000 |
commit | 13657b84995128a97815becba738466c055cc0f6 (patch) | |
tree | d789e0b281f0b8ca9b3841c43929aa4fea5a7e54 | |
parent | eb4b67934a3b80ad60e185bef48d7c16d2152cc5 (diff) |
Adapt kettenis' pinctrl changes in imx to sitaracm and
pinctrl-single,pins to handle mux settings and pad configuration.
The fdt data has offsets from the start of the pinmux address range so
the am335x specific pinmux offset from the scm base is added to the
offsets. This as not a new driver as sitaracm does manual table
driven pad configuration for gpio. If all the offsets in the
ti_padconf_devmap table were reduced by the am335x pinmux offset (0x800)
it may make sense to map only the pinmux memory region and not the
scm superset.
looks good kettenis@
-rw-r--r-- | sys/arch/armv7/omap/if_cpsw.c | 18 | ||||
-rw-r--r-- | sys/arch/armv7/omap/omap_com.c | 5 | ||||
-rw-r--r-- | sys/arch/armv7/omap/ommmc.c | 5 | ||||
-rw-r--r-- | sys/arch/armv7/omap/sitara_cm.c | 97 | ||||
-rw-r--r-- | sys/arch/armv7/omap/sitara_cm.h | 4 | ||||
-rw-r--r-- | sys/arch/armv7/omap/sitara_cmreg.h | 4 | ||||
-rw-r--r-- | sys/arch/armv7/omap/ti_iic.c | 39 |
7 files changed, 131 insertions, 41 deletions
diff --git a/sys/arch/armv7/omap/if_cpsw.c b/sys/arch/armv7/omap/if_cpsw.c index 8ec4d3e606e..6ced8b04da5 100644 --- a/sys/arch/armv7/omap/if_cpsw.c +++ b/sys/arch/armv7/omap/if_cpsw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_cpsw.c,v 1.36 2016/07/09 04:25:44 jsg Exp $ */ +/* $OpenBSD: if_cpsw.c,v 1.37 2016/07/17 02:45:05 jsg Exp $ */ /* $NetBSD: if_cpsw.c,v 1.3 2013/04/17 14:36:34 bouyer Exp $ */ /* @@ -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, struct device *self, void *aux) 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; @@ -355,6 +358,19 @@ cpsw_attach(struct device *parent, struct device *self, void *aux) */ 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); cpsw_get_port_config(sc->sc_port_config, faa->fa_node); diff --git a/sys/arch/armv7/omap/omap_com.c b/sys/arch/armv7/omap/omap_com.c index e750559898b..d2f8c165822 100644 --- a/sys/arch/armv7/omap/omap_com.c +++ b/sys/arch/armv7/omap/omap_com.c @@ -1,4 +1,4 @@ -/* $OpenBSD: omap_com.c,v 1.5 2016/06/19 14:38:13 jsg Exp $ */ +/* $OpenBSD: omap_com.c,v 1.6 2016/07/17 02:45:05 jsg Exp $ */ /* * Copyright 2003 Wasabi Systems, Inc. * All rights reserved. @@ -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> @@ -122,6 +123,8 @@ omapuart_attach(struct device *parent, struct device *self, void *aux) return; } + sitara_cm_pinctrlbyname(faa->fa_node, "default"); + com_attach_subr(sc); (void)arm_intr_establish(irq, IPL_TTY, comintr, diff --git a/sys/arch/armv7/omap/ommmc.c b/sys/arch/armv7/omap/ommmc.c index 58e915496d8..c6f530d0127 100644 --- a/sys/arch/armv7/omap/ommmc.c +++ b/sys/arch/armv7/omap/ommmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ommmc.c,v 1.25 2016/07/15 22:28:25 tom Exp $ */ +/* $OpenBSD: ommmc.c,v 1.26 2016/07/17 02:45:05 jsg Exp $ */ /* * Copyright (c) 2009 Dale Rahn <drahn@openbsd.org> @@ -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> @@ -334,6 +335,8 @@ ommmc_attach(struct device *parent, struct device *self, void *aux) printf("\n"); + sitara_cm_pinctrlbyname(faa->fa_node, "default"); + /* Enable ICLKEN, FCLKEN? */ prcm_enablemodule(PRCM_MMC0 + unit); diff --git a/sys/arch/armv7/omap/sitara_cm.c b/sys/arch/armv7/omap/sitara_cm.c index 4958a4fabcf..4cb69dbba5b 100644 --- a/sys/arch/armv7/omap/sitara_cm.c +++ b/sys/arch/armv7/omap/sitara_cm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sitara_cm.c,v 1.2 2013/11/06 19:03:07 syl Exp $ */ +/* $OpenBSD: sitara_cm.c,v 1.3 2016/07/17 02:45:05 jsg Exp $ */ /* $NetBSD: sitara_cm.c,v 1.1 2013/04/17 14:31:02 bouyer Exp $ */ /* * Copyright (c) 2010 @@ -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; @@ -392,3 +396,94 @@ sitara_cm_attach(struct device *parent, struct device *self, void *aux) 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; +} diff --git a/sys/arch/armv7/omap/sitara_cm.h b/sys/arch/armv7/omap/sitara_cm.h index 96be9673d0b..68158b2e57d 100644 --- a/sys/arch/armv7/omap/sitara_cm.h +++ b/sys/arch/armv7/omap/sitara_cm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sitara_cm.h,v 1.1 2013/09/04 14:38:32 patrick Exp $ */ +/* $OpenBSD: sitara_cm.h,v 1.2 2016/07/17 02:45:05 jsg Exp $ */ /* $NetBSD: sitara_cm.h,v 1.1 2013/04/17 14:31:02 bouyer Exp $ */ /* * Copyright (c) 2010 @@ -74,5 +74,7 @@ int sitara_cm_padconf_set_gpioflags(uint32_t gpio, uint32_t flags); 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_ */ diff --git a/sys/arch/armv7/omap/sitara_cmreg.h b/sys/arch/armv7/omap/sitara_cmreg.h index 65aeeeb53da..a4445486f2f 100644 --- a/sys/arch/armv7/omap/sitara_cmreg.h +++ b/sys/arch/armv7/omap/sitara_cmreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sitara_cmreg.h,v 1.1 2013/09/04 14:38:32 patrick Exp $ */ +/* $OpenBSD: sitara_cmreg.h,v 1.2 2016/07/17 02:45:05 jsg Exp $ */ /* $NetBSD: sitara_cmreg.h,v 1.1 2013/04/17 15:04:39 bouyer Exp $ */ /* @@ -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 diff --git a/sys/arch/armv7/omap/ti_iic.c b/sys/arch/armv7/omap/ti_iic.c index 55db923ba01..718e63c7f09 100644 --- a/sys/arch/armv7/omap/ti_iic.c +++ b/sys/arch/armv7/omap/ti_iic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ti_iic.c,v 1.5 2016/06/26 07:25:05 jsg Exp $ */ +/* $OpenBSD: ti_iic.c,v 1.6 2016/07/17 02:45:05 jsg Exp $ */ /* $NetBSD: ti_iic.c,v 1.4 2013/04/25 13:04:27 rkujawa Exp $ */ /* @@ -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, struct device *self, void *aux) 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,35 +194,13 @@ ti_iic_attach(struct device *parent, struct device *self, void *aux) 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", (int)I2C_REVNB_LO_MAJOR(rev), |