anna.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * arch/v850/kernel/anna.c -- Anna V850E2 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/config.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/major.h>
  19. #include <linux/irq.h>
  20. #include <asm/machdep.h>
  21. #include <asm/atomic.h>
  22. #include <asm/page.h>
  23. #include <asm/v850e_timer_d.h>
  24. #include <asm/v850e_uart.h>
  25. #include "mach.h"
  26. /* SRAM and SDRAM are vaguely contiguous (with a big hole in between; see
  27. mach_reserve_bootmem for details); use both as one big area. */
  28. #define RAM_START SRAM_ADDR
  29. #define RAM_END (SDRAM_ADDR + SDRAM_SIZE)
  30. /* The bits of this port are connected to an 8-LED bar-graph. */
  31. #define LEDS_PORT 0
  32. static void anna_led_tick (void);
  33. void __init mach_early_init (void)
  34. {
  35. ANNA_ILBEN = 0;
  36. V850E2_CSC(0) = 0x402F;
  37. V850E2_CSC(1) = 0x4000;
  38. V850E2_BPC = 0;
  39. V850E2_BSC = 0xAAAA;
  40. V850E2_BEC = 0;
  41. #if 0
  42. V850E2_BHC = 0xFFFF; /* icache all memory, dcache all */
  43. #else
  44. V850E2_BHC = 0; /* cache no memory */
  45. #endif
  46. V850E2_BCT(0) = 0xB088;
  47. V850E2_BCT(1) = 0x0008;
  48. V850E2_DWC(0) = 0x0027;
  49. V850E2_DWC(1) = 0;
  50. V850E2_BCC = 0x0006;
  51. V850E2_ASC = 0;
  52. V850E2_LBS = 0x0089;
  53. V850E2_SCR(3) = 0x21A9;
  54. V850E2_RFS(3) = 0x8121;
  55. v850e_intc_disable_irqs ();
  56. }
  57. void __init mach_setup (char **cmdline)
  58. {
  59. ANNA_PORT_PM (LEDS_PORT) = 0; /* Make all LED pins output pins. */
  60. mach_tick = anna_led_tick;
  61. }
  62. void __init mach_get_physical_ram (unsigned long *ram_start,
  63. unsigned long *ram_len)
  64. {
  65. *ram_start = RAM_START;
  66. *ram_len = RAM_END - RAM_START;
  67. }
  68. void __init mach_reserve_bootmem ()
  69. {
  70. /* The space between SRAM and SDRAM is filled with duplicate
  71. images of SRAM. Prevent the kernel from using them. */
  72. reserve_bootmem (SRAM_ADDR + SRAM_SIZE,
  73. SDRAM_ADDR - (SRAM_ADDR + SRAM_SIZE));
  74. }
  75. void mach_gettimeofday (struct timespec *tv)
  76. {
  77. tv->tv_sec = 0;
  78. tv->tv_nsec = 0;
  79. }
  80. void __init mach_sched_init (struct irqaction *timer_action)
  81. {
  82. /* Start hardware timer. */
  83. v850e_timer_d_configure (0, HZ);
  84. /* Install timer interrupt handler. */
  85. setup_irq (IRQ_INTCMD(0), timer_action);
  86. }
  87. static struct v850e_intc_irq_init irq_inits[] = {
  88. { "IRQ", 0, NUM_MACH_IRQS, 1, 7 },
  89. { "PIN", IRQ_INTP(0), IRQ_INTP_NUM, 1, 4 },
  90. { "CCC", IRQ_INTCCC(0), IRQ_INTCCC_NUM, 1, 5 },
  91. { "CMD", IRQ_INTCMD(0), IRQ_INTCMD_NUM, 1, 5 },
  92. { "DMA", IRQ_INTDMA(0), IRQ_INTDMA_NUM, 1, 2 },
  93. { "DMXER", IRQ_INTDMXER,1, 1, 2 },
  94. { "SRE", IRQ_INTSRE(0), IRQ_INTSRE_NUM, 3, 3 },
  95. { "SR", IRQ_INTSR(0), IRQ_INTSR_NUM, 3, 4 },
  96. { "ST", IRQ_INTST(0), IRQ_INTST_NUM, 3, 5 },
  97. { 0 }
  98. };
  99. #define NUM_IRQ_INITS ((sizeof irq_inits / sizeof irq_inits[0]) - 1)
  100. static struct hw_interrupt_type hw_itypes[NUM_IRQ_INITS];
  101. void __init mach_init_irqs (void)
  102. {
  103. v850e_intc_init_irq_types (irq_inits, hw_itypes);
  104. }
  105. void machine_restart (char *__unused)
  106. {
  107. #ifdef CONFIG_RESET_GUARD
  108. disable_reset_guard ();
  109. #endif
  110. asm ("jmp r0"); /* Jump to the reset vector. */
  111. }
  112. void machine_halt (void)
  113. {
  114. #ifdef CONFIG_RESET_GUARD
  115. disable_reset_guard ();
  116. #endif
  117. local_irq_disable (); /* Ignore all interrupts. */
  118. ANNA_PORT_IO(LEDS_PORT) = 0xAA; /* Note that we halted. */
  119. for (;;)
  120. asm ("halt; nop; nop; nop; nop; nop");
  121. }
  122. void machine_power_off (void)
  123. {
  124. machine_halt ();
  125. }
  126. /* Called before configuring an on-chip UART. */
  127. void anna_uart_pre_configure (unsigned chan, unsigned cflags, unsigned baud)
  128. {
  129. /* The Anna connects some general-purpose I/O pins on the CPU to
  130. the RTS/CTS lines of UART 1's serial connection. I/O pins P07
  131. and P37 are RTS and CTS respectively. */
  132. if (chan == 1) {
  133. ANNA_PORT_PM(0) &= ~0x80; /* P07 in output mode */
  134. ANNA_PORT_PM(3) |= 0x80; /* P37 in input mode */
  135. }
  136. }
  137. /* Minimum and maximum bounds for the moving upper LED boundary in the
  138. clock tick display. We can't use the last bit because it's used for
  139. UART0's CTS output. */
  140. #define MIN_MAX_POS 0
  141. #define MAX_MAX_POS 6
  142. /* There are MAX_MAX_POS^2 - MIN_MAX_POS^2 cycles in the animation, so if
  143. we pick 6 and 0 as above, we get 49 cycles, which is when divided into
  144. the standard 100 value for HZ, gives us an almost 1s total time. */
  145. #define TICKS_PER_FRAME \
  146. (HZ / (MAX_MAX_POS * MAX_MAX_POS - MIN_MAX_POS * MIN_MAX_POS))
  147. static void anna_led_tick ()
  148. {
  149. static unsigned counter = 0;
  150. if (++counter == TICKS_PER_FRAME) {
  151. static int pos = 0, max_pos = MAX_MAX_POS, dir = 1;
  152. if (dir > 0 && pos == max_pos) {
  153. dir = -1;
  154. if (max_pos == MIN_MAX_POS)
  155. max_pos = MAX_MAX_POS;
  156. else
  157. max_pos--;
  158. } else {
  159. if (dir < 0 && pos == 0)
  160. dir = 1;
  161. if (pos + dir <= max_pos) {
  162. /* Each bit of port 0 has a LED. */
  163. clear_bit (pos, &ANNA_PORT_IO(LEDS_PORT));
  164. pos += dir;
  165. set_bit (pos, &ANNA_PORT_IO(LEDS_PORT));
  166. }
  167. }
  168. counter = 0;
  169. }
  170. }