rte_me2_cb.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * arch/v850/kernel/rte_me2_cb.c -- Midas labs RTE-V850E/ME2-CB board
  3. *
  4. * Copyright (C) 2001,02,03 NEC Electronics Corporation
  5. * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file COPYING in the main directory of this
  9. * archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/bootmem.h>
  16. #include <linux/irq.h>
  17. #include <linux/fs.h>
  18. #include <linux/major.h>
  19. #include <linux/sched.h>
  20. #include <linux/delay.h>
  21. #include <asm/atomic.h>
  22. #include <asm/page.h>
  23. #include <asm/me2.h>
  24. #include <asm/rte_me2_cb.h>
  25. #include <asm/machdep.h>
  26. #include <asm/v850e_intc.h>
  27. #include <asm/v850e_cache.h>
  28. #include <asm/irq.h>
  29. #include "mach.h"
  30. extern unsigned long *_intv_start;
  31. extern unsigned long *_intv_end;
  32. /* LED access routines. */
  33. extern unsigned read_leds (int pos, char *buf, int len);
  34. extern unsigned write_leds (int pos, const char *buf, int len);
  35. /* SDRAM are almost contiguous (with a small hole in between;
  36. see mach_reserve_bootmem for details), so just use both as one big area. */
  37. #define RAM_START SDRAM_ADDR
  38. #define RAM_END (SDRAM_ADDR + SDRAM_SIZE)
  39. void __init mach_get_physical_ram (unsigned long *ram_start,
  40. unsigned long *ram_len)
  41. {
  42. *ram_start = RAM_START;
  43. *ram_len = RAM_END - RAM_START;
  44. }
  45. void mach_gettimeofday (struct timespec *tv)
  46. {
  47. tv->tv_sec = 0;
  48. tv->tv_nsec = 0;
  49. }
  50. /* Called before configuring an on-chip UART. */
  51. void rte_me2_cb_uart_pre_configure (unsigned chan,
  52. unsigned cflags, unsigned baud)
  53. {
  54. /* The RTE-V850E/ME2-CB connects some general-purpose I/O
  55. pins on the CPU to the RTS/CTS lines of UARTB channel 0's
  56. serial connection.
  57. I/O pins P21 and P22 are RTS and CTS respectively. */
  58. if (chan == 0) {
  59. /* Put P21 & P22 in I/O port mode. */
  60. ME2_PORT2_PMC &= ~0x6;
  61. /* Make P21 and output, and P22 an input. */
  62. ME2_PORT2_PM = (ME2_PORT2_PM & ~0xC) | 0x4;
  63. }
  64. me2_uart_pre_configure (chan, cflags, baud);
  65. }
  66. void __init mach_init_irqs (void)
  67. {
  68. /* Initialize interrupts. */
  69. me2_init_irqs ();
  70. rte_me2_cb_init_irqs ();
  71. }
  72. #ifdef CONFIG_ROM_KERNEL
  73. /* Initialization for kernel in ROM. */
  74. static inline rom_kernel_init (void)
  75. {
  76. /* If the kernel is in ROM, we have to copy any initialized data
  77. from ROM into RAM. */
  78. extern unsigned long _data_load_start, _sdata, _edata;
  79. register unsigned long *src = &_data_load_start;
  80. register unsigned long *dst = &_sdata, *end = &_edata;
  81. while (dst != end)
  82. *dst++ = *src++;
  83. }
  84. #endif /* CONFIG_ROM_KERNEL */
  85. static void install_interrupt_vectors (void)
  86. {
  87. unsigned long *p1, *p2;
  88. ME2_IRAMM = 0x03; /* V850E/ME2 iRAM write mode */
  89. /* vector copy to iRAM */
  90. p1 = (unsigned long *)0; /* v85x vector start */
  91. p2 = (unsigned long *)&_intv_start;
  92. while (p2 < (unsigned long *)&_intv_end)
  93. *p1++ = *p2++;
  94. ME2_IRAMM = 0x00; /* V850E/ME2 iRAM read mode */
  95. }
  96. /* CompactFlash */
  97. static void cf_power_on (void)
  98. {
  99. /* CF card detected? */
  100. if (CB_CF_STS0 & 0x0030)
  101. return;
  102. CB_CF_REG0 = 0x0002; /* reest on */
  103. mdelay (10);
  104. CB_CF_REG0 = 0x0003; /* power on */
  105. mdelay (10);
  106. CB_CF_REG0 = 0x0001; /* reset off */
  107. mdelay (10);
  108. }
  109. static void cf_power_off (void)
  110. {
  111. CB_CF_REG0 = 0x0003; /* power on */
  112. mdelay (10);
  113. CB_CF_REG0 = 0x0002; /* reest on */
  114. mdelay (10);
  115. }
  116. void __init mach_early_init (void)
  117. {
  118. install_interrupt_vectors ();
  119. /* CS1 SDRAM instruction cache enable */
  120. v850e_cache_enable (0x04, 0x03, 0);
  121. rte_cb_early_init ();
  122. /* CompactFlash power on */
  123. cf_power_on ();
  124. #if defined (CONFIG_ROM_KERNEL)
  125. rom_kernel_init ();
  126. #endif
  127. }
  128. /* RTE-V850E/ME2-CB Programmable Interrupt Controller. */
  129. static struct cb_pic_irq_init cb_pic_irq_inits[] = {
  130. { "CB_EXTTM0", IRQ_CB_EXTTM0, 1, 1, 6 },
  131. { "CB_EXTSIO", IRQ_CB_EXTSIO, 1, 1, 6 },
  132. { "CB_TOVER", IRQ_CB_TOVER, 1, 1, 6 },
  133. { "CB_GINT0", IRQ_CB_GINT0, 1, 1, 6 },
  134. { "CB_USB", IRQ_CB_USB, 1, 1, 6 },
  135. { "CB_LANC", IRQ_CB_LANC, 1, 1, 6 },
  136. { "CB_USB_VBUS_ON", IRQ_CB_USB_VBUS_ON, 1, 1, 6 },
  137. { "CB_USB_VBUS_OFF", IRQ_CB_USB_VBUS_OFF, 1, 1, 6 },
  138. { "CB_EXTTM1", IRQ_CB_EXTTM1, 1, 1, 6 },
  139. { "CB_EXTTM2", IRQ_CB_EXTTM2, 1, 1, 6 },
  140. { 0 }
  141. };
  142. #define NUM_CB_PIC_IRQ_INITS (ARRAY_SIZE(cb_pic_irq_inits) - 1)
  143. static struct hw_interrupt_type cb_pic_hw_itypes[NUM_CB_PIC_IRQ_INITS];
  144. static unsigned char cb_pic_active_irqs = 0;
  145. void __init rte_me2_cb_init_irqs (void)
  146. {
  147. cb_pic_init_irq_types (cb_pic_irq_inits, cb_pic_hw_itypes);
  148. /* Initalize on board PIC1 (not PIC0) enable */
  149. CB_PIC_INT0M = 0x0000;
  150. CB_PIC_INT1M = 0x0000;
  151. CB_PIC_INTR = 0x0000;
  152. CB_PIC_INTEN |= CB_PIC_INT1EN;
  153. ME2_PORT2_PMC |= 0x08; /* INTP23/SCK1 mode */
  154. ME2_PORT2_PFC &= ~0x08; /* INTP23 mode */
  155. ME2_INTR(2) &= ~0x08; /* INTP23 falling-edge detect */
  156. ME2_INTF(2) &= ~0x08; /* " */
  157. rte_cb_init_irqs (); /* gbus &c */
  158. }
  159. /* Enable interrupt handling for interrupt IRQ. */
  160. void cb_pic_enable_irq (unsigned irq)
  161. {
  162. CB_PIC_INT1M |= 1 << (irq - CB_PIC_BASE_IRQ);
  163. }
  164. void cb_pic_disable_irq (unsigned irq)
  165. {
  166. CB_PIC_INT1M &= ~(1 << (irq - CB_PIC_BASE_IRQ));
  167. }
  168. void cb_pic_shutdown_irq (unsigned irq)
  169. {
  170. cb_pic_disable_irq (irq);
  171. if (--cb_pic_active_irqs == 0)
  172. free_irq (IRQ_CB_PIC, 0);
  173. CB_PIC_INT1M &= ~(1 << (irq - CB_PIC_BASE_IRQ));
  174. }
  175. static irqreturn_t cb_pic_handle_irq (int irq, void *dev_id,
  176. struct pt_regs *regs)
  177. {
  178. irqreturn_t rval = IRQ_NONE;
  179. unsigned status = CB_PIC_INTR;
  180. unsigned enable = CB_PIC_INT1M;
  181. /* Only pay attention to enabled interrupts. */
  182. status &= enable;
  183. CB_PIC_INTEN &= ~CB_PIC_INT1EN;
  184. if (status) {
  185. unsigned mask = 1;
  186. irq = CB_PIC_BASE_IRQ;
  187. do {
  188. /* There's an active interrupt, find out which one,
  189. and call its handler. */
  190. while (! (status & mask)) {
  191. irq++;
  192. mask <<= 1;
  193. }
  194. status &= ~mask;
  195. CB_PIC_INTR = mask;
  196. /* Recursively call handle_irq to handle it. */
  197. handle_irq (irq, regs);
  198. rval = IRQ_HANDLED;
  199. } while (status);
  200. }
  201. CB_PIC_INTEN |= CB_PIC_INT1EN;
  202. return rval;
  203. }
  204. static void irq_nop (unsigned irq) { }
  205. static unsigned cb_pic_startup_irq (unsigned irq)
  206. {
  207. int rval;
  208. if (cb_pic_active_irqs == 0) {
  209. rval = request_irq (IRQ_CB_PIC, cb_pic_handle_irq,
  210. IRQF_DISABLED, "cb_pic_handler", 0);
  211. if (rval != 0)
  212. return rval;
  213. }
  214. cb_pic_active_irqs++;
  215. cb_pic_enable_irq (irq);
  216. return 0;
  217. }
  218. /* Initialize HW_IRQ_TYPES for INTC-controlled irqs described in array
  219. INITS (which is terminated by an entry with the name field == 0). */
  220. void __init cb_pic_init_irq_types (struct cb_pic_irq_init *inits,
  221. struct hw_interrupt_type *hw_irq_types)
  222. {
  223. struct cb_pic_irq_init *init;
  224. for (init = inits; init->name; init++) {
  225. struct hw_interrupt_type *hwit = hw_irq_types++;
  226. hwit->typename = init->name;
  227. hwit->startup = cb_pic_startup_irq;
  228. hwit->shutdown = cb_pic_shutdown_irq;
  229. hwit->enable = cb_pic_enable_irq;
  230. hwit->disable = cb_pic_disable_irq;
  231. hwit->ack = irq_nop;
  232. hwit->end = irq_nop;
  233. /* Initialize kernel IRQ infrastructure for this interrupt. */
  234. init_irq_handlers(init->base, init->num, init->interval, hwit);
  235. }
  236. }