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/snapgear |
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/snapgear')
-rw-r--r-- | arch/sh/boards/snapgear/Makefile | 6 | ||||
-rw-r--r-- | arch/sh/boards/snapgear/io.c | 226 | ||||
-rw-r--r-- | arch/sh/boards/snapgear/rtc.c | 333 | ||||
-rw-r--r-- | arch/sh/boards/snapgear/setup.c | 216 |
4 files changed, 781 insertions, 0 deletions
diff --git a/arch/sh/boards/snapgear/Makefile b/arch/sh/boards/snapgear/Makefile new file mode 100644 index 000000000000..59fc976bfc2f --- /dev/null +++ b/arch/sh/boards/snapgear/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | # | ||
2 | # Makefile for the SnapGear specific parts of the kernel | ||
3 | # | ||
4 | |||
5 | obj-y := setup.o io.o rtc.o | ||
6 | |||
diff --git a/arch/sh/boards/snapgear/io.c b/arch/sh/boards/snapgear/io.c new file mode 100644 index 000000000000..e2eb78fc381d --- /dev/null +++ b/arch/sh/boards/snapgear/io.c | |||
@@ -0,0 +1,226 @@ | |||
1 | /* | ||
2 | * linux/arch/sh/kernel/io_7751se.c | ||
3 | * | ||
4 | * Copyright (C) 2002 David McCullough <davidm@snapgear.com> | ||
5 | * Copyright (C) 2001 Ian da Silva, Jeremy Siegel | ||
6 | * Based largely on io_se.c. | ||
7 | * | ||
8 | * I/O routine for Hitachi 7751 SolutionEngine. | ||
9 | * | ||
10 | * Initial version only to support LAN access; some | ||
11 | * placeholder code from io_se.c left in with the | ||
12 | * expectation of later SuperIO and PCMCIA access. | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/types.h> | ||
17 | #include <linux/pci.h> | ||
18 | #include <asm/io.h> | ||
19 | #include <asm/addrspace.h> | ||
20 | |||
21 | #include <asm/pci.h> | ||
22 | #include "../../drivers/pci/pci-sh7751.h" | ||
23 | |||
24 | #ifdef CONFIG_SH_SECUREEDGE5410 | ||
25 | unsigned short secureedge5410_ioport; | ||
26 | #endif | ||
27 | |||
28 | /* | ||
29 | * The SnapGear uses the built-in PCI controller (PCIC) | ||
30 | * of the 7751 processor | ||
31 | */ | ||
32 | |||
33 | #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR) | ||
34 | #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR) | ||
35 | #define PCI_IO_AREA SH7751_PCI_IO_BASE | ||
36 | #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE | ||
37 | |||
38 | |||
39 | #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK)) | ||
40 | |||
41 | |||
42 | #define maybebadio(name,port) \ | ||
43 | printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \ | ||
44 | #name, (port), (__u32) __builtin_return_address(0)) | ||
45 | |||
46 | |||
47 | static inline void delay(void) | ||
48 | { | ||
49 | ctrl_inw(0xa0000000); | ||
50 | } | ||
51 | |||
52 | |||
53 | static inline volatile __u16 *port2adr(unsigned int port) | ||
54 | { | ||
55 | #if 0 | ||
56 | if (port >= 0x2000) | ||
57 | return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000)); | ||
58 | #endif | ||
59 | maybebadio(name,(unsigned long)port); | ||
60 | return (volatile __u16*)port; | ||
61 | } | ||
62 | |||
63 | |||
64 | /* In case someone configures the kernel w/o PCI support: in that */ | ||
65 | /* scenario, don't ever bother to check for PCI-window addresses */ | ||
66 | |||
67 | /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */ | ||
68 | #if defined(CONFIG_PCI) | ||
69 | #define CHECK_SH7751_PCIIO(port) \ | ||
70 | ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE))) | ||
71 | #else | ||
72 | #define CHECK_SH7751_PCIIO(port) (0) | ||
73 | #endif | ||
74 | |||
75 | /* | ||
76 | * General outline: remap really low stuff [eventually] to SuperIO, | ||
77 | * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO) | ||
78 | * is mapped through the PCI IO window. Stuff with high bits (PXSEG) | ||
79 | * should be way beyond the window, and is used w/o translation for | ||
80 | * compatibility. | ||
81 | */ | ||
82 | |||
83 | unsigned char snapgear_inb(unsigned long port) | ||
84 | { | ||
85 | if (PXSEG(port)) | ||
86 | return *(volatile unsigned char *)port; | ||
87 | else if (CHECK_SH7751_PCIIO(port)) | ||
88 | return *(volatile unsigned char *)PCI_IOMAP(port); | ||
89 | else | ||
90 | return (*port2adr(port))&0xff; | ||
91 | } | ||
92 | |||
93 | |||
94 | unsigned char snapgear_inb_p(unsigned long port) | ||
95 | { | ||
96 | unsigned char v; | ||
97 | |||
98 | if (PXSEG(port)) | ||
99 | v = *(volatile unsigned char *)port; | ||
100 | else if (CHECK_SH7751_PCIIO(port)) | ||
101 | v = *(volatile unsigned char *)PCI_IOMAP(port); | ||
102 | else | ||
103 | v = (*port2adr(port))&0xff; | ||
104 | delay(); | ||
105 | return v; | ||
106 | } | ||
107 | |||
108 | |||
109 | unsigned short snapgear_inw(unsigned long port) | ||
110 | { | ||
111 | if (PXSEG(port)) | ||
112 | return *(volatile unsigned short *)port; | ||
113 | else if (CHECK_SH7751_PCIIO(port)) | ||
114 | return *(volatile unsigned short *)PCI_IOMAP(port); | ||
115 | else if (port >= 0x2000) | ||
116 | return *port2adr(port); | ||
117 | else | ||
118 | maybebadio(inw, port); | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | |||
123 | unsigned int snapgear_inl(unsigned long port) | ||
124 | { | ||
125 | if (PXSEG(port)) | ||
126 | return *(volatile unsigned long *)port; | ||
127 | else if (CHECK_SH7751_PCIIO(port)) | ||
128 | return *(volatile unsigned int *)PCI_IOMAP(port); | ||
129 | else if (port >= 0x2000) | ||
130 | return *port2adr(port); | ||
131 | else | ||
132 | maybebadio(inl, port); | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | |||
137 | void snapgear_outb(unsigned char value, unsigned long port) | ||
138 | { | ||
139 | |||
140 | if (PXSEG(port)) | ||
141 | *(volatile unsigned char *)port = value; | ||
142 | else if (CHECK_SH7751_PCIIO(port)) | ||
143 | *((unsigned char*)PCI_IOMAP(port)) = value; | ||
144 | else | ||
145 | *(port2adr(port)) = value; | ||
146 | } | ||
147 | |||
148 | |||
149 | void snapgear_outb_p(unsigned char value, unsigned long port) | ||
150 | { | ||
151 | if (PXSEG(port)) | ||
152 | *(volatile unsigned char *)port = value; | ||
153 | else if (CHECK_SH7751_PCIIO(port)) | ||
154 | *((unsigned char*)PCI_IOMAP(port)) = value; | ||
155 | else | ||
156 | *(port2adr(port)) = value; | ||
157 | delay(); | ||
158 | } | ||
159 | |||
160 | |||
161 | void snapgear_outw(unsigned short value, unsigned long port) | ||
162 | { | ||
163 | if (PXSEG(port)) | ||
164 | *(volatile unsigned short *)port = value; | ||
165 | else if (CHECK_SH7751_PCIIO(port)) | ||
166 | *((unsigned short *)PCI_IOMAP(port)) = value; | ||
167 | else if (port >= 0x2000) | ||
168 | *port2adr(port) = value; | ||
169 | else | ||
170 | maybebadio(outw, port); | ||
171 | } | ||
172 | |||
173 | |||
174 | void snapgear_outl(unsigned int value, unsigned long port) | ||
175 | { | ||
176 | if (PXSEG(port)) | ||
177 | *(volatile unsigned long *)port = value; | ||
178 | else if (CHECK_SH7751_PCIIO(port)) | ||
179 | *((unsigned long*)PCI_IOMAP(port)) = value; | ||
180 | else | ||
181 | maybebadio(outl, port); | ||
182 | } | ||
183 | |||
184 | void snapgear_insl(unsigned long port, void *addr, unsigned long count) | ||
185 | { | ||
186 | maybebadio(insl, port); | ||
187 | } | ||
188 | |||
189 | void snapgear_outsl(unsigned long port, const void *addr, unsigned long count) | ||
190 | { | ||
191 | maybebadio(outsw, port); | ||
192 | } | ||
193 | |||
194 | /* Map ISA bus address to the real address. Only for PCMCIA. */ | ||
195 | |||
196 | |||
197 | /* ISA page descriptor. */ | ||
198 | static __u32 sh_isa_memmap[256]; | ||
199 | |||
200 | |||
201 | #if 0 | ||
202 | static int sh_isa_mmap(__u32 start, __u32 length, __u32 offset) | ||
203 | { | ||
204 | int idx; | ||
205 | |||
206 | if (start >= 0x100000 || (start & 0xfff) || (length != 0x1000)) | ||
207 | return -1; | ||
208 | |||
209 | idx = start >> 12; | ||
210 | sh_isa_memmap[idx] = 0xb8000000 + (offset &~ 0xfff); | ||
211 | #if 0 | ||
212 | printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)\n", | ||
213 | start, length, offset, idx, sh_isa_memmap[idx]); | ||
214 | #endif | ||
215 | return 0; | ||
216 | } | ||
217 | #endif | ||
218 | |||
219 | unsigned long snapgear_isa_port2addr(unsigned long offset) | ||
220 | { | ||
221 | int idx; | ||
222 | |||
223 | idx = (offset >> 12) & 0xff; | ||
224 | offset &= 0xfff; | ||
225 | return sh_isa_memmap[idx] + offset; | ||
226 | } | ||
diff --git a/arch/sh/boards/snapgear/rtc.c b/arch/sh/boards/snapgear/rtc.c new file mode 100644 index 000000000000..b71e009da35c --- /dev/null +++ b/arch/sh/boards/snapgear/rtc.c | |||
@@ -0,0 +1,333 @@ | |||
1 | /****************************************************************************/ | ||
2 | /* | ||
3 | * linux/arch/sh/boards/snapgear/rtc.c -- Secureedge5410 RTC code | ||
4 | * | ||
5 | * Copyright (C) 2002 David McCullough <davidm@snapgear.com> | ||
6 | * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org> | ||
7 | * | ||
8 | * The SecureEdge5410 can have one of 2 real time clocks, the SH | ||
9 | * built in version or the preferred external DS1302. Here we work out | ||
10 | * each to see what we have and then run with it. | ||
11 | */ | ||
12 | /****************************************************************************/ | ||
13 | |||
14 | #include <linux/init.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/sched.h> | ||
17 | #include <linux/time.h> | ||
18 | #include <linux/rtc.h> | ||
19 | #include <linux/mc146818rtc.h> | ||
20 | |||
21 | #include <asm/io.h> | ||
22 | #include <asm/rtc.h> | ||
23 | #include <asm/mc146818rtc.h> | ||
24 | |||
25 | /****************************************************************************/ | ||
26 | |||
27 | static int use_ds1302 = 0; | ||
28 | |||
29 | /****************************************************************************/ | ||
30 | /* | ||
31 | * we need to implement a DS1302 driver here that can operate in | ||
32 | * conjunction with the builtin rtc driver which is already quite friendly | ||
33 | */ | ||
34 | /*****************************************************************************/ | ||
35 | |||
36 | #define RTC_CMD_READ 0x81 /* Read command */ | ||
37 | #define RTC_CMD_WRITE 0x80 /* Write command */ | ||
38 | |||
39 | #define RTC_ADDR_YEAR 0x06 /* Address of year register */ | ||
40 | #define RTC_ADDR_DAY 0x05 /* Address of day of week register */ | ||
41 | #define RTC_ADDR_MON 0x04 /* Address of month register */ | ||
42 | #define RTC_ADDR_DATE 0x03 /* Address of day of month register */ | ||
43 | #define RTC_ADDR_HOUR 0x02 /* Address of hour register */ | ||
44 | #define RTC_ADDR_MIN 0x01 /* Address of minute register */ | ||
45 | #define RTC_ADDR_SEC 0x00 /* Address of second register */ | ||
46 | |||
47 | #define RTC_RESET 0x1000 | ||
48 | #define RTC_IODATA 0x0800 | ||
49 | #define RTC_SCLK 0x0400 | ||
50 | |||
51 | #define set_dirp(x) | ||
52 | #define get_dirp(x) 0 | ||
53 | #define set_dp(x) SECUREEDGE_WRITE_IOPORT(x, 0x1c00) | ||
54 | #define get_dp(x) SECUREEDGE_READ_IOPORT() | ||
55 | |||
56 | static void ds1302_sendbits(unsigned int val) | ||
57 | { | ||
58 | int i; | ||
59 | |||
60 | for (i = 8; (i); i--, val >>= 1) { | ||
61 | set_dp((get_dp() & ~RTC_IODATA) | ((val & 0x1) ? RTC_IODATA : 0)); | ||
62 | set_dp(get_dp() | RTC_SCLK); // clock high | ||
63 | set_dp(get_dp() & ~RTC_SCLK); // clock low | ||
64 | } | ||
65 | } | ||
66 | |||
67 | static unsigned int ds1302_recvbits(void) | ||
68 | { | ||
69 | unsigned int val; | ||
70 | int i; | ||
71 | |||
72 | for (i = 0, val = 0; (i < 8); i++) { | ||
73 | val |= (((get_dp() & RTC_IODATA) ? 1 : 0) << i); | ||
74 | set_dp(get_dp() | RTC_SCLK); // clock high | ||
75 | set_dp(get_dp() & ~RTC_SCLK); // clock low | ||
76 | } | ||
77 | return(val); | ||
78 | } | ||
79 | |||
80 | static unsigned int ds1302_readbyte(unsigned int addr) | ||
81 | { | ||
82 | unsigned int val; | ||
83 | unsigned long flags; | ||
84 | |||
85 | #if 0 | ||
86 | printk("SnapGear RTC: ds1302_readbyte(addr=%x)\n", addr); | ||
87 | #endif | ||
88 | |||
89 | local_irq_save(flags); | ||
90 | set_dirp(get_dirp() | RTC_RESET | RTC_IODATA | RTC_SCLK); | ||
91 | set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK)); | ||
92 | |||
93 | set_dp(get_dp() | RTC_RESET); | ||
94 | ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_READ); | ||
95 | set_dirp(get_dirp() & ~RTC_IODATA); | ||
96 | val = ds1302_recvbits(); | ||
97 | set_dp(get_dp() & ~RTC_RESET); | ||
98 | local_irq_restore(flags); | ||
99 | |||
100 | return(val); | ||
101 | } | ||
102 | |||
103 | static void ds1302_writebyte(unsigned int addr, unsigned int val) | ||
104 | { | ||
105 | unsigned long flags; | ||
106 | |||
107 | #if 0 | ||
108 | printk("SnapGear RTC: ds1302_writebyte(addr=%x)\n", addr); | ||
109 | #endif | ||
110 | |||
111 | local_irq_save(flags); | ||
112 | set_dirp(get_dirp() | RTC_RESET | RTC_IODATA | RTC_SCLK); | ||
113 | set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK)); | ||
114 | set_dp(get_dp() | RTC_RESET); | ||
115 | ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_WRITE); | ||
116 | ds1302_sendbits(val); | ||
117 | set_dp(get_dp() & ~RTC_RESET); | ||
118 | local_irq_restore(flags); | ||
119 | } | ||
120 | |||
121 | static void ds1302_reset(void) | ||
122 | { | ||
123 | unsigned long flags; | ||
124 | /* Hardware dependant reset/init */ | ||
125 | local_irq_save(flags); | ||
126 | set_dirp(get_dirp() | RTC_RESET | RTC_IODATA | RTC_SCLK); | ||
127 | set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK)); | ||
128 | local_irq_restore(flags); | ||
129 | } | ||
130 | |||
131 | /*****************************************************************************/ | ||
132 | |||
133 | static inline int bcd2int(int val) | ||
134 | { | ||
135 | return((((val & 0xf0) >> 4) * 10) + (val & 0xf)); | ||
136 | } | ||
137 | |||
138 | static inline int int2bcd(int val) | ||
139 | { | ||
140 | return(((val / 10) << 4) + (val % 10)); | ||
141 | } | ||
142 | |||
143 | /*****************************************************************************/ | ||
144 | /* | ||
145 | * Write and Read some RAM in the DS1302, if it works assume it's there | ||
146 | * Otherwise use the SH4 internal RTC | ||
147 | */ | ||
148 | |||
149 | void snapgear_rtc_gettimeofday(struct timespec *); | ||
150 | int snapgear_rtc_settimeofday(const time_t); | ||
151 | |||
152 | void __init secureedge5410_rtc_init(void) | ||
153 | { | ||
154 | unsigned char *test = "snapgear"; | ||
155 | int i; | ||
156 | |||
157 | ds1302_reset(); | ||
158 | |||
159 | use_ds1302 = 1; | ||
160 | |||
161 | for (i = 0; test[i]; i++) | ||
162 | ds1302_writebyte(32 + i, test[i]); | ||
163 | |||
164 | for (i = 0; test[i]; i++) | ||
165 | if (ds1302_readbyte(32 + i) != test[i]) { | ||
166 | use_ds1302 = 0; | ||
167 | break; | ||
168 | } | ||
169 | |||
170 | if (use_ds1302) { | ||
171 | rtc_get_time = snapgear_rtc_gettimeofday; | ||
172 | rtc_set_time = snapgear_rtc_settimeofday; | ||
173 | } else { | ||
174 | rtc_get_time = sh_rtc_gettimeofday; | ||
175 | rtc_set_time = sh_rtc_settimeofday; | ||
176 | } | ||
177 | |||
178 | printk("SnapGear RTC: using %s rtc.\n", use_ds1302 ? "ds1302" : "internal"); | ||
179 | } | ||
180 | |||
181 | /****************************************************************************/ | ||
182 | /* | ||
183 | * our generic interface that chooses the correct code to use | ||
184 | */ | ||
185 | |||
186 | void snapgear_rtc_gettimeofday(struct timespec *ts) | ||
187 | { | ||
188 | unsigned int sec, min, hr, day, mon, yr; | ||
189 | |||
190 | if (!use_ds1302) { | ||
191 | sh_rtc_gettimeofday(ts); | ||
192 | return; | ||
193 | } | ||
194 | |||
195 | sec = bcd2int(ds1302_readbyte(RTC_ADDR_SEC)); | ||
196 | min = bcd2int(ds1302_readbyte(RTC_ADDR_MIN)); | ||
197 | hr = bcd2int(ds1302_readbyte(RTC_ADDR_HOUR)); | ||
198 | day = bcd2int(ds1302_readbyte(RTC_ADDR_DATE)); | ||
199 | mon = bcd2int(ds1302_readbyte(RTC_ADDR_MON)); | ||
200 | yr = bcd2int(ds1302_readbyte(RTC_ADDR_YEAR)); | ||
201 | |||
202 | bad_time: | ||
203 | if (yr > 99 || mon < 1 || mon > 12 || day > 31 || day < 1 || | ||
204 | hr > 23 || min > 59 || sec > 59) { | ||
205 | printk(KERN_ERR | ||
206 | "SnapGear RTC: invalid value, resetting to 1 Jan 2000\n"); | ||
207 | ds1302_writebyte(RTC_ADDR_MIN, min = 0); | ||
208 | ds1302_writebyte(RTC_ADDR_HOUR, hr = 0); | ||
209 | ds1302_writebyte(RTC_ADDR_DAY, 7); | ||
210 | ds1302_writebyte(RTC_ADDR_DATE, day = 1); | ||
211 | ds1302_writebyte(RTC_ADDR_MON, mon = 1); | ||
212 | ds1302_writebyte(RTC_ADDR_YEAR, yr = 0); | ||
213 | ds1302_writebyte(RTC_ADDR_SEC, sec = 0); | ||
214 | } | ||
215 | |||
216 | ts->tv_sec = mktime(2000 + yr, mon, day, hr, min, sec); | ||
217 | if (ts->tv_sec < 0) { | ||
218 | #if 0 | ||
219 | printk("BAD TIME %d %d %d %d %d %d\n", yr, mon, day, hr, min, sec); | ||
220 | #endif | ||
221 | yr = 100; | ||
222 | goto bad_time; | ||
223 | } | ||
224 | ts->tv_nsec = 0; | ||
225 | } | ||
226 | |||
227 | int snapgear_rtc_settimeofday(const time_t secs) | ||
228 | { | ||
229 | int retval = 0; | ||
230 | int real_seconds, real_minutes, cmos_minutes; | ||
231 | unsigned long nowtime; | ||
232 | |||
233 | if (!use_ds1302) | ||
234 | return sh_rtc_settimeofday(secs); | ||
235 | |||
236 | /* | ||
237 | * This is called direct from the kernel timer handling code. | ||
238 | * It is supposed to synchronize the kernel clock to the RTC. | ||
239 | */ | ||
240 | |||
241 | nowtime = secs; | ||
242 | |||
243 | #if 1 | ||
244 | printk("SnapGear RTC: snapgear_rtc_settimeofday(nowtime=%ld)\n", nowtime); | ||
245 | #endif | ||
246 | |||
247 | /* STOP RTC */ | ||
248 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80); | ||
249 | |||
250 | cmos_minutes = bcd2int(ds1302_readbyte(RTC_ADDR_MIN)); | ||
251 | |||
252 | /* | ||
253 | * since we're only adjusting minutes and seconds, | ||
254 | * don't interfere with hour overflow. This avoids | ||
255 | * messing with unknown time zones but requires your | ||
256 | * RTC not to be off by more than 15 minutes | ||
257 | */ | ||
258 | real_seconds = nowtime % 60; | ||
259 | real_minutes = nowtime / 60; | ||
260 | if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1) | ||
261 | real_minutes += 30; /* correct for half hour time zone */ | ||
262 | real_minutes %= 60; | ||
263 | |||
264 | if (abs(real_minutes - cmos_minutes) < 30) { | ||
265 | ds1302_writebyte(RTC_ADDR_MIN, int2bcd(real_minutes)); | ||
266 | ds1302_writebyte(RTC_ADDR_SEC, int2bcd(real_seconds)); | ||
267 | } else { | ||
268 | printk(KERN_WARNING | ||
269 | "SnapGear RTC: can't update from %d to %d\n", | ||
270 | cmos_minutes, real_minutes); | ||
271 | retval = -1; | ||
272 | } | ||
273 | |||
274 | /* START RTC */ | ||
275 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80); | ||
276 | return(0); | ||
277 | } | ||
278 | |||
279 | unsigned char secureedge5410_cmos_read(int addr) | ||
280 | { | ||
281 | unsigned char val = 0; | ||
282 | |||
283 | if (!use_ds1302) | ||
284 | return(__CMOS_READ(addr, w)); | ||
285 | |||
286 | switch(addr) { | ||
287 | case RTC_SECONDS: val = ds1302_readbyte(RTC_ADDR_SEC); break; | ||
288 | case RTC_SECONDS_ALARM: break; | ||
289 | case RTC_MINUTES: val = ds1302_readbyte(RTC_ADDR_MIN); break; | ||
290 | case RTC_MINUTES_ALARM: break; | ||
291 | case RTC_HOURS: val = ds1302_readbyte(RTC_ADDR_HOUR); break; | ||
292 | case RTC_HOURS_ALARM: break; | ||
293 | case RTC_DAY_OF_WEEK: val = ds1302_readbyte(RTC_ADDR_DAY); break; | ||
294 | case RTC_DAY_OF_MONTH: val = ds1302_readbyte(RTC_ADDR_DATE); break; | ||
295 | case RTC_MONTH: val = ds1302_readbyte(RTC_ADDR_MON); break; | ||
296 | case RTC_YEAR: val = ds1302_readbyte(RTC_ADDR_YEAR); break; | ||
297 | case RTC_REG_A: /* RTC_FREQ_SELECT */ break; | ||
298 | case RTC_REG_B: /* RTC_CONTROL */ break; | ||
299 | case RTC_REG_C: /* RTC_INTR_FLAGS */ break; | ||
300 | case RTC_REG_D: val = RTC_VRT /* RTC_VALID */; break; | ||
301 | default: break; | ||
302 | } | ||
303 | |||
304 | return(val); | ||
305 | } | ||
306 | |||
307 | void secureedge5410_cmos_write(unsigned char val, int addr) | ||
308 | { | ||
309 | if (!use_ds1302) { | ||
310 | __CMOS_WRITE(val, addr, w); | ||
311 | return; | ||
312 | } | ||
313 | |||
314 | switch(addr) { | ||
315 | case RTC_SECONDS: ds1302_writebyte(RTC_ADDR_SEC, val); break; | ||
316 | case RTC_SECONDS_ALARM: break; | ||
317 | case RTC_MINUTES: ds1302_writebyte(RTC_ADDR_MIN, val); break; | ||
318 | case RTC_MINUTES_ALARM: break; | ||
319 | case RTC_HOURS: ds1302_writebyte(RTC_ADDR_HOUR, val); break; | ||
320 | case RTC_HOURS_ALARM: break; | ||
321 | case RTC_DAY_OF_WEEK: ds1302_writebyte(RTC_ADDR_DAY, val); break; | ||
322 | case RTC_DAY_OF_MONTH: ds1302_writebyte(RTC_ADDR_DATE, val); break; | ||
323 | case RTC_MONTH: ds1302_writebyte(RTC_ADDR_MON, val); break; | ||
324 | case RTC_YEAR: ds1302_writebyte(RTC_ADDR_YEAR, val); break; | ||
325 | case RTC_REG_A: /* RTC_FREQ_SELECT */ break; | ||
326 | case RTC_REG_B: /* RTC_CONTROL */ break; | ||
327 | case RTC_REG_C: /* RTC_INTR_FLAGS */ break; | ||
328 | case RTC_REG_D: /* RTC_VALID */ break; | ||
329 | default: break; | ||
330 | } | ||
331 | } | ||
332 | |||
333 | /****************************************************************************/ | ||
diff --git a/arch/sh/boards/snapgear/setup.c b/arch/sh/boards/snapgear/setup.c new file mode 100644 index 000000000000..08fc98342a0b --- /dev/null +++ b/arch/sh/boards/snapgear/setup.c | |||
@@ -0,0 +1,216 @@ | |||
1 | /****************************************************************************/ | ||
2 | /* | ||
3 | * linux/arch/sh/boards/snapgear/setup.c | ||
4 | * | ||
5 | * Copyright (C) 2002 David McCullough <davidm@snapgear.com> | ||
6 | * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org> | ||
7 | * | ||
8 | * Based on files with the following comments: | ||
9 | * | ||
10 | * Copyright (C) 2000 Kazumoto Kojima | ||
11 | * | ||
12 | * Modified for 7751 Solution Engine by | ||
13 | * Ian da Silva and Jeremy Siegel, 2001. | ||
14 | */ | ||
15 | /****************************************************************************/ | ||
16 | |||
17 | #include <linux/config.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/irq.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <linux/timer.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/sched.h> | ||
25 | |||
26 | #include <asm/machvec.h> | ||
27 | #include <asm/mach/io.h> | ||
28 | #include <asm/irq.h> | ||
29 | #include <asm/io.h> | ||
30 | #include <asm/cpu/timer.h> | ||
31 | |||
32 | extern void (*board_time_init)(void); | ||
33 | extern void secureedge5410_rtc_init(void); | ||
34 | extern void pcibios_init(void); | ||
35 | |||
36 | /****************************************************************************/ | ||
37 | /* | ||
38 | * EraseConfig handling functions | ||
39 | */ | ||
40 | |||
41 | static irqreturn_t eraseconfig_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
42 | { | ||
43 | volatile char dummy __attribute__((unused)) = * (volatile char *) 0xb8000000; | ||
44 | |||
45 | printk("SnapGear: erase switch interrupt!\n"); | ||
46 | |||
47 | return IRQ_HANDLED; | ||
48 | } | ||
49 | |||
50 | static int __init eraseconfig_init(void) | ||
51 | { | ||
52 | printk("SnapGear: EraseConfig init\n"); | ||
53 | /* Setup "EraseConfig" switch on external IRQ 0 */ | ||
54 | if (request_irq(IRL0_IRQ, eraseconfig_interrupt, SA_INTERRUPT, | ||
55 | "Erase Config", NULL)) | ||
56 | printk("SnapGear: failed to register IRQ%d for Reset witch\n", | ||
57 | IRL0_IRQ); | ||
58 | else | ||
59 | printk("SnapGear: registered EraseConfig switch on IRQ%d\n", | ||
60 | IRL0_IRQ); | ||
61 | return(0); | ||
62 | } | ||
63 | |||
64 | module_init(eraseconfig_init); | ||
65 | |||
66 | /****************************************************************************/ | ||
67 | /* | ||
68 | * Initialize IRQ setting | ||
69 | * | ||
70 | * IRL0 = erase switch | ||
71 | * IRL1 = eth0 | ||
72 | * IRL2 = eth1 | ||
73 | * IRL3 = crypto | ||
74 | */ | ||
75 | |||
76 | static void __init init_snapgear_IRQ(void) | ||
77 | { | ||
78 | /* enable individual interrupt mode for externals */ | ||
79 | ctrl_outw(ctrl_inw(INTC_ICR) | INTC_ICR_IRLM, INTC_ICR); | ||
80 | |||
81 | printk("Setup SnapGear IRQ/IPR ...\n"); | ||
82 | |||
83 | make_ipr_irq(IRL0_IRQ, IRL0_IPR_ADDR, IRL0_IPR_POS, IRL0_PRIORITY); | ||
84 | make_ipr_irq(IRL1_IRQ, IRL1_IPR_ADDR, IRL1_IPR_POS, IRL1_PRIORITY); | ||
85 | make_ipr_irq(IRL2_IRQ, IRL2_IPR_ADDR, IRL2_IPR_POS, IRL2_PRIORITY); | ||
86 | make_ipr_irq(IRL3_IRQ, IRL3_IPR_ADDR, IRL3_IPR_POS, IRL3_PRIORITY); | ||
87 | } | ||
88 | |||
89 | /****************************************************************************/ | ||
90 | /* | ||
91 | * Fast poll interrupt simulator. | ||
92 | */ | ||
93 | |||
94 | /* | ||
95 | * Leave all of the fast timer/fast poll stuff commented out for now, since | ||
96 | * it's not clear whether it actually works or not. Since it wasn't being used | ||
97 | * at all in 2.4, we'll assume it's not sane for 2.6 either.. -- PFM | ||
98 | */ | ||
99 | #if 0 | ||
100 | #define FAST_POLL 1000 | ||
101 | //#define FAST_POLL_INTR | ||
102 | |||
103 | #define FASTTIMER_IRQ 17 | ||
104 | #define FASTTIMER_IPR_ADDR INTC_IPRA | ||
105 | #define FASTTIMER_IPR_POS 2 | ||
106 | #define FASTTIMER_PRIORITY 3 | ||
107 | |||
108 | #ifdef FAST_POLL_INTR | ||
109 | #define TMU1_TCR_INIT 0x0020 | ||
110 | #else | ||
111 | #define TMU1_TCR_INIT 0 | ||
112 | #endif | ||
113 | #define TMU_TSTR_INIT 1 | ||
114 | #define TMU1_TCR_CALIB 0x0000 | ||
115 | |||
116 | |||
117 | #ifdef FAST_POLL_INTR | ||
118 | static void fast_timer_irq(int irq, void *dev_instance, struct pt_regs *regs) | ||
119 | { | ||
120 | unsigned long timer_status; | ||
121 | timer_status = ctrl_inw(TMU1_TCR); | ||
122 | timer_status &= ~0x100; | ||
123 | ctrl_outw(timer_status, TMU1_TCR); | ||
124 | } | ||
125 | #endif | ||
126 | |||
127 | /* | ||
128 | * return the current ticks on the fast timer | ||
129 | */ | ||
130 | |||
131 | unsigned long fast_timer_count(void) | ||
132 | { | ||
133 | return(ctrl_inl(TMU1_TCNT)); | ||
134 | } | ||
135 | |||
136 | /* | ||
137 | * setup a fast timer for profiling etc etc | ||
138 | */ | ||
139 | |||
140 | static void setup_fast_timer() | ||
141 | { | ||
142 | unsigned long interval; | ||
143 | |||
144 | #ifdef FAST_POLL_INTR | ||
145 | interval = (current_cpu_data.module_clock/4 + FAST_POLL/2) / FAST_POLL; | ||
146 | |||
147 | make_ipr_irq(FASTTIMER_IRQ, FASTTIMER_IPR_ADDR, FASTTIMER_IPR_POS, | ||
148 | FASTTIMER_PRIORITY); | ||
149 | |||
150 | printk("SnapGear: %dHz fast timer on IRQ %d\n",FAST_POLL,FASTTIMER_IRQ); | ||
151 | |||
152 | if (request_irq(FASTTIMER_IRQ, fast_timer_irq, 0, "SnapGear fast timer", | ||
153 | NULL) != 0) | ||
154 | printk("%s(%d): request_irq() failed?\n", __FILE__, __LINE__); | ||
155 | #else | ||
156 | printk("SnapGear: fast timer running\n",FAST_POLL,FASTTIMER_IRQ); | ||
157 | interval = 0xffffffff; | ||
158 | #endif | ||
159 | |||
160 | ctrl_outb(ctrl_inb(TMU_TSTR) & ~0x2, TMU_TSTR); /* disable timer 1 */ | ||
161 | ctrl_outw(TMU1_TCR_INIT, TMU1_TCR); | ||
162 | ctrl_outl(interval, TMU1_TCOR); | ||
163 | ctrl_outl(interval, TMU1_TCNT); | ||
164 | ctrl_outb(ctrl_inb(TMU_TSTR) | 0x2, TMU_TSTR); /* enable timer 1 */ | ||
165 | |||
166 | printk("Timer count 1 = 0x%x\n", fast_timer_count()); | ||
167 | udelay(1000); | ||
168 | printk("Timer count 2 = 0x%x\n", fast_timer_count()); | ||
169 | } | ||
170 | #endif | ||
171 | |||
172 | /****************************************************************************/ | ||
173 | |||
174 | const char *get_system_type(void) | ||
175 | { | ||
176 | return "SnapGear SecureEdge5410"; | ||
177 | } | ||
178 | |||
179 | /* | ||
180 | * The Machine Vector | ||
181 | */ | ||
182 | |||
183 | struct sh_machine_vector mv_snapgear __initmv = { | ||
184 | .mv_nr_irqs = 72, | ||
185 | |||
186 | .mv_inb = snapgear_inb, | ||
187 | .mv_inw = snapgear_inw, | ||
188 | .mv_inl = snapgear_inl, | ||
189 | .mv_outb = snapgear_outb, | ||
190 | .mv_outw = snapgear_outw, | ||
191 | .mv_outl = snapgear_outl, | ||
192 | |||
193 | .mv_inb_p = snapgear_inb_p, | ||
194 | .mv_inw_p = snapgear_inw, | ||
195 | .mv_inl_p = snapgear_inl, | ||
196 | .mv_outb_p = snapgear_outb_p, | ||
197 | .mv_outw_p = snapgear_outw, | ||
198 | .mv_outl_p = snapgear_outl, | ||
199 | |||
200 | .mv_isa_port2addr = snapgear_isa_port2addr, | ||
201 | |||
202 | .mv_init_irq = init_snapgear_IRQ, | ||
203 | }; | ||
204 | ALIAS_MV(snapgear) | ||
205 | |||
206 | /* | ||
207 | * Initialize the board | ||
208 | */ | ||
209 | |||
210 | int __init platform_setup(void) | ||
211 | { | ||
212 | board_time_init = secureedge5410_rtc_init; | ||
213 | |||
214 | return 0; | ||
215 | } | ||
216 | |||