リビジョン | 773502668478573ab38ad2e84187a6053a6b831a (tree) |
---|---|
日時 | 2016-05-26 23:01:36 |
作者 | Yoshinori Sato <ysato@user...> |
コミッター | Yoshinori Sato |
sh: timer driver
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
@@ -7,6 +7,7 @@ | ||
7 | 7 | |
8 | 8 | |
9 | 9 | obj-$(CONFIG_CMD_BOOTM) += bootm.o |
10 | +ifndef CONFIG_DM | |
10 | 11 | ifneq ($(CONFIG_TIMER)$(CONFIG_SPL_BUILD),y) |
11 | 12 | ifeq ($(CONFIG_CPU_SH2),y) |
12 | 13 | obj-y += time_sh2.o |
@@ -14,6 +15,7 @@ else | ||
14 | 15 | obj-y += time.o |
15 | 16 | endif |
16 | 17 | endif |
18 | +endif | |
17 | 19 | obj-$(CONFIG_CMD_SH_ZIMAGEBOOT) += zimageboot.o |
18 | 20 | |
19 | 21 | udivsi3-y := udivsi3_i4i-Os.o |
@@ -46,6 +46,12 @@ config OMAP_TIMER | ||
46 | 46 | help |
47 | 47 | Select this to enable an timer for Omap devices. |
48 | 48 | |
49 | +config SH3_TIMER | |
50 | + bool "SH3 timer support" | |
51 | + depends on TIMER | |
52 | + help | |
53 | + Select this to enable an timer for SH4 devices. | |
54 | + | |
49 | 55 | config SH4_TIMER |
50 | 56 | bool "SH4 timer support" |
51 | 57 | depends on TIMER |
@@ -9,4 +9,5 @@ obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o | ||
9 | 9 | obj-$(CONFIG_SANDBOX_TIMER) += sandbox_timer.o |
10 | 10 | obj-$(CONFIG_X86_TSC_TIMER) += tsc_timer.o |
11 | 11 | obj-$(CONFIG_OMAP_TIMER) += omap-timer.o |
12 | +obj-$(CONFIG_SH3_TIMER) += sh3_timer.o | |
12 | 13 | obj-$(CONFIG_SH4_TIMER) += sh4_timer.o |
@@ -0,0 +1,83 @@ | ||
1 | +/* | |
2 | + * (C) Copyright 2016 | |
3 | + * Yoshinori Sato <ysato@users.sourceforge.jp> | |
4 | + * | |
5 | + * SPDX-License-Identifier: GPL-2.0+ | |
6 | + */ | |
7 | + | |
8 | +#include <common.h> | |
9 | +#include <dm.h> | |
10 | +#include <timer.h> | |
11 | +#include <asm/processor.h> | |
12 | +#include <asm/io.h> | |
13 | + | |
14 | +DECLARE_GLOBAL_DATA_PTR; | |
15 | + | |
16 | +struct sh3_timer_platdata { | |
17 | + unsigned char *regs; | |
18 | + int ch; | |
19 | +}; | |
20 | + | |
21 | +static int timer_read_counter(struct udevice *dev, u64 *count) | |
22 | +{ | |
23 | + struct sh3_timer_platdata *plat = dev_get_platdata(dev); | |
24 | + | |
25 | + *count = timer_conv_64(~readl(plat->regs + 4 + plat->ch * 12 + 4)); | |
26 | + return 0; | |
27 | +} | |
28 | + | |
29 | +static void tmu_timer_start(unsigned char *reg, unsigned int timer) | |
30 | +{ | |
31 | + if (timer > 2) | |
32 | + return; | |
33 | + writeb(readb(reg + 2) | (1 << timer), reg + 2); | |
34 | +} | |
35 | + | |
36 | +static void tmu_timer_stop(unsigned char *reg, unsigned int timer) | |
37 | +{ | |
38 | + if (timer > 2) | |
39 | + return; | |
40 | + writeb(readb(reg + 2) & ~(1 << timer), reg + 2); | |
41 | +} | |
42 | + | |
43 | +static int sh3_timer_probe(struct udevice *dev) | |
44 | +{ | |
45 | + struct sh3_timer_platdata *plat = dev_get_platdata(dev); | |
46 | + | |
47 | + writew(0, plat->regs + 4 + (plat->ch * 12) + 8); | |
48 | + | |
49 | + tmu_timer_stop(plat->regs, plat->ch); | |
50 | + tmu_timer_start(plat->regs, plat->ch); | |
51 | + | |
52 | + return 0; | |
53 | +} | |
54 | + | |
55 | +static int sh3_timer_ofdata_to_platdata(struct udevice *dev) | |
56 | +{ | |
57 | + struct sh3_timer_platdata *plat = dev_get_platdata(dev); | |
58 | + | |
59 | + plat->regs = map_physmem(dev_get_addr(dev), 48, MAP_NOCACHE); | |
60 | + plat->ch = fdtdec_get_int(gd->fdt_blob, dev->of_offset, | |
61 | + "renesas,channel", 0); | |
62 | + return 0; | |
63 | +} | |
64 | + | |
65 | +static const struct timer_ops sh3_timer_ops = { | |
66 | + .get_count = timer_read_counter, | |
67 | +}; | |
68 | + | |
69 | +static const struct udevice_id sh3_timer_ids[] = { | |
70 | + { .compatible = "renesas,sh3-tmu" }, | |
71 | + {} | |
72 | +}; | |
73 | + | |
74 | +U_BOOT_DRIVER(sh3_timer) = { | |
75 | + .name = "sh3_timer", | |
76 | + .id = UCLASS_TIMER, | |
77 | + .of_match = of_match_ptr(sh3_timer_ids), | |
78 | + .ofdata_to_platdata = of_match_ptr(sh3_timer_ofdata_to_platdata), | |
79 | + .platdata_auto_alloc_size = sizeof(struct sh3_timer_platdata), | |
80 | + .probe = sh3_timer_probe, | |
81 | + .ops = &sh3_timer_ops, | |
82 | + .flags = DM_FLAG_PRE_RELOC, | |
83 | +}; |
@@ -1,12 +1,6 @@ | ||
1 | 1 | /* |
2 | - * (C) Copyright 2009 | |
3 | - * Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | |
4 | - * | |
5 | - * (C) Copyright 2007-2012 | |
6 | - * Nobobuhiro Iwamatsu <iwamatsu@nigauri.org> | |
7 | - * | |
8 | - * (C) Copyright 2003 | |
9 | - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
2 | + * (C) Copyright 2016 | |
3 | + * Yoshinori Sato <ysato@users.sourceforge.jp> | |
10 | 4 | * |
11 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
12 | 6 | */ |