anna.c 5.0 KB

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