cpu9260.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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-2011
  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/io.h>
  30. #include <asm/arch/at91sam9260.h>
  31. #include <asm/arch/at91sam9_smc.h>
  32. #include <asm/arch/at91_common.h>
  33. #include <asm/arch/at91_matrix.h>
  34. #include <asm/arch/at91_pmc.h>
  35. #include <asm/arch/at91_rstc.h>
  36. #include <asm/arch/at91_pio.h>
  37. #include <asm/arch/clk.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. at91_smc_t *smc = (at91_smc_t *) ATMEL_BASE_SMC;
  53. at91_matrix_t *matrix = (at91_matrix_t *) ATMEL_BASE_MATRIX;
  54. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  55. /* Enable CS3 */
  56. csa = readl(&matrix->csa) | AT91_MATRIX_CSA_EBI_CS3A;
  57. writel(csa, &matrix->csa);
  58. /* Configure SMC CS3 for NAND/SmartMedia */
  59. #if defined(CONFIG_CPU9G20)
  60. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  61. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  62. &smc->cs[3].setup);
  63. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(4) |
  64. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(4),
  65. &smc->cs[3].pulse);
  66. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
  67. &smc->cs[3].cycle);
  68. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  69. AT91_SMC_MODE_EXNW_DISABLE |
  70. AT91_SMC_MODE_DBW_8 |
  71. AT91_SMC_MODE_TDF_CYCLE(3),
  72. &smc->cs[3].mode);
  73. #elif defined(CONFIG_CPU9260)
  74. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  75. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  76. &smc->cs[3].setup);
  77. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  78. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  79. &smc->cs[3].pulse);
  80. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  81. &smc->cs[3].cycle);
  82. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  83. AT91_SMC_MODE_EXNW_DISABLE |
  84. AT91_SMC_MODE_DBW_8 |
  85. AT91_SMC_MODE_TDF_CYCLE(2),
  86. &smc->cs[3].mode);
  87. #endif
  88. writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
  89. /* Configure RDY/BSY */
  90. at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  91. /* Enable NandFlash */
  92. at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  93. }
  94. #endif
  95. #ifdef CONFIG_MACB
  96. static void cpu9260_macb_hw_init(void)
  97. {
  98. unsigned long rstcmr;
  99. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  100. at91_rstc_t *rstc = (at91_rstc_t *) ATMEL_BASE_RSTC;
  101. /* Enable clock */
  102. writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
  103. at91_set_pio_pullup(AT91_PIO_PORTA, 17, 1);
  104. rstcmr = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
  105. /* Need to reset PHY -> 500ms reset */
  106. writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0xD) |
  107. AT91_RSTC_MR_URSTEN, &rstc->mr);
  108. writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
  109. /* Wait for end hardware reset */
  110. while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
  111. ;
  112. /* Restore NRST value */
  113. writel(AT91_RSTC_KEY | rstcmr | AT91_RSTC_MR_URSTEN, &rstc->mr);
  114. at91_macb_hw_init();
  115. }
  116. #endif
  117. int board_early_init_f(void)
  118. {
  119. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  120. writel((1 << ATMEL_ID_PIOA) |
  121. (1 << ATMEL_ID_PIOB) |
  122. (1 << ATMEL_ID_PIOC),
  123. &pmc->pcer);
  124. at91_seriald_hw_init();
  125. return 0;
  126. }
  127. int board_init(void)
  128. {
  129. /* arch number of the board */
  130. #if defined(CONFIG_CPU9G20)
  131. gd->bd->bi_arch_number = MACH_TYPE_CPUAT9G20;
  132. #elif defined(CONFIG_CPU9260)
  133. gd->bd->bi_arch_number = MACH_TYPE_CPUAT9260;
  134. #endif
  135. /* adress of boot parameters */
  136. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  137. #ifdef CONFIG_CMD_NAND
  138. cpu9260_nand_hw_init();
  139. #endif
  140. #ifdef CONFIG_MACB
  141. cpu9260_macb_hw_init();
  142. #endif
  143. #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
  144. status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
  145. #endif
  146. return 0;
  147. }
  148. int dram_init(void)
  149. {
  150. gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
  151. CONFIG_SYS_SDRAM_SIZE);
  152. return 0;
  153. }
  154. int board_eth_init(bd_t *bis)
  155. {
  156. int rc = 0;
  157. #ifdef CONFIG_MACB
  158. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0);
  159. #endif
  160. return rc;
  161. }