]> Git Repo - J-u-boot.git/blame - drivers/timer/atmel_pit_timer.c
dm: treewide: Rename auto_alloc_size members to be shorter
[J-u-boot.git] / drivers / timer / atmel_pit_timer.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
47edaea4
WY
2/*
3 * Copyright (C) 2017 Microchip Corporation
4 * Wenyou.Yang <[email protected]>
47edaea4
WY
5 */
6
7#include <common.h>
8#include <clk.h>
9#include <dm.h>
10#include <timer.h>
11#include <asm/io.h>
cd93d625 12#include <linux/bitops.h>
47edaea4
WY
13
14#define AT91_PIT_VALUE 0xfffff
15#define AT91_PIT_PITEN BIT(24) /* Timer Enabled */
16
17struct atmel_pit_regs {
18 u32 mode;
19 u32 status;
20 u32 value;
21 u32 value_image;
22};
23
24struct atmel_pit_platdata {
25 struct atmel_pit_regs *regs;
26};
27
8af7bb91 28static u64 atmel_pit_get_count(struct udevice *dev)
47edaea4
WY
29{
30 struct atmel_pit_platdata *plat = dev_get_platdata(dev);
31 struct atmel_pit_regs *const regs = plat->regs;
32 u32 val = readl(&regs->value_image);
33
8af7bb91 34 return timer_conv_64(val);
47edaea4
WY
35}
36
37static int atmel_pit_probe(struct udevice *dev)
38{
39 struct atmel_pit_platdata *plat = dev_get_platdata(dev);
40 struct atmel_pit_regs *const regs = plat->regs;
41 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
42 struct clk clk;
43 ulong clk_rate;
44 int ret;
45
46 ret = clk_get_by_index(dev, 0, &clk);
47 if (ret)
48 return -EINVAL;
49
50 clk_rate = clk_get_rate(&clk);
51 if (!clk_rate)
52 return -EINVAL;
53
54 uc_priv->clock_rate = clk_rate / 16;
55
56 writel(AT91_PIT_VALUE | AT91_PIT_PITEN, &regs->mode);
57
58 return 0;
59}
60
61static int atmel_pit_ofdata_to_platdata(struct udevice *dev)
62{
63 struct atmel_pit_platdata *plat = dev_get_platdata(dev);
64
702e57e1 65 plat->regs = dev_read_addr_ptr(dev);
47edaea4
WY
66
67 return 0;
68}
69
70static const struct timer_ops atmel_pit_ops = {
71 .get_count = atmel_pit_get_count,
72};
73
74static const struct udevice_id atmel_pit_ids[] = {
75 { .compatible = "atmel,at91sam9260-pit" },
76 { }
77};
78
79U_BOOT_DRIVER(atmel_pit) = {
80 .name = "atmel_pit",
81 .id = UCLASS_TIMER,
82 .of_match = atmel_pit_ids,
83 .ofdata_to_platdata = atmel_pit_ofdata_to_platdata,
41575d8e 84 .platdata_auto = sizeof(struct atmel_pit_platdata),
47edaea4
WY
85 .probe = atmel_pit_probe,
86 .ops = &atmel_pit_ops,
47edaea4 87};
This page took 0.165712 seconds and 4 git commands to generate.