cpu_init.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* Initializes CPU and basic hardware such as memory
  2. * controllers, IRQ controller and system timer 0.
  3. *
  4. * (C) Copyright 2007
  5. * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. *
  25. */
  26. #include <common.h>
  27. #include <asm/asi.h>
  28. #include <asm/leon.h>
  29. #include <config.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /* reset CPU (jump to 0, without reset) */
  32. void start(void);
  33. struct {
  34. gd_t gd_area;
  35. bd_t bd;
  36. } global_data;
  37. /*
  38. * Breath some life into the CPU...
  39. *
  40. * Set up the memory map,
  41. * initialize a bunch of registers.
  42. *
  43. * Run from FLASH/PROM:
  44. * - until memory controller is set up, only registers avaiable
  45. * - no global variables available for writing
  46. * - constants avaiable
  47. */
  48. void cpu_init_f(void)
  49. {
  50. LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
  51. /* initialize the IRQMP */
  52. leon2->Interrupt_Force = 0;
  53. leon2->Interrupt_Pending = 0;
  54. leon2->Interrupt_Clear = 0xfffe; /* clear all old pending interrupts */
  55. leon2->Interrupt_Mask = 0xfffe0000; /* mask all IRQs */
  56. /* cache */
  57. /* I/O port setup */
  58. #ifdef LEON2_IO_PORT_DIR
  59. leon2->PIO_Direction = LEON2_IO_PORT_DIR;
  60. #endif
  61. #ifdef LEON2_IO_PORT_DATA
  62. leon2->PIO_Data = LEON2_IO_PORT_DATA;
  63. #endif
  64. #ifdef LEON2_IO_PORT_INT
  65. leon2->PIO_Interrupt = LEON2_IO_PORT_INT;
  66. #else
  67. leon2->PIO_Interrupt = 0;
  68. #endif
  69. }
  70. void cpu_init_f2(void)
  71. {
  72. }
  73. /*
  74. * initialize higher level parts of CPU like time base and timers
  75. */
  76. int cpu_init_r(void)
  77. {
  78. LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
  79. /* initialize prescaler common to all timers to 1MHz */
  80. leon2->Scaler_Counter = leon2->Scaler_Reload =
  81. (((CONFIG_SYS_CLK_FREQ / 1000) + 500) / 1000) - 1;
  82. return (0);
  83. }
  84. /* Uses Timer 0 to get accurate
  85. * pauses. Max 2 raised to 32 ticks
  86. *
  87. */
  88. void cpu_wait_ticks(unsigned long ticks)
  89. {
  90. unsigned long start = get_timer(0);
  91. while (get_timer(start) < ticks) ;
  92. }
  93. /* initiate and setup timer0 interrupt to 1MHz
  94. * Return irq number for timer int or a negative number for
  95. * dealing with self
  96. */
  97. int timer_interrupt_init_cpu(void)
  98. {
  99. LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
  100. /* 1ms ticks */
  101. leon2->Timer_Counter_1 = 0;
  102. leon2->Timer_Reload_1 = 999; /* (((1000000 / 100) - 1)) */
  103. leon2->Timer_Control_1 =
  104. (LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS | LEON2_TIMER_CTRL_LD);
  105. return LEON2_TIMER1_IRQNO;
  106. }
  107. /*
  108. * This function is intended for SHORT delays only.
  109. */
  110. unsigned long cpu_usec2ticks(unsigned long usec)
  111. {
  112. /* timer set to 1kHz ==> 1 clk tick = 1 msec */
  113. if (usec < 1000)
  114. return 1;
  115. return (usec / 1000);
  116. }
  117. unsigned long cpu_ticks2usec(unsigned long ticks)
  118. {
  119. /* 1tick = 1usec */
  120. return ticks * 1000;
  121. }