summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-04-10 22:02:46 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-04-10 22:02:46 +0000
commit17cc5fb9e4760f72ddd8329c19a1df302a5bdd0c (patch)
treeb2679c431f496fdad859e98862ad149a02e00973 /sys
parent2831b432f846a64b3daa93a4caa17e89fecc2366 (diff)
Add omcm(4), omclock(4) and omsysc(4) drivers that support the new bus
structure that is used in current mainline Linux device trees. ok jsg@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/armv7/conf/GENERIC8
-rw-r--r--sys/arch/armv7/conf/RAMDISK8
-rw-r--r--sys/arch/armv7/omap/files.omap14
-rw-r--r--sys/arch/armv7/omap/omclock.c161
-rw-r--r--sys/arch/armv7/omap/omcm.c58
-rw-r--r--sys/arch/armv7/omap/omgpio.c7
-rw-r--r--sys/arch/armv7/omap/ommmc.c9
-rw-r--r--sys/arch/armv7/omap/omsysc.c78
-rw-r--r--sys/arch/armv7/omap/ti_iic.c7
9 files changed, 335 insertions, 15 deletions
diff --git a/sys/arch/armv7/conf/GENERIC b/sys/arch/armv7/conf/GENERIC
index 86b8063b287..9671eb542f9 100644
--- a/sys/arch/armv7/conf/GENERIC
+++ b/sys/arch/armv7/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.128 2020/04/05 13:11:13 kettenis Exp $
+# $OpenBSD: GENERIC,v 1.129 2020/04/10 22:02:45 kettenis Exp $
#
# For further information on compiling OpenBSD kernels, see the config(8)
# man page.
@@ -70,7 +70,9 @@ omap0 at mainbus?
omapid* at omap?
# OMAP on-chip devices
-intc* at fdt? # OMAP3 interrupt controller
+intc* at fdt? early 1 # OMAP3 interrupt controller
+omclock* at fdt? early 1
+omcm* at fdt? early 1
omwugen* at fdt? # Wake-up generator
#edma* at fdt? # OMAP3 dma controller
prcm* at omap? # power/clock controller
@@ -79,6 +81,8 @@ omdog* at fdt? # watchdog timer
omgpio* at fdt? # user-visible GPIO pins?
gpio* at omgpio?
omrng* at fdt?
+omsysc* at fdt? early 1
+omsysc* at fdt?
tiiic* at fdt?
iic* at tiiic?
gptimer* at omap? # general purpose timers
diff --git a/sys/arch/armv7/conf/RAMDISK b/sys/arch/armv7/conf/RAMDISK
index c39c8ef13a2..1494f32d59a 100644
--- a/sys/arch/armv7/conf/RAMDISK
+++ b/sys/arch/armv7/conf/RAMDISK
@@ -1,4 +1,4 @@
-# $OpenBSD: RAMDISK,v 1.114 2020/04/05 13:11:13 kettenis Exp $
+# $OpenBSD: RAMDISK,v 1.115 2020/04/10 22:02:45 kettenis Exp $
machine armv7 arm
@@ -63,7 +63,9 @@ omap0 at mainbus?
omapid* at omap?
# OMAP on-chip devices
-intc* at fdt? # OMAP3 interrupt controller
+intc* at fdt? early 1 # OMAP3 interrupt controller
+omclock* at fdt? early 1
+omcm* at fdt? early 1
omwugen* at fdt? # Wake-up generator
#edma* at fdt? # OMAP3 dma controller
prcm* at omap? # power/clock controller
@@ -72,6 +74,8 @@ omdog* at fdt? # watchdog timer
omgpio* at fdt? # user-visible GPIO pins?
gpio* at omgpio?
omrng* at fdt?
+omsysc* at fdt? early 1
+omsysc* at fdt?
tiiic* at fdt?
iic* at tiiic?
gptimer* at omap? # general purpose timers
diff --git a/sys/arch/armv7/omap/files.omap b/sys/arch/armv7/omap/files.omap
index 7be42f523a4..6d9285e9042 100644
--- a/sys/arch/armv7/omap/files.omap
+++ b/sys/arch/armv7/omap/files.omap
@@ -1,4 +1,4 @@
-# $OpenBSD: files.omap,v 1.25 2020/04/05 13:11:13 kettenis Exp $
+# $OpenBSD: files.omap,v 1.26 2020/04/10 22:02:45 kettenis Exp $
define omap {}
device omap: omap
@@ -9,6 +9,14 @@ file arch/armv7/omap/omap3.c
file arch/armv7/omap/omap4.c
file arch/armv7/omap/am335x.c
+device omcm: fdt
+attach omcm at fdt
+file arch/armv7/omap/omcm.c omcm
+
+device omclock
+attach omclock at fdt
+file arch/armv7/omap/omclock.c omclock
+
device ommmc: sdmmcbus
attach ommmc at fdt
file arch/armv7/omap/ommmc.c ommmc
@@ -68,6 +76,10 @@ device omehci: usbus
attach omehci at fdt
file arch/armv7/omap/omehci.c omehci
+device omsysc: fdt
+attach omsysc at fdt
+file arch/armv7/omap/omsysc.c omsysc
+
device omusbtll
attach omusbtll at omap
file arch/armv7/omap/omusbtll.c omusbtll
diff --git a/sys/arch/armv7/omap/omclock.c b/sys/arch/armv7/omap/omclock.c
new file mode 100644
index 00000000000..ab93cf278ab
--- /dev/null
+++ b/sys/arch/armv7/omap/omclock.c
@@ -0,0 +1,161 @@
+/* $OpenBSD: omclock.c,v 1.1 2020/04/10 22:02:45 kettenis Exp $ */
+/*
+ * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <machine/bus.h>
+#include <machine/fdt.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_clock.h>
+#include <dev/ofw/fdt.h>
+
+#define IDLEST_MASK (0x3 << 16)
+#define IDLEST_FUNC (0x0 << 16)
+#define IDLEST_TRANS (0x1 << 16)
+#define IDLEST_IDLE (0x2 << 16)
+#define IDLEST_DISABLED (0x3 << 16)
+#define MODULEMODE_MASK (0x3 << 0)
+#define MODULEMODE_DISABLED (0x0 << 0)
+#define MODULEMODE_ENABLED (0x2 << 0)
+
+#define HREAD4(sc, reg) \
+ (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg)))
+#define HWRITE4(sc, reg, val) \
+ bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val))
+#define HSET4(sc, reg, bits) \
+ HWRITE4((sc), (reg), HREAD4((sc), (reg)) | (bits))
+#define HCLR4(sc, reg, bits) \
+ HWRITE4((sc), (reg), HREAD4((sc), (reg)) & ~(bits))
+
+struct omclock_softc {
+ struct device sc_dev;
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+ int sc_node;
+
+ struct clock_device sc_cd;
+};
+
+int omclock_match(struct device *, void *, void *);
+void omclock_attach(struct device *, struct device *, void *);
+
+struct cfattach omclock_ca = {
+ sizeof (struct omclock_softc), omclock_match, omclock_attach
+};
+
+struct cfdriver omclock_cd = {
+ NULL, "omclock", DV_DULL
+};
+
+uint32_t omclock_get_frequency(void *, uint32_t *);
+int omclock_set_frequency(void *, uint32_t *, uint32_t);
+void omclock_enable(void *, uint32_t *, int);
+
+int
+omclock_match(struct device *parent, void *match, void *aux)
+{
+ struct fdt_attach_args *faa = aux;
+
+ return OF_is_compatible(faa->fa_node, "ti,clkctrl");
+}
+
+void
+omclock_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct omclock_softc *sc = (struct omclock_softc *)self;
+ struct fdt_attach_args *faa = aux;
+ char name[32];
+
+ if (faa->fa_nreg < 1) {
+ printf(": no registers\n");
+ return;
+ }
+
+ 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)) {
+ printf(": can't map registers\n");
+ return;
+ }
+
+ sc->sc_node = faa->fa_node;
+ if (OF_getprop(sc->sc_node, "name", name, sizeof(name)) > 0) {
+ name[sizeof(name) - 1] = 0;
+ printf(": \"%s\"", name);
+ }
+
+ printf("\n");
+
+ sc->sc_cd.cd_node = faa->fa_node;
+ sc->sc_cd.cd_cookie = sc;
+ sc->sc_cd.cd_get_frequency = omclock_get_frequency;
+ sc->sc_cd.cd_set_frequency = omclock_set_frequency;
+ sc->sc_cd.cd_enable = omclock_enable;
+ clock_register(&sc->sc_cd);
+}
+
+uint32_t
+omclock_get_frequency(void *cookie, uint32_t *cells)
+{
+ printf("%s: 0x%08x 0x%08x\n", __func__, cells[0], cells[1]);
+ return 0;
+}
+
+int
+omclock_set_frequency(void *cookie, uint32_t *cells, uint32_t freq)
+{
+ printf("%s: 0x%08x 0x%08x\n", __func__, cells[0], cells[1]);
+ return -1;
+}
+
+void
+omclock_enable(void *cookie, uint32_t *cells, int on)
+{
+ struct omclock_softc *sc = cookie;
+ uint32_t base = cells[0];
+ uint32_t idx = cells[1];
+ uint32_t reg;
+ int retry;
+
+ reg = HREAD4(sc, base);
+ if (idx == 0) {
+ reg &= ~MODULEMODE_MASK;
+ if (on)
+ reg |= MODULEMODE_ENABLED;
+ else
+ reg |= MODULEMODE_DISABLED;
+ } else {
+ if (on)
+ reg |= (1U << idx);
+ else
+ reg &= ~(1U << idx);
+ }
+ HWRITE4(sc, base, reg);
+
+ if (idx == 0) {
+ retry = 100;
+ while (--retry > 0) {
+ if ((HREAD4(sc, base) & IDLEST_MASK) == IDLEST_FUNC)
+ break;
+ delay(10);
+ }
+ /* XXX Hope for the best if this loop times out. */
+ }
+}
diff --git a/sys/arch/armv7/omap/omcm.c b/sys/arch/armv7/omap/omcm.c
new file mode 100644
index 00000000000..f94bf124a5c
--- /dev/null
+++ b/sys/arch/armv7/omap/omcm.c
@@ -0,0 +1,58 @@
+/* $OpenBSD: omcm.c,v 1.1 2020/04/10 22:02:45 kettenis Exp $ */
+/*
+ * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+
+#include <machine/fdt.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/fdt.h>
+
+#include <arm/simplebus/simplebusvar.h>
+
+struct omcm_softc {
+ struct simplebus_softc sc_bus;
+};
+
+int omcm_match(struct device *, void *, void *);
+void omcm_attach(struct device *, struct device *, void *);
+
+struct cfattach omcm_ca = {
+ sizeof(struct omcm_softc), omcm_match, omcm_attach
+};
+
+struct cfdriver omcm_cd = {
+ NULL, "omcm", DV_DULL
+};
+
+int
+omcm_match(struct device *parent, void *cfdata, void *aux)
+{
+ struct fdt_attach_args *faa = aux;
+
+ return OF_is_compatible(faa->fa_node, "ti,omap4-cm");
+}
+
+void
+omcm_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct omcm_softc *sc = (struct omcm_softc *)self;
+ struct fdt_attach_args *faa = aux;
+
+ simplebus_attach(parent, &sc->sc_bus.sc_dev, faa);
+}
diff --git a/sys/arch/armv7/omap/omgpio.c b/sys/arch/armv7/omap/omgpio.c
index 72244341441..fe6f664a87d 100644
--- a/sys/arch/armv7/omap/omgpio.c
+++ b/sys/arch/armv7/omap/omgpio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: omgpio.c,v 1.11 2020/04/06 13:01:36 kettenis Exp $ */
+/* $OpenBSD: omgpio.c,v 1.12 2020/04/10 22:02:45 kettenis Exp $ */
/*
* Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org>
*
@@ -265,7 +265,7 @@ omgpio_attach(struct device *parent, struct device *self, void *aux)
if (faa->fa_nreg < 1)
return;
- unit = 0;
+ unit = -1;
if ((len = OF_getprop(faa->fa_node, "ti,hwmods", hwmods,
sizeof(hwmods))) == 6) {
if ((strncmp(hwmods, "gpio", 4) == 0) &&
@@ -273,7 +273,8 @@ omgpio_attach(struct device *parent, struct device *self, void *aux)
unit = hwmods[4] - '1';
}
- prcm_enablemodule(PRCM_GPIO0 + unit);
+ if (unit != -1)
+ prcm_enablemodule(PRCM_GPIO0 + unit);
sc->sc_node = faa->fa_node;
sc->sc_iot = faa->fa_iot;
diff --git a/sys/arch/armv7/omap/ommmc.c b/sys/arch/armv7/omap/ommmc.c
index 3d8d6b2f197..7f669ea93f0 100644
--- a/sys/arch/armv7/omap/ommmc.c
+++ b/sys/arch/armv7/omap/ommmc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ommmc.c,v 1.34 2020/04/06 13:03:02 kettenis Exp $ */
+/* $OpenBSD: ommmc.c,v 1.35 2020/04/10 22:02:45 kettenis Exp $ */
/*
* Copyright (c) 2009 Dale Rahn <drahn@openbsd.org>
@@ -320,7 +320,7 @@ ommmc_attach(struct device *parent, struct device *self, void *aux)
size = faa->fa_reg[0].size;
}
- unit = 0;
+ unit = -1;
if ((len = OF_getprop(faa->fa_node, "ti,hwmods", hwmods,
sizeof(hwmods))) == 5) {
if (!strncmp(hwmods, "mmc", 3) &&
@@ -338,7 +338,8 @@ ommmc_attach(struct device *parent, struct device *self, void *aux)
pinctrl_byname(faa->fa_node, "default");
/* Enable ICLKEN, FCLKEN? */
- prcm_enablemodule(PRCM_MMC0 + unit);
+ if (unit != -1)
+ prcm_enablemodule(PRCM_MMC0 + unit);
sc->sc_ih = arm_intr_establish_fdt(faa->fa_node, IPL_SDMMC,
ommmc_intr, sc, DEVNAME(sc));
@@ -448,7 +449,7 @@ ommmc_attach(struct device *parent, struct device *self, void *aux)
}
width = OF_getpropint(faa->fa_node, "bus-width", 1);
/* with bbb emmc width > 1 ommmc_wait_intr MMCHS_STAT_CC times out */
- if (unit != 0)
+ if (unit > 0)
width = 1;
if (width >= 8)
saa.caps |= SMC_CAPS_8BIT_MODE;
diff --git a/sys/arch/armv7/omap/omsysc.c b/sys/arch/armv7/omap/omsysc.c
new file mode 100644
index 00000000000..077cbd71578
--- /dev/null
+++ b/sys/arch/armv7/omap/omsysc.c
@@ -0,0 +1,78 @@
+/* $OpenBSD: omsysc.c,v 1.1 2020/04/10 22:02:45 kettenis Exp $ */
+/*
+ * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <machine/fdt.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_clock.h>
+#include <dev/ofw/fdt.h>
+
+#include <arm/simplebus/simplebusvar.h>
+
+struct omsysc_softc {
+ struct simplebus_softc sc_bus;
+};
+
+int omsysc_match(struct device *, void *, void *);
+void omsysc_attach(struct device *, struct device *, void *);
+
+struct cfattach omsysc_ca = {
+ sizeof(struct omsysc_softc), omsysc_match, omsysc_attach
+};
+
+struct cfdriver omsysc_cd = {
+ NULL, "omsysc", DV_DULL
+};
+
+int
+omsysc_match(struct device *parent, void *cfdata, void *aux)
+{
+ struct fdt_attach_args *faa = aux;
+ struct cfdata *cf = cfdata;
+ int node;
+
+ /*
+ * On AM33xx we need to make sure we attach the PRCM and SCM
+ * modules since they provide clock and pinctrl for other
+ * hardware modules. Therefore we attach those during the
+ * "early" phase.
+ */
+ node = OF_child(faa->fa_node);
+ if (node && cf->cf_loc[0]) {
+ return (OF_is_compatible(node, "ti,am3-prcm") ||
+ OF_is_compatible(node, "ti,am3-scm"));
+ }
+
+ return OF_is_compatible(faa->fa_node, "ti,sysc");
+}
+
+void
+omsysc_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct omsysc_softc *sc = (struct omsysc_softc *)self;
+ struct fdt_attach_args *faa = aux;
+
+ if (OF_getproplen(faa->fa_node, "ti,hwmods") < 0 &&
+ OF_is_compatible(faa->fa_node, "ti,sysc-omap2"))
+ clock_enable(faa->fa_node, "fck");
+
+ simplebus_attach(parent, &sc->sc_bus.sc_dev, faa);
+}
diff --git a/sys/arch/armv7/omap/ti_iic.c b/sys/arch/armv7/omap/ti_iic.c
index e21de45a767..30c927ce479 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.12 2020/01/13 13:32:17 mpi Exp $ */
+/* $OpenBSD: ti_iic.c,v 1.13 2020/04/10 22:02:45 kettenis Exp $ */
/* $NetBSD: ti_iic.c,v 1.4 2013/04/25 13:04:27 rkujawa Exp $ */
/*
@@ -174,7 +174,7 @@ ti_iic_attach(struct device *parent, struct device *self, void *aux)
sc->sc_iot = faa->fa_iot;
sc->sc_node = faa->fa_node;
- unit = 0;
+ unit = -1;
if ((len = OF_getprop(faa->fa_node, "ti,hwmods", hwmods,
sizeof(hwmods))) == 5) {
if (!strncmp(hwmods, "i2c", 3) &&
@@ -195,7 +195,8 @@ ti_iic_attach(struct device *parent, struct device *self, void *aux)
sc->sc_ih = arm_intr_establish_fdt(faa->fa_node, IPL_NET,
ti_iic_intr, sc, DEVNAME(sc));
- prcm_enablemodule(PRCM_I2C0 + unit);
+ if (unit != -1)
+ prcm_enablemodule(PRCM_I2C0 + unit);
rev = I2C_READ_REG(sc, AM335X_I2C_REVNB_LO);
printf(" rev %d.%d\n",