config.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * arch/m68k/bvme6000/config.c
  3. *
  4. * Copyright (C) 1997 Richard Hirst [richard@sleepie.demon.co.uk]
  5. *
  6. * Based on:
  7. *
  8. * linux/amiga/config.c
  9. *
  10. * Copyright (C) 1993 Hamish Macdonald
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file README.legal in the main directory of this archive
  14. * for more details.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/kernel.h>
  18. #include <linux/mm.h>
  19. #include <linux/tty.h>
  20. #include <linux/console.h>
  21. #include <linux/linkage.h>
  22. #include <linux/init.h>
  23. #include <linux/major.h>
  24. #include <linux/genhd.h>
  25. #include <linux/rtc.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/bcd.h>
  28. #include <asm/bootinfo.h>
  29. #include <asm/bootinfo-vme.h>
  30. #include <asm/byteorder.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/setup.h>
  33. #include <asm/irq.h>
  34. #include <asm/traps.h>
  35. #include <asm/machdep.h>
  36. #include <asm/bvme6000hw.h>
  37. static void bvme6000_get_model(char *model);
  38. extern void bvme6000_sched_init(irq_handler_t handler);
  39. extern u32 bvme6000_gettimeoffset(void);
  40. extern int bvme6000_hwclk (int, struct rtc_time *);
  41. extern void bvme6000_reset (void);
  42. void bvme6000_set_vectors (void);
  43. int __init bvme6000_parse_bootinfo(const struct bi_record *bi)
  44. {
  45. if (be16_to_cpu(bi->tag) == BI_VME_TYPE)
  46. return 0;
  47. else
  48. return 1;
  49. }
  50. void bvme6000_reset(void)
  51. {
  52. volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
  53. pr_info("\r\n\nCalled bvme6000_reset\r\n"
  54. "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r");
  55. /* The string of returns is to delay the reset until the whole
  56. * message is output. */
  57. /* Enable the watchdog, via PIT port C bit 4 */
  58. pit->pcddr |= 0x10; /* WDOG enable */
  59. while(1)
  60. ;
  61. }
  62. static void bvme6000_get_model(char *model)
  63. {
  64. sprintf(model, "BVME%d000", m68k_cputype == CPU_68060 ? 6 : 4);
  65. }
  66. /*
  67. * This function is called during kernel startup to initialize
  68. * the bvme6000 IRQ handling routines.
  69. */
  70. static void __init bvme6000_init_IRQ(void)
  71. {
  72. m68k_setup_user_interrupt(VEC_USER, 192);
  73. }
  74. void __init config_bvme6000(void)
  75. {
  76. volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
  77. /* Board type is only set by newer versions of vmelilo/tftplilo */
  78. if (!vme_brdtype) {
  79. if (m68k_cputype == CPU_68060)
  80. vme_brdtype = VME_TYPE_BVME6000;
  81. else
  82. vme_brdtype = VME_TYPE_BVME4000;
  83. }
  84. #if 0
  85. /* Call bvme6000_set_vectors() so ABORT will work, along with BVMBug
  86. * debugger. Note trap_init() will splat the abort vector, but
  87. * bvme6000_init_IRQ() will put it back again. Hopefully. */
  88. bvme6000_set_vectors();
  89. #endif
  90. mach_max_dma_address = 0xffffffff;
  91. mach_sched_init = bvme6000_sched_init;
  92. mach_init_IRQ = bvme6000_init_IRQ;
  93. arch_gettimeoffset = bvme6000_gettimeoffset;
  94. mach_hwclk = bvme6000_hwclk;
  95. mach_reset = bvme6000_reset;
  96. mach_get_model = bvme6000_get_model;
  97. pr_info("Board is %sconfigured as a System Controller\n",
  98. *config_reg_ptr & BVME_CONFIG_SW1 ? "" : "not ");
  99. /* Now do the PIT configuration */
  100. pit->pgcr = 0x00; /* Unidirectional 8 bit, no handshake for now */
  101. pit->psrr = 0x18; /* PIACK and PIRQ functions enabled */
  102. pit->pacr = 0x00; /* Sub Mode 00, H2 i/p, no DMA */
  103. pit->padr = 0x00; /* Just to be tidy! */
  104. pit->paddr = 0x00; /* All inputs for now (safest) */
  105. pit->pbcr = 0x80; /* Sub Mode 1x, H4 i/p, no DMA */
  106. pit->pbdr = 0xbc | (*config_reg_ptr & BVME_CONFIG_SW1 ? 0 : 0x40);
  107. /* PRI, SYSCON?, Level3, SCC clks from xtal */
  108. pit->pbddr = 0xf3; /* Mostly outputs */
  109. pit->pcdr = 0x01; /* PA transceiver disabled */
  110. pit->pcddr = 0x03; /* WDOG disable */
  111. /* Disable snooping for Ethernet and VME accesses */
  112. bvme_acr_addrctl = 0;
  113. }
  114. irqreturn_t bvme6000_abort_int (int irq, void *dev_id)
  115. {
  116. unsigned long *new = (unsigned long *)vectors;
  117. unsigned long *old = (unsigned long *)0xf8000000;
  118. /* Wait for button release */
  119. while (*(volatile unsigned char *)BVME_LOCAL_IRQ_STAT & BVME_ABORT_STATUS)
  120. ;
  121. *(new+4) = *(old+4); /* Illegal instruction */
  122. *(new+9) = *(old+9); /* Trace */
  123. *(new+47) = *(old+47); /* Trap #15 */
  124. *(new+0x1f) = *(old+0x1f); /* ABORT switch */
  125. return IRQ_HANDLED;
  126. }
  127. static irqreturn_t bvme6000_timer_int (int irq, void *dev_id)
  128. {
  129. irq_handler_t timer_routine = dev_id;
  130. unsigned long flags;
  131. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  132. unsigned char msr;
  133. local_irq_save(flags);
  134. msr = rtc->msr & 0xc0;
  135. rtc->msr = msr | 0x20; /* Ack the interrupt */
  136. timer_routine(0, NULL);
  137. local_irq_restore(flags);
  138. return IRQ_HANDLED;
  139. }
  140. /*
  141. * Set up the RTC timer 1 to mode 2, so T1 output toggles every 5ms
  142. * (40000 x 125ns). It will interrupt every 10ms, when T1 goes low.
  143. * So, when reading the elapsed time, you should read timer1,
  144. * subtract it from 39999, and then add 40000 if T1 is high.
  145. * That gives you the number of 125ns ticks in to the 10ms period,
  146. * so divide by 8 to get the microsecond result.
  147. */
  148. void bvme6000_sched_init (irq_handler_t timer_routine)
  149. {
  150. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  151. unsigned char msr = rtc->msr & 0xc0;
  152. rtc->msr = 0; /* Ensure timer registers accessible */
  153. if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, 0, "timer",
  154. timer_routine))
  155. panic ("Couldn't register timer int");
  156. rtc->t1cr_omr = 0x04; /* Mode 2, ext clk */
  157. rtc->t1msb = 39999 >> 8;
  158. rtc->t1lsb = 39999 & 0xff;
  159. rtc->irr_icr1 &= 0xef; /* Route timer 1 to INTR pin */
  160. rtc->msr = 0x40; /* Access int.cntrl, etc */
  161. rtc->pfr_icr0 = 0x80; /* Just timer 1 ints enabled */
  162. rtc->irr_icr1 = 0;
  163. rtc->t1cr_omr = 0x0a; /* INTR+T1 active lo, push-pull */
  164. rtc->t0cr_rtmr &= 0xdf; /* Stop timers in standby */
  165. rtc->msr = 0; /* Access timer 1 control */
  166. rtc->t1cr_omr = 0x05; /* Mode 2, ext clk, GO */
  167. rtc->msr = msr;
  168. if (request_irq(BVME_IRQ_ABORT, bvme6000_abort_int, 0,
  169. "abort", bvme6000_abort_int))
  170. panic ("Couldn't register abort int");
  171. }
  172. /* This is always executed with interrupts disabled. */
  173. /*
  174. * NOTE: Don't accept any readings within 5us of rollover, as
  175. * the T1INT bit may be a little slow getting set. There is also
  176. * a fault in the chip, meaning that reads may produce invalid
  177. * results...
  178. */
  179. u32 bvme6000_gettimeoffset(void)
  180. {
  181. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  182. volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
  183. unsigned char msr = rtc->msr & 0xc0;
  184. unsigned char t1int, t1op;
  185. u32 v = 800000, ov;
  186. rtc->msr = 0; /* Ensure timer registers accessible */
  187. do {
  188. ov = v;
  189. t1int = rtc->msr & 0x20;
  190. t1op = pit->pcdr & 0x04;
  191. rtc->t1cr_omr |= 0x40; /* Latch timer1 */
  192. v = rtc->t1msb << 8; /* Read timer1 */
  193. v |= rtc->t1lsb; /* Read timer1 */
  194. } while (t1int != (rtc->msr & 0x20) ||
  195. t1op != (pit->pcdr & 0x04) ||
  196. abs(ov-v) > 80 ||
  197. v > 39960);
  198. v = 39999 - v;
  199. if (!t1op) /* If in second half cycle.. */
  200. v += 40000;
  201. v /= 8; /* Convert ticks to microseconds */
  202. if (t1int)
  203. v += 10000; /* Int pending, + 10ms */
  204. rtc->msr = msr;
  205. return v * 1000;
  206. }
  207. /*
  208. * Looks like op is non-zero for setting the clock, and zero for
  209. * reading the clock.
  210. *
  211. * struct hwclk_time {
  212. * unsigned sec; 0..59
  213. * unsigned min; 0..59
  214. * unsigned hour; 0..23
  215. * unsigned day; 1..31
  216. * unsigned mon; 0..11
  217. * unsigned year; 00...
  218. * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
  219. * };
  220. */
  221. int bvme6000_hwclk(int op, struct rtc_time *t)
  222. {
  223. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  224. unsigned char msr = rtc->msr & 0xc0;
  225. rtc->msr = 0x40; /* Ensure clock and real-time-mode-register
  226. * are accessible */
  227. if (op)
  228. { /* Write.... */
  229. rtc->t0cr_rtmr = t->tm_year%4;
  230. rtc->bcd_tenms = 0;
  231. rtc->bcd_sec = bin2bcd(t->tm_sec);
  232. rtc->bcd_min = bin2bcd(t->tm_min);
  233. rtc->bcd_hr = bin2bcd(t->tm_hour);
  234. rtc->bcd_dom = bin2bcd(t->tm_mday);
  235. rtc->bcd_mth = bin2bcd(t->tm_mon + 1);
  236. rtc->bcd_year = bin2bcd(t->tm_year%100);
  237. if (t->tm_wday >= 0)
  238. rtc->bcd_dow = bin2bcd(t->tm_wday+1);
  239. rtc->t0cr_rtmr = t->tm_year%4 | 0x08;
  240. }
  241. else
  242. { /* Read.... */
  243. do {
  244. t->tm_sec = bcd2bin(rtc->bcd_sec);
  245. t->tm_min = bcd2bin(rtc->bcd_min);
  246. t->tm_hour = bcd2bin(rtc->bcd_hr);
  247. t->tm_mday = bcd2bin(rtc->bcd_dom);
  248. t->tm_mon = bcd2bin(rtc->bcd_mth)-1;
  249. t->tm_year = bcd2bin(rtc->bcd_year);
  250. if (t->tm_year < 70)
  251. t->tm_year += 100;
  252. t->tm_wday = bcd2bin(rtc->bcd_dow)-1;
  253. } while (t->tm_sec != bcd2bin(rtc->bcd_sec));
  254. }
  255. rtc->msr = msr;
  256. return 0;
  257. }