From 89fd0cccf9cff1537567b63eaa7a33110bd43a2c Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 15 Sep 2022 16:20:37 +0200 Subject: timer: orion-timer: Add support for other Armada SoC's This patch adds support for other Marvell Armada SoC's, supporting the 25MHz fixed clock operation, like the Armada XP etc. Signed-off-by: Stefan Roese Tested-by: Tony Dinh --- drivers/timer/Kconfig | 5 ++++- drivers/timer/orion-timer.c | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 4 deletions(-) (limited to 'drivers/timer') diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index 1b492360396..fd8745ffc2e 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -203,8 +203,11 @@ config OMAP_TIMER config ORION_TIMER bool "Orion timer support" depends on TIMER + default y if ARCH_KIRKWOOD || (ARCH_MVEBU && ARMADA_32BIT) + select TIMER_EARLY if ARCH_MVEBU help - Select this to enable an timer for Orion devices. + Select this to enable an timer for Orion and Armada devices + like Armada XP etc. config RISCV_TIMER bool "RISC-V timer support" diff --git a/drivers/timer/orion-timer.c b/drivers/timer/orion-timer.c index d7d1a1b2446..14f318e57d4 100644 --- a/drivers/timer/orion-timer.c +++ b/drivers/timer/orion-timer.c @@ -11,10 +11,34 @@ #define TIMER0_RELOAD 0x10 #define TIMER0_VAL 0x14 +enum input_clock_type { + INPUT_CLOCK_NON_FIXED, + INPUT_CLOCK_25MHZ, /* input clock rate is fixed to 25MHz */ +}; + struct orion_timer_priv { void *base; }; +#define MVEBU_TIMER_FIXED_RATE_25MHZ 25000000 + +/** + * timer_early_get_rate() - Get the timer rate before driver model + */ +unsigned long notrace timer_early_get_rate(void) +{ + return MVEBU_TIMER_FIXED_RATE_25MHZ; +} + +/** + * timer_early_get_count() - Get the timer count before driver model + * + */ +u64 notrace timer_early_get_count(void) +{ + return timer_conv_64(~readl(MVEBU_TIMER_BASE + TIMER0_VAL)); +} + static uint64_t orion_timer_get_count(struct udevice *dev) { struct orion_timer_priv *priv = dev_get_priv(dev); @@ -25,6 +49,7 @@ static uint64_t orion_timer_get_count(struct udevice *dev) static int orion_timer_probe(struct udevice *dev) { struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); + enum input_clock_type type = dev_get_driver_data(dev); struct orion_timer_priv *priv = dev_get_priv(dev); priv->base = devfdt_remap_addr_index(dev, 0); @@ -33,11 +58,20 @@ static int orion_timer_probe(struct udevice *dev) return -ENOMEM; } - uc_priv->clock_rate = CONFIG_SYS_TCLK; - writel(~0, priv->base + TIMER0_VAL); writel(~0, priv->base + TIMER0_RELOAD); + if (type == INPUT_CLOCK_25MHZ) { + /* + * On Armada XP / 38x ..., the 25MHz clock source needs to + * be enabled + */ + setbits_le32(priv->base + TIMER_CTRL, BIT(11)); + uc_priv->clock_rate = MVEBU_TIMER_FIXED_RATE_25MHZ; + } else { + uc_priv->clock_rate = CONFIG_SYS_TCLK; + } + /* enable timer */ setbits_le32(priv->base + TIMER_CTRL, TIMER0_EN | TIMER0_RELOAD_EN); @@ -49,7 +83,9 @@ static const struct timer_ops orion_timer_ops = { }; static const struct udevice_id orion_timer_ids[] = { - { .compatible = "marvell,orion-timer" }, + { .compatible = "marvell,orion-timer", .data = INPUT_CLOCK_NON_FIXED }, + { .compatible = "marvell,armada-370-timer", .data = INPUT_CLOCK_25MHZ }, + { .compatible = "marvell,armada-xp-timer", .data = INPUT_CLOCK_25MHZ }, {} }; -- cgit v1.2.3 From a68f13a3b6b4995ba5d0ad929eb9b79dc2a0a8c3 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Thu, 15 Sep 2022 16:20:38 +0200 Subject: timer: orion-timer: Add timer_get_boot_us() for BOOTSTAGE support Add timer_get_boot_us() to support boards, that have CONFIG_BOOTSTAGE enabled, like pogo_v4. Signed-off-by: Stefan Roese Tested-by: Tony Dinh --- drivers/timer/orion-timer.c | 83 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 19 deletions(-) (limited to 'drivers/timer') diff --git a/drivers/timer/orion-timer.c b/drivers/timer/orion-timer.c index 14f318e57d4..cd63ea91623 100644 --- a/drivers/timer/orion-timer.c +++ b/drivers/timer/orion-timer.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include #include +#include #include #include #include @@ -22,12 +23,56 @@ struct orion_timer_priv { #define MVEBU_TIMER_FIXED_RATE_25MHZ 25000000 +static bool early_init_done __section(".data") = false; + +/* Common functions for early (boot) and DM based timer */ +static void orion_timer_init(void *base, enum input_clock_type type) +{ + writel(~0, base + TIMER0_VAL); + writel(~0, base + TIMER0_RELOAD); + + if (type == INPUT_CLOCK_25MHZ) { + /* + * On Armada XP / 38x ..., the 25MHz clock source needs to + * be enabled + */ + setbits_le32(base + TIMER_CTRL, BIT(11)); + } + + /* enable timer */ + setbits_le32(base + TIMER_CTRL, TIMER0_EN | TIMER0_RELOAD_EN); +} + +static uint64_t orion_timer_get_count(void *base) +{ + return timer_conv_64(~readl(base + TIMER0_VAL)); +} + +/* Early (e.g. bootstage etc) timer functions */ +static void notrace timer_early_init(void) +{ + /* Only init the timer once */ + if (early_init_done) + return; + early_init_done = true; + + if (IS_ENABLED(CONFIG_ARCH_MVEBU)) + orion_timer_init((void *)MVEBU_TIMER_BASE, INPUT_CLOCK_25MHZ); + else + orion_timer_init((void *)MVEBU_TIMER_BASE, INPUT_CLOCK_NON_FIXED); +} + /** * timer_early_get_rate() - Get the timer rate before driver model */ unsigned long notrace timer_early_get_rate(void) { - return MVEBU_TIMER_FIXED_RATE_25MHZ; + timer_early_init(); + + if (IS_ENABLED(CONFIG_ARCH_MVEBU)) + return MVEBU_TIMER_FIXED_RATE_25MHZ; + else + return CONFIG_SYS_TCLK; } /** @@ -36,14 +81,25 @@ unsigned long notrace timer_early_get_rate(void) */ u64 notrace timer_early_get_count(void) { - return timer_conv_64(~readl(MVEBU_TIMER_BASE + TIMER0_VAL)); + timer_early_init(); + + return orion_timer_get_count((void *)MVEBU_TIMER_BASE); } -static uint64_t orion_timer_get_count(struct udevice *dev) +ulong timer_get_boot_us(void) +{ + u64 ticks; + + ticks = timer_early_get_count(); + return lldiv(ticks * 1000, timer_early_get_rate()); +} + +/* DM timer functions */ +static uint64_t dm_orion_timer_get_count(struct udevice *dev) { struct orion_timer_priv *priv = dev_get_priv(dev); - return timer_conv_64(~readl(priv->base + TIMER0_VAL)); + return orion_timer_get_count(priv->base); } static int orion_timer_probe(struct udevice *dev) @@ -58,28 +114,17 @@ static int orion_timer_probe(struct udevice *dev) return -ENOMEM; } - writel(~0, priv->base + TIMER0_VAL); - writel(~0, priv->base + TIMER0_RELOAD); - - if (type == INPUT_CLOCK_25MHZ) { - /* - * On Armada XP / 38x ..., the 25MHz clock source needs to - * be enabled - */ - setbits_le32(priv->base + TIMER_CTRL, BIT(11)); + if (type == INPUT_CLOCK_25MHZ) uc_priv->clock_rate = MVEBU_TIMER_FIXED_RATE_25MHZ; - } else { + else uc_priv->clock_rate = CONFIG_SYS_TCLK; - } - - /* enable timer */ - setbits_le32(priv->base + TIMER_CTRL, TIMER0_EN | TIMER0_RELOAD_EN); + orion_timer_init(priv->base, type); return 0; } static const struct timer_ops orion_timer_ops = { - .get_count = orion_timer_get_count, + .get_count = dm_orion_timer_get_count, }; static const struct udevice_id orion_timer_ids[] = { -- cgit v1.2.3