[PATCH 24/52] [microblaze] time support

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <monstr@...>
Cc: <linux-kernel@...>, <stephen.neuendorffer@...>, <john.williams@...>, <microblaze-uclinux@...>
Date: Thursday, January 24, 2008 - 11:02 am

From: Michal Simek <monstr@monstr.eu>


Signed-off-by: Michal Simek <monstr@monstr.eu>
---
 arch/microblaze/kernel/time.c  |   90 ++++++++++++++++++++++++++++++++++++++++
 include/asm-microblaze/delay.h |   28 ++++++++++++
 include/asm-microblaze/timex.h |   21 +++++++++
 3 files changed, 139 insertions(+), 0 deletions(-)
 create mode 100644 arch/microblaze/kernel/time.c
 create mode 100644 include/asm-microblaze/delay.h
 create mode 100644 include/asm-microblaze/timex.h

diff --git a/arch/microblaze/kernel/time.c b/arch/microblaze/kernel/time.c
new file mode 100644
index 0000000..d5ebdff
--- /dev/null
+++ b/arch/microblaze/kernel/time.c
@@ -0,0 +1,90 @@
+/*
+ * arch/microblaze/kernel/time.c
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2006 Atmark Techno, Inc.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/param.h>
+#include <linux/jiffies.h>
+#include <linux/time.h>
+#include <linux/hrtimer.h>
+#include <asm/bug.h>
+#include <asm/setup.h>
+
+void time_init(void)
+{
+	system_timer_init();
+}
+
+int do_settimeofday(struct timespec *tv)
+{
+	if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
+		return -EINVAL;
+
+	write_seqlock_irq(&xtime_lock);
+
+	/* This is revolting. We need to set the xtime.tv_nsec
+	 * correctly. However, the value in this location is
+	 * is value at the last tick.
+	 * Discover what correction gettimeofday
+	 * would have done, and then undo it!
+	 */
+#if 0
+	tv->tv_nsec -= mach_gettimeoffset() * 1000;
+#endif
+
+	while (tv->tv_nsec < 0) {
+		tv->tv_nsec += NSEC_PER_SEC;
+		tv->tv_sec--;
+	}
+
+	xtime.tv_sec = tv->tv_sec;
+	xtime.tv_nsec = tv->tv_nsec;
+
+	time_adjust = 0;
+	time_status |= STA_UNSYNC;
+	time_maxerror = NTP_PHASE_LIMIT;
+	time_esterror = NTP_PHASE_LIMIT;
+
+	write_sequnlock_irq(&xtime_lock);
+	clock_was_set();
+	return 0;
+}
+EXPORT_SYMBOL(do_settimeofday);
+
+/*
+ * This version of gettimeofday has near microsecond resolution.
+ */
+void do_gettimeofday(struct timeval *tv)
+{
+	unsigned long seq;
+	unsigned long usec, sec;
+	/* unsigned long max_ntp_tick = tick_usec - tickadj; */
+
+	do {
+		seq = read_seqbegin(&xtime_lock);
+		usec = do_gettimeoffset();
+		sec = xtime.tv_sec;
+		usec += (xtime.tv_nsec / 1000);
+	} while (read_seqretry(&xtime_lock, seq));
+
+	while (usec >= 1000000) {
+		usec -= 1000000;
+		sec++;
+	}
+
+	tv->tv_sec = sec;
+	tv->tv_usec = usec;
+}
+EXPORT_SYMBOL(do_gettimeofday);
+
+unsigned long long sched_clock(void)
+{
+	return (unsigned long long)jiffies * (1000000000 / HZ);
+}
diff --git a/include/asm-microblaze/delay.h b/include/asm-microblaze/delay.h
new file mode 100644
index 0000000..1eaa74c
--- /dev/null
+++ b/include/asm-microblaze/delay.h
@@ -0,0 +1,28 @@
+/*
+ * include/asm-microblaze/delay.h
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2006 Atmark Techno, Inc.
+ */
+
+#ifndef _ASM_DELAY_H
+#define _ASM_DELAY_H
+
+extern inline void __delay(unsigned long loops)
+{
+	asm volatile ("# __delay		\n\t"		\
+			"1: addi	%0, %0, -1 \t\n"	\
+			"bneid	%0, 1b		\t\n"		\
+			"nop			\t\n"
+			: "=r" (loops)
+			: "0" (loops));
+}
+
+static inline void udelay(unsigned long usec)
+{
+}
+
+#endif /* _ASM_DELAY_H */
diff --git a/include/asm-microblaze/timex.h b/include/asm-microblaze/timex.h
new file mode 100644
index 0000000..17d2f11
--- /dev/null
+++ b/include/asm-microblaze/timex.h
@@ -0,0 +1,21 @@
+/*
+ * include/asm-microblaze/timex.h
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2006 Atmark Techno, Inc.
+ * FIXME -- need review
+ */
+
+#ifndef _ASM_TIMEX_H
+#define _ASM_TIMEX_H
+
+#define CLOCK_TICK_RATE 1000 /* Timer input freq. */
+
+typedef unsigned long cycles_t;
+
+#define get_cycles()	(0)
+
+#endif /* _ASM_TIMEX_H */
-- 
1.5.4.rc4.14.g6fc74

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Microblaze init port, , (Thu Jan 24, 11:02 am)
Re: Microblaze init port, Geert Uytterhoeven, (Sun Jan 27, 7:59 am)
Re: [PATCH 11/52] [microblaze] kernel modules support, Jan Engelhardt, (Sat Jan 26, 12:27 pm)
[PATCH 12/52] [microblaze] lmb support, , (Thu Jan 24, 11:02 am)
Re: [PATCH 12/52] [microblaze] lmb support, Jan Engelhardt, (Sun Jan 27, 8:51 am)
Re: [PATCH 17/52] [microblaze] checksum support, Jan Engelhardt, (Tue Jan 29, 5:30 pm)
Re: [PATCH 17/52] [microblaze] checksum support, Geert Uytterhoeven, (Sun Jan 27, 7:57 am)
Re: [PATCH 17/52] [microblaze] checksum support, Michal Simek, (Sun Jan 27, 9:41 am)
Re: [PATCH 17/52] [microblaze] checksum support, Geert Uytterhoeven, (Sun Jan 27, 11:12 am)
[PATCH 22/52] [microblaze] asm-offsets, , (Thu Jan 24, 11:02 am)
[PATCH 24/52] [microblaze] time support, , (Thu Jan 24, 11:02 am)
[PATCH 26/52] [microblaze] IPC support, , (Thu Jan 24, 11:03 am)
[PATCH 38/52] [microblaze] dma support, , (Thu Jan 24, 11:03 am)
Re: [PATCH 03/52] [microblaze] Cpuinfo handling, Jan Engelhardt, (Sun Jan 27, 8:55 am)