cpu9260.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian.pop@leadtechdesign.com>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. * Ilko Iliev <www.ronetix.at>
  6. *
  7. * (C) Copyright 2009
  8. * Eric Benard <eric@eukrea.com>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <asm/sizes.h>
  30. #include <asm/arch/at91sam9260.h>
  31. #include <asm/arch/at91sam9_matrix.h>
  32. #include <asm/arch/at91sam9_smc.h>
  33. #include <asm/arch/at91_common.h>
  34. #include <asm/arch/at91_pmc.h>
  35. #include <asm/arch/at91_rstc.h>
  36. #include <asm/arch/gpio.h>
  37. #include <asm/arch/io.h>
  38. #include <asm/arch/hardware.h>
  39. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  40. #include <net.h>
  41. #endif
  42. #include <netdev.h>
  43. DECLARE_GLOBAL_DATA_PTR;
  44. /* ------------------------------------------------------------------------- */
  45. /*
  46. * Miscelaneous platform dependent initialisations
  47. */
  48. #ifdef CONFIG_CMD_NAND
  49. static void cpu9260_nand_hw_init(void)
  50. {
  51. unsigned long csa;
  52. /* Enable CS3 */
  53. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  54. at91_sys_write(AT91_MATRIX_EBICSA,
  55. csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  56. /* Configure SMC CS3 for NAND/SmartMedia */
  57. #if defined(CONFIG_CPU9G20)
  58. at91_sys_write(AT91_SMC_SETUP(3),
  59. AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(0) |
  60. AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(0));
  61. at91_sys_write(AT91_SMC_PULSE(3),
  62. AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(4) |
  63. AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(4));
  64. at91_sys_write(AT91_SMC_CYCLE(3),
  65. AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
  66. at91_sys_write(AT91_SMC_MODE(3),
  67. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  68. AT91_SMC_EXNWMODE_DISABLE |
  69. AT91_SMC_DBW_8 |
  70. AT91_SMC_TDF_(3));
  71. #elif defined(CONFIG_CPU9260)
  72. at91_sys_write(AT91_SMC_SETUP(3),
  73. AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0) |
  74. AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
  75. at91_sys_write(AT91_SMC_PULSE(3),
  76. AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3) |
  77. AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  78. at91_sys_write(AT91_SMC_CYCLE(3),
  79. AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  80. at91_sys_write(AT91_SMC_MODE(3),
  81. AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
  82. AT91_SMC_EXNWMODE_DISABLE |
  83. AT91_SMC_DBW_8 |
  84. AT91_SMC_TDF_(2));
  85. #endif
  86. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_PIOC);
  87. /* Configure RDY/BSY */
  88. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  89. /* Enable NandFlash */
  90. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  91. }
  92. #endif
  93. #ifdef CONFIG_MACB
  94. static void cpu9260_macb_hw_init(void)
  95. {
  96. unsigned long rstc;
  97. /* Enable clock */
  98. at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_EMAC);
  99. /*
  100. * Disable pull-up on:
  101. * RXDV (PA17) => PHY normal mode (not Test mode)
  102. * ERX0 (PA14) => PHY ADDR0
  103. * ERX1 (PA15) => PHY ADDR1
  104. * ERX2 (PA25) => PHY ADDR2
  105. * ERX3 (PA26) => PHY ADDR3
  106. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  107. *
  108. * PHY has internal pull-down
  109. */
  110. writel(pin_to_mask(AT91_PIN_PA14) |
  111. pin_to_mask(AT91_PIN_PA15) |
  112. pin_to_mask(AT91_PIN_PA17) |
  113. pin_to_mask(AT91_PIN_PA25) |
  114. pin_to_mask(AT91_PIN_PA26) |
  115. pin_to_mask(AT91_PIN_PA28),
  116. pin_to_controller(AT91_PIN_PA0) + PIO_PUDR);
  117. rstc = at91_sys_read(AT91_RSTC_MR) & AT91_RSTC_ERSTL;
  118. /* Need to reset PHY -> 500ms reset */
  119. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  120. (AT91_RSTC_ERSTL & (0x0D << 8)) |
  121. AT91_RSTC_URSTEN);
  122. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
  123. /* Wait for end hardware reset */
  124. while (!(at91_sys_read(AT91_RSTC_SR) & AT91_RSTC_NRSTL))
  125. ;
  126. /* Restore NRST value */
  127. at91_sys_write(AT91_RSTC_MR, AT91_RSTC_KEY |
  128. (rstc) |
  129. AT91_RSTC_URSTEN);
  130. /* Re-enable pull-up */
  131. writel(pin_to_mask(AT91_PIN_PA14) |
  132. pin_to_mask(AT91_PIN_PA15) |
  133. pin_to_mask(AT91_PIN_PA17) |
  134. pin_to_mask(AT91_PIN_PA25) |
  135. pin_to_mask(AT91_PIN_PA26) |
  136. pin_to_mask(AT91_PIN_PA28),
  137. pin_to_controller(AT91_PIN_PA0) + PIO_PUER);
  138. at91_macb_hw_init();
  139. }
  140. #endif
  141. int board_init(void)
  142. {
  143. /* Enable Ctrlc */
  144. console_init_f();
  145. /* arch number of the board */
  146. #if defined(CONFIG_CPU9G20)
  147. gd->bd->bi_arch_number = MACH_TYPE_CPUAT9G20;
  148. #elif defined(CONFIG_CPU9260)
  149. gd->bd->bi_arch_number = MACH_TYPE_CPUAT9260;
  150. #endif
  151. /* adress of boot parameters */
  152. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  153. at91_serial_hw_init();
  154. #ifdef CONFIG_CMD_NAND
  155. cpu9260_nand_hw_init();
  156. #endif
  157. #ifdef CONFIG_MACB
  158. cpu9260_macb_hw_init();
  159. #endif
  160. #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
  161. status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
  162. #endif
  163. return 0;
  164. }
  165. int dram_init(void)
  166. {
  167. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  168. if (get_ram_size((long *) PHYS_SDRAM, PHYS_SDRAM_SIZE) !=
  169. PHYS_SDRAM_SIZE)
  170. return -1;
  171. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  172. return 0;
  173. }
  174. #ifdef CONFIG_RESET_PHY_R
  175. void reset_phy(void)
  176. {
  177. }
  178. #endif
  179. int board_eth_init(bd_t *bis)
  180. {
  181. int rc = 0;
  182. #ifdef CONFIG_MACB
  183. rc = macb_eth_initialize(0, (void *)AT91SAM9260_BASE_EMAC, 0x00);
  184. #endif
  185. return rc;
  186. }