diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sh/boards/sh03 |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/sh/boards/sh03')
-rw-r--r-- | arch/sh/boards/sh03/Makefile | 6 | ||||
-rw-r--r-- | arch/sh/boards/sh03/led.c | 49 | ||||
-rw-r--r-- | arch/sh/boards/sh03/rtc.c | 144 | ||||
-rw-r--r-- | arch/sh/boards/sh03/setup.c | 72 |
4 files changed, 271 insertions, 0 deletions
diff --git a/arch/sh/boards/sh03/Makefile b/arch/sh/boards/sh03/Makefile new file mode 100644 index 000000000000..321be50e36a5 --- /dev/null +++ b/arch/sh/boards/sh03/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | # | ||
2 | # Makefile for the Interface (CTP/PCI-SH03) specific parts of the kernel | ||
3 | # | ||
4 | |||
5 | obj-y := setup.o rtc.o | ||
6 | obj-$(CONFIG_HEARTBEAT) += led.o | ||
diff --git a/arch/sh/boards/sh03/led.c b/arch/sh/boards/sh03/led.c new file mode 100644 index 000000000000..c851b0bec80f --- /dev/null +++ b/arch/sh/boards/sh03/led.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * linux/arch/sh/boards/sh03/led.c | ||
3 | * | ||
4 | * Copyright (C) 2004 Saito.K Interface Corporation. | ||
5 | * | ||
6 | * This file contains Interface CTP/PCI-SH03 specific LED code. | ||
7 | */ | ||
8 | |||
9 | #include <linux/config.h> | ||
10 | #include <linux/sched.h> | ||
11 | |||
12 | /* Cycle the LED's in the clasic Knightrider/Sun pattern */ | ||
13 | void heartbeat_sh03(void) | ||
14 | { | ||
15 | static unsigned int cnt = 0, period = 0; | ||
16 | volatile unsigned char* p = (volatile unsigned char*)0xa0800000; | ||
17 | static unsigned bit = 0, up = 1; | ||
18 | |||
19 | cnt += 1; | ||
20 | if (cnt < period) { | ||
21 | return; | ||
22 | } | ||
23 | |||
24 | cnt = 0; | ||
25 | |||
26 | /* Go through the points (roughly!): | ||
27 | * f(0)=10, f(1)=16, f(2)=20, f(5)=35,f(inf)->110 | ||
28 | */ | ||
29 | period = 110 - ( (300<<FSHIFT)/ | ||
30 | ((avenrun[0]/5) + (3<<FSHIFT)) ); | ||
31 | |||
32 | if (up) { | ||
33 | if (bit == 7) { | ||
34 | bit--; | ||
35 | up=0; | ||
36 | } else { | ||
37 | bit ++; | ||
38 | } | ||
39 | } else { | ||
40 | if (bit == 0) { | ||
41 | bit++; | ||
42 | up=1; | ||
43 | } else { | ||
44 | bit--; | ||
45 | } | ||
46 | } | ||
47 | *p = 1<<bit; | ||
48 | |||
49 | } | ||
diff --git a/arch/sh/boards/sh03/rtc.c b/arch/sh/boards/sh03/rtc.c new file mode 100644 index 000000000000..cbeca7037ba5 --- /dev/null +++ b/arch/sh/boards/sh03/rtc.c | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | * linux/arch/sh/boards/sh03/rtc.c -- CTP/PCI-SH03 on-chip RTC support | ||
3 | * | ||
4 | * Copyright (C) 2004 Saito.K & Jeanne(ksaito@interface.co.jp) | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | #include <linux/init.h> | ||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/sched.h> | ||
11 | #include <linux/time.h> | ||
12 | #include <asm/io.h> | ||
13 | #include <linux/rtc.h> | ||
14 | #include <linux/spinlock.h> | ||
15 | |||
16 | #define RTC_BASE 0xb0000000 | ||
17 | #define RTC_SEC1 (RTC_BASE + 0) | ||
18 | #define RTC_SEC10 (RTC_BASE + 1) | ||
19 | #define RTC_MIN1 (RTC_BASE + 2) | ||
20 | #define RTC_MIN10 (RTC_BASE + 3) | ||
21 | #define RTC_HOU1 (RTC_BASE + 4) | ||
22 | #define RTC_HOU10 (RTC_BASE + 5) | ||
23 | #define RTC_WEE1 (RTC_BASE + 6) | ||
24 | #define RTC_DAY1 (RTC_BASE + 7) | ||
25 | #define RTC_DAY10 (RTC_BASE + 8) | ||
26 | #define RTC_MON1 (RTC_BASE + 9) | ||
27 | #define RTC_MON10 (RTC_BASE + 10) | ||
28 | #define RTC_YEA1 (RTC_BASE + 11) | ||
29 | #define RTC_YEA10 (RTC_BASE + 12) | ||
30 | #define RTC_YEA100 (RTC_BASE + 13) | ||
31 | #define RTC_YEA1000 (RTC_BASE + 14) | ||
32 | #define RTC_CTL (RTC_BASE + 15) | ||
33 | #define RTC_BUSY 1 | ||
34 | #define RTC_STOP 2 | ||
35 | |||
36 | #ifndef BCD_TO_BIN | ||
37 | #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10) | ||
38 | #endif | ||
39 | |||
40 | #ifndef BIN_TO_BCD | ||
41 | #define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10) | ||
42 | #endif | ||
43 | |||
44 | extern void (*rtc_get_time)(struct timespec *); | ||
45 | extern int (*rtc_set_time)(const time_t); | ||
46 | extern spinlock_t rtc_lock; | ||
47 | |||
48 | unsigned long get_cmos_time(void) | ||
49 | { | ||
50 | unsigned int year, mon, day, hour, min, sec; | ||
51 | int i; | ||
52 | |||
53 | spin_lock(&rtc_lock); | ||
54 | again: | ||
55 | for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */ | ||
56 | if (!(ctrl_inb(RTC_CTL) & RTC_BUSY)) | ||
57 | break; | ||
58 | do { | ||
59 | sec = (ctrl_inb(RTC_SEC1) & 0xf) + (ctrl_inb(RTC_SEC10) & 0x7) * 10; | ||
60 | min = (ctrl_inb(RTC_MIN1) & 0xf) + (ctrl_inb(RTC_MIN10) & 0xf) * 10; | ||
61 | hour = (ctrl_inb(RTC_HOU1) & 0xf) + (ctrl_inb(RTC_HOU10) & 0xf) * 10; | ||
62 | day = (ctrl_inb(RTC_DAY1) & 0xf) + (ctrl_inb(RTC_DAY10) & 0xf) * 10; | ||
63 | mon = (ctrl_inb(RTC_MON1) & 0xf) + (ctrl_inb(RTC_MON10) & 0xf) * 10; | ||
64 | year = (ctrl_inb(RTC_YEA1) & 0xf) + (ctrl_inb(RTC_YEA10) & 0xf) * 10 | ||
65 | + (ctrl_inb(RTC_YEA100 ) & 0xf) * 100 | ||
66 | + (ctrl_inb(RTC_YEA1000) & 0xf) * 1000; | ||
67 | } while (sec != (ctrl_inb(RTC_SEC1) & 0xf) + (ctrl_inb(RTC_SEC10) & 0x7) * 10); | ||
68 | if (year == 0 || mon < 1 || mon > 12 || day > 31 || day < 1 || | ||
69 | hour > 23 || min > 59 || sec > 59) { | ||
70 | printk(KERN_ERR | ||
71 | "SH-03 RTC: invalid value, resetting to 1 Jan 2000\n"); | ||
72 | printk("year=%d, mon=%d, day=%d, hour=%d, min=%d, sec=%d\n", | ||
73 | year, mon, day, hour, min, sec); | ||
74 | |||
75 | ctrl_outb(0, RTC_SEC1); ctrl_outb(0, RTC_SEC10); | ||
76 | ctrl_outb(0, RTC_MIN1); ctrl_outb(0, RTC_MIN10); | ||
77 | ctrl_outb(0, RTC_HOU1); ctrl_outb(0, RTC_HOU10); | ||
78 | ctrl_outb(6, RTC_WEE1); | ||
79 | ctrl_outb(1, RTC_DAY1); ctrl_outb(0, RTC_DAY10); | ||
80 | ctrl_outb(1, RTC_MON1); ctrl_outb(0, RTC_MON10); | ||
81 | ctrl_outb(0, RTC_YEA1); ctrl_outb(0, RTC_YEA10); | ||
82 | ctrl_outb(0, RTC_YEA100); | ||
83 | ctrl_outb(2, RTC_YEA1000); | ||
84 | ctrl_outb(0, RTC_CTL); | ||
85 | goto again; | ||
86 | } | ||
87 | |||
88 | spin_unlock(&rtc_lock); | ||
89 | return mktime(year, mon, day, hour, min, sec); | ||
90 | } | ||
91 | |||
92 | void sh03_rtc_gettimeofday(struct timespec *tv) | ||
93 | { | ||
94 | |||
95 | tv->tv_sec = get_cmos_time(); | ||
96 | tv->tv_nsec = 0; | ||
97 | } | ||
98 | |||
99 | static int set_rtc_mmss(unsigned long nowtime) | ||
100 | { | ||
101 | int retval = 0; | ||
102 | int real_seconds, real_minutes, cmos_minutes; | ||
103 | int i; | ||
104 | |||
105 | /* gets recalled with irq locally disabled */ | ||
106 | spin_lock(&rtc_lock); | ||
107 | for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */ | ||
108 | if (!(ctrl_inb(RTC_CTL) & RTC_BUSY)) | ||
109 | break; | ||
110 | cmos_minutes = (ctrl_inb(RTC_MIN1) & 0xf) + (ctrl_inb(RTC_MIN10) & 0xf) * 10; | ||
111 | real_seconds = nowtime % 60; | ||
112 | real_minutes = nowtime / 60; | ||
113 | if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1) | ||
114 | real_minutes += 30; /* correct for half hour time zone */ | ||
115 | real_minutes %= 60; | ||
116 | |||
117 | if (abs(real_minutes - cmos_minutes) < 30) { | ||
118 | ctrl_outb(real_seconds % 10, RTC_SEC1); | ||
119 | ctrl_outb(real_seconds / 10, RTC_SEC10); | ||
120 | ctrl_outb(real_minutes % 10, RTC_MIN1); | ||
121 | ctrl_outb(real_minutes / 10, RTC_MIN10); | ||
122 | } else { | ||
123 | printk(KERN_WARNING | ||
124 | "set_rtc_mmss: can't update from %d to %d\n", | ||
125 | cmos_minutes, real_minutes); | ||
126 | retval = -1; | ||
127 | } | ||
128 | spin_unlock(&rtc_lock); | ||
129 | |||
130 | return retval; | ||
131 | } | ||
132 | |||
133 | int sh03_rtc_settimeofday(const time_t secs) | ||
134 | { | ||
135 | unsigned long nowtime = secs; | ||
136 | |||
137 | return set_rtc_mmss(nowtime); | ||
138 | } | ||
139 | |||
140 | void sh03_time_init(void) | ||
141 | { | ||
142 | rtc_get_time = sh03_rtc_gettimeofday; | ||
143 | rtc_set_time = sh03_rtc_settimeofday; | ||
144 | } | ||
diff --git a/arch/sh/boards/sh03/setup.c b/arch/sh/boards/sh03/setup.c new file mode 100644 index 000000000000..d2a08ca5eb85 --- /dev/null +++ b/arch/sh/boards/sh03/setup.c | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * linux/arch/sh/boards/sh03/setup.c | ||
3 | * | ||
4 | * Copyright (C) 2004 Interface Co.,Ltd. Saito.K | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | #include <linux/config.h> | ||
9 | #include <linux/init.h> | ||
10 | #include <linux/irq.h> | ||
11 | #include <linux/hdreg.h> | ||
12 | #include <linux/ide.h> | ||
13 | #include <asm/io.h> | ||
14 | #include <asm/sh03/io.h> | ||
15 | #include <asm/sh03/sh03.h> | ||
16 | #include <asm/addrspace.h> | ||
17 | #include "../../drivers/pci/pci-sh7751.h" | ||
18 | |||
19 | extern void (*board_time_init)(void); | ||
20 | |||
21 | const char *get_system_type(void) | ||
22 | { | ||
23 | return "Interface CTP/PCI-SH03)"; | ||
24 | } | ||
25 | |||
26 | void init_sh03_IRQ(void) | ||
27 | { | ||
28 | ctrl_outw(ctrl_inw(INTC_ICR) | INTC_ICR_IRLM, INTC_ICR); | ||
29 | |||
30 | make_ipr_irq(IRL0_IRQ, IRL0_IPR_ADDR, IRL0_IPR_POS, IRL0_PRIORITY); | ||
31 | make_ipr_irq(IRL1_IRQ, IRL1_IPR_ADDR, IRL1_IPR_POS, IRL1_PRIORITY); | ||
32 | make_ipr_irq(IRL2_IRQ, IRL2_IPR_ADDR, IRL2_IPR_POS, IRL2_PRIORITY); | ||
33 | make_ipr_irq(IRL3_IRQ, IRL3_IPR_ADDR, IRL3_IPR_POS, IRL3_PRIORITY); | ||
34 | } | ||
35 | |||
36 | extern void *cf_io_base; | ||
37 | |||
38 | unsigned long sh03_isa_port2addr(unsigned long port) | ||
39 | { | ||
40 | if (PXSEG(port)) | ||
41 | return port; | ||
42 | /* CompactFlash (IDE) */ | ||
43 | if (((port >= 0x1f0) && (port <= 0x1f7)) || (port == 0x3f6)) { | ||
44 | return (unsigned long)cf_io_base + port; | ||
45 | } | ||
46 | return port + SH7751_PCI_IO_BASE; | ||
47 | } | ||
48 | |||
49 | /* | ||
50 | * The Machine Vector | ||
51 | */ | ||
52 | |||
53 | struct sh_machine_vector mv_sh03 __initmv = { | ||
54 | .mv_nr_irqs = 48, | ||
55 | .mv_isa_port2addr = sh03_isa_port2addr, | ||
56 | .mv_init_irq = init_sh03_IRQ, | ||
57 | |||
58 | #ifdef CONFIG_HEARTBEAT | ||
59 | .mv_heartbeat = heartbeat_sh03, | ||
60 | #endif | ||
61 | }; | ||
62 | |||
63 | ALIAS_MV(sh03) | ||
64 | |||
65 | /* arch/sh/boards/sh03/rtc.c */ | ||
66 | void sh03_time_init(void); | ||
67 | |||
68 | int __init platform_setup(void) | ||
69 | { | ||
70 | board_time_init = sh03_time_init; | ||
71 | return 0; | ||
72 | } | ||