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