This driver supports the peripheral block timer found on the Broadcom BCA SoCs. It is 30-bit up-count timer running at 50MHz and can be used as the system clock source such as on BCM63138.
Signed-off-by: William Zhang <william.zh...@broadcom.com> --- MAINTAINERS | 1 + drivers/timer/Kconfig | 8 ++++ drivers/timer/Makefile | 1 + drivers/timer/bcmbca_timer.c | 93 ++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 drivers/timer/bcmbca_timer.c diff --git a/MAINTAINERS b/MAINTAINERS index d1d13c733db4..8c3a7d77f17d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -216,6 +216,7 @@ M: Joel Peshkin <joel.pesh...@broadcom.com> S: Maintained F: arch/arm/mach-bcmbca/ F: board/broadcom/bcmbca/ +F: drivers/timer/bcmbca-timer.c N: bcmbca N: bcm[9]?47622 N: bcm[9]?63148 diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index 20b5af7e260f..2e5af97b3ad5 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -125,6 +125,14 @@ config SPL_ATMEL_TCB_TIMER Select this to enable the use of the timer counter as a monotonic counter in SPL. + +config BCMBCA_TIMER + bool "Broadcom BCMBCA SoC timer support" + depends on TIMER + help + Select this to enable peripheral timer support for Broadcom + BCMBCA SoC devices + config CADENCE_TTC_TIMER bool "Cadence TTC (Triple Timer Counter)" depends on TIMER diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile index d9822a537009..d581db7563c5 100644 --- a/drivers/timer/Makefile +++ b/drivers/timer/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_AST_TIMER) += ast_timer.o obj-$(CONFIG_ATCPIT100_TIMER) += atcpit100_timer.o obj-$(CONFIG_$(SPL_)ATMEL_PIT_TIMER) += atmel_pit_timer.o obj-$(CONFIG_$(SPL_)ATMEL_TCB_TIMER) += atmel_tcb_timer.o +obj-$(CONFIG_BCMBCA_TIMER) += bcmbca_timer.o obj-$(CONFIG_CADENCE_TTC_TIMER) += cadence-ttc.o obj-$(CONFIG_DESIGNWARE_APB_TIMER) += dw-apb-timer.o obj-$(CONFIG_GXP_TIMER) += gxp-timer.o diff --git a/drivers/timer/bcmbca_timer.c b/drivers/timer/bcmbca_timer.c new file mode 100644 index 000000000000..78a8a67f22a7 --- /dev/null +++ b/drivers/timer/bcmbca_timer.c @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Broadcom BCMBCA Broadband SoC timer driver + * Copyright 2022 Broadcom Ltd. + */ + +#include <common.h> +#include <dm.h> +#include <timer.h> +#include <clk.h> +#include <asm/io.h> +#include <linux/ioport.h> +#include <linux/io.h> + +#define TIMER_CTL 0 +#define TIMER_CNT 0x10 + +#define BCMBCA_TIMER_ENABLE BIT(31) +#define BCMBCA_TIMER_CNT_MASK 0x3fffffff +#define BCMBCA_TIMER_CNT_HIGH_SHIFT 30 + +struct bcmbca_timer_priv { + void __iomem *reg_base; + u32 cnt_high; + u32 cnt_low; +}; + +static u64 bcmbca_timer_get_count(struct udevice *dev) +{ + u64 cnt_high_64; + struct bcmbca_timer_priv *priv = dev_get_priv(dev); + u32 val = readl(priv->reg_base + TIMER_CNT) & BCMBCA_TIMER_CNT_MASK; + + /* handle hardware counter overflow case*/ + if (val < priv->cnt_low) + priv->cnt_high++; + priv->cnt_low = val; + cnt_high_64 = (u64)priv->cnt_high; + + return (cnt_high_64 << BCMBCA_TIMER_CNT_HIGH_SHIFT | priv->cnt_low); +} + +static void bcmbca_timer_start(struct udevice *dev) +{ + struct bcmbca_timer_priv *priv = dev_get_priv(dev); + + writel(BCMBCA_TIMER_ENABLE | BCMBCA_TIMER_CNT_MASK, + priv->reg_base + TIMER_CTL); +} + +static int bcmbca_timer_probe(struct udevice *dev) +{ + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); + struct bcmbca_timer_priv *priv = dev_get_priv(dev); + struct clk clk; + int ret; + + priv->reg_base = dev_remap_addr(dev); + + if (!priv->reg_base) + return -ENOENT; + + ret = clk_get_by_index(dev, 0, &clk); + if (ret) + return ret; + + uc_priv->clock_rate = clk_get_rate(&clk); + if (!uc_priv->clock_rate) + return -EINVAL; + + bcmbca_timer_start(dev); + + return 0; +} + +static const struct timer_ops bcmbca_timer_ops = { + .get_count = bcmbca_timer_get_count, +}; + +static const struct udevice_id bcmbca_timer_ids[] = { + { .compatible = "brcm,bcm-timers" }, + { } +}; + +U_BOOT_DRIVER(bcmbca_timer) = { + .name = "bcmbca_timer", + .id = UCLASS_TIMER, + .of_match = bcmbca_timer_ids, + .priv_auto = sizeof(struct bcmbca_timer_priv), + .probe = bcmbca_timer_probe, + .ops = &bcmbca_timer_ops, + .flags = DM_FLAG_PRE_RELOC, +}; -- 2.37.1
smime.p7s
Description: S/MIME Cryptographic Signature