Skip to contentSkip to conversation

mxs: timrot: Add support to i.MX23

PATCH Superseded Fadil Berisha 2 participants 6 messages Feb 24, 2013

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mxs: timrot: Add support to i.MX23

This patch add timer support to i.MX23 and complete bit fields and values on regs-timrot.h.
Testet on imx23-olinuxino board.

---
v2 - Updated the struct mxs_timrot_regs so the mapping works for all registers

 arch/arm/cpu/arm926ejs/mxs/timer.c          |   39 ++++++++---
 arch/arm/include/asm/arch-mxs/regs-timrot.h |  101 +++++++++++++++++++++++++++
 2 files changed, 130 insertions(+), 10 deletions(-)
arch/arm/cpu/arm926ejs/mxs/timer.c +29 -10
index 4ed75e6..507b190 100644
@@ -32,7 +32,11 @@
 #include <asm/arch/sys_proto.h>
 
 /* Maximum fixed count */
-#define TIMER_LOAD_VAL	0xffffffff
+#if defined(CONFIG_MX23)
+#define TIMER_LOAD_VAL 0xffff
+#elif defined(CONFIG_MX28)
+#define TIMER_LOAD_VAL 0xffffffff
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -42,22 +46,22 @@ DECLARE_GLOBAL_DATA_PTR;
 /*
  * This driver uses 1kHz clock source.
  */
-#define	MX28_INCREMENTER_HZ		1000
+#define	MXS_INCREMENTER_HZ		1000
 
 static inline unsigned long tick_to_time(unsigned long tick)
 {
-	return tick / (MX28_INCREMENTER_HZ / CONFIG_SYS_HZ);
+	return tick / (MXS_INCREMENTER_HZ / CONFIG_SYS_HZ);
 }
 
 static inline unsigned long time_to_tick(unsigned long time)
 {
-	return time * (MX28_INCREMENTER_HZ / CONFIG_SYS_HZ);
+	return time * (MXS_INCREMENTER_HZ / CONFIG_SYS_HZ);
 }
 
 /* Calculate how many ticks happen in "us" microseconds */
 static inline unsigned long us_to_tick(unsigned long us)
 {
-	return (us * MX28_INCREMENTER_HZ) / 1000000;
+	return (us * MXS_INCREMENTER_HZ) / 1000000;
 }
 
 int timer_init(void)
@@ -69,7 +73,11 @@ int timer_init(void)
 	mxs_reset_block(&timrot_regs->hw_timrot_rotctrl_reg);
 
 	/* Set fixed_count to 0 */
+#if defined(CONFIG_MX23)
+	writel(0, &timrot_regs->hw_timrot_timcount0);
+#elif defined(CONFIG_MX28)
 	writel(0, &timrot_regs->hw_timrot_fixed_count0);
+#endif
 
 	/* Set UPDATE bit and 1Khz frequency */
 	writel(TIMROT_TIMCTRLn_UPDATE | TIMROT_TIMCTRLn_RELOAD |
@@ -77,7 +85,11 @@ int timer_init(void)
 		&timrot_regs->hw_timrot_timctrl0);
 
 	/* Set fixed_count to maximal value */
+#if defined(CONFIG_MX23)
+	writel(TIMER_LOAD_VAL-1, &timrot_regs->hw_timrot_timcount0);
+#elif defined(CONFIG_MX28)
 	writel(TIMER_LOAD_VAL, &timrot_regs->hw_timrot_fixed_count0);
+#endif
 
 	return 0;
 }
