pm9g45.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * (C) Copyright 2010
  3. * Ilko Iliev <iliev@ronetix.at>
  4. * Asen Dimov <dimov@ronetix.at>
  5. * Ronetix GmbH <www.ronetix.at>
  6. *
  7. * (C) Copyright 2007-2008
  8. * Stelian Pop <stelian.pop@leadtechdesign.com>
  9. * Lead Tech Design <www.leadtechdesign.com>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <asm/sizes.h>
  31. #include <asm/arch/at91sam9g45.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/at91_matrix.h>
  37. #include <asm/arch/at91_pio.h>
  38. #include <asm/arch/clk.h>
  39. #include <asm/arch/io.h>
  40. #include <asm/arch/hardware.h>
  41. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  42. #include <net.h>
  43. #endif
  44. #include <netdev.h>
  45. DECLARE_GLOBAL_DATA_PTR;
  46. /*
  47. * Miscelaneous platform dependent initialisations
  48. */
  49. #ifdef CONFIG_CMD_NAND
  50. static void pm9g45_nand_hw_init(void)
  51. {
  52. unsigned long csa;
  53. at91_smc_t *smc = (at91_smc_t *) AT91_SMC_BASE;
  54. at91_matrix_t *matrix = (at91_matrix_t *) AT91_MATRIX_BASE;
  55. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  56. /* Enable CS3 */
  57. csa = readl(&matrix->ccr[6]) | AT91_MATRIX_CSA_EBI_CS3A;
  58. writel(csa, &matrix->ccr[6]);
  59. /* Configure SMC CS3 for NAND/SmartMedia */
  60. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  61. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  62. &smc->cs[3].setup);
  63. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
  64. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
  65. &smc->cs[3].pulse);
  66. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
  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. writel(1 << AT91SAM9G45_ID_PIOC, &pmc->pcer);
  74. #ifdef CONFIG_SYS_NAND_READY_PIN
  75. /* Configure RDY/BSY */
  76. at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  77. #endif
  78. /* Enable NandFlash */
  79. at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  80. }
  81. #endif
  82. #ifdef CONFIG_MACB
  83. static void pm9g45_macb_hw_init(void)
  84. {
  85. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  86. /*
  87. * PD2 enables the 50MHz oscillator for Ethernet PHY
  88. * 1 - enable
  89. * 0 - disable
  90. */
  91. at91_set_pio_output(AT91_PIO_PORTD, 2, 1);
  92. at91_set_pio_value(AT91_PIO_PORTD, 2, 1); /* 1- enable, 0 - disable */
  93. /* Enable clock */
  94. writel(1 << AT91SAM9G45_ID_EMAC, &pmc->pcer);
  95. /*
  96. * Disable pull-up on:
  97. * RXDV (PA15) => PHY normal mode (not Test mode)
  98. * ERX0 (PA12) => PHY ADDR0
  99. * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
  100. *
  101. * PHY has internal pull-down
  102. */
  103. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0);
  104. at91_set_pio_pullup(AT91_PIO_PORTA, 12, 0);
  105. at91_set_pio_pullup(AT91_PIO_PORTA, 13, 0);
  106. /* Re-enable pull-up */
  107. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
  108. at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
  109. at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
  110. at91_macb_hw_init();
  111. }
  112. #endif
  113. int board_init(void)
  114. {
  115. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  116. /* Enable Ctrlc */
  117. console_init_f();
  118. writel((1 << AT91SAM9G45_ID_PIOA) |
  119. (1 << AT91SAM9G45_ID_PIOB) |
  120. (1 << AT91SAM9G45_ID_PIOC) |
  121. (1 << AT91SAM9G45_ID_PIODE), &pmc->pcer);
  122. /* arch number of AT91SAM9M10G45EK-Board */
  123. gd->bd->bi_arch_number = MACH_TYPE_PM9G45;
  124. /* adress of boot parameters */
  125. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  126. at91_serial_hw_init();
  127. #ifdef CONFIG_CMD_NAND
  128. pm9g45_nand_hw_init();
  129. #endif
  130. #ifdef CONFIG_MACB
  131. pm9g45_macb_hw_init();
  132. #endif
  133. return 0;
  134. }
  135. int dram_init(void)
  136. {
  137. /* dram_init must store complete ramsize in gd->ram_size */
  138. gd->ram_size = get_ram_size((volatile void *)PHYS_SDRAM,
  139. PHYS_SDRAM_SIZE);
  140. return 0;
  141. }
  142. void dram_init_banksize(void)
  143. {
  144. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  145. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  146. }
  147. #ifdef CONFIG_RESET_PHY_R
  148. void reset_phy(void)
  149. {
  150. #ifdef CONFIG_MACB
  151. /*
  152. * Initialize ethernet HW addr prior to starting Linux,
  153. * needed for nfsroot
  154. */
  155. eth_init(gd->bd);
  156. #endif
  157. }
  158. #endif
  159. int board_eth_init(bd_t *bis)
  160. {
  161. int rc = 0;
  162. #ifdef CONFIG_MACB
  163. rc = macb_eth_initialize(0, (void *)AT91_EMAC_BASE, 0x01);
  164. #endif
  165. return rc;
  166. }