summaryrefslogtreecommitdiffstats
path: root/drivers/clocksource
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-12-11 15:00:43 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-12-20 08:50:49 +0100
commit51b4a313e16c9fd76f392787d757c6f24ba5d3de (patch)
treefae3dc50826c3e9bc69b8c9b973ee61531e4812c /drivers/clocksource
parentac3f5c7e7cffe682202b68a6645979fa327212f7 (diff)
downloadbarebox-51b4a313e16c9fd76f392787d757c6f24ba5d3de.tar.gz
barebox-51b4a313e16c9fd76f392787d757c6f24ba5d3de.tar.xz
ARM: omap: dmtimer: Turn into a driver
Turn OMAP dmtimer into a driver and move to drivers/clocksource. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/clocksource')
-rw-r--r--drivers/clocksource/Kconfig3
-rw-r--r--drivers/clocksource/Makefile1
-rw-r--r--drivers/clocksource/timer-ti-dm.c119
3 files changed, 123 insertions, 0 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 337a7a2e13..2228d44bde 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -88,4 +88,7 @@ config CLOCKSOURCE_DW_APB_TIMER
help
Enables the support for the dw_apb timer.
+config CLOCKSOURCE_TI_DM
+ bool
+
endmenu
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index ab78f0700d..3b154cbc2a 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_CLOCKSOURCE_ARMV8_TIMER) += armv8-timer.o
obj-$(CONFIG_CLOCKSOURCE_ARM_GLOBAL_TIMER) += arm_global_timer.o
obj-$(CONFIG_CLOCKSOURCE_IMX_GPT) += timer-imx-gpt.o
obj-$(CONFIG_CLOCKSOURCE_DW_APB_TIMER) += dw_apb_timer.o
+obj-$(CONFIG_CLOCKSOURCE_TI_DM) += timer-ti-dm.o \ No newline at end of file
diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c
new file mode 100644
index 0000000000..f41f0bb423
--- /dev/null
+++ b/drivers/clocksource/timer-ti-dm.c
@@ -0,0 +1,119 @@
+/**
+ * @file
+ * @brief Support DMTimer counter
+ *
+ * FileName: arch/arm/mach-omap/dmtimer.c
+ */
+/*
+ * This File is based on arch/arm/mach-omap/s32k_clksource.c
+ * (C) Copyright 2008
+ * Texas Instruments, <www.ti.com>
+ * Nishanth Menon <x0nishan@ti.com>
+ *
+ * (C) Copyright 2012 Phytec Messtechnik GmbH
+ * Author: Teresa Gámez <t.gamez@phytec.de>
+ * (C) Copyright 2015 Phytec Messtechnik GmbH
+ * Author: Daniel Schultz <d.schultz@phytec.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <common.h>
+#include <clock.h>
+#include <init.h>
+#include <io.h>
+#include <mach/am33xx-silicon.h>
+#include <mach/am33xx-clock.h>
+
+#include <stdio.h>
+
+#define CLK_RC32K 32768
+
+#define TIDR 0x0
+#define TIOCP_CFG 0x10
+#define IRQ_EOI 0x20
+#define IRQSTATUS_RAW 0x24
+#define IRQSTATUS 0x28
+#define IRQSTATUS_SET 0x2c
+#define IRQSTATUS_CLR 0x30
+#define IRQWAKEEN 0x34
+#define TCLR 0x38
+#define TCRR 0x3C
+#define TLDR 0x40
+#define TTGR 0x44
+#define TWPS 0x48
+#define TMAR 0x4C
+#define TCAR1 0x50
+#define TSICR 0x54
+#define TCAR2 0x58
+
+static void *base;
+
+/**
+ * @brief Provide a simple counter read
+ *
+ * @return DMTimer counter
+ */
+static uint64_t dmtimer_read(void)
+{
+ return readl(base + TCRR);
+}
+
+static struct clocksource dmtimer_cs = {
+ .read = dmtimer_read,
+ .mask = CLOCKSOURCE_MASK(32),
+ .shift = 10,
+};
+
+static int omap_dmtimer_probe(struct device_d *dev)
+{
+ struct resource *iores;
+ u64 clk_speed;
+
+ /* one timer is enough */
+ if (base)
+ return 0;
+
+ iores = dev_request_mem_resource(dev, 0);
+ if (IS_ERR(iores))
+ return PTR_ERR(iores);
+ base = IOMEM(iores->start);
+
+ clk_speed = am33xx_get_osc_clock();
+ clk_speed *= 1000;
+ dmtimer_cs.mult = clocksource_hz2mult(clk_speed, dmtimer_cs.shift);
+
+ /* Enable counter */
+ writel(0x3, base + TCLR);
+
+ return init_clock(&dmtimer_cs);
+}
+
+static __maybe_unused struct of_device_id omap_dmtimer_dt_ids[] = {
+ {
+ .compatible = "ti,am335x-timer",
+ }, {
+ /* sentinel */
+ }
+};
+
+static struct driver_d omap_dmtimer_driver = {
+ .name = "omap-dmtimer",
+ .probe = omap_dmtimer_probe,
+ .of_compatible = DRV_OF_COMPAT(omap_dmtimer_dt_ids),
+};
+
+static int omap_dmtimer_init(void)
+{
+ return platform_driver_register(&omap_dmtimer_driver);
+}
+postcore_initcall(omap_dmtimer_init);