summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233/timrot-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-05-02 21:37:38 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2016-05-28 17:18:32 +0200
commit643c0a1e0e80ee6010353201792ba6e2be7e1ced (patch)
tree0b039050be720483935978575f77351db143463f /firmware/target/arm/imx233/timrot-imx233.c
parent423c64770c04a62e34775c37a7e09a60f6ccbc4c (diff)
downloadrockbox-643c0a1e0e80ee6010353201792ba6e2be7e1ced.tar.gz
rockbox-643c0a1e0e80ee6010353201792ba6e2be7e1ced.tar.bz2
rockbox-643c0a1e0e80ee6010353201792ba6e2be7e1ced.zip
imx233: simplify timrot API
The old timrot setup API was very low-level and unfriendly. The new one makes in easier to select the frequency source. Use to simplify timer and kernel timer code. Change-Id: Iffcdf11c00e925be9ec8d9a4efc74b197b6bd2aa
Diffstat (limited to 'firmware/target/arm/imx233/timrot-imx233.c')
-rw-r--r--firmware/target/arm/imx233/timrot-imx233.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/timrot-imx233.c b/firmware/target/arm/imx233/timrot-imx233.c
index 7c5e60c30e..91f24924d6 100644
--- a/firmware/target/arm/imx233/timrot-imx233.c
+++ b/firmware/target/arm/imx233/timrot-imx233.c
@@ -65,6 +65,49 @@ void imx233_timrot_set_priority(unsigned timer_nr, unsigned prio)
imx233_icoll_set_priority(INT_SRC_TIMER(timer_nr), prio);
}
+static unsigned map_src(enum imx233_timrot_src_t src, unsigned *prescale)
+{
+ *prescale = BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_1;
+ switch(src)
+ {
+ case TIMER_SRC_24MHZ:
+ return BV_TIMROT_TIMCTRLn_SELECT__TICK_ALWAYS;
+ case TIMER_SRC_12MHZ:
+ *prescale = BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_2;
+ return BV_TIMROT_TIMCTRLn_SELECT__TICK_ALWAYS;
+ case TIMER_SRC_6MHZ:
+ *prescale = BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_4;
+ return BV_TIMROT_TIMCTRLn_SELECT__TICK_ALWAYS;
+ case TIMER_SRC_3MHZ:
+ *prescale = BV_TIMROT_TIMCTRLn_PRESCALE__DIV_BY_8;
+ return BV_TIMROT_TIMCTRLn_SELECT__TICK_ALWAYS;
+ case TIMER_SRC_32KHZ:
+ return BV_TIMROT_TIMCTRLn_SELECT__32KHZ_XTAL;
+ case TIMER_SRC_8KHZ:
+ return BV_TIMROT_TIMCTRLn_SELECT__8KHZ_XTAL;
+ case TIMER_SRC_4KHZ:
+ return BV_TIMROT_TIMCTRLn_SELECT__4KHZ_XTAL;
+ case TIMER_SRC_1KHZ:
+ return BV_TIMROT_TIMCTRLn_SELECT__1KHZ_XTAL;
+ case TIMER_SRC_STOP:
+ default:
+ return BV_TIMROT_TIMCTRLn_SELECT__NEVER_TICK;
+ }
+}
+
+void imx233_timrot_setup_simple(unsigned timer_nr, bool periodic, unsigned count,
+ enum imx233_timrot_src_t src, imx233_timer_fn_t fn)
+{
+ unsigned prescale;
+ unsigned hw_src = map_src(src, &prescale);
+ imx233_timrot_setup(timer_nr, periodic, count, hw_src, prescale, false, fn);
+}
+
+unsigned imx233_timrot_get_count(unsigned timer_nr)
+{
+ return BF_RD(TIMROT_TIMCOUNTn(timer_nr), RUNNING_COUNT);
+}
+
struct imx233_timrot_info_t imx233_timrot_get_info(unsigned timer_nr)
{
struct imx233_timrot_info_t info;