Re: [PATCHv1 09/12] unicore32 core architecture: timer and time

Previous thread: [PATCHv1 08/12] unicore32 core architecture: mm related: consistent device DMA handling by Guan Xuetao on Saturday, December 25, 2010 - 11:53 am. (1 message)

Next thread: [PATCHv1 10/12] unicore32 core architecture: interrupts ang gpio by Guan Xuetao on Saturday, December 25, 2010 - 11:55 am. (1 message)
From: Guan Xuetao
Date: Saturday, December 25, 2010 - 11:54 am

From: Guan Xuetao <guanxuetao@mprc.pku.edu.cn>

Patch 9 implements timer and time. RTC and PWM device drivers are also here.

Signed-off-by: Guan Xuetao <guanxuetao@mprc.pku.edu.cn>
---
 arch/unicore32/include/asm/timex.h |   34 +++
 arch/unicore32/kernel/time.c       |  157 +++++++++++++++
 drivers/staging/puv3/puv3_pwm.c    |  271 +++++++++++++++++++++++++
 drivers/staging/puv3/puv3_rtc.c    |  388 ++++++++++++++++++++++++++++++++++++
 4 files changed, 850 insertions(+), 0 deletions(-)

diff --git a/arch/unicore32/include/asm/timex.h b/arch/unicore32/include/asm/timex.h
new file mode 100644
index 0000000..faf16ba
--- /dev/null
+++ b/arch/unicore32/include/asm/timex.h
@@ -0,0 +1,34 @@
+/*
+ * linux/arch/unicore32/include/asm/timex.h
+ *
+ * Code specific to PKUnity SoC and UniCore ISA
+ *
+ * Copyright (C) 2001-2010 GUAN Xue-tao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __UNICORE_TIMEX_H__
+#define __UNICORE_TIMEX_H__
+
+#ifdef	CONFIG_ARCH_FPGA
+
+/* in FPGA, APB clock is 33M, and OST clock is 32K, */
+/* so, 1M is selected for timer interrupt correctly */
+#define	CLOCK_TICK_RATE		(32*1024)
+
+#endif
+
+#if defined(CONFIG_PUV3_DB0913)		\
+	|| defined(CONFIG_PUV3_NB0916)	\
+	|| defined(CONFIG_PUV3_SMW0919)
+
+#define  CLOCK_TICK_RATE         (14318000)
+
+#endif
+
+#include <asm-generic/timex.h>
+
+#endif
diff --git a/arch/unicore32/kernel/time.c b/arch/unicore32/kernel/time.c
new file mode 100644
index 0000000..ed9cabf
--- /dev/null
+++ b/arch/unicore32/kernel/time.c
@@ -0,0 +1,157 @@
+/*
+ * linux/arch/unicore32/mach-puv3/time.c
+ *
+ * Code specific to PKUnity SoC and UniCore ISA
+ *
+ *	Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
+ *	Copyright (C) 2001-2010 Guan Xuetao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms ...
From: john stultz
Date: Monday, December 27, 2010 - 2:27 pm

Use "clocksource_register_hz(&cksrc_puv3_oscr, CLOCK_TICK_RATE );" and
the kernel will fill in mult/shift appropriately.

If you have any troubles after doing so, let me know.

thanks
-john
--

From: Guan Xuetao
Date: Sunday, January 2, 2011 - 2:47 am

When using clocksource_register_hz(&cksrc_puv3_oscr, CLOCK_TICK_RATE ),
 the shift value become 0, and mult value become 0x838a91a7, and the system will be broken
after printing "Switching to clocksource oscr".

When using clocksource_register_khz(&cksrc_puv3_oscr, CLOCK_TICK_RATE ),
the shift value become 0, and mult value become  0x4359611, and the system will run smoothly,
but timer interrupt seems too frequently. Perhaps it is 4 times faster.

For comparison, originally, when shift value is set to 0x12, the mult value become 1175e5e.


Thanks john.

Guan Xuetao


--

From: Guan Xuetao
Date: Sunday, January 2, 2011 - 10:52 pm

The error is the implementation of do_div() function.
When replacing the arch-specific div64.h with asm-generic/div64.h, clocksource_rigister_hz() works.

Guan Xuetao

--

From: john stultz
Date: Monday, January 3, 2011 - 12:58 pm

Oh great! You had me worried I had a bug in the mult/shift calculation.

Great to hear all is working now! If you run into other clock/time
related troubles, please let me know.

thanks
-john



--

Previous thread: [PATCHv1 08/12] unicore32 core architecture: mm related: consistent device DMA handling by Guan Xuetao on Saturday, December 25, 2010 - 11:53 am. (1 message)

Next thread: [PATCHv1 10/12] unicore32 c