1 // SPDX-License-Identifier: GPL-2.0+
3 * Renesas RZ/A1 R7S72100 OSTM Timer driver
5 * Copyright (C) 2019 Marek Vasut <marek.vasut@gmail.com>
9 #include <clock_legacy.h>
11 #include <asm/global_data.h>
16 #include <linux/bitops.h>
24 #define OSTM_CTL_D BIT(1)
26 DECLARE_GLOBAL_DATA_PTR;
32 static u64 ostm_get_count(struct udevice *dev)
34 struct ostm_priv *priv = dev_get_priv(dev);
36 return timer_conv_64(readl(priv->regs + OSTM_CNT));
39 static int ostm_probe(struct udevice *dev)
41 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
42 struct ostm_priv *priv = dev_get_priv(dev);
43 #if CONFIG_IS_ENABLED(CLK)
47 ret = clk_get_by_index(dev, 0, &clk);
51 uc_priv->clock_rate = clk_get_rate(&clk);
55 uc_priv->clock_rate = get_board_sys_clk() / 2;
58 readb(priv->regs + OSTM_CTL);
59 writeb(OSTM_CTL_D, priv->regs + OSTM_CTL);
61 setbits_8(priv->regs + OSTM_TT, BIT(0));
62 writel(0xffffffff, priv->regs + OSTM_CMP);
63 setbits_8(priv->regs + OSTM_TS, BIT(0));
68 static int ostm_of_to_plat(struct udevice *dev)
70 struct ostm_priv *priv = dev_get_priv(dev);
72 priv->regs = dev_read_addr(dev);
77 static const struct timer_ops ostm_ops = {
78 .get_count = ostm_get_count,
81 static const struct udevice_id ostm_ids[] = {
82 { .compatible = "renesas,ostm" },
86 U_BOOT_DRIVER(ostm_timer) = {
92 .of_to_plat = ostm_of_to_plat,
93 .priv_auto = sizeof(struct ostm_priv),