1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/init.h>
3 #include <linux/types.h>
4 #include <linux/kernel.h>
8 #include <linux/vt_kern.h>
9 #include <linux/interrupt.h>
11 #include <asm/setup.h>
12 #include <asm/bootinfo.h>
13 #include <asm/bootinfo-apollo.h>
14 #include <asm/byteorder.h>
15 #include <asm/apollohw.h>
17 #include <asm/machdep.h>
18 #include <asm/config.h>
22 u_long sio01_physaddr;
23 u_long sio23_physaddr;
27 u_long cpuctrl_physaddr;
28 u_long timer_physaddr;
31 extern void dn_sched_init(void);
32 extern int dn_dummy_hwclk(int, struct rtc_time *);
33 static void dn_dummy_reset(void);
34 #ifdef CONFIG_HEARTBEAT
35 static void dn_heartbeat(int on);
37 static irqreturn_t dn_timer_int(int irq,void *);
38 static void dn_get_model(char *model);
39 static const char *apollo_models[] = {
40 [APOLLO_DN3000-APOLLO_DN3000] = "DN3000 (Otter)",
41 [APOLLO_DN3010-APOLLO_DN3000] = "DN3010 (Otter)",
42 [APOLLO_DN3500-APOLLO_DN3000] = "DN3500 (Cougar II)",
43 [APOLLO_DN4000-APOLLO_DN3000] = "DN4000 (Mink)",
44 [APOLLO_DN4500-APOLLO_DN3000] = "DN4500 (Roadrunner)"
47 int __init apollo_parse_bootinfo(const struct bi_record *record)
50 const void *data = record->data;
52 switch (be16_to_cpu(record->tag)) {
54 apollo_model = be32_to_cpup(data);
64 static void __init dn_setup_model(void)
66 pr_info("Apollo hardware found: [%s]\n",
67 apollo_models[apollo_model - APOLLO_DN3000]);
69 switch(apollo_model) {
71 panic("Unknown apollo model");
75 sio01_physaddr=SAU8_SIO01_PHYSADDR;
76 rtc_physaddr=SAU8_RTC_PHYSADDR;
77 pica_physaddr=SAU8_PICA;
78 picb_physaddr=SAU8_PICB;
79 cpuctrl_physaddr=SAU8_CPUCTRL;
80 timer_physaddr=SAU8_TIMER;
83 sio01_physaddr=SAU7_SIO01_PHYSADDR;
84 sio23_physaddr=SAU7_SIO23_PHYSADDR;
85 rtc_physaddr=SAU7_RTC_PHYSADDR;
86 pica_physaddr=SAU7_PICA;
87 picb_physaddr=SAU7_PICB;
88 cpuctrl_physaddr=SAU7_CPUCTRL;
89 timer_physaddr=SAU7_TIMER;
92 panic("Apollo model not yet supported");
95 sio01_physaddr=SAU7_SIO01_PHYSADDR;
96 sio23_physaddr=SAU7_SIO23_PHYSADDR;
97 rtc_physaddr=SAU7_RTC_PHYSADDR;
98 pica_physaddr=SAU7_PICA;
99 picb_physaddr=SAU7_PICB;
100 cpuctrl_physaddr=SAU7_CPUCTRL;
101 timer_physaddr=SAU7_TIMER;
104 panic("Undefined apollo model");
111 static void dn_serial_print(const char *str)
115 sio01.rhrb_thrb = (unsigned char)'\r';
116 while (!(sio01.srb_csrb & 0x4))
119 sio01.rhrb_thrb = (unsigned char)*str++;
120 while (!(sio01.srb_csrb & 0x4))
125 void __init config_apollo(void)
131 mach_sched_init=dn_sched_init; /* */
132 mach_init_IRQ=dn_init_IRQ;
133 mach_hwclk = dn_dummy_hwclk; /* */
134 mach_reset = dn_dummy_reset; /* */
135 #ifdef CONFIG_HEARTBEAT
136 mach_heartbeat = dn_heartbeat;
138 mach_get_model = dn_get_model;
142 /* clear DMA translation table */
148 irqreturn_t dn_timer_int(int irq, void *dev_id)
150 unsigned char *at = (unsigned char *)apollo_timer;
152 legacy_timer_tick(1);
155 READ_ONCE(*(at + 3));
156 READ_ONCE(*(at + 5));
161 void dn_sched_init(void)
163 /* program timer 1 */
164 *(volatile unsigned char *)(apollo_timer + 3) = 0x01;
165 *(volatile unsigned char *)(apollo_timer + 1) = 0x40;
166 *(volatile unsigned char *)(apollo_timer + 5) = 0x09;
167 *(volatile unsigned char *)(apollo_timer + 7) = 0xc4;
169 /* enable IRQ of PIC B */
170 *(volatile unsigned char *)(pica+1)&=(~8);
173 pr_info("*(0x10803) %02x\n",
174 *(volatile unsigned char *)(apollo_timer + 0x3));
175 pr_info("*(0x10803) %02x\n",
176 *(volatile unsigned char *)(apollo_timer + 0x3));
179 if (request_irq(IRQ_APOLLO, dn_timer_int, 0, "time", NULL))
180 pr_err("Couldn't register timer interrupt\n");
183 int dn_dummy_hwclk(int op, struct rtc_time *t) {
187 t->tm_sec=rtc->second;
188 t->tm_min=rtc->minute;
189 t->tm_hour=rtc->hours;
190 t->tm_mday=rtc->day_of_month;
191 t->tm_wday=rtc->day_of_week;
192 t->tm_mon = rtc->month - 1;
193 t->tm_year=rtc->year;
197 rtc->second=t->tm_sec;
198 rtc->minute=t->tm_min;
199 rtc->hours=t->tm_hour;
200 rtc->day_of_month=t->tm_mday;
202 rtc->day_of_week=t->tm_wday;
203 rtc->month = t->tm_mon + 1;
204 rtc->year = t->tm_year % 100;
211 static void dn_dummy_reset(void)
213 dn_serial_print("The end !\n");
219 static void dn_get_model(char *model)
221 strcpy(model, "Apollo ");
222 if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500)
223 strcat(model, apollo_models[apollo_model - APOLLO_DN3000]);
226 #ifdef CONFIG_HEARTBEAT
227 static int dn_cpuctrl=0xff00;
229 static void dn_heartbeat(int on) {