1#include <linux/types.h>
2#include <linux/kernel.h>
3#include <linux/mm.h>
4#include <linux/tty.h>
5#include <linux/console.h>
6#include <linux/rtc.h>
7#include <linux/vt_kern.h>
8#include <linux/interrupt.h>
9
10#include <asm/setup.h>
11#include <asm/bootinfo.h>
12#include <asm/system.h>
13#include <asm/pgtable.h>
14#include <asm/apollohw.h>
15#include <asm/irq.h>
16#include <asm/rtc.h>
17#include <asm/machdep.h>
18
19u_long sio01_physaddr;
20u_long sio23_physaddr;
21u_long rtc_physaddr;
22u_long pica_physaddr;
23u_long picb_physaddr;
24u_long cpuctrl_physaddr;
25u_long timer_physaddr;
26u_long apollo_model;
27
28extern void dn_sched_init(irq_handler_t handler);
29extern void dn_init_IRQ(void);
30extern unsigned long dn_gettimeoffset(void);
31extern int dn_dummy_hwclk(int, struct rtc_time *);
32extern int dn_dummy_set_clock_mmss(unsigned long);
33extern void dn_dummy_reset(void);
34extern void dn_dummy_waitbut(void);
35extern struct fb_info *dn_fb_init(long *);
36extern void dn_dummy_debug_init(void);
37extern irqreturn_t dn_process_int(int irq, struct pt_regs *fp);
38#ifdef CONFIG_HEARTBEAT
39static void dn_heartbeat(int on);
40#endif
41static irqreturn_t dn_timer_int(int irq,void *);
42static void dn_get_model(char *model);
43static const char *apollo_models[] = {
44	[APOLLO_DN3000-APOLLO_DN3000] = "DN3000 (Otter)",
45	[APOLLO_DN3010-APOLLO_DN3000] = "DN3010 (Otter)",
46	[APOLLO_DN3500-APOLLO_DN3000] = "DN3500 (Cougar II)",
47	[APOLLO_DN4000-APOLLO_DN3000] = "DN4000 (Mink)",
48	[APOLLO_DN4500-APOLLO_DN3000] = "DN4500 (Roadrunner)"
49};
50
51int apollo_parse_bootinfo(const struct bi_record *record) {
52
53	int unknown = 0;
54	const unsigned long *data = record->data;
55
56	switch(record->tag) {
57		case BI_APOLLO_MODEL:
58			apollo_model=*data;
59			break;
60
61		default:
62			 unknown=1;
63	}
64
65	return unknown;
66}
67
68void dn_setup_model(void) {
69
70
71	printk("Apollo hardware found: ");
72	printk("[%s]\n", apollo_models[apollo_model - APOLLO_DN3000]);
73
74	switch(apollo_model) {
75		case APOLLO_UNKNOWN:
76			panic("Unknown apollo model");
77			break;
78		case APOLLO_DN3000:
79		case APOLLO_DN3010:
80			sio01_physaddr=SAU8_SIO01_PHYSADDR;
81			rtc_physaddr=SAU8_RTC_PHYSADDR;
82			pica_physaddr=SAU8_PICA;
83			picb_physaddr=SAU8_PICB;
84			cpuctrl_physaddr=SAU8_CPUCTRL;
85			timer_physaddr=SAU8_TIMER;
86			break;
87		case APOLLO_DN4000:
88			sio01_physaddr=SAU7_SIO01_PHYSADDR;
89			sio23_physaddr=SAU7_SIO23_PHYSADDR;
90			rtc_physaddr=SAU7_RTC_PHYSADDR;
91			pica_physaddr=SAU7_PICA;
92			picb_physaddr=SAU7_PICB;
93			cpuctrl_physaddr=SAU7_CPUCTRL;
94			timer_physaddr=SAU7_TIMER;
95			break;
96		case APOLLO_DN4500:
97			panic("Apollo model not yet supported");
98			break;
99		case APOLLO_DN3500:
100			sio01_physaddr=SAU7_SIO01_PHYSADDR;
101			sio23_physaddr=SAU7_SIO23_PHYSADDR;
102			rtc_physaddr=SAU7_RTC_PHYSADDR;
103			pica_physaddr=SAU7_PICA;
104			picb_physaddr=SAU7_PICB;
105			cpuctrl_physaddr=SAU7_CPUCTRL;
106			timer_physaddr=SAU7_TIMER;
107			break;
108		default:
109			panic("Undefined apollo model");
110			break;
111	}
112
113
114}
115
116int dn_serial_console_wait_key(struct console *co) {
117
118	while(!(sio01.srb_csrb & 1))
119		barrier();
120	return sio01.rhrb_thrb;
121}
122
123void dn_serial_console_write (struct console *co, const char *str,unsigned int count)
124{
125   while(count--) {
126	if (*str == '\n') {
127	sio01.rhrb_thrb = (unsigned char)'\r';
128	while (!(sio01.srb_csrb & 0x4))
129                ;
130	}
131    sio01.rhrb_thrb = (unsigned char)*str++;
132    while (!(sio01.srb_csrb & 0x4))
133            ;
134  }
135}
136
137void dn_serial_print (const char *str)
138{
139    while (*str) {
140        if (*str == '\n') {
141            sio01.rhrb_thrb = (unsigned char)'\r';
142            while (!(sio01.srb_csrb & 0x4))
143                ;
144        }
145        sio01.rhrb_thrb = (unsigned char)*str++;
146        while (!(sio01.srb_csrb & 0x4))
147            ;
148    }
149}
150
151void config_apollo(void) {
152
153	int i;
154
155	dn_setup_model();
156
157	mach_sched_init=dn_sched_init; /* */
158	mach_init_IRQ=dn_init_IRQ;
159	mach_gettimeoffset   = dn_gettimeoffset;
160	mach_max_dma_address = 0xffffffff;
161	mach_hwclk           = dn_dummy_hwclk; /* */
162	mach_set_clock_mmss  = dn_dummy_set_clock_mmss; /* */
163	mach_reset	     = dn_dummy_reset;  /* */
164#ifdef CONFIG_HEARTBEAT
165	mach_heartbeat = dn_heartbeat;
166#endif
167	mach_get_model       = dn_get_model;
168
169	cpuctrl=0xaa00;
170
171	/* clear DMA translation table */
172	for(i=0;i<0x400;i++)
173		addr_xlat_map[i]=0;
174
175}
176
177irqreturn_t dn_timer_int(int irq, void *dev_id)
178{
179	irq_handler_t timer_handler = dev_id;
180
181	volatile unsigned char x;
182
183	timer_handler(irq, dev_id);
184
185	x=*(volatile unsigned char *)(timer+3);
186	x=*(volatile unsigned char *)(timer+5);
187
188	return IRQ_HANDLED;
189}
190
191void dn_sched_init(irq_handler_t timer_routine)
192{
193	/* program timer 1 */
194	*(volatile unsigned char *)(timer+3)=0x01;
195	*(volatile unsigned char *)(timer+1)=0x40;
196	*(volatile unsigned char *)(timer+5)=0x09;
197	*(volatile unsigned char *)(timer+7)=0xc4;
198
199	/* enable IRQ of PIC B */
200	*(volatile unsigned char *)(pica+1)&=(~8);
201
202
203	request_irq(IRQ_APOLLO, dn_timer_int, 0, "time", timer_routine);
204}
205
206unsigned long dn_gettimeoffset(void) {
207
208	return 0xdeadbeef;
209
210}
211
212int dn_dummy_hwclk(int op, struct rtc_time *t) {
213
214
215  if(!op) { /* read */
216    t->tm_sec=rtc->second;
217    t->tm_min=rtc->minute;
218    t->tm_hour=rtc->hours;
219    t->tm_mday=rtc->day_of_month;
220    t->tm_wday=rtc->day_of_week;
221    t->tm_mon=rtc->month;
222    t->tm_year=rtc->year;
223  } else {
224    rtc->second=t->tm_sec;
225    rtc->minute=t->tm_min;
226    rtc->hours=t->tm_hour;
227    rtc->day_of_month=t->tm_mday;
228    if(t->tm_wday!=-1)
229      rtc->day_of_week=t->tm_wday;
230    rtc->month=t->tm_mon;
231    rtc->year=t->tm_year;
232  }
233
234  return 0;
235
236}
237
238int dn_dummy_set_clock_mmss(unsigned long nowtime) {
239
240  printk("set_clock_mmss\n");
241
242  return 0;
243
244}
245
246void dn_dummy_reset(void) {
247
248  dn_serial_print("The end !\n");
249
250  for(;;);
251
252}
253
254void dn_dummy_waitbut(void) {
255
256  dn_serial_print("waitbut\n");
257
258}
259
260static void dn_get_model(char *model)
261{
262    strcpy(model, "Apollo ");
263    if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500)
264        strcat(model, apollo_models[apollo_model - APOLLO_DN3000]);
265}
266
267#ifdef CONFIG_HEARTBEAT
268static int dn_cpuctrl=0xff00;
269
270static void dn_heartbeat(int on) {
271
272	if(on) {
273		dn_cpuctrl&=~0x100;
274		cpuctrl=dn_cpuctrl;
275	}
276	else {
277		dn_cpuctrl&=~0x100;
278		dn_cpuctrl|=0x100;
279		cpuctrl=dn_cpuctrl;
280	}
281}
282#endif
283