summaryrefslogtreecommitdiff
path: root/drivers/timer
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2016-01-21 11:49:49 -0500
committerTom Rini <[email protected]>2016-01-21 11:49:49 -0500
commit6905f4d3c7be46fed4859f51f0a8f9a1107c22e7 (patch)
treedd2fb0d12e56b3d69560b26a11ee0f0130ea0a5a /drivers/timer
parent45fe3809b9923b92f221d70eb45ae071059fd5e0 (diff)
parent747440d0fa95f2205a8fcef49b6c7845700b6246 (diff)
Merge git://git.denx.de/u-boot-dm
Diffstat (limited to 'drivers/timer')
-rw-r--r--drivers/timer/Kconfig6
-rw-r--r--drivers/timer/Makefile1
-rw-r--r--drivers/timer/omap-timer.c108
-rw-r--r--drivers/timer/sandbox_timer.c10
-rw-r--r--drivers/timer/timer-uclass.c56
5 files changed, 181 insertions, 0 deletions
diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
index 2b10d2bc6c4..ff65a731def 100644
--- a/drivers/timer/Kconfig
+++ b/drivers/timer/Kconfig
@@ -30,4 +30,10 @@ config X86_TSC_TIMER
help
Select this to enable Time-Stamp Counter (TSC) timer for x86.
+config OMAP_TIMER
+ bool "Omap timer support"
+ depends on TIMER
+ help
+ Select this to enable an timer for Omap devices.
+
endmenu
diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
index fe954eca9a5..f351fbb4e0c 100644
--- a/drivers/timer/Makefile
+++ b/drivers/timer/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_TIMER) += timer-uclass.o
obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o
obj-$(CONFIG_SANDBOX_TIMER) += sandbox_timer.o
obj-$(CONFIG_X86_TSC_TIMER) += tsc_timer.o
+obj-$(CONFIG_OMAP_TIMER) += omap-timer.o
diff --git a/drivers/timer/omap-timer.c b/drivers/timer/omap-timer.c
new file mode 100644
index 00000000000..3bb38c522c0
--- /dev/null
+++ b/drivers/timer/omap-timer.c
@@ -0,0 +1,108 @@
+/*
+ * TI OMAP timer driver
+ *
+ * Copyright (C) 2015, Texas Instruments, Incorporated
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+#include <asm/io.h>
+#include <asm/arch/clock.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Timer register bits */
+#define TCLR_START BIT(0) /* Start=1 */
+#define TCLR_AUTO_RELOAD BIT(1) /* Auto reload */
+#define TCLR_PRE_EN BIT(5) /* Pre-scaler enable */
+#define TCLR_PTV_SHIFT (2) /* Pre-scaler shift value */
+
+#define TIMER_CLOCK (V_SCLK / (2 << CONFIG_SYS_PTV))
+
+struct omap_gptimer_regs {
+ unsigned int tidr; /* offset 0x00 */
+ unsigned char res1[12];
+ unsigned int tiocp_cfg; /* offset 0x10 */
+ unsigned char res2[12];
+ unsigned int tier; /* offset 0x20 */
+ unsigned int tistatr; /* offset 0x24 */
+ unsigned int tistat; /* offset 0x28 */
+ unsigned int tisr; /* offset 0x2c */
+ unsigned int tcicr; /* offset 0x30 */
+ unsigned int twer; /* offset 0x34 */
+ unsigned int tclr; /* offset 0x38 */
+ unsigned int tcrr; /* offset 0x3c */
+ unsigned int tldr; /* offset 0x40 */
+ unsigned int ttgr; /* offset 0x44 */
+ unsigned int twpc; /* offset 0x48 */
+ unsigned int tmar; /* offset 0x4c */
+ unsigned int tcar1; /* offset 0x50 */
+ unsigned int tscir; /* offset 0x54 */
+ unsigned int tcar2; /* offset 0x58 */
+};
+
+/* Omap Timer Priv */
+struct omap_timer_priv {
+ struct omap_gptimer_regs *regs;
+};
+
+static int omap_timer_get_count(struct udevice *dev, u64 *count)
+{
+ struct omap_timer_priv *priv = dev_get_priv(dev);
+
+ *count = readl(&priv->regs->tcrr);
+
+ return 0;
+}
+
+static int omap_timer_probe(struct udevice *dev)
+{
+ struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+ struct omap_timer_priv *priv = dev_get_priv(dev);
+
+ uc_priv->clock_rate = TIMER_CLOCK;
+
+ /* start the counter ticking up, reload value on overflow */
+ writel(0, &priv->regs->tldr);
+ /* enable timer */
+ writel((CONFIG_SYS_PTV << 2) | TCLR_PRE_EN | TCLR_AUTO_RELOAD |
+ TCLR_START, &priv->regs->tclr);
+
+ return 0;
+}
+
+static int omap_timer_ofdata_to_platdata(struct udevice *dev)
+{
+ struct omap_timer_priv *priv = dev_get_priv(dev);
+
+ priv->regs = (struct omap_gptimer_regs *)dev_get_addr(dev);
+
+ return 0;
+}
+
+
+static const struct timer_ops omap_timer_ops = {
+ .get_count = omap_timer_get_count,
+};
+
+static const struct udevice_id omap_timer_ids[] = {
+ { .compatible = "ti,am335x-timer" },
+ { .compatible = "ti,am4372-timer" },
+ { .compatible = "ti,omap5430-timer" },
+ {}
+};
+
+U_BOOT_DRIVER(omap_timer) = {
+ .name = "omap_timer",
+ .id = UCLASS_TIMER,
+ .of_match = omap_timer_ids,
+ .ofdata_to_platdata = omap_timer_ofdata_to_platdata,
+ .priv_auto_alloc_size = sizeof(struct omap_timer_priv),
+ .probe = omap_timer_probe,
+ .ops = &omap_timer_ops,
+ .flags = DM_FLAG_PRE_RELOC,
+};
diff --git a/drivers/timer/sandbox_timer.c b/drivers/timer/sandbox_timer.c
index 00a9944f78e..a8da9363494 100644
--- a/drivers/timer/sandbox_timer.c
+++ b/drivers/timer/sandbox_timer.c
@@ -27,6 +27,11 @@ static int sandbox_timer_get_count(struct udevice *dev, u64 *count)
static int sandbox_timer_probe(struct udevice *dev)
{
+ struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+ if (!uc_priv->clock_rate)
+ uc_priv->clock_rate = 1000000;
+
return 0;
}
@@ -47,3 +52,8 @@ U_BOOT_DRIVER(sandbox_timer) = {
.ops = &sandbox_timer_ops,
.flags = DM_FLAG_PRE_RELOC,
};
+
+/* This is here in case we don't have a device tree */
+U_BOOT_DEVICE(sandbox_timer_non_fdt) = {
+ .name = "sandbox_timer",
+};
diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index aca421bdea3..83d1a35e062 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -6,6 +6,8 @@
#include <common.h>
#include <dm.h>
+#include <dm/lists.h>
+#include <dm/device-internal.h>
#include <errno.h>
#include <timer.h>
@@ -47,6 +49,16 @@ static int timer_pre_probe(struct udevice *dev)
return 0;
}
+static int timer_post_probe(struct udevice *dev)
+{
+ struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+ if (!uc_priv->clock_rate)
+ return -EINVAL;
+
+ return 0;
+}
+
u64 timer_conv_64(u32 count)
{
/* increment tbh if tbl has rolled over */
@@ -56,9 +68,53 @@ u64 timer_conv_64(u32 count)
return ((u64)gd->timebase_h << 32) | gd->timebase_l;
}
+int notrace dm_timer_init(void)
+{
+ const void *blob = gd->fdt_blob;
+ struct udevice *dev = NULL;
+ int node;
+ int ret;
+
+ if (gd->timer)
+ return 0;
+
+ /* Check for a chosen timer to be used for tick */
+ node = fdtdec_get_chosen_node(blob, "tick-timer");
+ if (node < 0) {
+ /* No chosen timer, trying first available timer */
+ ret = uclass_first_device(UCLASS_TIMER, &dev);
+ if (ret)
+ return ret;
+ if (!dev)
+ return -ENODEV;
+ } else {
+ if (uclass_get_device_by_of_offset(UCLASS_TIMER, node, &dev)) {
+ /*
+ * If the timer is not marked to be bound before
+ * relocation, bind it anyway.
+ */
+ if (node > 0 &&
+ !lists_bind_fdt(gd->dm_root, blob, node, &dev)) {
+ ret = device_probe(dev);
+ if (ret)
+ return ret;
+ }
+ }
+ }
+
+ if (dev) {
+ gd->timer = dev;
+ return 0;
+ }
+
+ return -ENODEV;
+}
+
UCLASS_DRIVER(timer) = {
.id = UCLASS_TIMER,
.name = "timer",
.pre_probe = timer_pre_probe,
+ .flags = DM_UC_FLAG_SEQ_ALIAS,
+ .post_probe = timer_post_probe,
.per_device_auto_alloc_size = sizeof(struct timer_dev_priv),
};