Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/m68k/hp300/config.c | |
3 | * | |
4 | * Copyright (C) 1998 Philip Blundell <philb@gnu.org> | |
5 | * | |
6 | * This file contains the HP300-specific initialisation code. It gets | |
7 | * called by setup.c. | |
8 | */ | |
9 | ||
1da177e4 LT |
10 | #include <linux/module.h> |
11 | #include <linux/init.h> | |
12 | #include <linux/string.h> | |
13 | #include <linux/kernel.h> | |
14 | #include <linux/console.h> | |
15 | ||
16 | #include <asm/bootinfo.h> | |
4c3c522b | 17 | #include <asm/bootinfo-hp300.h> |
1da177e4 LT |
18 | #include <asm/machdep.h> |
19 | #include <asm/blinken.h> | |
20 | #include <asm/io.h> /* readb() and writeb() */ | |
21 | #include <asm/hp300hw.h> | |
22 | #include <asm/rtc.h> | |
23 | ||
1da177e4 LT |
24 | #include "time.h" |
25 | ||
26 | unsigned long hp300_model; | |
27 | unsigned long hp300_uart_scode = -1; | |
f808b865 GU |
28 | unsigned char hp300_ledstate; |
29 | EXPORT_SYMBOL(hp300_ledstate); | |
1da177e4 LT |
30 | |
31 | static char s_hp330[] __initdata = "330"; | |
32 | static char s_hp340[] __initdata = "340"; | |
33 | static char s_hp345[] __initdata = "345"; | |
34 | static char s_hp360[] __initdata = "360"; | |
35 | static char s_hp370[] __initdata = "370"; | |
36 | static char s_hp375[] __initdata = "375"; | |
37 | static char s_hp380[] __initdata = "380"; | |
38 | static char s_hp385[] __initdata = "385"; | |
39 | static char s_hp400[] __initdata = "400"; | |
40 | static char s_hp425t[] __initdata = "425t"; | |
41 | static char s_hp425s[] __initdata = "425s"; | |
42 | static char s_hp425e[] __initdata = "425e"; | |
43 | static char s_hp433t[] __initdata = "433t"; | |
44 | static char s_hp433s[] __initdata = "433s"; | |
45 | static char *hp300_models[] __initdata = { | |
46 | [HP_320] = NULL, | |
47 | [HP_330] = s_hp330, | |
48 | [HP_340] = s_hp340, | |
49 | [HP_345] = s_hp345, | |
50 | [HP_350] = NULL, | |
51 | [HP_360] = s_hp360, | |
52 | [HP_370] = s_hp370, | |
53 | [HP_375] = s_hp375, | |
54 | [HP_380] = s_hp380, | |
55 | [HP_385] = s_hp385, | |
56 | [HP_400] = s_hp400, | |
57 | [HP_425T] = s_hp425t, | |
58 | [HP_425S] = s_hp425s, | |
59 | [HP_425E] = s_hp425e, | |
60 | [HP_433T] = s_hp433t, | |
61 | [HP_433S] = s_hp433s, | |
62 | }; | |
63 | ||
64 | static char hp300_model_name[13] = "HP9000/"; | |
65 | ||
66 | extern void hp300_reset(void); | |
1da177e4 LT |
67 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
68 | extern int hp300_setup_serial_console(void) __init; | |
69 | #endif | |
70 | ||
71 | int __init hp300_parse_bootinfo(const struct bi_record *record) | |
72 | { | |
73 | int unknown = 0; | |
74 | const unsigned long *data = record->data; | |
75 | ||
76 | switch (record->tag) { | |
77 | case BI_HP300_MODEL: | |
78 | hp300_model = *data; | |
79 | break; | |
80 | ||
81 | case BI_HP300_UART_SCODE: | |
82 | hp300_uart_scode = *data; | |
83 | break; | |
84 | ||
85 | case BI_HP300_UART_ADDR: | |
86 | /* serial port address: ignored here */ | |
87 | break; | |
88 | ||
89 | default: | |
90 | unknown = 1; | |
91 | } | |
92 | ||
93 | return unknown; | |
94 | } | |
95 | ||
96 | #ifdef CONFIG_HEARTBEAT | |
97 | static void hp300_pulse(int x) | |
98 | { | |
99 | if (x) | |
100 | blinken_leds(0x10, 0); | |
101 | else | |
102 | blinken_leds(0, 0x10); | |
103 | } | |
104 | #endif | |
105 | ||
106 | static void hp300_get_model(char *model) | |
107 | { | |
108 | strcpy(model, hp300_model_name); | |
109 | } | |
110 | ||
111 | #define RTCBASE 0xf0420000 | |
112 | #define RTC_DATA 0x1 | |
113 | #define RTC_CMD 0x3 | |
114 | ||
115 | #define RTC_BUSY 0x02 | |
116 | #define RTC_DATA_RDY 0x01 | |
117 | ||
118 | #define rtc_busy() (in_8(RTCBASE + RTC_CMD) & RTC_BUSY) | |
119 | #define rtc_data_available() (in_8(RTCBASE + RTC_CMD) & RTC_DATA_RDY) | |
120 | #define rtc_status() (in_8(RTCBASE + RTC_CMD)) | |
121 | #define rtc_command(x) out_8(RTCBASE + RTC_CMD, (x)) | |
122 | #define rtc_read_data() (in_8(RTCBASE + RTC_DATA)) | |
123 | #define rtc_write_data(x) out_8(RTCBASE + RTC_DATA, (x)) | |
124 | ||
125 | #define RTC_SETREG 0xe0 | |
126 | #define RTC_WRITEREG 0xc2 | |
127 | #define RTC_READREG 0xc3 | |
128 | ||
129 | #define RTC_REG_SEC2 0 | |
130 | #define RTC_REG_SEC1 1 | |
131 | #define RTC_REG_MIN2 2 | |
132 | #define RTC_REG_MIN1 3 | |
133 | #define RTC_REG_HOUR2 4 | |
134 | #define RTC_REG_HOUR1 5 | |
135 | #define RTC_REG_WDAY 6 | |
136 | #define RTC_REG_DAY2 7 | |
137 | #define RTC_REG_DAY1 8 | |
138 | #define RTC_REG_MON2 9 | |
139 | #define RTC_REG_MON1 10 | |
140 | #define RTC_REG_YEAR2 11 | |
141 | #define RTC_REG_YEAR1 12 | |
142 | ||
143 | #define RTC_HOUR1_24HMODE 0x8 | |
144 | ||
145 | #define RTC_STAT_MASK 0xf0 | |
146 | #define RTC_STAT_RDY 0x40 | |
147 | ||
148 | static inline unsigned char hp300_rtc_read(unsigned char reg) | |
149 | { | |
150 | unsigned char s, ret; | |
151 | unsigned long flags; | |
152 | ||
153 | local_irq_save(flags); | |
154 | ||
155 | while (rtc_busy()); | |
156 | rtc_command(RTC_SETREG); | |
157 | while (rtc_busy()); | |
158 | rtc_write_data(reg); | |
159 | while (rtc_busy()); | |
160 | rtc_command(RTC_READREG); | |
161 | ||
162 | do { | |
163 | while (!rtc_data_available()); | |
164 | s = rtc_status(); | |
165 | ret = rtc_read_data(); | |
166 | } while ((s & RTC_STAT_MASK) != RTC_STAT_RDY); | |
167 | ||
168 | local_irq_restore(flags); | |
169 | ||
170 | return ret; | |
171 | } | |
172 | ||
173 | static inline unsigned char hp300_rtc_write(unsigned char reg, | |
174 | unsigned char val) | |
175 | { | |
176 | unsigned char s, ret; | |
177 | unsigned long flags; | |
178 | ||
179 | local_irq_save(flags); | |
180 | ||
181 | while (rtc_busy()); | |
182 | rtc_command(RTC_SETREG); | |
183 | while (rtc_busy()); | |
184 | rtc_write_data((val << 4) | reg); | |
185 | while (rtc_busy()); | |
186 | rtc_command(RTC_WRITEREG); | |
187 | while (rtc_busy()); | |
188 | rtc_command(RTC_READREG); | |
189 | ||
190 | do { | |
191 | while (!rtc_data_available()); | |
192 | s = rtc_status(); | |
193 | ret = rtc_read_data(); | |
194 | } while ((s & RTC_STAT_MASK) != RTC_STAT_RDY); | |
195 | ||
196 | local_irq_restore(flags); | |
197 | ||
198 | return ret; | |
199 | } | |
200 | ||
201 | static int hp300_hwclk(int op, struct rtc_time *t) | |
202 | { | |
203 | if (!op) { /* read */ | |
204 | t->tm_sec = hp300_rtc_read(RTC_REG_SEC1) * 10 + | |
205 | hp300_rtc_read(RTC_REG_SEC2); | |
206 | t->tm_min = hp300_rtc_read(RTC_REG_MIN1) * 10 + | |
207 | hp300_rtc_read(RTC_REG_MIN2); | |
208 | t->tm_hour = (hp300_rtc_read(RTC_REG_HOUR1) & 3) * 10 + | |
209 | hp300_rtc_read(RTC_REG_HOUR2); | |
210 | t->tm_wday = -1; | |
211 | t->tm_mday = hp300_rtc_read(RTC_REG_DAY1) * 10 + | |
212 | hp300_rtc_read(RTC_REG_DAY2); | |
213 | t->tm_mon = hp300_rtc_read(RTC_REG_MON1) * 10 + | |
214 | hp300_rtc_read(RTC_REG_MON2) - 1; | |
215 | t->tm_year = hp300_rtc_read(RTC_REG_YEAR1) * 10 + | |
216 | hp300_rtc_read(RTC_REG_YEAR2); | |
217 | if (t->tm_year <= 69) | |
218 | t->tm_year += 100; | |
219 | } else { | |
220 | hp300_rtc_write(RTC_REG_SEC1, t->tm_sec / 10); | |
221 | hp300_rtc_write(RTC_REG_SEC2, t->tm_sec % 10); | |
222 | hp300_rtc_write(RTC_REG_MIN1, t->tm_min / 10); | |
223 | hp300_rtc_write(RTC_REG_MIN2, t->tm_min % 10); | |
224 | hp300_rtc_write(RTC_REG_HOUR1, | |
225 | ((t->tm_hour / 10) & 3) | RTC_HOUR1_24HMODE); | |
226 | hp300_rtc_write(RTC_REG_HOUR2, t->tm_hour % 10); | |
227 | hp300_rtc_write(RTC_REG_DAY1, t->tm_mday / 10); | |
228 | hp300_rtc_write(RTC_REG_DAY2, t->tm_mday % 10); | |
229 | hp300_rtc_write(RTC_REG_MON1, (t->tm_mon + 1) / 10); | |
230 | hp300_rtc_write(RTC_REG_MON2, (t->tm_mon + 1) % 10); | |
231 | if (t->tm_year >= 100) | |
232 | t->tm_year -= 100; | |
233 | hp300_rtc_write(RTC_REG_YEAR1, t->tm_year / 10); | |
234 | hp300_rtc_write(RTC_REG_YEAR2, t->tm_year % 10); | |
235 | } | |
236 | ||
237 | return 0; | |
238 | } | |
239 | ||
240 | static unsigned int hp300_get_ss(void) | |
241 | { | |
242 | return hp300_rtc_read(RTC_REG_SEC1) * 10 + | |
243 | hp300_rtc_read(RTC_REG_SEC2); | |
244 | } | |
245 | ||
35353bb8 RZ |
246 | static void __init hp300_init_IRQ(void) |
247 | { | |
248 | } | |
249 | ||
1da177e4 LT |
250 | void __init config_hp300(void) |
251 | { | |
252 | mach_sched_init = hp300_sched_init; | |
253 | mach_init_IRQ = hp300_init_IRQ; | |
1da177e4 | 254 | mach_get_model = hp300_get_model; |
c8d5ba18 | 255 | arch_gettimeoffset = hp300_gettimeoffset; |
1da177e4 LT |
256 | mach_hwclk = hp300_hwclk; |
257 | mach_get_ss = hp300_get_ss; | |
258 | mach_reset = hp300_reset; | |
259 | #ifdef CONFIG_HEARTBEAT | |
260 | mach_heartbeat = hp300_pulse; | |
1da177e4 LT |
261 | #endif |
262 | mach_max_dma_address = 0xffffffff; | |
263 | ||
264 | if (hp300_model >= HP_330 && hp300_model <= HP_433S && hp300_model != HP_350) { | |
265 | printk(KERN_INFO "Detected HP9000 model %s\n", hp300_models[hp300_model-HP_320]); | |
266 | strcat(hp300_model_name, hp300_models[hp300_model-HP_320]); | |
267 | } | |
268 | else { | |
269 | panic("Unknown HP9000 Model"); | |
270 | } | |
271 | #ifdef CONFIG_SERIAL_8250_CONSOLE | |
272 | hp300_setup_serial_console(); | |
273 | #endif | |
274 | } |