blob: 432bc8bacfc2b376dcfcb5a439a6f16e637ab503 [file] [log] [blame]
Geert Uytterhoevena4df02a2013-06-25 21:15:24 +02001#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/types.h>
3#include <linux/kernel.h>
4#include <linux/mm.h>
5#include <linux/tty.h>
6#include <linux/console.h>
7#include <linux/rtc.h>
8#include <linux/vt_kern.h>
9#include <linux/interrupt.h>
10
11#include <asm/setup.h>
12#include <asm/bootinfo.h>
Geert Uytterhoeven4c3c5222013-10-02 11:37:33 +020013#include <asm/bootinfo-apollo.h>
Geert Uytterhoevenabe48102013-10-04 11:41:24 +020014#include <asm/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/pgtable.h>
16#include <asm/apollohw.h>
17#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/machdep.h>
19
20u_long sio01_physaddr;
21u_long sio23_physaddr;
22u_long rtc_physaddr;
23u_long pica_physaddr;
24u_long picb_physaddr;
25u_long cpuctrl_physaddr;
26u_long timer_physaddr;
27u_long apollo_model;
28
David Howells40220c12006-10-09 12:19:47 +010029extern void dn_sched_init(irq_handler_t handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030extern void dn_init_IRQ(void);
Stephen Warrenc8d5ba12012-11-08 11:34:55 -070031extern u32 dn_gettimeoffset(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032extern int dn_dummy_hwclk(int, struct rtc_time *);
33extern int dn_dummy_set_clock_mmss(unsigned long);
34extern void dn_dummy_reset(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#ifdef CONFIG_HEARTBEAT
36static void dn_heartbeat(int on);
37#endif
Al Viro2850bc22006-10-07 14:16:45 +010038static irqreturn_t dn_timer_int(int irq,void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static void dn_get_model(char *model);
40static const char *apollo_models[] = {
41 [APOLLO_DN3000-APOLLO_DN3000] = "DN3000 (Otter)",
42 [APOLLO_DN3010-APOLLO_DN3000] = "DN3010 (Otter)",
43 [APOLLO_DN3500-APOLLO_DN3000] = "DN3500 (Cougar II)",
44 [APOLLO_DN4000-APOLLO_DN3000] = "DN4000 (Mink)",
45 [APOLLO_DN4500-APOLLO_DN3000] = "DN4500 (Roadrunner)"
46};
47
Geert Uytterhoevena4df02a2013-06-25 21:15:24 +020048int __init apollo_parse_bootinfo(const struct bi_record *record)
49{
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 int unknown = 0;
Geert Uytterhoevenabe48102013-10-04 11:41:24 +020051 const void *data = record->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Geert Uytterhoevenabe48102013-10-04 11:41:24 +020053 switch (be16_to_cpu(record->tag)) {
54 case BI_APOLLO_MODEL:
55 apollo_model = be32_to_cpup(data);
56 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Geert Uytterhoevenabe48102013-10-04 11:41:24 +020058 default:
59 unknown=1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 }
61
62 return unknown;
63}
64
Geert Uytterhoevena4df02a2013-06-25 21:15:24 +020065static void __init dn_setup_model(void)
66{
Fabian Frederickce00aa02014-05-10 12:40:53 +020067 pr_info("Apollo hardware found: [%s]\n",
68 apollo_models[apollo_model - APOLLO_DN3000]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 switch(apollo_model) {
71 case APOLLO_UNKNOWN:
72 panic("Unknown apollo model");
73 break;
74 case APOLLO_DN3000:
75 case APOLLO_DN3010:
76 sio01_physaddr=SAU8_SIO01_PHYSADDR;
77 rtc_physaddr=SAU8_RTC_PHYSADDR;
78 pica_physaddr=SAU8_PICA;
79 picb_physaddr=SAU8_PICB;
80 cpuctrl_physaddr=SAU8_CPUCTRL;
81 timer_physaddr=SAU8_TIMER;
82 break;
83 case APOLLO_DN4000:
84 sio01_physaddr=SAU7_SIO01_PHYSADDR;
85 sio23_physaddr=SAU7_SIO23_PHYSADDR;
86 rtc_physaddr=SAU7_RTC_PHYSADDR;
87 pica_physaddr=SAU7_PICA;
88 picb_physaddr=SAU7_PICB;
89 cpuctrl_physaddr=SAU7_CPUCTRL;
90 timer_physaddr=SAU7_TIMER;
91 break;
92 case APOLLO_DN4500:
93 panic("Apollo model not yet supported");
94 break;
95 case APOLLO_DN3500:
96 sio01_physaddr=SAU7_SIO01_PHYSADDR;
97 sio23_physaddr=SAU7_SIO23_PHYSADDR;
98 rtc_physaddr=SAU7_RTC_PHYSADDR;
99 pica_physaddr=SAU7_PICA;
100 picb_physaddr=SAU7_PICB;
101 cpuctrl_physaddr=SAU7_CPUCTRL;
102 timer_physaddr=SAU7_TIMER;
103 break;
104 default:
105 panic("Undefined apollo model");
106 break;
107 }
108
109
110}
111
112int dn_serial_console_wait_key(struct console *co) {
113
114 while(!(sio01.srb_csrb & 1))
115 barrier();
116 return sio01.rhrb_thrb;
117}
118
119void dn_serial_console_write (struct console *co, const char *str,unsigned int count)
120{
121 while(count--) {
122 if (*str == '\n') {
123 sio01.rhrb_thrb = (unsigned char)'\r';
124 while (!(sio01.srb_csrb & 0x4))
125 ;
126 }
127 sio01.rhrb_thrb = (unsigned char)*str++;
128 while (!(sio01.srb_csrb & 0x4))
129 ;
130 }
131}
132
133void dn_serial_print (const char *str)
134{
135 while (*str) {
136 if (*str == '\n') {
137 sio01.rhrb_thrb = (unsigned char)'\r';
138 while (!(sio01.srb_csrb & 0x4))
139 ;
140 }
141 sio01.rhrb_thrb = (unsigned char)*str++;
142 while (!(sio01.srb_csrb & 0x4))
143 ;
144 }
145}
146
Al Viro66a3f822007-07-20 04:33:28 +0100147void __init config_apollo(void)
148{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 int i;
150
151 dn_setup_model();
152
153 mach_sched_init=dn_sched_init; /* */
154 mach_init_IRQ=dn_init_IRQ;
Stephen Warrenc8d5ba12012-11-08 11:34:55 -0700155 arch_gettimeoffset = dn_gettimeoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 mach_max_dma_address = 0xffffffff;
157 mach_hwclk = dn_dummy_hwclk; /* */
158 mach_set_clock_mmss = dn_dummy_set_clock_mmss; /* */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 mach_reset = dn_dummy_reset; /* */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#ifdef CONFIG_HEARTBEAT
161 mach_heartbeat = dn_heartbeat;
162#endif
163 mach_get_model = dn_get_model;
164
165 cpuctrl=0xaa00;
166
167 /* clear DMA translation table */
168 for(i=0;i<0x400;i++)
169 addr_xlat_map[i]=0;
170
171}
172
Al Viro2850bc22006-10-07 14:16:45 +0100173irqreturn_t dn_timer_int(int irq, void *dev_id)
Roman Zippel0aa78102006-06-25 05:47:02 -0700174{
David Howells40220c12006-10-09 12:19:47 +0100175 irq_handler_t timer_handler = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 volatile unsigned char x;
178
Al Viro2850bc22006-10-07 14:16:45 +0100179 timer_handler(irq, dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Geert Uytterhoeven1525e062012-07-20 21:54:29 +0200181 x = *(volatile unsigned char *)(apollo_timer + 3);
182 x = *(volatile unsigned char *)(apollo_timer + 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 return IRQ_HANDLED;
185}
186
David Howells40220c12006-10-09 12:19:47 +0100187void dn_sched_init(irq_handler_t timer_routine)
Al Viro2850bc22006-10-07 14:16:45 +0100188{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /* program timer 1 */
Geert Uytterhoeven1525e062012-07-20 21:54:29 +0200190 *(volatile unsigned char *)(apollo_timer + 3) = 0x01;
191 *(volatile unsigned char *)(apollo_timer + 1) = 0x40;
192 *(volatile unsigned char *)(apollo_timer + 5) = 0x09;
193 *(volatile unsigned char *)(apollo_timer + 7) = 0xc4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 /* enable IRQ of PIC B */
196 *(volatile unsigned char *)(pica+1)&=(~8);
197
198#if 0
Fabian Frederickce00aa02014-05-10 12:40:53 +0200199 pr_info("*(0x10803) %02x\n",
200 *(volatile unsigned char *)(apollo_timer + 0x3));
201 pr_info("*(0x10803) %02x\n",
202 *(volatile unsigned char *)(apollo_timer + 0x3));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#endif
204
Geert Uytterhoeven84430652008-12-30 14:01:07 +0100205 if (request_irq(IRQ_APOLLO, dn_timer_int, 0, "time", timer_routine))
206 pr_err("Couldn't register timer interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
Stephen Warrenc8d5ba12012-11-08 11:34:55 -0700209u32 dn_gettimeoffset(void)
210{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return 0xdeadbeef;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
214int dn_dummy_hwclk(int op, struct rtc_time *t) {
215
216
217 if(!op) { /* read */
218 t->tm_sec=rtc->second;
219 t->tm_min=rtc->minute;
220 t->tm_hour=rtc->hours;
221 t->tm_mday=rtc->day_of_month;
222 t->tm_wday=rtc->day_of_week;
223 t->tm_mon=rtc->month;
224 t->tm_year=rtc->year;
225 } else {
226 rtc->second=t->tm_sec;
227 rtc->minute=t->tm_min;
228 rtc->hours=t->tm_hour;
229 rtc->day_of_month=t->tm_mday;
230 if(t->tm_wday!=-1)
231 rtc->day_of_week=t->tm_wday;
232 rtc->month=t->tm_mon;
233 rtc->year=t->tm_year;
234 }
235
236 return 0;
237
238}
239
Fabian Frederickce00aa02014-05-10 12:40:53 +0200240int dn_dummy_set_clock_mmss(unsigned long nowtime)
241{
242 pr_info("set_clock_mmss\n");
243 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
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