diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2016-10-22 15:16:26 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2016-10-22 15:16:26 +0000 |
commit | eeb784d40527c81cd36cf571ae2d1f02f5e6c474 (patch) | |
tree | e84da07aff20c610ec9284887442a70d2b9514a8 /sys/arch/armv7/sunxi | |
parent | be4ab8031fa0646d6dea070f22e8da9956524f30 (diff) |
Attach sxitimer(4) using the fdt.
Diffstat (limited to 'sys/arch/armv7/sunxi')
-rw-r--r-- | sys/arch/armv7/sunxi/files.sunxi | 4 | ||||
-rw-r--r-- | sys/arch/armv7/sunxi/sunxi.c | 8 | ||||
-rw-r--r-- | sys/arch/armv7/sunxi/sxitimer.c | 124 |
3 files changed, 74 insertions, 62 deletions
diff --git a/sys/arch/armv7/sunxi/files.sunxi b/sys/arch/armv7/sunxi/files.sunxi index 68f8e7bd056..339d206c596 100644 --- a/sys/arch/armv7/sunxi/files.sunxi +++ b/sys/arch/armv7/sunxi/files.sunxi @@ -1,4 +1,4 @@ -# $OpenBSD: files.sunxi,v 1.15 2016/10/09 11:14:22 kettenis Exp $ +# $OpenBSD: files.sunxi,v 1.16 2016/10/22 15:16:25 kettenis Exp $ define sunxi {} device sunxi: sunxi @@ -21,7 +21,7 @@ attach sxiintc at fdt file arch/armv7/sunxi/sxiintc.c sxiintc device sxitimer -attach sxitimer at sunxi +attach sxitimer at fdt file arch/armv7/sunxi/sxitimer.c sxitimer device sxidog diff --git a/sys/arch/armv7/sunxi/sunxi.c b/sys/arch/armv7/sunxi/sunxi.c index 8d921d5959b..c6d42d368e0 100644 --- a/sys/arch/armv7/sunxi/sunxi.c +++ b/sys/arch/armv7/sunxi/sunxi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sunxi.c,v 1.20 2016/10/09 11:14:22 kettenis Exp $ */ +/* $OpenBSD: sunxi.c,v 1.21 2016/10/22 15:16:25 kettenis Exp $ */ /* * Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.com> * @@ -40,16 +40,10 @@ struct cfdriver sunxi_cd = { }; struct board_dev sun4i_devs[] = { - { "sxitimer", 0 }, - { "sxitimer", 1 }, - { "sxitimer", 2 }, { NULL, 0 } }; struct board_dev sun5i_devs[] = { - { "sxitimer", 0 }, - { "sxitimer", 1 }, - { "sxitimer", 2 }, { NULL, 0 } }; diff --git a/sys/arch/armv7/sunxi/sxitimer.c b/sys/arch/armv7/sunxi/sxitimer.c index b2647799072..76864b49413 100644 --- a/sys/arch/armv7/sunxi/sxitimer.c +++ b/sys/arch/armv7/sunxi/sxitimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxitimer.c,v 1.7 2016/10/21 20:03:57 kettenis Exp $ */ +/* $OpenBSD: sxitimer.c,v 1.8 2016/10/22 15:16:25 kettenis Exp $ */ /* * Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org> * Copyright (c) 2013 Raphael Graf <r@undefined.ch> @@ -30,12 +30,16 @@ #include <arm/cpufunc.h> #include <machine/bus.h> +#include <machine/fdt.h> #include <machine/intr.h> #include <armv7/armv7/armv7var.h> #include <armv7/sunxi/sunxireg.h> /* #include <armv7/sunxi/sxipiovar.h> */ +#include <dev/ofw/openfirm.h> +#include <dev/ofw/fdt.h> + #define TIMER_IER 0x00 #define TIMER_ISR 0x04 #define TIMER_IRQ(x) (1 << (x)) @@ -74,6 +78,7 @@ #define TIMER_SYNC 3 +int sxitimer_match(struct device *, void *, void *); void sxitimer_attach(struct device *, struct device *, void *); int sxitimer_tickintr(void *); int sxitimer_statintr(void *); @@ -116,29 +121,34 @@ struct sxitimer_softc { struct device sc_dev; }; -struct cfattach sxitimer_ca = { - sizeof (struct sxitimer_softc), NULL, sxitimer_attach +struct cfattach sxitimer_ca = { + sizeof (struct sxitimer_softc), sxitimer_match, sxitimer_attach }; struct cfdriver sxitimer_cd = { NULL, "sxitimer", DV_DULL }; +int +sxitimer_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return OF_is_compatible(faa->fa_node, "allwinner,sun4i-a10-timer"); +} + void -sxitimer_attach(struct device *parent, struct device *self, void *args) +sxitimer_attach(struct device *parent, struct device *self, void *aux) { - struct armv7_attach_args *aa = args; + struct fdt_attach_args *faa = aux; uint32_t freq, ival, now; - int unit = self->dv_unit; - if (unit != 0) - goto skip_init; + KASSERT(faa->fa_nreg > 0); - sxitimer_iot = aa->aa_iot; - - if (bus_space_map(sxitimer_iot, aa->aa_dev->mem[0].addr, - aa->aa_dev->mem[0].size, 0, &sxitimer_ioh)) - panic("sxitimer_attach: bus_space_map failed!"); + sxitimer_iot = faa->fa_iot; + if (bus_space_map(sxitimer_iot, faa->fa_reg[0].addr, + faa->fa_reg[0].size, 0, &sxitimer_ioh)) + panic("%s: bus_space_map failed!", __func__); /* clear counter, loop until ready */ bus_space_write_4(sxitimer_iot, sxitimer_ioh, CNT64_CTRL, @@ -147,53 +157,61 @@ sxitimer_attach(struct device *parent, struct device *self, void *args) & CNT64_CLR_EN) continue; -skip_init: /* timers are down-counters, from interval to 0 */ now = 0xffffffff; /* known big value */ - freq = sxitimer_freq[unit]; + freq = sxitimer_freq[TICKTIMER]; /* stop timer, and set clk src */ bus_space_write_4(sxitimer_iot, sxitimer_ioh, - TIMER_CTRL(unit), TIMER_OSC24M); - - switch (unit) { /* XXX more XXXXTIMER magic for less lines? */ - case TICKTIMER: - ival = sxitimer_tick_tpi = freq / hz; - sxitimer_tick_nextevt = now - ival; - - sxitimer_ticks_err_cnt = freq % hz; - sxitimer_ticks_err_sum = 0; - - printf(": ticktimer %dhz @ %dKHz", hz, freq / 1000); - break; - case STATTIMER: - /* 100/1000 or 128/1024 ? */ - stathz = 128; - profhz = 1024; - sxitimer_setstatclockrate(stathz); - - ival = sxitimer_stat_tpi = freq / stathz; - sxitimer_stat_nextevt = now - ival; - - printf(": stattimer %dhz @ %dKHz", stathz, freq / 1000); - break; - case CNTRTIMER: - ival = now; - - sxitimer_timecounter.tc_frequency = freq; - tc_init(&sxitimer_timecounter); - arm_clock_register(sxitimer_cpu_initclocks, sxitimer_delay, - sxitimer_setstatclockrate, NULL); - - printf(": cntrtimer @ %dKHz", freq / 1000); - break; - default: - panic("sxitimer_attach: unit = %d", unit); - break; - } + TIMER_CTRL(TICKTIMER), TIMER_OSC24M); + + ival = sxitimer_tick_tpi = freq / hz; + sxitimer_tick_nextevt = now - ival; + + sxitimer_ticks_err_cnt = freq % hz; + sxitimer_ticks_err_sum = 0; + + bus_space_write_4(sxitimer_iot, sxitimer_ioh, + TIMER_INTV(TICKTIMER), ival); + + /* timers are down-counters, from interval to 0 */ + now = 0xffffffff; /* known big value */ + freq = sxitimer_freq[STATTIMER]; + + /* stop timer, and set clk src */ + bus_space_write_4(sxitimer_iot, sxitimer_ioh, + TIMER_CTRL(STATTIMER), TIMER_OSC24M); + + /* 100/1000 or 128/1024 ? */ + stathz = 128; + profhz = 1024; + sxitimer_setstatclockrate(stathz); + + ival = sxitimer_stat_tpi = freq / stathz; + sxitimer_stat_nextevt = now - ival; + + bus_space_write_4(sxitimer_iot, sxitimer_ioh, + TIMER_INTV(STATTIMER), ival); + + /* timers are down-counters, from interval to 0 */ + now = 0xffffffff; /* known big value */ + freq = sxitimer_freq[CNTRTIMER]; + + /* stop timer, and set clk src */ + bus_space_write_4(sxitimer_iot, sxitimer_ioh, + TIMER_CTRL(CNTRTIMER), TIMER_OSC24M); + + ival = now; + + sxitimer_timecounter.tc_frequency = freq; + tc_init(&sxitimer_timecounter); + arm_clock_register(sxitimer_cpu_initclocks, sxitimer_delay, + sxitimer_setstatclockrate, NULL); + + printf(": cntrtimer @ %dKHz", freq / 1000); bus_space_write_4(sxitimer_iot, sxitimer_ioh, - TIMER_INTV(unit), ival); + TIMER_INTV(CNTRTIMER), ival); printf("\n"); } |