summaryrefslogtreecommitdiff
path: root/arch/m68k/hp300/config.c
blob: b7609f791522a45f12170799cdae4f89bc8ab80f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
 *  linux/arch/m68k/hp300/config.c
 *
 *  Copyright (C) 1998 Philip Blundell <philb@gnu.org>
 *
 *  This file contains the HP300-specific initialisation code.  It gets
 *  called by setup.c.
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/console.h>

#include <asm/bootinfo.h>
#include <asm/machdep.h>
#include <asm/blinken.h>
#include <asm/io.h>                               /* readb() and writeb() */
#include <asm/hp300hw.h>
#include <asm/rtc.h>

#include "time.h"

unsigned long hp300_model;
unsigned long hp300_uart_scode = -1;
unsigned char hp300_ledstate;
EXPORT_SYMBOL(hp300_ledstate);

static char s_hp330[] __initdata = "330";
static char s_hp340[] __initdata = "340";
static char s_hp345[] __initdata = "345";
static char s_hp360[] __initdata = "360";
static char s_hp370[] __initdata = "370";
static char s_hp375[] __initdata = "375";
static char s_hp380[] __initdata = "380";
static char s_hp385[] __initdata = "385";
static char s_hp400[] __initdata = "400";
static char s_hp425t[] __initdata = "425t";
static char s_hp425s[] __initdata = "425s";
static char s_hp425e[] __initdata = "425e";
static char s_hp433t[] __initdata = "433t";
static char s_hp433s[] __initdata = "433s";
static char *hp300_models[] __initdata = {
	[HP_320]	= NULL,
	[HP_330]	= s_hp330,
	[HP_340]	= s_hp340,
	[HP_345]	= s_hp345,
	[HP_350]	= NULL,
	[HP_360]	= s_hp360,
	[HP_370]	= s_hp370,
	[HP_375]	= s_hp375,
	[HP_380]	= s_hp380,
	[HP_385]	= s_hp385,
	[HP_400]	= s_hp400,
	[HP_425T]	= s_hp425t,
	[HP_425S]	= s_hp425s,
	[HP_425E]	= s_hp425e,
	[HP_433T]	= s_hp433t,
	[HP_433S]	= s_hp433s,
};

static char hp300_model_name[13] = "HP9000/";

extern void hp300_reset(void);
#ifdef CONFIG_SERIAL_8250_CONSOLE
extern int hp300_setup_serial_console(void) __init;
#endif

int __init hp300_parse_bootinfo(const struct bi_record *record)
{
	int unknown = 0;
	const unsigned long *data = record->data;

	switch (record->tag) {
	case BI_HP300_MODEL:
		hp300_model = *data;
		break;

	case BI_HP300_UART_SCODE:
		hp300_uart_scode = *data;
		break;

	case BI_HP300_UART_ADDR:
		/* serial port address: ignored here */
		break;

        default:
		unknown = 1;
	}

	return unknown;
}

#ifdef CONFIG_HEARTBEAT
static void hp300_pulse(int x)
{
	if (x)
		blinken_leds(0x10, 0);
	else
		blinken_leds(0, 0x10);
}
#endif

static void hp300_get_model(char *model)
{
	strcpy(model, hp300_model_name);
}

#define RTCBASE			0xf0420000
#define RTC_DATA		0x1
#define RTC_CMD			0x3

#define	RTC_BUSY		0x02
#define	RTC_DATA_RDY		0x01

#define rtc_busy()		(in_8(RTCBASE + RTC_CMD) & RTC_BUSY)
#define rtc_data_available()	(in_8(RTCBASE + RTC_CMD) & RTC_DATA_RDY)
#define rtc_status()		(in_8(RTCBASE + RTC_CMD))
#define rtc_command(x)		out_8(RTCBASE + RTC_CMD, (x))
#define rtc_read_data()		(in_8(RTCBASE + RTC_DATA))
#define rtc_write_data(x)	out_8(RTCBASE + RTC_DATA, (x))

#define RTC_SETREG	0xe0
#define RTC_WRITEREG	0xc2
#define RTC_READREG	0xc3

#define RTC_REG_SEC2	0
#define RTC_REG_SEC1	1
#define RTC_REG_MIN2	2
#define RTC_REG_MIN1	3
#define RTC_REG_HOUR2	4
#define RTC_REG_HOUR1	5
#define RTC_REG_WDAY	6
#define RTC_REG_DAY2	7
#define RTC_REG_DAY1	8
#define RTC_REG_MON2	9
#define RTC_REG_MON1	10
#define RTC_REG_YEAR2	11
#define RTC_REG_YEAR1	12

#define RTC_HOUR1_24HMODE 0x8

#define RTC_STAT_MASK	0xf0
#define RTC_STAT_RDY	0x40

