config.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. #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>
  16. #include <asm/irq.h>
  17. #include <asm/machdep.h>
  18. u_long sio01_physaddr;
  19. u_long sio23_physaddr;
  20. u_long rtc_physaddr;
  21. u_long pica_physaddr;
  22. u_long picb_physaddr;
  23. u_long cpuctrl_physaddr;
  24. u_long timer_physaddr;
  25. u_long apollo_model;
  26. extern void dn_sched_init(irq_handler_t handler);
  27. extern void dn_init_IRQ(void);
  28. extern int dn_dummy_hwclk(int, struct rtc_time *);
  29. extern void dn_dummy_reset(void);
  30. #ifdef CONFIG_HEARTBEAT
  31. static void dn_heartbeat(int on);
  32. #endif
  33. static irqreturn_t dn_timer_int(int irq,void *);
  34. static void dn_get_model(char *model);
  35. static const char *apollo_models[] = {
  36. [APOLLO_DN3000-APOLLO_DN3000] = "DN3000 (Otter)",
  37. [APOLLO_DN3010-APOLLO_DN3000] = "DN3010 (Otter)",
  38. [APOLLO_DN3500-APOLLO_DN3000] = "DN3500 (Cougar II)",
  39. [APOLLO_DN4000-APOLLO_DN3000] = "DN4000 (Mink)",
  40. [APOLLO_DN4500-APOLLO_DN3000] = "DN4500 (Roadrunner)"
  41. };
  42. int __init apollo_parse_bootinfo(const struct bi_record *record)
  43. {
  44. int unknown = 0;
  45. const void *data = record->data;
  46. switch (be16_to_cpu(record->tag)) {
  47. case BI_APOLLO_MODEL:
  48. apollo_model = be32_to_cpup(data);
  49. break;
  50. default:
  51. unknown=1;
  52. }
  53. return unknown;
  54. }
  55. static void __init dn_setup_model(void)
  56. {
  57. pr_info("Apollo hardware found: [%s]\n",
  58. apollo_models[apollo_model - APOLLO_DN3000]);
  59. switch(apollo_model) {
  60. case APOLLO_UNKNOWN:
  61. panic("Unknown apollo model");
  62. break;
  63. case APOLLO_DN3000:
  64. case APOLLO_DN3010:
  65. sio01_physaddr=SAU8_SIO01_PHYSADDR;
  66. rtc_physaddr=SAU8_RTC_PHYSADDR;
  67. pica_physaddr=SAU8_PICA;
  68. picb_physaddr=SAU8_PICB;
  69. cpuctrl_physaddr=SAU8_CPUCTRL;
  70. timer_physaddr=SAU8_TIMER;
  71. break;
  72. case APOLLO_DN4000:
  73. sio01_physaddr=SAU7_SIO01_PHYSADDR;
  74. sio23_physaddr=SAU7_SIO23_PHYSADDR;
  75. rtc_physaddr=SAU7_RTC_PHYSADDR;
  76. pica_physaddr=SAU7_PICA;
  77. picb_physaddr=SAU7_PICB;
  78. cpuctrl_physaddr=SAU7_CPUCTRL;
  79. timer_physaddr=SAU7_TIMER;
  80. break;
  81. case APOLLO_DN4500:
  82. panic("Apollo model not yet supported");
  83. break;
  84. case APOLLO_DN3500:
  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. default:
  94. panic("Undefined apollo model");
  95. break;
  96. }
  97. }
  98. int dn_serial_console_wait_key(struct console *co) {
  99. while(!(sio01.srb_csrb & 1))
  100. barrier();
  101. return sio01.rhrb_thrb;
  102. }
  103. void dn_serial_console_write (struct console *co, const char *str,unsigned int count)
  104. {
  105. while(count--) {
  106. if (*str == '\n') {
  107. sio01.rhrb_thrb = (unsigned char)'\r';
  108. while (!(sio01.srb_csrb & 0x4))
  109. ;
  110. }
  111. sio01.rhrb_thrb = (unsigned char)*str++;
  112. while (!(sio01.srb_csrb & 0x4))
  113. ;
  114. }
  115. }
  116. void dn_serial_print (const char *str)
  117. {
  118. while (*str) {
  119. if (*str == '\n') {
  120. sio01.rhrb_thrb = (unsigned char)'\r';
  121. while (!(sio01.srb_csrb & 0x4))
  122. ;
  123. }
  124. sio01.rhrb_thrb = (unsigned char)*str++;
  125. while (!(sio01.srb_csrb & 0x4))
  126. ;
  127. }
  128. }
  129. void __init config_apollo(void)
  130. {
  131. int i;
  132. dn_setup_model();
  133. mach_sched_init=dn_sched_init; /* */
  134. mach_init_IRQ=dn_init_IRQ;
  135. mach_max_dma_address = 0xffffffff;
  136. mach_hwclk = dn_dummy_hwclk; /* */
  137. mach_reset = dn_dummy_reset; /* */
  138. #ifdef CONFIG_HEARTBEAT
  139. mach_heartbeat = dn_heartbeat;
  140. #endif
  141. mach_get_model = dn_get_model;
  142. cpuctrl=0xaa00;
  143. /* clear DMA translation table */
  144. for(i=0;i<0x400;i++)
  145. addr_xlat_map[i]=0;
  146. }
  147. irqreturn_t dn_timer_int(int irq, void *dev_id)
  148. {
  149. irq_handler_t timer_handler = dev_id;
  150. volatile unsigned char x;
  151. timer_handler(irq, dev_id);
  152. x = *(volatile unsigned char *)(apollo_timer + 3);
  153. x = *(volatile unsigned char *)(apollo_timer + 5);
  154. return IRQ_HANDLED;
  155. }
  156. void dn_sched_init(irq_handler_t timer_routine)
  157. {
  158. /* program timer 1 */
  159. *(volatile unsigned char *)(apollo_timer + 3) = 0x01;
  160. *(volatile unsigned char *)(apollo_timer + 1) = 0x40;
  161. *(volatile unsigned char *)(apollo_timer + 5) = 0x09;
  162. *(volatile unsigned char *)(apollo_timer + 7) = 0xc4;
  163. /* enable IRQ of PIC B */
  164. *(volatile unsigned char *)(pica+1)&=(~8);
  165. #if 0
  166. pr_info("*(0x10803) %02x\n",
  167. *(volatile unsigned char *)(apollo_timer + 0x3));
  168. pr_info("*(0x10803) %02x\n",
  169. *(volatile unsigned char *)(apollo_timer + 0x3));
  170. #endif
  171. if (request_irq(IRQ_APOLLO, dn_timer_int, 0, "time", timer_routine))
  172. pr_err("Couldn't register timer interrupt\n");
  173. }
  174. int dn_dummy_hwclk(int op, struct rtc_time *t) {
  175. if(!op) { /* read */
  176. t->tm_sec=rtc->second;
  177. t->tm_min=rtc->minute;
  178. t->tm_hour=rtc->hours;
  179. t->tm_mday=rtc->day_of_month;
  180. t->tm_wday=rtc->day_of_week;
  181. t->tm_mon = rtc->month - 1;
  182. t->tm_year=rtc->year;
  183. if (t->tm_year < 70)
  184. t->tm_year += 100;
  185. } else {
  186. rtc->second=t->tm_sec;
  187. rtc->minute=t->tm_min;
  188. rtc->hours=t->tm_hour;
  189. rtc->day_of_month=t->tm_mday;
  190. if(t->tm_wday!=-1)
  191. rtc->day_of_week=t->tm_wday;
  192. rtc->month = t->tm_mon + 1;
  193. rtc->year = t->tm_year % 100;
  194. }
  195. return 0;
  196. }
  197. void dn_dummy_reset(void) {
  198. dn_serial_print("The end !\n");
  199. for(;;);
  200. }
  201. void dn_dummy_waitbut(void) {
  202. dn_serial_print("waitbut\n");
  203. }
  204. static void dn_get_model(char *model)
  205. {
  206. strcpy(model, "Apollo ");
  207. if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500)
  208. strcat(model, apollo_models[apollo_model - APOLLO_DN3000]);
  209. }
  210. #ifdef CONFIG_HEARTBEAT
  211. static int dn_cpuctrl=0xff00;
  212. static void dn_heartbeat(int on) {
  213. if(on) {
  214. dn_cpuctrl&=~0x100;
  215. cpuctrl=dn_cpuctrl;
  216. }
  217. else {
  218. dn_cpuctrl&=~0x100;
  219. dn_cpuctrl|=0x100;
  220. cpuctrl=dn_cpuctrl;
  221. }
  222. }
  223. #endif