cpu_init.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Initializes CPU and basic hardware such as memory
  2. * controllers, IRQ controller and system timer 0.
  3. *
  4. * (C) Copyright 2007, 2015
  5. * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <asm/asi.h>
  11. #include <asm/leon.h>
  12. #include <asm/io.h>
  13. #include <config.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. /*
  16. * Breath some life into the CPU...
  17. *
  18. * Set up the memory map,
  19. * initialize a bunch of registers.
  20. *
  21. * Run from FLASH/PROM:
  22. * - until memory controller is set up, only registers available
  23. * - no global variables available for writing
  24. * - constants available
  25. */
  26. void cpu_init_f(void)
  27. {
  28. LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
  29. /* initialize the IRQMP */
  30. leon2->Interrupt_Force = 0;
  31. leon2->Interrupt_Pending = 0;
  32. leon2->Interrupt_Clear = 0xfffe; /* clear all old pending interrupts */
  33. leon2->Interrupt_Mask = 0xfffe0000; /* mask all IRQs */
  34. /* cache */
  35. /* I/O port setup */
  36. #ifdef LEON2_IO_PORT_DIR
  37. leon2->PIO_Direction = LEON2_IO_PORT_DIR;
  38. #endif
  39. #ifdef LEON2_IO_PORT_DATA
  40. leon2->PIO_Data = LEON2_IO_PORT_DATA;
  41. #endif
  42. #ifdef LEON2_IO_PORT_INT
  43. leon2->PIO_Interrupt = LEON2_IO_PORT_INT;
  44. #else
  45. leon2->PIO_Interrupt = 0;
  46. #endif
  47. /* disable timers */
  48. leon2->Timer_Control_1 = leon2->Timer_Control_2 = 0;
  49. }
  50. int arch_cpu_init(void)
  51. {
  52. gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
  53. gd->bus_clk = CONFIG_SYS_CLK_FREQ;
  54. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  55. return 0;
  56. }
  57. /*
  58. * initialize higher level parts of CPU
  59. */
  60. int cpu_init_r(void)
  61. {
  62. return 0;
  63. }
  64. /* initiate and setup timer0 to configured HZ. Base clock is 1MHz.
  65. */
  66. int timer_init(void)
  67. {
  68. LEON2_regs *leon2 = (LEON2_regs *)LEON2_PREGS;
  69. /* initialize prescaler common to all timers to 1MHz */
  70. leon2->Scaler_Counter = leon2->Scaler_Reload =
  71. (((CONFIG_SYS_CLK_FREQ / 1000) + 500) / 1000) - 1;
  72. /* SYS_HZ ticks per second */
  73. leon2->Timer_Counter_1 = 0;
  74. leon2->Timer_Reload_1 = (CONFIG_SYS_TIMER_RATE / CONFIG_SYS_HZ) - 1;
  75. leon2->Timer_Control_1 = LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS |
  76. LEON2_TIMER_CTRL_LD;
  77. CONFIG_SYS_TIMER_COUNTER = (void *)&leon2->Timer_Counter_1;
  78. return 0;
  79. }