| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 | 
|  | 2 | #include <linux/init.h> | 
|  | 3 | #include <linux/types.h> | 
|  | 4 | #include <linux/kernel.h> | 
|  | 5 | #include <linux/mm.h> | 
|  | 6 | #include <linux/tty.h> | 
|  | 7 | #include <linux/console.h> | 
|  | 8 | #include <linux/rtc.h> | 
|  | 9 | #include <linux/vt_kern.h> | 
|  | 10 | #include <linux/interrupt.h> | 
|  | 11 |  | 
|  | 12 | #include <asm/setup.h> | 
|  | 13 | #include <asm/bootinfo.h> | 
|  | 14 | #include <asm/bootinfo-apollo.h> | 
|  | 15 | #include <asm/byteorder.h> | 
|  | 16 | #include <asm/pgtable.h> | 
|  | 17 | #include <asm/apollohw.h> | 
|  | 18 | #include <asm/irq.h> | 
|  | 19 | #include <asm/machdep.h> | 
|  | 20 |  | 
|  | 21 | u_long sio01_physaddr; | 
|  | 22 | u_long sio23_physaddr; | 
|  | 23 | u_long rtc_physaddr; | 
|  | 24 | u_long pica_physaddr; | 
|  | 25 | u_long picb_physaddr; | 
|  | 26 | u_long cpuctrl_physaddr; | 
|  | 27 | u_long timer_physaddr; | 
|  | 28 | u_long apollo_model; | 
|  | 29 |  | 
|  | 30 | extern void dn_sched_init(irq_handler_t handler); | 
|  | 31 | extern void dn_init_IRQ(void); | 
|  | 32 | extern u32 dn_gettimeoffset(void); | 
|  | 33 | extern int dn_dummy_hwclk(int, struct rtc_time *); | 
|  | 34 | extern void dn_dummy_reset(void); | 
|  | 35 | #ifdef CONFIG_HEARTBEAT | 
|  | 36 | static void dn_heartbeat(int on); | 
|  | 37 | #endif | 
|  | 38 | static irqreturn_t dn_timer_int(int irq,void *); | 
|  | 39 | static void dn_get_model(char *model); | 
|  | 40 | static 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 |  | 
|  | 48 | int __init apollo_parse_bootinfo(const struct bi_record *record) | 
|  | 49 | { | 
|  | 50 | int unknown = 0; | 
|  | 51 | const void *data = record->data; | 
|  | 52 |  | 
|  | 53 | switch (be16_to_cpu(record->tag)) { | 
|  | 54 | case BI_APOLLO_MODEL: | 
|  | 55 | apollo_model = be32_to_cpup(data); | 
|  | 56 | break; | 
|  | 57 |  | 
|  | 58 | default: | 
|  | 59 | unknown=1; | 
|  | 60 | } | 
|  | 61 |  | 
|  | 62 | return unknown; | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | static void __init dn_setup_model(void) | 
|  | 66 | { | 
|  | 67 | pr_info("Apollo hardware found: [%s]\n", | 
|  | 68 | apollo_models[apollo_model - APOLLO_DN3000]); | 
|  | 69 |  | 
|  | 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 |  | 
|  | 112 | int dn_serial_console_wait_key(struct console *co) { | 
|  | 113 |  | 
|  | 114 | while(!(sio01.srb_csrb & 1)) | 
|  | 115 | barrier(); | 
|  | 116 | return sio01.rhrb_thrb; | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | void 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 |  | 
|  | 133 | void 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 |  | 
|  | 147 | void __init config_apollo(void) | 
|  | 148 | { | 
|  | 149 | int i; | 
|  | 150 |  | 
|  | 151 | dn_setup_model(); | 
|  | 152 |  | 
|  | 153 | mach_sched_init=dn_sched_init; /* */ | 
|  | 154 | mach_init_IRQ=dn_init_IRQ; | 
|  | 155 | arch_gettimeoffset   = dn_gettimeoffset; | 
|  | 156 | mach_max_dma_address = 0xffffffff; | 
|  | 157 | mach_hwclk           = dn_dummy_hwclk; /* */ | 
|  | 158 | mach_reset	     = dn_dummy_reset;  /* */ | 
|  | 159 | #ifdef CONFIG_HEARTBEAT | 
|  | 160 | mach_heartbeat = dn_heartbeat; | 
|  | 161 | #endif | 
|  | 162 | mach_get_model       = dn_get_model; | 
|  | 163 |  | 
|  | 164 | cpuctrl=0xaa00; | 
|  | 165 |  | 
|  | 166 | /* clear DMA translation table */ | 
|  | 167 | for(i=0;i<0x400;i++) | 
|  | 168 | addr_xlat_map[i]=0; | 
|  | 169 |  | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | irqreturn_t dn_timer_int(int irq, void *dev_id) | 
|  | 173 | { | 
|  | 174 | irq_handler_t timer_handler = dev_id; | 
|  | 175 |  | 
|  | 176 | volatile unsigned char x; | 
|  | 177 |  | 
|  | 178 | timer_handler(irq, dev_id); | 
|  | 179 |  | 
|  | 180 | x = *(volatile unsigned char *)(apollo_timer + 3); | 
|  | 181 | x = *(volatile unsigned char *)(apollo_timer + 5); | 
|  | 182 |  | 
|  | 183 | return IRQ_HANDLED; | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | void dn_sched_init(irq_handler_t timer_routine) | 
|  | 187 | { | 
|  | 188 | /* program timer 1 */ | 
|  | 189 | *(volatile unsigned char *)(apollo_timer + 3) = 0x01; | 
|  | 190 | *(volatile unsigned char *)(apollo_timer + 1) = 0x40; | 
|  | 191 | *(volatile unsigned char *)(apollo_timer + 5) = 0x09; | 
|  | 192 | *(volatile unsigned char *)(apollo_timer + 7) = 0xc4; | 
|  | 193 |  | 
|  | 194 | /* enable IRQ of PIC B */ | 
|  | 195 | *(volatile unsigned char *)(pica+1)&=(~8); | 
|  | 196 |  | 
|  | 197 | #if 0 | 
|  | 198 | pr_info("*(0x10803) %02x\n", | 
|  | 199 | *(volatile unsigned char *)(apollo_timer + 0x3)); | 
|  | 200 | pr_info("*(0x10803) %02x\n", | 
|  | 201 | *(volatile unsigned char *)(apollo_timer + 0x3)); | 
|  | 202 | #endif | 
|  | 203 |  | 
|  | 204 | if (request_irq(IRQ_APOLLO, dn_timer_int, 0, "time", timer_routine)) | 
|  | 205 | pr_err("Couldn't register timer interrupt\n"); | 
|  | 206 | } | 
|  | 207 |  | 
|  | 208 | u32 dn_gettimeoffset(void) | 
|  | 209 | { | 
|  | 210 | return 0xdeadbeef; | 
|  | 211 | } | 
|  | 212 |  | 
|  | 213 | int dn_dummy_hwclk(int op, struct rtc_time *t) { | 
|  | 214 |  | 
|  | 215 |  | 
|  | 216 | if(!op) { /* read */ | 
|  | 217 | t->tm_sec=rtc->second; | 
|  | 218 | t->tm_min=rtc->minute; | 
|  | 219 | t->tm_hour=rtc->hours; | 
|  | 220 | t->tm_mday=rtc->day_of_month; | 
|  | 221 | t->tm_wday=rtc->day_of_week; | 
|  | 222 | t->tm_mon = rtc->month - 1; | 
|  | 223 | t->tm_year=rtc->year; | 
|  | 224 | if (t->tm_year < 70) | 
|  | 225 | t->tm_year += 100; | 
|  | 226 | } else { | 
|  | 227 | rtc->second=t->tm_sec; | 
|  | 228 | rtc->minute=t->tm_min; | 
|  | 229 | rtc->hours=t->tm_hour; | 
|  | 230 | rtc->day_of_month=t->tm_mday; | 
|  | 231 | if(t->tm_wday!=-1) | 
|  | 232 | rtc->day_of_week=t->tm_wday; | 
|  | 233 | rtc->month = t->tm_mon + 1; | 
|  | 234 | rtc->year = t->tm_year % 100; | 
|  | 235 | } | 
|  | 236 |  | 
|  | 237 | return 0; | 
|  | 238 |  | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 | void dn_dummy_reset(void) { | 
|  | 242 |  | 
|  | 243 | dn_serial_print("The end !\n"); | 
|  | 244 |  | 
|  | 245 | for(;;); | 
|  | 246 |  | 
|  | 247 | } | 
|  | 248 |  | 
|  | 249 | void dn_dummy_waitbut(void) { | 
|  | 250 |  | 
|  | 251 | dn_serial_print("waitbut\n"); | 
|  | 252 |  | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 | static void dn_get_model(char *model) | 
|  | 256 | { | 
|  | 257 | strcpy(model, "Apollo "); | 
|  | 258 | if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500) | 
|  | 259 | strcat(model, apollo_models[apollo_model - APOLLO_DN3000]); | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | #ifdef CONFIG_HEARTBEAT | 
|  | 263 | static int dn_cpuctrl=0xff00; | 
|  | 264 |  | 
|  | 265 | static void dn_heartbeat(int on) { | 
|  | 266 |  | 
|  | 267 | if(on) { | 
|  | 268 | dn_cpuctrl&=~0x100; | 
|  | 269 | cpuctrl=dn_cpuctrl; | 
|  | 270 | } | 
|  | 271 | else { | 
|  | 272 | dn_cpuctrl&=~0x100; | 
|  | 273 | dn_cpuctrl|=0x100; | 
|  | 274 | cpuctrl=dn_cpuctrl; | 
|  | 275 | } | 
|  | 276 | } | 
|  | 277 | #endif | 
|  | 278 |  |