1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Microchip Corporation
11 #include <linux/bitops.h>
13 #define AT91_PIT_VALUE 0xfffff
14 #define AT91_PIT_PITEN BIT(24) /* Timer Enabled */
16 struct atmel_pit_regs {
23 struct atmel_pit_plat {
24 struct atmel_pit_regs *regs;
27 static u64 atmel_pit_get_count(struct udevice *dev)
29 struct atmel_pit_plat *plat = dev_get_plat(dev);
30 struct atmel_pit_regs *const regs = plat->regs;
31 u32 val = readl(®s->value_image);
33 return timer_conv_64(val);
36 static int atmel_pit_probe(struct udevice *dev)
38 struct atmel_pit_plat *plat = dev_get_plat(dev);
39 struct atmel_pit_regs *const regs = plat->regs;
40 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
45 ret = clk_get_by_index(dev, 0, &clk);
49 clk_rate = clk_get_rate(&clk);
53 uc_priv->clock_rate = clk_rate / 16;
55 writel(AT91_PIT_VALUE | AT91_PIT_PITEN, ®s->mode);
60 static int atmel_pit_of_to_plat(struct udevice *dev)
62 struct atmel_pit_plat *plat = dev_get_plat(dev);
64 plat->regs = dev_read_addr_ptr(dev);
69 static const struct timer_ops atmel_pit_ops = {
70 .get_count = atmel_pit_get_count,
73 static const struct udevice_id atmel_pit_ids[] = {
74 { .compatible = "atmel,at91sam9260-pit" },
78 U_BOOT_DRIVER(atmel_pit) = {
81 .of_match = atmel_pit_ids,
82 .of_to_plat = atmel_pit_of_to_plat,
83 .plat_auto = sizeof(struct atmel_pit_plat),
84 .probe = atmel_pit_probe,
85 .ops = &atmel_pit_ops,