diff options
author | Wadim Egorov <w.egorov@phytec.de> | 2016-08-24 14:49:24 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-08-26 07:28:31 +0200 |
commit | 413a35395aef648dd605f8c06dd7c481d588a815 (patch) | |
tree | dfa2d707f0d2504832038b3600a0d218a4db2db9 /drivers/clocksource | |
parent | b9c57abc8c3ce61f17f6ca10811356e475541784 (diff) | |
download | barebox-413a35395aef648dd605f8c06dd7c481d588a815.tar.gz barebox-413a35395aef648dd605f8c06dd7c481d588a815.tar.xz |
clocksource: Add rk3288 timer driver
This driver comes from the u-boot (v2016.01).
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/clocksource')
-rw-r--r-- | drivers/clocksource/Kconfig | 4 | ||||
-rw-r--r-- | drivers/clocksource/Makefile | 1 | ||||
-rw-r--r-- | drivers/clocksource/rk_timer.c | 73 |
3 files changed, 78 insertions, 0 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 3fb09fbec4..f1ab554f96 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -49,3 +49,7 @@ config CLOCKSOURCE_ORION config CLOCKSOURCE_UEMD bool depends on ARCH_UEMD + +config CLOCKSOURCE_ROCKCHIP + bool + depends on ARCH_ROCKCHIP diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 4eb1656ee0..39982ffb28 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -7,3 +7,4 @@ obj-$(CONFIG_CLOCKSOURCE_MVEBU) += mvebu.o obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o obj-$(CONFIG_CLOCKSOURCE_ORION) += orion.o obj-$(CONFIG_CLOCKSOURCE_UEMD) += uemd.o +obj-$(CONFIG_CLOCKSOURCE_ROCKCHIP)+= rk_timer.o diff --git a/drivers/clocksource/rk_timer.c b/drivers/clocksource/rk_timer.c new file mode 100644 index 0000000000..baa517c62f --- /dev/null +++ b/drivers/clocksource/rk_timer.c @@ -0,0 +1,73 @@ +/* + * (C) Copyright 2015 Rockchip Electronics Co., Ltd + * + * (C) Copyright 2016 PHYTEC Messtechnik GmbH + * Author: Wadim Egorov <w.egorov@phytec.de> + + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <clock.h> +#include <init.h> +#include <io.h> +#include <mach/timer.h> +#include <stdio.h> +#include <mach/hardware.h> +#include <mach/cru_rk3288.h> +#include <common.h> + +struct rk_timer *timer_ptr; + +static uint64_t rockchip_get_ticks(void) +{ + uint64_t timebase_h, timebase_l; + + timebase_l = readl(&timer_ptr->timer_curr_value0); + timebase_h = readl(&timer_ptr->timer_curr_value1); + + return timebase_h << 32 | timebase_l; +} + +static struct clocksource rkcs = { + .read = rockchip_get_ticks, + .mask = CLOCKSOURCE_MASK(32), + .shift = 10, +}; + +static int rockchip_timer_probe(struct device_d *dev) +{ + struct resource *iores; + + iores = dev_request_mem_resource(dev, 0); + if (IS_ERR(iores)) + return PTR_ERR(iores); + timer_ptr = IOMEM(iores->start) + 0x20 * CONFIG_RK_TIMER; + + rkcs.mult = clocksource_hz2mult(OSC_HZ, rkcs.shift); + + writel(0xffffffff, &timer_ptr->timer_load_count0); + writel(0xffffffff, &timer_ptr->timer_load_count1); + writel(1, &timer_ptr->timer_ctrl_reg); + + return init_clock(&rkcs); +} + +static __maybe_unused struct of_device_id rktimer_dt_ids[] = { + { + .compatible = "rockchip,rk3288-timer", + }, { + /* sentinel */ + } +}; + +static struct driver_d rktimer_driver = { + .name = "rockchip-timer", + .probe = rockchip_timer_probe, + .of_compatible = DRV_OF_COMPAT(rktimer_dt_ids), +}; + +static int rktimer_init(void) +{ + return platform_driver_register(&rktimer_driver); +} +core_initcall(rktimer_init); |