static inline unsigned char hp300_rtc_read(unsigned char reg)
{
	unsigned char s, ret;
	unsigned long flags;

	local_irq_save(flags);

	while (rtc_busy());
	rtc_command(RTC_SETREG);
	while (rtc_busy());
	rtc_write_data(reg);
	while (rtc_busy());
	rtc_command(RTC_READREG);

	do {
		while (!rtc_data_available());
		s = rtc_status();
		ret = rtc_read_data();
	} while ((s & RTC_STAT_MASK) != RTC_STAT_RDY);

	local_irq_restore(flags);

	return ret;
}

static inline unsigned char hp300_rtc_write(unsigned char reg,
					    unsigned char val)
{
	unsigned char s, ret;
	unsigned long flags;

	local_irq_save(flags);

	while (rtc_busy());
	rtc_command(RTC_SETREG);
	while (rtc_busy());
	rtc_write_data((val << 4) | reg);
	while (rtc_busy());
	rtc_command(RTC_WRITEREG);
	while (rtc_busy());
	rtc_command(RTC_READREG);

	do {
		while (!rtc_data_available());
		s = rtc_status();
		ret = rtc_read_data();
	} while ((s & RTC_STAT_MASK) != RTC_STAT_RDY);

	local_irq_restore(flags);

	return ret;
}

static int hp300_hwclk(int op, struct rtc_time *t)
{
	if (!op) { /* read */
		t->tm_sec  = hp300_rtc_read(RTC_REG_SEC1) * 10 +
			hp300_rtc_read(RTC_REG_SEC2);
		t->tm_min  = hp300_rtc_read(RTC_REG_MIN1) * 10 +
			hp300_rtc_read(RTC_REG_MIN2);
		t->tm_hour = (hp300_rtc_read(RTC_REG_HOUR1) & 3) * 10 +
			hp300_rtc_read(RTC_REG_HOUR2);
		t->tm_wday = -1;
		t->tm_mday = hp300_rtc_read(RTC_REG_DAY1) * 10 +
			hp300_rtc_read(RTC_REG_DAY2);
		t->tm_mon  = hp300_rtc_read(RTC_REG_MON1) * 10 +
			hp300_rtc_read(RTC_REG_MON2) - 1;
		t->tm_year = hp300_rtc_read(RTC_REG_YEAR1) * 10 +
			hp300_rtc_read(RTC_REG_YEAR2);
		if (t->tm_year <= 69)
			t->tm_year += 100;
	} else {
		hp300_rtc_write(RTC_REG_SEC1, t->tm_sec / 10);
		hp300_rtc_write(RTC_REG_SEC2, t->tm_sec % 10);
		hp300_rtc_write(RTC_REG_MIN1, t->tm_min / 10);
		hp300_rtc_write(RTC_REG_MIN2, t->tm_min % 10);
		hp300_rtc_write(RTC_REG_HOUR1,
				((t->tm_hour / 10) & 3) | RTC_HOUR1_24HMODE);
		hp300_rtc_write(RTC_REG_HOUR2, t->tm_hour % 10);
		hp300_rtc_write(RTC_REG_DAY1, t->tm_mday / 10);
		hp300_rtc_write(RTC_REG_DAY2, t->tm_mday % 10);
		hp300_rtc_write(RTC_REG_MON1, (t->tm_mon + 1) / 10);
		hp300_rtc_write(RTC_REG_MON2, (t->tm_mon + 1) % 10);
		if (t->tm_year >= 100)
			t->tm_year -= 100;
		hp300_rtc_write(RTC_REG_YEAR1, t->tm_year / 10);
		hp300_rtc_write(RTC_REG_YEAR2, t->tm_year % 10);
	}

	return 0;
}

static unsigned int hp300_get_ss(void)
{
	return hp300_rtc_read(RTC_REG_SEC1) * 10 +
		hp300_rtc_read(RTC_REG_SEC2);
}

static void __init hp300_init_IRQ(void)
{
}

void __init config_hp300(void)
{
	mach_sched_init      = hp300_sched_init;
	mach_init_IRQ        = hp300_init_IRQ;
	mach_get_model       = hp300_get_model;
	arch_gettimeoffset   = hp300_gettimeoffset;
	mach_hwclk	     = hp300_hwclk;
	mach_get_ss	     = hp300_get_ss;
	mach_reset           = hp300_reset;
#ifdef CONFIG_HEARTBEAT
	mach_heartbeat       = hp300_pulse;
#endif
	mach_max_dma_address = 0xffffffff;

	if (hp300_model >= HP_330 && hp300_model <= HP_433S && hp300_model != HP_350) {
		printk(KERN_INFO "Detected HP9000 model %s\n", hp300_models[hp300_model-HP_320]);
		strcat(hp300_model_name, hp300_models[hp300_model-HP_320]);
	}
	else {
		panic("Unknown HP9000 Model");
	}
#ifdef CONFIG_SERIAL_8250_CONSOLE
	hp300_setup_serial_console();
#endif
}