2 * Andestech ATCPIT100 timer driver
5 * Rick Chen, NDS32 Software Engineering, rick@andestech.com
7 * SPDX-License-Identifier: GPL-2.0+
15 #define REG32_TMR(x) (*(u32 *) ((plat->regs) + (x>>2)))
18 * Definition of register offsets
21 /* ID and Revision Register */
24 /* Configuration Register */
27 /* Interrupt Enable Register */
29 #define CH_INT_EN(c , i) ((1<<i)<<(4*c))
31 /* Interrupt Status Register */
33 #define CH_INT_STA(c , i) ((1<<i)<<(4*c))
35 /* Channel Enable Register */
37 #define CH_TMR_EN(c , t) ((1<<t)<<(4*c))
39 /* Ch n Control REgister */
40 #define CH_CTL(n) (0x20+0x10*n)
41 /* Channel clock source , bit 3 , 0:External clock , 1:APB clock */
42 #define APB_CLK (1<<3)
43 /* Channel mode , bit 0~2 */
49 #define CH_REL(n) (0x24+0x10*n)
50 #define CH_CNT(n) (0x28+0x10*n)
52 struct atctmr_timer_regs {
53 u32 id_rev; /* 0x00 */
54 u32 reservd[3]; /* 0x04 ~ 0x0c */
56 u32 int_en; /* 0x14 */
57 u32 int_st; /* 0x18 */
59 u32 ch0_ctrl; /* 0x20 */
60 u32 ch0_reload; /* 0x24 */
61 u32 ch0_cntr; /* 0x28 */
62 u32 reservd1; /* 0x2c */
63 u32 ch1_ctrl; /* 0x30 */
64 u32 ch1_reload; /* 0x34 */
65 u32 int_mask; /* 0x38 */
68 struct atcpit_timer_platdata {
72 static int atcpit_timer_get_count(struct udevice *dev, u64 *count)
74 struct atcpit_timer_platdata *plat = dev_get_platdata(dev);
76 val = ~(REG32_TMR(CH_CNT(1))+0xffffffff);
77 *count = timer_conv_64(val);
81 static int atcpit_timer_probe(struct udevice *dev)
83 struct atcpit_timer_platdata *plat = dev_get_platdata(dev);
84 REG32_TMR(CH_REL(1)) = 0xffffffff;
85 REG32_TMR(CH_CTL(1)) = APB_CLK|TMR_32;
86 REG32_TMR(CH_EN) |= CH_TMR_EN(1 , 0);
90 static int atcpit_timer_ofdata_to_platdata(struct udevice *dev)
92 struct atcpit_timer_platdata *plat = dev_get_platdata(dev);
93 plat->regs = map_physmem(devfdt_get_addr(dev) , 0x100 , MAP_NOCACHE);
97 static const struct timer_ops atcpit_timer_ops = {
98 .get_count = atcpit_timer_get_count,
101 static const struct udevice_id atcpit_timer_ids[] = {
102 { .compatible = "andestech,atcpit100" },
106 U_BOOT_DRIVER(atcpit100_timer) = {
107 .name = "atcpit100_timer",
109 .of_match = atcpit_timer_ids,
110 .ofdata_to_platdata = atcpit_timer_ofdata_to_platdata,
111 .platdata_auto_alloc_size = sizeof(struct atcpit_timer_platdata),
112 .probe = atcpit_timer_probe,
113 .ops = &atcpit_timer_ops,
114 .flags = DM_FLAG_PRE_RELOC,