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