1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Microchip Corporation
4 * Wenyou.Yang <wenyou.yang@microchip.com>
12 #include <linux/bitops.h>
14 #define AT91_PIT_VALUE 0xfffff
15 #define AT91_PIT_PITEN BIT(24) /* Timer Enabled */
17 struct atmel_pit_regs {
24 struct atmel_pit_platdata {
25 struct atmel_pit_regs *regs;
28 static int atmel_pit_get_count(struct udevice *dev, u64 *count)
30 struct atmel_pit_platdata *plat = dev_get_platdata(dev);
31 struct atmel_pit_regs *const regs = plat->regs;
32 u32 val = readl(®s->value_image);
34 *count = timer_conv_64(val);
39 static int atmel_pit_probe(struct udevice *dev)
41 struct atmel_pit_platdata *plat = dev_get_platdata(dev);
42 struct atmel_pit_regs *const regs = plat->regs;
43 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
48 ret = clk_get_by_index(dev, 0, &clk);
52 clk_rate = clk_get_rate(&clk);
56 uc_priv->clock_rate = clk_rate / 16;
58 writel(AT91_PIT_VALUE | AT91_PIT_PITEN, ®s->mode);
63 static int atmel_pit_ofdata_to_platdata(struct udevice *dev)
65 struct atmel_pit_platdata *plat = dev_get_platdata(dev);
67 plat->regs = dev_read_addr_ptr(dev);
72 static const struct timer_ops atmel_pit_ops = {
73 .get_count = atmel_pit_get_count,
76 static const struct udevice_id atmel_pit_ids[] = {
77 { .compatible = "atmel,at91sam9260-pit" },
81 U_BOOT_DRIVER(atmel_pit) = {
84 .of_match = atmel_pit_ids,
85 .ofdata_to_platdata = atmel_pit_ofdata_to_platdata,
86 .platdata_auto_alloc_size = sizeof(struct atmel_pit_platdata),
87 .probe = atmel_pit_probe,
88 .ops = &atmel_pit_ops,