config.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 <asm/bootinfo.h>
  28. #include <asm/system.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/setup.h>
  31. #include <asm/irq.h>
  32. #include <asm/traps.h>
  33. #include <asm/rtc.h>
  34. #include <asm/machdep.h>
  35. #include <asm/bvme6000hw.h>
  36. extern irqreturn_t bvme6000_process_int (int level, struct pt_regs *regs);
  37. extern void bvme6000_init_IRQ (void);
  38. extern void bvme6000_free_irq (unsigned int, void *);
  39. extern int show_bvme6000_interrupts(struct seq_file *, void *);
  40. extern void bvme6000_enable_irq (unsigned int);
  41. extern void bvme6000_disable_irq (unsigned int);
  42. static void bvme6000_get_model(char *model);
  43. static int bvme6000_get_hardware_list(char *buffer);
  44. extern int bvme6000_request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *devname, void *dev_id);
  45. extern void bvme6000_sched_init(irqreturn_t (*handler)(int, void *, struct pt_regs *));
  46. extern unsigned long bvme6000_gettimeoffset (void);
  47. extern int bvme6000_hwclk (int, struct rtc_time *);
  48. extern int bvme6000_set_clock_mmss (unsigned long);
  49. extern void bvme6000_reset (void);
  50. extern void bvme6000_waitbut(void);
  51. void bvme6000_set_vectors (void);
  52. static unsigned char bcd2bin (unsigned char b);
  53. static unsigned char bin2bcd (unsigned char b);
  54. /* Save tick handler routine pointer, will point to do_timer() in
  55. * kernel/sched.c, called via bvme6000_process_int() */
  56. static irqreturn_t (*tick_handler)(int, void *, struct pt_regs *);
  57. int bvme6000_parse_bootinfo(const struct bi_record *bi)
  58. {
  59. if (bi->tag == BI_VME_TYPE)
  60. return 0;
  61. else
  62. return 1;
  63. }
  64. void bvme6000_reset(void)
  65. {
  66. volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
  67. printk ("\r\n\nCalled bvme6000_reset\r\n"
  68. "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r");
  69. /* The string of returns is to delay the reset until the whole
  70. * message is output. */
  71. /* Enable the watchdog, via PIT port C bit 4 */
  72. pit->pcddr |= 0x10; /* WDOG enable */
  73. while(1)
  74. ;
  75. }
  76. static void bvme6000_get_model(char *model)
  77. {
  78. sprintf(model, "BVME%d000", m68k_cputype == CPU_68060 ? 6 : 4);
  79. }
  80. /* No hardware options on BVME6000? */
  81. static int bvme6000_get_hardware_list(char *buffer)
  82. {
  83. *buffer = '\0';
  84. return 0;
  85. }
  86. void __init config_bvme6000(void)
  87. {
  88. volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
  89. /* Board type is only set by newer versions of vmelilo/tftplilo */
  90. if (!vme_brdtype) {
  91. if (m68k_cputype == CPU_68060)
  92. vme_brdtype = VME_TYPE_BVME6000;
  93. else
  94. vme_brdtype = VME_TYPE_BVME4000;
  95. }
  96. #if 0
  97. /* Call bvme6000_set_vectors() so ABORT will work, along with BVMBug
  98. * debugger. Note trap_init() will splat the abort vector, but
  99. * bvme6000_init_IRQ() will put it back again. Hopefully. */
  100. bvme6000_set_vectors();
  101. #endif
  102. mach_max_dma_address = 0xffffffff;
  103. mach_sched_init = bvme6000_sched_init;
  104. mach_init_IRQ = bvme6000_init_IRQ;
  105. mach_gettimeoffset = bvme6000_gettimeoffset;
  106. mach_hwclk = bvme6000_hwclk;
  107. mach_set_clock_mmss = bvme6000_set_clock_mmss;
  108. mach_reset = bvme6000_reset;
  109. mach_free_irq = bvme6000_free_irq;
  110. mach_process_int = bvme6000_process_int;
  111. mach_get_irq_list = show_bvme6000_interrupts;
  112. mach_request_irq = bvme6000_request_irq;
  113. enable_irq = bvme6000_enable_irq;
  114. disable_irq = bvme6000_disable_irq;
  115. mach_get_model = bvme6000_get_model;
  116. mach_get_hardware_list = bvme6000_get_hardware_list;
  117. printk ("Board is %sconfigured as a System Controller\n",
  118. *config_reg_ptr & BVME_CONFIG_SW1 ? "" : "not ");
  119. /* Now do the PIT configuration */
  120. pit->pgcr = 0x00; /* Unidirectional 8 bit, no handshake for now */
  121. pit->psrr = 0x18; /* PIACK and PIRQ fucntions enabled */
  122. pit->pacr = 0x00; /* Sub Mode 00, H2 i/p, no DMA */
  123. pit->padr = 0x00; /* Just to be tidy! */
  124. pit->paddr = 0x00; /* All inputs for now (safest) */
  125. pit->pbcr = 0x80; /* Sub Mode 1x, H4 i/p, no DMA */
  126. pit->pbdr = 0xbc | (*config_reg_ptr & BVME_CONFIG_SW1 ? 0 : 0x40);
  127. /* PRI, SYSCON?, Level3, SCC clks from xtal */
  128. pit->pbddr = 0xf3; /* Mostly outputs */
  129. pit->pcdr = 0x01; /* PA transceiver disabled */
  130. pit->pcddr = 0x03; /* WDOG disable */
  131. /* Disable snooping for Ethernet and VME accesses */
  132. bvme_acr_addrctl = 0;
  133. }
  134. irqreturn_t bvme6000_abort_int (int irq, void *dev_id, struct pt_regs *fp)
  135. {
  136. unsigned long *new = (unsigned long *)vectors;
  137. unsigned long *old = (unsigned long *)0xf8000000;
  138. /* Wait for button release */
  139. while (*(volatile unsigned char *)BVME_LOCAL_IRQ_STAT & BVME_ABORT_STATUS)
  140. ;
  141. *(new+4) = *(old+4); /* Illegal instruction */
  142. *(new+9) = *(old+9); /* Trace */
  143. *(new+47) = *(old+47); /* Trap #15 */
  144. *(new+0x1f) = *(old+0x1f); /* ABORT switch */
  145. return IRQ_HANDLED;
  146. }
  147. static irqreturn_t bvme6000_timer_int (int irq, void *dev_id, struct pt_regs *fp)
  148. {
  149. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  150. unsigned char msr = rtc->msr & 0xc0;
  151. rtc->msr = msr | 0x20; /* Ack the interrupt */
  152. return tick_handler(irq, dev_id, fp);
  153. }
  154. /*
  155. * Set up the RTC timer 1 to mode 2, so T1 output toggles every 5ms
  156. * (40000 x 125ns). It will interrupt every 10ms, when T1 goes low.
  157. * So, when reading the elapsed time, you should read timer1,
  158. * subtract it from 39999, and then add 40000 if T1 is high.
  159. * That gives you the number of 125ns ticks in to the 10ms period,
  160. * so divide by 8 to get the microsecond result.
  161. */
  162. void bvme6000_sched_init (irqreturn_t (*timer_routine)(int, void *, struct pt_regs *))
  163. {
  164. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  165. unsigned char msr = rtc->msr & 0xc0;
  166. rtc->msr = 0; /* Ensure timer registers accessible */
  167. tick_handler = timer_routine;
  168. if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, 0,
  169. "timer", bvme6000_timer_int))
  170. panic ("Couldn't register timer int");
  171. rtc->t1cr_omr = 0x04; /* Mode 2, ext clk */
  172. rtc->t1msb = 39999 >> 8;
  173. rtc->t1lsb = 39999 & 0xff;
  174. rtc->irr_icr1 &= 0xef; /* Route timer 1 to INTR pin */
  175. rtc->msr = 0x40; /* Access int.cntrl, etc */
  176. rtc->pfr_icr0 = 0x80; /* Just timer 1 ints enabled */
  177. rtc->irr_icr1 = 0;
  178. rtc->t1cr_omr = 0x0a; /* INTR+T1 active lo, push-pull */
  179. rtc->t0cr_rtmr &= 0xdf; /* Stop timers in standby */
  180. rtc->msr = 0; /* Access timer 1 control */
  181. rtc->t1cr_omr = 0x05; /* Mode 2, ext clk, GO */
  182. rtc->msr = msr;
  183. if (request_irq(BVME_IRQ_ABORT, bvme6000_abort_int, 0,
  184. "abort", bvme6000_abort_int))
  185. panic ("Couldn't register abort int");
  186. }
  187. /* This is always executed with interrupts disabled. */
  188. /*
  189. * NOTE: Don't accept any readings within 5us of rollover, as
  190. * the T1INT bit may be a little slow getting set. There is also
  191. * a fault in the chip, meaning that reads may produce invalid
  192. * results...
  193. */
  194. unsigned long bvme6000_gettimeoffset (void)
  195. {
  196. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  197. volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
  198. unsigned char msr = rtc->msr & 0xc0;
  199. unsigned char t1int, t1op;
  200. unsigned long v = 800000, ov;
  201. rtc->msr = 0; /* Ensure timer registers accessible */
  202. do {
  203. ov = v;
  204. t1int = rtc->msr & 0x20;
  205. t1op = pit->pcdr & 0x04;
  206. rtc->t1cr_omr |= 0x40; /* Latch timer1 */
  207. v = rtc->t1msb << 8; /* Read timer1 */
  208. v |= rtc->t1lsb; /* Read timer1 */
  209. } while (t1int != (rtc->msr & 0x20) ||
  210. t1op != (pit->pcdr & 0x04) ||
  211. abs(ov-v) > 80 ||
  212. v > 39960);
  213. v = 39999 - v;
  214. if (!t1op) /* If in second half cycle.. */
  215. v += 40000;
  216. v /= 8; /* Convert ticks to microseconds */
  217. if (t1int)
  218. v += 10000; /* Int pending, + 10ms */
  219. rtc->msr = msr;
  220. return v;
  221. }
  222. static unsigned char bcd2bin (unsigned char b)
  223. {
  224. return ((b>>4)*10 + (b&15));
  225. }
  226. static unsigned char bin2bcd (unsigned char b)
  227. {
  228. return (((b/10)*16) + (b%10));
  229. }
  230. /*
  231. * Looks like op is non-zero for setting the clock, and zero for
  232. * reading the clock.
  233. *
  234. * struct hwclk_time {
  235. * unsigned sec; 0..59
  236. * unsigned min; 0..59
  237. * unsigned hour; 0..23
  238. * unsigned day; 1..31
  239. * unsigned mon; 0..11
  240. * unsigned year; 00...
  241. * int wday; 0..6, 0 is Sunday, -1 means unknown/don't set
  242. * };
  243. */
  244. int bvme6000_hwclk(int op, struct rtc_time *t)
  245. {
  246. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  247. unsigned char msr = rtc->msr & 0xc0;
  248. rtc->msr = 0x40; /* Ensure clock and real-time-mode-register
  249. * are accessible */
  250. if (op)
  251. { /* Write.... */
  252. rtc->t0cr_rtmr = t->tm_year%4;
  253. rtc->bcd_tenms = 0;
  254. rtc->bcd_sec = bin2bcd(t->tm_sec);
  255. rtc->bcd_min = bin2bcd(t->tm_min);
  256. rtc->bcd_hr = bin2bcd(t->tm_hour);
  257. rtc->bcd_dom = bin2bcd(t->tm_mday);
  258. rtc->bcd_mth = bin2bcd(t->tm_mon + 1);
  259. rtc->bcd_year = bin2bcd(t->tm_year%100);
  260. if (t->tm_wday >= 0)
  261. rtc->bcd_dow = bin2bcd(t->tm_wday+1);
  262. rtc->t0cr_rtmr = t->tm_year%4 | 0x08;
  263. }
  264. else
  265. { /* Read.... */
  266. do {
  267. t->tm_sec = bcd2bin(rtc->bcd_sec);
  268. t->tm_min = bcd2bin(rtc->bcd_min);
  269. t->tm_hour = bcd2bin(rtc->bcd_hr);
  270. t->tm_mday = bcd2bin(rtc->bcd_dom);
  271. t->tm_mon = bcd2bin(rtc->bcd_mth)-1;
  272. t->tm_year = bcd2bin(rtc->bcd_year);
  273. if (t->tm_year < 70)
  274. t->tm_year += 100;
  275. t->tm_wday = bcd2bin(rtc->bcd_dow)-1;
  276. } while (t->tm_sec != bcd2bin(rtc->bcd_sec));
  277. }
  278. rtc->msr = msr;
  279. return 0;
  280. }
  281. /*
  282. * Set the minutes and seconds from seconds value 'nowtime'. Fail if
  283. * clock is out by > 30 minutes. Logic lifted from atari code.
  284. * Algorithm is to wait for the 10ms register to change, and then to
  285. * wait a short while, and then set it.
  286. */
  287. int bvme6000_set_clock_mmss (unsigned long nowtime)
  288. {
  289. int retval = 0;
  290. short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
  291. unsigned char rtc_minutes, rtc_tenms;
  292. volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
  293. unsigned char msr = rtc->msr & 0xc0;
  294. unsigned long flags;
  295. volatile int i;
  296. rtc->msr = 0; /* Ensure clock accessible */
  297. rtc_minutes = bcd2bin (rtc->bcd_min);
  298. if ((rtc_minutes < real_minutes
  299. ? real_minutes - rtc_minutes
  300. : rtc_minutes - real_minutes) < 30)
  301. {
  302. local_irq_save(flags);
  303. rtc_tenms = rtc->bcd_tenms;
  304. while (rtc_tenms == rtc->bcd_tenms)
  305. ;
  306. for (i = 0; i < 1000; i++)
  307. ;
  308. rtc->bcd_min = bin2bcd(real_minutes);
  309. rtc->bcd_sec = bin2bcd(real_seconds);
  310. local_irq_restore(flags);
  311. }
  312. else
  313. retval = -1;
  314. rtc->msr = msr;
  315. return retval;
  316. }