diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/clocksource/Kconfig | 4 | ||||
-rw-r--r-- | drivers/clocksource/Makefile | 1 | ||||
-rw-r--r-- | drivers/clocksource/kvx_timer.c | 59 |
3 files changed, 64 insertions, 0 deletions
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 39ddd159f9..8805cda39e 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -47,6 +47,10 @@ config CLOCKSOURCE_EFI_X86 bool "EFI X86 HW driver" depends on EFI_BOOTUP && X86 +config CLOCKSOURCE_KVX + bool "KVX core timer clocksource" + depends on KVX + config CLOCKSOURCE_MVEBU bool depends on ARCH_MVEBU diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index cba6344bbb..b4607f787f 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_CLOCKSOURCE_CLPS711X) += clps711x.o obj-$(CONFIG_CLOCKSOURCE_DIGIC) += digic.o obj-$(CONFIG_CLOCKSOURCE_EFI) += efi.o obj-$(CONFIG_CLOCKSOURCE_EFI_X86) += efi_x86.o +obj-$(CONFIG_CLOCKSOURCE_KVX) += kvx_timer.o obj-$(CONFIG_CLOCKSOURCE_MVEBU) += mvebu.o obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o obj-$(CONFIG_CLOCKSOURCE_ORION) += orion.o diff --git a/drivers/clocksource/kvx_timer.c b/drivers/clocksource/kvx_timer.c new file mode 100644 index 0000000000..f16d77b9dd --- /dev/null +++ b/drivers/clocksource/kvx_timer.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2018 Kalray Inc. + */ + +#include <common.h> +#include <clock.h> +#include <init.h> + +#include <linux/clk.h> +#include <linux/err.h> + +#include <asm/sfr.h> + +static uint64_t kvx_pm_read(void) +{ + return kvx_sfr_get(PM0); +} + +static struct clocksource kvx_clksrc = { + .read = kvx_pm_read, + .mask = CLOCKSOURCE_MASK(64), + .shift = 0, +}; + +static int kvx_timer_probe(struct device_d *dev) +{ + struct clk *clk; + uint32_t clk_freq; + struct device_node *np = dev->device_node; + + /* Get clock frequency */ + clk = clk_get(dev, NULL); + if (IS_ERR(clk)) { + dev_err(dev, "Failed to get CPU clock: %ld\n", PTR_ERR(clk)); + return PTR_ERR(clk); + } + + clk_freq = clk_get_rate(clk); + clk_put(clk); + + /* Init clocksource */ + kvx_clksrc.mult = clocksource_hz2mult(clk_freq, kvx_clksrc.shift); + + return init_clock(&kvx_clksrc); +} + +static struct of_device_id kvx_timer_dt_ids[] = { + { .compatible = "kalray,kvx-core-timer", }, + { } +}; + +static struct driver_d kvx_timer_driver = { + .name = "kvx-timer", + .probe = kvx_timer_probe, + .of_compatible = DRV_OF_COMPAT(kvx_timer_dt_ids), +}; + +device_platform_driver(kvx_timer_driver); |