pm9g45.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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@popies.net>
  9. * Lead Tech Design <www.leadtechdesign.com>
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <linux/sizes.h>
  15. #include <asm/io.h>
  16. #include <asm/gpio.h>
  17. #include <asm/arch/at91sam9_smc.h>
  18. #include <asm/arch/at91_common.h>
  19. #include <asm/arch/at91_rstc.h>
  20. #include <asm/arch/at91_matrix.h>
  21. #include <asm/arch/gpio.h>
  22. #include <asm/arch/clk.h>
  23. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  24. #include <net.h>
  25. #endif
  26. #include <netdev.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /*
  29. * Miscelaneous platform dependent initialisations
  30. */
  31. #ifdef CONFIG_CMD_NAND
  32. static void pm9g45_nand_hw_init(void)
  33. {
  34. unsigned long csa;
  35. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  36. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  37. /* Enable CS3 */
  38. csa = readl(&matrix->ccr[6]) | AT91_MATRIX_CSA_EBI_CS3A;
  39. writel(csa, &matrix->ccr[6]);
  40. /* Configure SMC CS3 for NAND/SmartMedia */
  41. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  42. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  43. &smc->cs[3].setup);
  44. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
  45. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
  46. &smc->cs[3].pulse);
  47. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
  48. &smc->cs[3].cycle);
  49. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  50. AT91_SMC_MODE_EXNW_DISABLE |
  51. AT91_SMC_MODE_DBW_8 |
  52. AT91_SMC_MODE_TDF_CYCLE(3),
  53. &smc->cs[3].mode);
  54. at91_periph_clk_enable(ATMEL_ID_PIOC);
  55. #ifdef CONFIG_SYS_NAND_READY_PIN
  56. /* Configure RDY/BSY */
  57. gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
  58. #endif
  59. /* Enable NandFlash */
  60. gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  61. }
  62. #endif
  63. #ifdef CONFIG_MACB
  64. static void pm9g45_macb_hw_init(void)
  65. {
  66. /*
  67. * PD2 enables the 50MHz oscillator for Ethernet PHY
  68. * 1 - enable
  69. * 0 - disable
  70. */
  71. at91_set_pio_output(AT91_PIO_PORTD, 2, 1);
  72. at91_set_pio_value(AT91_PIO_PORTD, 2, 1); /* 1- enable, 0 - disable */
  73. at91_periph_clk_enable(ATMEL_ID_EMAC);
  74. /*
  75. * Disable pull-up on:
  76. * RXDV (PA15) => PHY normal mode (not Test mode)
  77. * ERX0 (PA12) => PHY ADDR0
  78. * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
  79. *
  80. * PHY has internal pull-down
  81. */
  82. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0);
  83. at91_set_pio_pullup(AT91_PIO_PORTA, 12, 0);
  84. at91_set_pio_pullup(AT91_PIO_PORTA, 13, 0);
  85. /* Re-enable pull-up */
  86. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
  87. at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
  88. at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
  89. at91_macb_hw_init();
  90. }
  91. #endif
  92. int board_early_init_f(void)
  93. {
  94. at91_periph_clk_enable(ATMEL_ID_PIOA);
  95. at91_periph_clk_enable(ATMEL_ID_PIOB);
  96. at91_periph_clk_enable(ATMEL_ID_PIOC);
  97. at91_periph_clk_enable(ATMEL_ID_PIODE);
  98. at91_seriald_hw_init();
  99. return 0;
  100. }
  101. int board_init(void)
  102. {
  103. /* arch number of AT91SAM9M10G45EK-Board */
  104. gd->bd->bi_arch_number = MACH_TYPE_PM9G45;
  105. /* adress of boot parameters */
  106. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  107. #ifdef CONFIG_CMD_NAND
  108. pm9g45_nand_hw_init();
  109. #endif
  110. #ifdef CONFIG_MACB
  111. pm9g45_macb_hw_init();
  112. #endif
  113. return 0;
  114. }
  115. int dram_init(void)
  116. {
  117. /* dram_init must store complete ramsize in gd->ram_size */
  118. gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
  119. PHYS_SDRAM_SIZE);
  120. return 0;
  121. }
  122. void dram_init_banksize(void)
  123. {
  124. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  125. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  126. }
  127. #ifdef CONFIG_RESET_PHY_R
  128. void reset_phy(void)
  129. {
  130. #ifdef CONFIG_MACB
  131. /*
  132. * Initialize ethernet HW addr prior to starting Linux,
  133. * needed for nfsroot
  134. */
  135. eth_init();
  136. #endif
  137. }
  138. #endif
  139. int board_eth_init(bd_t *bis)
  140. {
  141. int rc = 0;
  142. #ifdef CONFIG_MACB
  143. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x01);
  144. #endif
  145. return rc;
  146. }