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>
21 #define OSTM_CTL_D BIT(1)
23 DECLARE_GLOBAL_DATA_PTR;
29 static int ostm_get_count(struct udevice *dev, u64 *count)
31 struct ostm_priv *priv = dev_get_priv(dev);
33 *count = timer_conv_64(readl(priv->regs + OSTM_CNT));
38 static int ostm_probe(struct udevice *dev)
40 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
41 struct ostm_priv *priv = dev_get_priv(dev);
42 #if CONFIG_IS_ENABLED(CLK)
46 ret = clk_get_by_index(dev, 0, &clk);
50 uc_priv->clock_rate = clk_get_rate(&clk);
54 uc_priv->clock_rate = CONFIG_SYS_CLK_FREQ / 2;
57 readb(priv->regs + OSTM_CTL);
58 writeb(OSTM_CTL_D, priv->regs + OSTM_CTL);
60 setbits_8(priv->regs + OSTM_TT, BIT(0));
61 writel(0xffffffff, priv->regs + OSTM_CMP);
62 setbits_8(priv->regs + OSTM_TS, BIT(0));
67 static int ostm_ofdata_to_platdata(struct udevice *dev)
69 struct ostm_priv *priv = dev_get_priv(dev);
71 priv->regs = dev_read_addr(dev);
76 static const struct timer_ops ostm_ops = {
77 .get_count = ostm_get_count,
80 static const struct udevice_id ostm_ids[] = {
81 { .compatible = "renesas,ostm" },
85 U_BOOT_DRIVER(ostm_timer) = {
91 .ofdata_to_platdata = ostm_ofdata_to_platdata,
92 .priv_auto_alloc_size = sizeof(struct ostm_priv),