config.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * arch/m68k/mvme147/config.c
  3. *
  4. * Copyright (C) 1996 Dave Frascone [chaos@mindspring.com]
  5. * Cloned from Richard Hirst [richard@sleepie.demon.co.uk]
  6. *
  7. * Based on:
  8. *
  9. * Copyright (C) 1993 Hamish Macdonald
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file README.legal in the main directory of this archive
  13. * for more details.
  14. */
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/tty.h>
  19. #include <linux/console.h>
  20. #include <linux/linkage.h>
  21. #include <linux/init.h>
  22. #include <linux/major.h>
  23. #include <linux/genhd.h>
  24. #include <linux/rtc.h>
  25. #include <linux/interrupt.h>
  26. #include <asm/bootinfo.h>
  27. #include <asm/system.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/setup.h>
  30. #include <asm/irq.h>
  31. #include <asm/traps.h>
  32. #include <asm/rtc.h>
  33. #include <asm/machdep.h>
  34. #include <asm/mvme147hw.h>
  35. extern irqreturn_t mvme147_process_int (int level, struct pt_regs *regs);
  36. extern void mvme147_init_IRQ (void);
  37. extern void mvme147_free_irq (unsigned int, void *);
  38. extern int show_mvme147_interrupts (struct seq_file *, void *);
  39. extern void mvme147_enable_irq (unsigned int);
  40. extern void mvme147_disable_irq (unsigned int);
  41. static void mvme147_get_model(char *model);
  42. static int mvme147_get_hardware_list(char *buffer);
  43. extern int mvme147_request_irq (unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *devname, void *dev_id);
  44. extern void mvme147_sched_init(irqreturn_t (*handler)(int, void *, struct pt_regs *));
  45. extern unsigned long mvme147_gettimeoffset (void);
  46. extern int mvme147_hwclk (int, struct rtc_time *);
  47. extern int mvme147_set_clock_mmss (unsigned long);
  48. extern void mvme147_reset (void);
  49. extern void mvme147_waitbut(void);
  50. static int bcd2int (unsigned char b);
  51. /* Save tick handler routine pointer, will point to do_timer() in
  52. * kernel/sched.c, called via mvme147_process_int() */
  53. irqreturn_t (*tick_handler)(int, void *, struct pt_regs *);
  54. int mvme147_parse_bootinfo(const struct bi_record *bi)
  55. {
  56. if (bi->tag == BI_VME_TYPE || bi->tag == BI_VME_BRDINFO)
  57. return 0;
  58. else
  59. return 1;
  60. }
  61. void mvme147_reset(void)
  62. {
  63. printk ("\r\n\nCalled mvme147_reset\r\n");
  64. m147_pcc->watchdog = 0x0a; /* Clear timer */
  65. m147_pcc->watchdog = 0xa5; /* Enable watchdog - 100ms to reset */
  66. while (1)
  67. ;
  68. }
  69. static void mvme147_get_model(char *model)
  70. {
  71. sprintf(model, "Motorola MVME147");
  72. }
  73. static int mvme147_get_hardware_list(char *buffer)
  74. {
  75. *buffer = '\0';
  76. return 0;
  77. }
  78. void __init config_mvme147(void)
  79. {
  80. mach_max_dma_address = 0x01000000;
  81. mach_sched_init = mvme147_sched_init;
  82. mach_init_IRQ = mvme147_init_IRQ;
  83. mach_gettimeoffset = mvme147_gettimeoffset;
  84. mach_hwclk = mvme147_hwclk;
  85. mach_set_clock_mmss = mvme147_set_clock_mmss;
  86. mach_reset = mvme147_reset;
  87. mach_free_irq = mvme147_free_irq;
  88. mach_process_int = mvme147_process_int;
  89. mach_get_irq_list = show_mvme147_interrupts;
  90. mach_request_irq = mvme147_request_irq;
  91. enable_irq = mvme147_enable_irq;
  92. disable_irq = mvme147_disable_irq;
  93. mach_get_model = mvme147_get_model;
  94. mach_get_hardware_list = mvme147_get_hardware_list;
  95. /* Board type is only set by newer versions of vmelilo/tftplilo */
  96. if (!vme_brdtype)
  97. vme_brdtype = VME_TYPE_MVME147;
  98. }
  99. /* Using pcc tick timer 1 */
  100. static irqreturn_t mvme147_timer_int (int irq, void *dev_id, struct pt_regs *fp)
  101. {
  102. m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR;
  103. m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
  104. return tick_handler(irq, dev_id, fp);
  105. }
  106. void mvme147_sched_init (irqreturn_t (*timer_routine)(int, void *, struct pt_regs *))
  107. {
  108. tick_handler = timer_routine;
  109. request_irq (PCC_IRQ_TIMER1, mvme147_timer_int,
  110. IRQ_FLG_REPLACE, "timer 1", NULL);
  111. /* Init the clock with a value */
  112. /* our clock goes off every 6.25us */
  113. m147_pcc->t1_preload = PCC_TIMER_PRELOAD;
  114. m147_pcc->t1_cntrl = 0x0; /* clear timer */
  115. m147_pcc->t1_cntrl = 0x3; /* start timer */
  116. m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR; /* clear pending ints */
  117. m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
  118. }
  119. /* This is always executed with interrupts disabled. */
  120. /* XXX There are race hazards in this code XXX */
  121. unsigned long mvme147_gettimeoffset (void)
  122. {
  123. volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012;
  124. unsigned short n;
  125. n = *cp;
  126. while (n != *cp)
  127. n = *cp;
  128. n -= PCC_TIMER_PRELOAD;
  129. return (unsigned long)n * 25 / 4;
  130. }
  131. static int bcd2int (unsigned char b)
  132. {
  133. return ((b>>4)*10 + (b&15));
  134. }
  135. int mvme147_hwclk(int op, struct rtc_time *t)
  136. {
  137. #warning check me!
  138. if (!op) {
  139. m147_rtc->ctrl = RTC_READ;
  140. t->tm_year = bcd2int (m147_rtc->bcd_year);
  141. t->tm_mon = bcd2int (m147_rtc->bcd_mth);
  142. t->tm_mday = bcd2int (m147_rtc->bcd_dom);
  143. t->tm_hour = bcd2int (m147_rtc->bcd_hr);
  144. t->tm_min = bcd2int (m147_rtc->bcd_min);
  145. t->tm_sec = bcd2int (m147_rtc->bcd_sec);
  146. m147_rtc->ctrl = 0;
  147. }
  148. return 0;
  149. }
  150. int mvme147_set_clock_mmss (unsigned long nowtime)
  151. {
  152. return 0;
  153. }
  154. /*------------------- Serial console stuff ------------------------*/
  155. static void scc_delay (void)
  156. {
  157. int n;
  158. volatile int trash;
  159. for (n = 0; n < 20; n++)
  160. trash = n;
  161. }
  162. static void scc_write (char ch)
  163. {
  164. volatile char *p = (volatile char *)M147_SCC_A_ADDR;
  165. do {
  166. scc_delay();
  167. }
  168. while (!(*p & 4));
  169. scc_delay();
  170. *p = 8;
  171. scc_delay();
  172. *p = ch;
  173. }
  174. void m147_scc_write (struct console *co, const char *str, unsigned count)
  175. {
  176. unsigned long flags;
  177. local_irq_save(flags);
  178. while (count--)
  179. {
  180. if (*str == '\n')
  181. scc_write ('\r');
  182. scc_write (*str++);
  183. }
  184. local_irq_restore(flags);
  185. }
  186. void mvme147_init_console_port (struct console *co, int cflag)
  187. {
  188. co->write = m147_scc_write;
  189. }