lowlevel_init.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * (C) Copyright 2009 Faraday Technology
  3. * Po-Yu Chuang <ratbert@faraday-tech.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <config.h>
  20. #include <version.h>
  21. #include <asm/macro.h>
  22. #include <asm/arch/ftsdmc020.h>
  23. /*
  24. * parameters for the SDRAM controller
  25. */
  26. #define TP0_A (CONFIG_FTSDMC020_BASE + FTSDMC020_OFFSET_TP0)
  27. #define TP1_A (CONFIG_FTSDMC020_BASE + FTSDMC020_OFFSET_TP1)
  28. #define CR_A (CONFIG_FTSDMC020_BASE + FTSDMC020_OFFSET_CR)
  29. #define B0_BSR_A (CONFIG_FTSDMC020_BASE + FTSDMC020_OFFSET_BANK0_BSR)
  30. #define ACR_A (CONFIG_FTSDMC020_BASE + FTSDMC020_OFFSET_ACR)
  31. #define TP0_D CONFIG_SYS_FTSDMC020_TP0
  32. #define TP1_D CONFIG_SYS_FTSDMC020_TP1
  33. #define CR_D1 FTSDMC020_CR_IPREC
  34. #define CR_D2 FTSDMC020_CR_ISMR
  35. #define CR_D3 FTSDMC020_CR_IREF
  36. #define B0_BSR_D (CONFIG_SYS_FTSDMC020_BANK0_BSR | \
  37. FTSDMC020_BANK_BASE(PHYS_SDRAM_1))
  38. #define ACR_D FTSDMC020_ACR_TOC(0x18)
  39. /*
  40. * numeric 7 segment display
  41. */
  42. .macro led, num
  43. write32 CONFIG_DEBUG_LED, \num
  44. .endm
  45. /*
  46. * Waiting for SDRAM to set up
  47. */
  48. .macro wait_sdram
  49. ldr r0, =CONFIG_FTSDMC020_BASE
  50. 1:
  51. ldr r1, [r0, #FTSDMC020_OFFSET_CR]
  52. cmp r1, #0
  53. bne 1b
  54. .endm
  55. .globl lowlevel_init
  56. lowlevel_init:
  57. mov r11, lr
  58. led 0x0
  59. bl init_sdmc
  60. led 0x1
  61. /* everything is fine now */
  62. mov lr, r11
  63. mov pc, lr
  64. /*
  65. * memory initialization
  66. */
  67. init_sdmc:
  68. led 0x10
  69. /* set SDRAM register */
  70. write32 TP0_A, TP0_D
  71. led 0x11
  72. write32 TP1_A, TP1_D
  73. led 0x12
  74. /* set to precharge */
  75. write32 CR_A, CR_D1
  76. led 0x13
  77. wait_sdram
  78. led 0x14
  79. /* set mode register */
  80. write32 CR_A, CR_D2
  81. led 0x15
  82. wait_sdram
  83. led 0x16
  84. /* set to refresh */
  85. write32 CR_A, CR_D3
  86. led 0x17
  87. wait_sdram
  88. led 0x18
  89. write32 B0_BSR_A, B0_BSR_D
  90. led 0x19
  91. write32 ACR_A, ACR_D
  92. led 0x1a
  93. mov pc, lr