summaryrefslogtreecommitdiffstats
path: root/drivers/clocksource
diff options
context:
space:
mode:
authorCarlo Caione <carlo.caione@gmail.com>2012-10-18 21:42:39 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-10-21 10:51:19 +0200
commitc03235485c88707bfbdb364061b14bc5e3b989c8 (patch)
tree245797bca16cea2ec27d65153b2d4f85903cda9c /drivers/clocksource
parent04b941cbac6b1aaf16653478a2abbba84ff3eefb (diff)
downloadbarebox-c03235485c88707bfbdb364061b14bc5e3b989c8.tar.gz
barebox-c03235485c88707bfbdb364061b14bc5e3b989c8.tar.xz
BCM2835: add clocksource driver
Signed-off-by: Carlo Caione <carlo.caione@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/clocksource')
-rw-r--r--drivers/clocksource/Kconfig4
-rw-r--r--drivers/clocksource/Makefile1
-rw-r--r--drivers/clocksource/bcm2835.c90
3 files changed, 95 insertions, 0 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 9d6d293ee3..09acdd74c5 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -2,6 +2,10 @@ config ARM_SMP_TWD
bool
depends on ARM && CPU_V7
+config CLOCKSOURCE_BCM2835
+ bool
+ depends on ARCH_BCM2835
+
config CLOCKSOURCE_NOMADIK
bool
depends on ARM
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index bef465cea7..92d7c1344a 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -1,2 +1,3 @@
obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o
+obj-$(CONFIG_CLOCKSOURCE_BCM2835) += bcm2835.o
obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
diff --git a/drivers/clocksource/bcm2835.c b/drivers/clocksource/bcm2835.c
new file mode 100644
index 0000000000..d5fe0f03a2
--- /dev/null
+++ b/drivers/clocksource/bcm2835.c
@@ -0,0 +1,90 @@
+/*
+ * Author: Carlo Caione <carlo@carlocaione.org>
+ *
+ * Based on clocksource for nomadik
+ *
+ * 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 <io.h>
+#include <init.h>
+#include <driver.h>
+#include <errno.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+/* Registers */
+#define ST_CLO 0x04
+
+static __iomem void *stc_base;
+
+static uint64_t stc_read_cycles(void)
+{
+ return readl(stc_base + ST_CLO);
+}
+
+static struct clocksource bcm2835_stc = {
+ .read = stc_read_cycles,
+ .mask = CLOCKSOURCE_MASK(32),
+};
+
+static int bcm2835_cs_probe(struct device_d *dev)
+{
+ static struct clk *stc_clk;
+ u32 rate;
+ int ret;
+
+ stc_clk = clk_get(dev, NULL);
+ if (IS_ERR(stc_clk)) {
+ ret = PTR_ERR(stc_clk);
+ dev_err(dev, "clock not found: %d\n", ret);
+ return ret;
+ }
+
+ ret = clk_enable(stc_clk);
+ if (ret) {
+ dev_err(dev, "clock failed to enable: %d\n", ret);
+ clk_put(stc_clk);
+ return ret;
+ }
+
+ rate = clk_get_rate(stc_clk);
+ stc_base = dev_request_mem_region(dev, 0);
+
+ clocks_calc_mult_shift(&bcm2835_stc.mult, &bcm2835_stc.shift, rate, NSEC_PER_SEC, 60);
+ init_clock(&bcm2835_stc);
+
+ return 0;
+}
+
+static __maybe_unused struct of_device_id bcm2835_cs_dt_ids[] = {
+ {
+ .compatible = "brcm,bcm2835-system-timer",
+ }, {
+ /* sentinel */
+ }
+};
+
+static struct driver_d bcm2835_cs_driver = {
+ .name = "bcm2835-cs",
+ .probe = bcm2835_cs_probe,
+ .of_compatible = DRV_OF_COMPAT(bcm2835_cs_dt_ids),
+};
+
+static int bcm2835_cs_init(void)
+{
+ return platform_driver_register(&bcm2835_cs_driver);
+}
+coredevice_initcall(bcm2835_cs_init);