1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2011 by Amaury Pouly
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "timrot-imx233.h"
22 #include "clkctrl-imx233.h"
24 imx233_timer_fn_t timer_fns
[4];
26 #define define_timer_irq(nr) \
27 void INT_TIMER##nr(void) \
31 __REG_CLR(HW_TIMROT_TIMCTRL(nr)) = HW_TIMROT_TIMCTRL__IRQ; \
39 void imx233_setup_timer(unsigned timer_nr
, bool reload
, unsigned count
,
40 unsigned src
, unsigned prescale
, bool polarity
, imx233_timer_fn_t fn
)
42 timer_fns
[timer_nr
] = fn
;
44 HW_TIMROT_TIMCTRL(timer_nr
) = src
| prescale
;
46 __REG_SET(HW_TIMROT_TIMCTRL(timer_nr
)) = HW_TIMROT_TIMCTRL__POLARITY
;
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;
54 HW_TIMROT_TIMCOUNT(timer_nr
) = count
;
55 /* only enable interrupt if function is set */
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
;
65 imx233_enable_interrupt(INT_SRC_TIMER(timer_nr
), false);
67 __REG_SET(HW_TIMROT_TIMCTRL(timer_nr
)) = HW_TIMROT_TIMCTRL__UPDATE
;
70 void imx233_timrot_init(void)
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);