@@ -86,9 +98,16 @@ unsigned long long get_ticks(void)
 {
 	struct mxs_timrot_regs *timrot_regs =
 		(struct mxs_timrot_regs *)MXS_TIMROT_BASE;
+	uint32_t now;
 
 	/* Current tick value */
-	uint32_t now = readl(&timrot_regs->hw_timrot_running_count0);
+#if defined(CONFIG_MX23)
+	/* upper bits are the valid */
+	now = readl(&timrot_regs->hw_timrot_timcount0) >> 
+		TIMROT_RUNNING_COUNTn_RUNNING_COUNT_OFFSET;
+#elif defined(CONFIG_MX28)
+	now = readl(&timrot_regs->hw_timrot_running_count0);
+#endif
 
 	if (lastdec >= now) {
 		/*
@@ -117,17 +136,17 @@ ulong get_timer(ulong base)
 }
 
 /* We use the HW_DIGCTL_MICROSECONDS register for sub-millisecond timer. */
-#define	MX28_HW_DIGCTL_MICROSECONDS	0x8001c0c0
+#define	MXS_HW_DIGCTL_MICROSECONDS	0x8001c0c0
 
 void __udelay(unsigned long usec)
 {
 	uint32_t old, new, incr;
 	uint32_t counter = 0;
 
-	old = readl(MX28_HW_DIGCTL_MICROSECONDS);
+	old = readl(MXS_HW_DIGCTL_MICROSECONDS);
 
 	while (counter < usec) {
-		new = readl(MX28_HW_DIGCTL_MICROSECONDS);
+		new = readl(MXS_HW_DIGCTL_MICROSECONDS);
 
 		/* Check if the timer wrapped. */
 		if (new < old) {
@@ -152,5 +171,5 @@ void __udelay(unsigned long usec)
 
 ulong get_tbclk(void)
 {
-	return MX28_INCREMENTER_HZ;
+	return MXS_INCREMENTER_HZ;
 }
arch/arm/include/asm/arch-mxs/regs-timrot.h +101 -0

184 lines not on this page · raw message

Signature · 1 line
1.7.10
#1 lore raw

PATCH v2 1/1 mxs: timrot: Add support to i.MX23

Dear Fadil Berisha,

Quoted 3 lines

This patch add timer support to i.MX23 and complete bit fields and values on regs-timrot.h.
Testet on imx23-olinuxino board.

Also document that you renamed some macros, even if I'd prefer if you pulled those out into separate patch to make this easier to review.

Moreover:

$ ./tools/checkpatch.pl /tmp/\[PATCH\ v2\]\ mxs_timrot_Add\ support\ to\ 
i.MX23.mbox 
ERROR: trailing whitespace
#149: FILE: arch/arm/cpu/arm926ejs/mxs/timer.c:106:
+^Inow = readl(&timrot_regs->hw_timrot_timcount0) >> $

ERROR: trailing whitespace
#376: FILE: arch/arm/include/asm/arch-mxs/regs-timrot.h:261:
+#define^ITIMROT_TIMCOUNT3_HIGH_FIXED_COUNT_MASK^I0xffff $

total: 2 errors, 0 warnings, 287 lines checked

NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or
scripts/cleanfile

NOTE: Ignored message types: COMPLEX_MACRO CONSIDER_KSTRTO MINMAX MULTISTATEMENT_MACRO_USE_DO_WHILE

/tmp/[PATCH v2] mxs_timrot_Add support to i.MX23.mbox has style problems, please review.

If any of these errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.

[...]

#2 lore raw

PATCH v2 1/1 mxs: timrot: Add support to i.MX23

Dear Marek Vasut

Quoted 2 lines

Also document that you renamed some macros, even if I'd prefer if you pulled those out into separate patch to make this easier to review.

This is documented in comment for patch version v2:
"v2 - Updated the struct mxs_timrot_regs so the mapping works for all registers" Since macro names corespondent to registers names, no need for extra documentation.

Quoted 1 line

ERROR: trailing whitespace

Will fix in next version

Fadil Berisha

#3 lore raw

PATCH v2 1/1 mxs: timrot: Add support to i.MX23

Dear Fadil Berisha,

Quoted 9 lines

Dear Marek Vasut

Quoted 2 lines

Also document that you renamed some macros, even if I'd prefer if you pulled those out into separate patch to make this easier to review.

This is documented in comment for patch version v2:
"v2 - Updated the struct mxs_timrot_regs so the mapping works for all registers" Since macro names corespondent to registers names, no need for extra documentation.

I meant MXS_INCREMENTER_HZ macro and such.

Quoted 5 lines
Quoted 1 line

ERROR: trailing whitespace

Will fix in next version

Fadil Berisha

Best regards,
Marek Vasut

#4 lore raw

PATCH v2 1/1 mxs: timrot: Add support to i.MX23

Dear Marek Vasut

Quoted 1 line

I meant MXS_INCREMENTER_HZ macro and such.

This change is made to respect Otavio's comment related to this patch
http://lists.denx.de/pipermail/u-boot/2013-February/146906.html I did also changes to local macro MXS_HW_DIGCTL_MICROSECONDS.

Let me know If you want to submit those changes on separate patch.

Best Regards
Fadil Berisha

#5 lore raw

PATCH v2 1/1 mxs: timrot: Add support to i.MX23

Dear Fadil Berisha,

Quoted 9 lines

Dear Marek Vasut

Quoted 1 line

I meant MXS_INCREMENTER_HZ macro and such.

This change is made to respect Otavio's comment related to this patch
http://lists.denx.de/pipermail/u-boot/2013-February/146906.html I did also changes to local macro MXS_HW_DIGCTL_MICROSECONDS.

Let me know If you want to submit those changes on separate patch.

Yes, it'd be nice to have the macro renames and the other stuff submitted separatelly.

Quoted 2 lines

Best Regards
Fadil Berisha

Best regards,
Marek Vasut