config.c 9.0 KB

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