Revision | 277fa69f11b19c0cb07940161a0316c789a49da0 (tree) |
---|---|
Time | 2020-07-26 18:03:24 |
Author | Yoshinori Sato <ysato@user...> |
Commiter | Yoshinori Sato |
update rx-timer
@@ -23,22 +23,23 @@ | ||
23 | 23 | #include <common.h> |
24 | 24 | #include <dm.h> |
25 | 25 | #include <timer.h> |
26 | +#include <clk.h> | |
27 | +#include <fdtdec.h> | |
26 | 28 | #include <asm/io.h> |
27 | 29 | |
28 | 30 | DECLARE_GLOBAL_DATA_PTR; |
29 | 31 | |
30 | -struct rx_timer_platdata { | |
31 | - unsigned char *regs; | |
32 | - int unit; | |
32 | +struct rx_timer_priv { | |
33 | + unsigned char *base; | |
33 | 34 | }; |
34 | 35 | |
35 | 36 | static int timer_read_counter(struct udevice *dev, u64 *count) |
36 | 37 | { |
37 | - struct rx_timer_platdata *plat = dev_get_platdata(dev); | |
38 | + struct rx_timer_priv *priv = dev_get_priv(dev); | |
38 | 39 | u32 tcnt; |
39 | 40 | |
40 | - tcnt = (readw(plat->regs + (plat->unit * 0x0400) + 0x186) << 16) & 0xffff0000; | |
41 | - tcnt |= (readw(plat->regs + (plat->unit * 0x0400) + 0x206) & 0xffff); | |
41 | + tcnt = (readw(priv->base + 0x186) << 16) & 0xffff0000; | |
42 | + tcnt |= (readw(priv->base + 0x206) & 0xffff); | |
42 | 43 | *count = timer_conv_64(tcnt); |
43 | 44 | |
44 | 45 | return 0; |
@@ -46,22 +47,30 @@ static int timer_read_counter(struct udevice *dev, u64 *count) | ||
46 | 47 | |
47 | 48 | static int rx_timer_probe(struct udevice *dev) |
48 | 49 | { |
49 | - struct rx_timer_platdata *plat = dev_get_platdata(dev); | |
50 | + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); | |
51 | + struct rx_timer_priv *priv = dev_get_priv(dev); | |
52 | + struct clk clk; | |
53 | + fdt_addr_t addr; | |
54 | + int ret; | |
55 | + u32 rate; | |
50 | 56 | |
51 | - writeb(0x07, plat->regs + (plat->unit * 0x0400) + 0x180); | |
52 | - writeb(0x07, plat->regs + (plat->unit * 0x0400) + 0x200); | |
53 | - writeb(0x06, plat->regs + (plat->unit * 0x0400) + 0x080); | |
57 | + addr = dev_read_addr(dev); | |
58 | + if (addr == FDT_ADDR_T_NONE) | |
59 | + return -EINVAL; | |
54 | 60 | |
55 | - return 0; | |
56 | -} | |
61 | + priv->base = (unsigned char *)addr; | |
57 | 62 | |
58 | -static int rx_timer_ofdata_to_platdata(struct udevice *dev) | |
59 | -{ | |
60 | - struct rx_timer_platdata *plat = dev_get_platdata(dev); | |
63 | + ret = clk_get_by_index(dev, 0, &clk); | |
64 | + if (ret < 0) | |
65 | + return ret; | |
66 | + rate = clk_get_rate(&clk); | |
67 | + rate /= 1024; | |
68 | + uc_priv->clock_rate = rate; | |
69 | + | |
70 | + writeb(0x07, addr + 0x180); | |
71 | + writeb(0x07, addr + 0x200); | |
72 | + writeb(0x06, addr + 0x080); | |
61 | 73 | |
62 | - plat->regs = map_physmem(dev_read_addr(dev), 0x0700, MAP_NOCACHE); | |
63 | - plat->unit = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), | |
64 | - "renesas,unit", 0); | |
65 | 74 | return 0; |
66 | 75 | } |
67 | 76 |
@@ -78,9 +87,7 @@ U_BOOT_DRIVER(rx_timer) = { | ||
78 | 87 | .name = "rx_timer", |
79 | 88 | .id = UCLASS_TIMER, |
80 | 89 | .of_match = rx_timer_ids, |
81 | - .ofdata_to_platdata = rx_timer_ofdata_to_platdata, | |
82 | - .platdata_auto_alloc_size = sizeof(struct rx_timer_platdata), | |
90 | + .priv_auto_alloc_size = sizeof(struct rx_timer_priv), | |
83 | 91 | .probe = rx_timer_probe, |
84 | 92 | .ops = &rx_timer_ops, |
85 | - .flags = DM_FLAG_PRE_RELOC, | |
86 | 93 | }; |