diff options
Diffstat (limited to 'firmware/target/arm/imx233/timrot-imx233.c')
-rw-r--r-- | firmware/target/arm/imx233/timrot-imx233.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/timrot-imx233.c b/firmware/target/arm/imx233/timrot-imx233.c new file mode 100644 index 0000000000..64a7c63f24 --- /dev/null +++ b/firmware/target/arm/imx233/timrot-imx233.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Amaury Pouly | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "timrot-imx233.h" | ||
22 | #include "clkctrl-imx233.h" | ||
23 | |||
24 | imx233_timer_fn_t timer_fns[4]; | ||
25 | |||
26 | #define define_timer_irq(nr) \ | ||
27 | void INT_TIMER##nr(void) \ | ||
28 | { \ | ||
29 | if(timer_fns[nr]) \ | ||
30 | timer_fns[nr](); \ | ||
31 | __REG_CLR(HW_TIMROT_TIMCTRL(nr)) = HW_TIMROT_TIMCTRL__IRQ; \ | ||
32 | } | ||
33 | |||
34 | define_timer_irq(0) | ||
35 | define_timer_irq(1) | ||
36 | define_timer_irq(2) | ||
37 | define_timer_irq(3) | ||
38 | |||
39 | void imx233_setup_timer(unsigned timer_nr, bool reload, unsigned count, | ||
40 | unsigned src, unsigned prescale, bool polarity, imx233_timer_fn_t fn) | ||
41 | { | ||
42 | timer_fns[timer_nr] = fn; | ||
43 | |||
44 | HW_TIMROT_TIMCTRL(timer_nr) = src | prescale; | ||
45 | if(polarity) | ||
46 | __REG_SET(HW_TIMROT_TIMCTRL(timer_nr)) = HW_TIMROT_TIMCTRL__POLARITY; | ||
47 | if(reload) | ||
48 | { | ||
49 | __REG_SET(HW_TIMROT_TIMCTRL(timer_nr)) = HW_TIMROT_TIMCTRL__RELOAD; | ||
50 | /* manual says count - 1 for reload timers */ | ||
51 | HW_TIMROT_TIMCOUNT(timer_nr) = count - 1; | ||
52 | } | ||
53 | else | ||
54 | HW_TIMROT_TIMCOUNT(timer_nr) = count; | ||
55 | /* only enable interrupt if function is set */ | ||
56 | if(fn != NULL) | ||
57 | { | ||
58 | /* enable interrupt */ | ||
59 | imx233_enable_interrupt(INT_SRC_TIMER(timer_nr), true); | ||
60 | /* clear irq bit and enable */ | ||
61 | __REG_CLR(HW_TIMROT_TIMCTRL(timer_nr)) = HW_TIMROT_TIMCTRL__IRQ; | ||
62 | __REG_SET(HW_TIMROT_TIMCTRL(timer_nr)) = HW_TIMROT_TIMCTRL__IRQ_EN; | ||
63 | } | ||
64 | else | ||
65 | imx233_enable_interrupt(INT_SRC_TIMER(timer_nr), false); | ||
66 | /* finally update */ | ||
67 | __REG_SET(HW_TIMROT_TIMCTRL(timer_nr)) = HW_TIMROT_TIMCTRL__UPDATE; | ||
68 | } | ||
69 | |||
70 | void imx233_timrot_init(void) | ||
71 | { | ||
72 | __REG_CLR(HW_TIMROT_ROTCTRL) = __BLOCK_CLKGATE; | ||
73 | __REG_CLR(HW_TIMROT_ROTCTRL) = __BLOCK_SFTRST; | ||
74 | /* enable xtal path to timrot */ | ||
75 | imx233_enable_timrot_xtal_clk32k(true); | ||
76 | } | ||