This patch does a couple of misc things: . fix a typo in ddb5477 debug.c file (mistakingly includes non-existent debug.h file) . create a common irq file for DDB boards (which calls board-specific setup_irq()). I think this should move to arch/mips/kernel/irq.c. . Move to_tm() to common time.h/time.c file so that other time/rtc code can share it. Jun 010620 diff -Nru link-010620/arch/mips/kernel/time.c.orig link-010620/arch/mips/kernel/time.c --- link-010620/arch/mips/kernel/time.c.orig Sun Apr 22 20:18:17 2001 +++ link-010620/arch/mips/kernel/time.c Wed Jun 20 22:06:05 2001 @@ -4,7 +4,7 @@ * * arch/mips/kernel/time.c * Common time service routines for MIPS machines. See - * Documents/MIPS/time.txt. + * Documents/mips/time.README. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -540,3 +540,96 @@ MIPS_ASSERT(board_timer_setup != NULL); board_timer_setup(&timer_irqaction); } + +/* ================================================== */ +#define FEBRUARY 2 +#define STARTOFTIME 1970 +#define SECDAY 86400L +#define SECYR (SECDAY * 365) +#define leapyear(year) ((year) % 4 == 0) +#define days_in_year(a) (leapyear(a) ? 366 : 365) +#define days_in_month(a) (month_days[(a) - 1]) + +static int month_days[12] = { + 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; + +/* + * This only works for the Gregorian calendar - i.e. after 1752 (in the UK) + */ +static void +GregorianDay(struct rtc_time * tm) +{ + int leapsToDate; + int lastYear; + int day; + int MonthOffset[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; + + lastYear=tm->tm_year-1; + + /* + * Number of leap corrections to apply up to end of last year + */ + leapsToDate = lastYear/4 - lastYear/100 + lastYear/400; + + /* + * This year is a leap year if it is divisible by 4 except when it is + * divisible by 100 unless it is divisible by 400 + * + * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 will be + */ + if((tm->tm_year%4==0) && + ((tm->tm_year%100!=0) || (tm->tm_year%400==0)) && + (tm->tm_mon>2)) + { + /* + * We are past Feb. 29 in a leap year + */ + day=1; + } + else + { + day=0; + } + day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + + tm->tm_mday; + + tm->tm_wday=day%7; +} + + +void to_tm(unsigned long tim, struct rtc_time * tm) +{ + register int i; + register long hms, day; + + day = tim / SECDAY; + hms = tim % SECDAY; + + /* Hours, minutes, seconds are easy */ + tm->tm_hour = hms / 3600; + tm->tm_min = (hms % 3600) / 60; + tm->tm_sec = (hms % 3600) % 60; + + /* Number of years in days */ + for (i = STARTOFTIME; day >= days_in_year(i); i++) + day -= days_in_year(i); + tm->tm_year = i; + + /* Number of months in days left */ + if (leapyear(tm->tm_year)) + days_in_month(FEBRUARY) = 29; + for (i = 1; day >= days_in_month(i); i++) + day -= days_in_month(i); + days_in_month(FEBRUARY) = 28; + tm->tm_mon = i; + + /* Days are what is left over (+1) from all that. */ + tm->tm_mday = day + 1; + + /* + * Determine the day of week + */ + GregorianDay(tm); +} + diff -Nru link-010620/arch/mips/ddb5xxx/common/Makefile.orig link-010620/arch/mips/ddb5xxx/common/Makefile --- link-010620/arch/mips/ddb5xxx/common/Makefile.orig Sun Jun 10 09:57:40 2001 +++ link-010620/arch/mips/ddb5xxx/common/Makefile Wed Jun 20 21:29:45 2001 @@ -13,6 +13,6 @@ O_TARGET:= ddb5xxx.o -obj-y += irq_cpu.o nile4.o prom.o pci.o pci_auto.o rtc_ds1386.o +obj-y += irq.o irq_cpu.o nile4.o prom.o pci.o pci_auto.o rtc_ds1386.o include $(TOPDIR)/Rules.make diff -Nru link-010620/arch/mips/ddb5xxx/common/rtc_ds1386.c.orig link-010620/arch/mips/ddb5xxx/common/rtc_ds1386.c --- link-010620/arch/mips/ddb5xxx/common/rtc_ds1386.c.orig Sun Jun 10 09:57:40 2001 +++ link-010620/arch/mips/ddb5xxx/common/rtc_ds1386.c Wed Jun 20 21:51:12 2001 @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -82,7 +81,6 @@ return mktime(year, month, day, hour, minute, second); } -void to_tm(unsigned long tim, struct rtc_time * tm); static int rtc_ds1386_set_time(unsigned long t) { @@ -172,96 +170,3 @@ } -/* ================================================== */ -#define TICK_SIZE tick -#define FEBRUARY 2 -#define STARTOFTIME 1970 -#define SECDAY 86400L -#define SECYR (SECDAY * 365) -#define leapyear(year) ((year) % 4 == 0) -#define days_in_year(a) (leapyear(a) ? 366 : 365) -#define days_in_month(a) (month_days[(a) - 1]) - -static int month_days[12] = { - 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 -}; - -/* - * This only works for the Gregorian calendar - i.e. after 1752 (in the UK) - */ -static void -GregorianDay(struct rtc_time * tm) -{ - int leapsToDate; - int lastYear; - int day; - int MonthOffset[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; - - lastYear=tm->tm_year-1; - - /* - * Number of leap corrections to apply up to end of last year - */ - leapsToDate = lastYear/4 - lastYear/100 + lastYear/400; - - /* - * This year is a leap year if it is divisible by 4 except when it is - * divisible by 100 unless it is divisible by 400 - * - * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 will be - */ - if((tm->tm_year%4==0) && - ((tm->tm_year%100!=0) || (tm->tm_year%400==0)) && - (tm->tm_mon>2)) - { - /* - * We are past Feb. 29 in a leap year - */ - day=1; - } - else - { - day=0; - } - - day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] + - tm->tm_mday; - - tm->tm_wday=day%7; -} - - -void to_tm(unsigned long tim, struct rtc_time * tm) -{ - register int i; - register long hms, day; - - day = tim / SECDAY; - hms = tim % SECDAY; - - /* Hours, minutes, seconds are easy */ - tm->tm_hour = hms / 3600; - tm->tm_min = (hms % 3600) / 60; - tm->tm_sec = (hms % 3600) % 60; - - /* Number of years in days */ - for (i = STARTOFTIME; day >= days_in_year(i); i++) - day -= days_in_year(i); - tm->tm_year = i; - - /* Number of months in days left */ - if (leapyear(tm->tm_year)) - days_in_month(FEBRUARY) = 29; - for (i = 1; day >= days_in_month(i); i++) - day -= days_in_month(i); - days_in_month(FEBRUARY) = 28; - tm->tm_mon = i; - - /* Days are what is left over (+1) from all that. */ - tm->tm_mday = day + 1; - - /* - * Determine the day of week - */ - GregorianDay(tm); -} diff -Nru link-010620/arch/mips/ddb5xxx/common/irq.c.orig link-010620/arch/mips/ddb5xxx/common/irq.c --- link-010620/arch/mips/ddb5xxx/common/irq.c.orig Wed Jun 20 21:57:00 2001 +++ link-010620/arch/mips/ddb5xxx/common/irq.c Wed Jun 20 21:29:28 2001 @@ -0,0 +1,38 @@ +/*********************************************************************** + * + * Copyright 2001 MontaVista Software Inc. + * Author: jsun@mvista.com or jsun@junsun.net + * + * arch/mips/ddb5xxx/common/irq.c + * Common irq code for DDB boards. This really should belong + * arch/mips/kernel/irq.c. Need to talk to Ralf. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + *********************************************************************** + */ + +#include +#include /* for __init */ + +void (*irq_setup)(void); + +void __init init_IRQ(void) +{ + +#ifdef CONFIG_REMOTE_DEBUG + extern void breakpoint(void); + extern void set_debug_traps(void); + + printk("Wait for gdb client connection ...\n"); + set_debug_traps(); + breakpoint(); +#endif + + /* invoke board-specific irq setup */ + irq_setup(); +} + diff -Nru link-010620/arch/mips/ddb5xxx/ddb5477/debug.c.orig link-010620/arch/mips/ddb5xxx/ddb5477/debug.c --- link-010620/arch/mips/ddb5xxx/ddb5477/debug.c.orig Sun Jun 10 09:57:41 2001 +++ link-010620/arch/mips/ddb5xxx/ddb5477/debug.c Wed Jun 20 21:25:41 2001 @@ -18,7 +18,6 @@ #include #include /* SA_INTERRUPT */ -#include "debug.h" #include #include diff -Nru link-010620/arch/mips/ddb5xxx/ddb5477/irq.c.orig link-010620/arch/mips/ddb5xxx/ddb5477/irq.c --- link-010620/arch/mips/ddb5xxx/ddb5477/irq.c.orig Sun Jun 10 09:57:41 2001 +++ link-010620/arch/mips/ddb5xxx/ddb5477/irq.c Wed Jun 20 21:27:45 2001 @@ -172,22 +172,3 @@ } } } - -void (*irq_setup)(void); - -void __init init_IRQ(void) -{ - -#ifdef CONFIG_REMOTE_DEBUG - extern void breakpoint(void); - extern void set_debug_traps(void); - - printk("Wait for gdb client connection ...\n"); - set_debug_traps(); - breakpoint(); -#endif - - /* invoke board-specific irq setup */ - irq_setup(); -} - diff -Nru link-010620/include/asm-mips/time.h.orig link-010620/include/asm-mips/time.h --- link-010620/include/asm-mips/time.h.orig Wed Jun 20 21:23:37 2001 +++ link-010620/include/asm-mips/time.h Wed Jun 20 21:43:11 2001 @@ -12,24 +12,36 @@ *********************************************************************** */ +/* + * Please refer to Documentation/MIPS/time.README. + */ + #ifndef _ASM_TIME_H #define _ASM_TIME_H #include /* for struct pt_regs */ #include /* for asmlinkage */ +#include /* for struct rtc_time */ /* * RTC ops. By default, they point a no-RTC functions. * rtc_get_time - mktime(year, mon, day, hour, min, sec) in seconds. - * rtc_set_time - reverse the above translation + * rtc_set_time - reverse the above translation and set time to RTC. */ extern unsigned long (*rtc_get_time)(void); extern int (*rtc_set_time)(unsigned long); /* + * to_tm() converts system time back to (year, mon, day, hour, min, sec). + * It is intended to help implement rtc_set_time() functions. + * Copied from PPC implementation. + */ +extern void to_tm(unsigned long tim, struct rtc_time * tm); + +/* * do_gettimeoffset(). By default, this func pointer points to * do_null_gettimeoffset(), which leads to the same resolution as HZ. - * Higher resolution versions are vailable. + * Higher resolution versions are vailable, which gives ~1us resolution. */ extern unsigned long (*do_gettimeoffset)(void);