as85ep1.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * arch/v850/kernel/as85ep1.c -- AS85EP1 V850E evaluation chip/board
  3. *
  4. * Copyright (C) 2002,03 NEC Electronics Corporation
  5. * Copyright (C) 2002,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/module.h>
  15. #include <linux/init.h>
  16. #include <linux/bootmem.h>
  17. #include <linux/major.h>
  18. #include <linux/irq.h>
  19. #include <asm/machdep.h>
  20. #include <asm/atomic.h>
  21. #include <asm/page.h>
  22. #include <asm/v850e_timer_d.h>
  23. #include <asm/v850e_uart.h>
  24. #include "mach.h"
  25. /* SRAM and SDRAM are vaguely contiguous (with a big hole in between; see
  26. mach_reserve_bootmem for details); use both as one big area. */
  27. #define RAM_START SRAM_ADDR
  28. #define RAM_END (SDRAM_ADDR + SDRAM_SIZE)
  29. /* The bits of this port are connected to an 8-LED bar-graph. */
  30. #define LEDS_PORT 4
  31. static void as85ep1_led_tick (void);
  32. extern char _intv_copy_src_start, _intv_copy_src_end;
  33. extern char _intv_copy_dst_start;
  34. void __init mach_early_init (void)
  35. {
  36. #ifndef CONFIG_ROM_KERNEL
  37. const u32 *src;
  38. register u32 *dst asm ("ep");
  39. #endif
  40. AS85EP1_CSC(0) = 0x0403;
  41. AS85EP1_BCT(0) = 0xB8B8;
  42. AS85EP1_DWC(0) = 0x0104;
  43. AS85EP1_BCC = 0x0012;
  44. AS85EP1_ASC = 0;
  45. AS85EP1_LBS = 0x00A9;
  46. AS85EP1_PORT_PMC(6) = 0xFF; /* valid A0,A1,A20-A25 */
  47. AS85EP1_PORT_PMC(7) = 0x0E; /* valid CS1-CS3 */
  48. AS85EP1_PORT_PMC(9) = 0xFF; /* valid D16-D23 */
  49. AS85EP1_PORT_PMC(10) = 0xFF; /* valid D24-D31 */
  50. AS85EP1_RFS(1) = 0x800c;
  51. AS85EP1_RFS(3) = 0x800c;
  52. AS85EP1_SCR(1) = 0x20A9;
  53. AS85EP1_SCR(3) = 0x20A9;
  54. #ifndef CONFIG_ROM_KERNEL
  55. /* The early chip we have is buggy, and writing the interrupt
  56. vectors into low RAM may screw up, so for non-ROM kernels, we
  57. only rely on the reset vector being downloaded, and copy the
  58. rest of the interrupt vectors into place here. The specific bug
  59. is that writing address N, where (N & 0x10) == 0x10, will _also_
  60. write to address (N - 0x10). We avoid this (effectively) by
  61. writing in 16-byte chunks backwards from the end. */
  62. AS85EP1_IRAMM = 0x3; /* "write-mode" for the internal instruction memory */
  63. src = (u32 *)(((u32)&_intv_copy_src_end - 1) & ~0xF);
  64. dst = (u32 *)&_intv_copy_dst_start
  65. + (src - (u32 *)&_intv_copy_src_start);
  66. do {
  67. u32 t0 = src[0], t1 = src[1], t2 = src[2], t3 = src[3];
  68. dst[0] = t0; dst[1] = t1; dst[2] = t2; dst[3] = t3;
  69. dst -= 4;
  70. src -= 4;
  71. } while (src > (u32 *)&_intv_copy_src_start);
  72. AS85EP1_IRAMM = 0x0; /* "read-mode" for the internal instruction memory */
  73. #endif /* !CONFIG_ROM_KERNEL */
  74. v850e_intc_disable_irqs ();
  75. }
  76. void __init mach_setup (char **cmdline)
  77. {
  78. AS85EP1_PORT_PMC (LEDS_PORT) = 0; /* Make the LEDs port an I/O port. */
  79. AS85EP1_PORT_PM (LEDS_PORT) = 0; /* Make all the bits output pins. */
  80. mach_tick = as85ep1_led_tick;
  81. }
  82. void __init mach_get_physical_ram (unsigned long *ram_start,
  83. unsigned long *ram_len)
  84. {
  85. *ram_start = RAM_START;
  86. *ram_len = RAM_END - RAM_START;
  87. }
  88. /* Convenience macros. */
  89. #define SRAM_END (SRAM_ADDR + SRAM_SIZE)
  90. #define SDRAM_END (SDRAM_ADDR + SDRAM_SIZE)
  91. void __init mach_reserve_bootmem ()
  92. {
  93. if (SDRAM_ADDR < RAM_END && SDRAM_ADDR > RAM_START)
  94. /* We can't use the space between SRAM and SDRAM, so
  95. prevent the kernel from trying. */
  96. reserve_bootmem (SRAM_END, SDRAM_ADDR - SRAM_END);
  97. }
  98. void mach_gettimeofday (struct timespec *tv)
  99. {
  100. tv->tv_sec = 0;
  101. tv->tv_nsec = 0;
  102. }
  103. void __init mach_sched_init (struct irqaction *timer_action)
  104. {
  105. /* Start hardware timer. */
  106. v850e_timer_d_configure (0, HZ);
  107. /* Install timer interrupt handler. */
  108. setup_irq (IRQ_INTCMD(0), timer_action);
  109. }
  110. static struct v850e_intc_irq_init irq_inits[] = {
  111. { "IRQ", 0, NUM_MACH_IRQS, 1, 7 },
  112. { "CCC", IRQ_INTCCC(0), IRQ_INTCCC_NUM, 1, 5 },
  113. { "CMD", IRQ_INTCMD(0), IRQ_INTCMD_NUM, 1, 5 },
  114. { "SRE", IRQ_INTSRE(0), IRQ_INTSRE_NUM, 3, 3 },
  115. { "SR", IRQ_INTSR(0), IRQ_INTSR_NUM, 3, 4 },
  116. { "ST", IRQ_INTST(0), IRQ_INTST_NUM, 3, 5 },
  117. { 0 }
  118. };
  119. #define NUM_IRQ_INITS ((sizeof irq_inits / sizeof irq_inits[0]) - 1)
  120. static struct hw_interrupt_type hw_itypes[NUM_IRQ_INITS];
  121. void __init mach_init_irqs (void)
  122. {
  123. v850e_intc_init_irq_types (irq_inits, hw_itypes);
  124. }
  125. void machine_restart (char *__unused)
  126. {
  127. #ifdef CONFIG_RESET_GUARD
  128. disable_reset_guard ();
  129. #endif
  130. asm ("jmp r0"); /* Jump to the reset vector. */
  131. }
  132. void machine_halt (void)
  133. {
  134. #ifdef CONFIG_RESET_GUARD
  135. disable_reset_guard ();
  136. #endif
  137. local_irq_disable (); /* Ignore all interrupts. */
  138. AS85EP1_PORT_IO (LEDS_PORT) = 0xAA; /* Note that we halted. */
  139. for (;;)
  140. asm ("halt; nop; nop; nop; nop; nop");
  141. }
  142. void machine_power_off (void)
  143. {
  144. machine_halt ();
  145. }
  146. /* Called before configuring an on-chip UART. */
  147. void as85ep1_uart_pre_configure (unsigned chan, unsigned cflags, unsigned baud)
  148. {
  149. /* Make the shared uart/port pins be uart pins. */
  150. AS85EP1_PORT_PMC(3) |= (0x5 << chan);
  151. /* The AS85EP1 connects some general-purpose I/O pins on the CPU to
  152. the RTS/CTS lines of UART 1's serial connection. I/O pins P53
  153. and P54 are RTS and CTS respectively. */
  154. if (chan == 1) {
  155. /* Put P53 & P54 in I/O port mode. */
  156. AS85EP1_PORT_PMC(5) &= ~0x18;
  157. /* Make P53 an output, and P54 an input. */
  158. AS85EP1_PORT_PM(5) |= 0x10;
  159. }
  160. }
  161. /* Minimum and maximum bounds for the moving upper LED boundary in the
  162. clock tick display. */
  163. #define MIN_MAX_POS 0
  164. #define MAX_MAX_POS 7
  165. /* There are MAX_MAX_POS^2 - MIN_MAX_POS^2 cycles in the animation, so if
  166. we pick 6 and 0 as above, we get 49 cycles, which is when divided into
  167. the standard 100 value for HZ, gives us an almost 1s total time. */
  168. #define TICKS_PER_FRAME \
  169. (HZ / (MAX_MAX_POS * MAX_MAX_POS - MIN_MAX_POS * MIN_MAX_POS))
  170. static void as85ep1_led_tick ()
  171. {
  172. static unsigned counter = 0;
  173. if (++counter == TICKS_PER_FRAME) {
  174. static int pos = 0, max_pos = MAX_MAX_POS, dir = 1;
  175. if (dir > 0 && pos == max_pos) {
  176. dir = -1;
  177. if (max_pos == MIN_MAX_POS)
  178. max_pos = MAX_MAX_POS;
  179. else
  180. max_pos--;
  181. } else {
  182. if (dir < 0 && pos == 0)
  183. dir = 1;
  184. if (pos + dir <= max_pos) {
  185. /* Each bit of port 0 has a LED. */
  186. set_bit (pos, &AS85EP1_PORT_IO(LEDS_PORT));
  187. pos += dir;
  188. clear_bit (pos, &AS85EP1_PORT_IO(LEDS_PORT));
  189. }
  190. }
  191. counter = 0;
  192. }
  193. }