ethernut5.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2011
  4. * egnite GmbH <info@egnite.de>
  5. *
  6. * (C) Copyright 2010
  7. * Ole Reinhardt <ole.reinhardt@thermotemp.de>
  8. */
  9. /*
  10. * Ethernut 5 general board support
  11. *
  12. * Ethernut is an open source hardware and software project for
  13. * embedded Ethernet devices. Hardware layouts and CAD files are
  14. * freely available under BSD-like license.
  15. *
  16. * Ethernut 5 is the first member of the Ethernut board family
  17. * with U-Boot and Linux support. This implementation is based
  18. * on the original work done by Ole Reinhardt, but heavily modified
  19. * to support additional features and the latest board revision 5.0F.
  20. *
  21. * Main board components are by default:
  22. *
  23. * Atmel AT91SAM9XE512 CPU with 512 kBytes NOR Flash
  24. * 2 x 64 MBytes Micron MT48LC32M16A2P SDRAM
  25. * 512 MBytes Micron MT29F4G08ABADA NAND Flash
  26. * 4 MBytes Atmel AT45DB321D DataFlash
  27. * SMSC LAN8710 Ethernet PHY
  28. * Atmel ATmega168 MCU used for power management
  29. * Linear Technology LTC4411 PoE controller
  30. *
  31. * U-Boot relevant board interfaces are:
  32. *
  33. * 100 Mbit Ethernet with IEEE 802.3af PoE
  34. * RS-232 serial port
  35. * USB host and device
  36. * MMC/SD-Card slot
  37. * Expansion port with I2C, SPI and more...
  38. *
  39. * Typically the U-Boot image is loaded from serial DataFlash into
  40. * SDRAM by the samboot boot loader, which is located in internal
  41. * NOR Flash and provides all essential initializations like CPU
  42. * and peripheral clocks and, of course, the SDRAM configuration.
  43. *
  44. * For testing purposes it is also possibly to directly transfer
  45. * the image into SDRAM via JTAG. A tested configuration exists
  46. * for the Turtelizer 2 hardware dongle and the OpenOCD software.
  47. * In this case the latter will do the basic hardware configuration
  48. * via its reset-init script.
  49. *
  50. * For additional information visit the project home page at
  51. * http://www.ethernut.de/
  52. */
  53. #include <common.h>
  54. #include <net.h>
  55. #include <netdev.h>
  56. #include <miiphy.h>
  57. #include <i2c.h>
  58. #include <mmc.h>
  59. #include <atmel_mci.h>
  60. #include <asm/arch/at91sam9260.h>
  61. #include <asm/arch/at91sam9260_matrix.h>
  62. #include <asm/arch/at91sam9_smc.h>
  63. #include <asm/arch/at91_common.h>
  64. #include <asm/arch/clk.h>
  65. #include <asm/arch/gpio.h>
  66. #include <asm/io.h>
  67. #include <asm/gpio.h>
  68. #include "ethernut5_pwrman.h"
  69. DECLARE_GLOBAL_DATA_PTR;
  70. /*
  71. * This is called last during early initialization. Most of the basic
  72. * hardware interfaces are up and running.
  73. *
  74. * The SDRAM hardware has been configured by the first stage boot loader.
  75. * We only need to announce its size, using u-boot's memory check.
  76. */
  77. int dram_init(void)
  78. {
  79. gd->ram_size = get_ram_size(
  80. (void *)CONFIG_SYS_SDRAM_BASE,
  81. CONFIG_SYS_SDRAM_SIZE);
  82. return 0;
  83. }
  84. #ifdef CONFIG_CMD_NAND
  85. static void ethernut5_nand_hw_init(void)
  86. {
  87. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  88. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  89. unsigned long csa;
  90. /* Assign CS3 to NAND/SmartMedia Interface */
  91. csa = readl(&matrix->ebicsa);
  92. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  93. writel(csa, &matrix->ebicsa);
  94. /* Configure SMC CS3 for NAND/SmartMedia */
  95. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  96. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  97. &smc->cs[3].setup);
  98. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  99. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  100. &smc->cs[3].pulse);
  101. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  102. &smc->cs[3].cycle);
  103. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  104. AT91_SMC_MODE_EXNW_DISABLE |
  105. AT91_SMC_MODE_DBW_8 |
  106. AT91_SMC_MODE_TDF_CYCLE(2),
  107. &smc->cs[3].mode);
  108. #ifdef CONFIG_SYS_NAND_READY_PIN
  109. /* Ready pin is optional. */
  110. at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  111. #endif
  112. gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  113. }
  114. #endif
  115. /*
  116. * This is called first during late initialization.
  117. */
  118. int board_init(void)
  119. {
  120. at91_periph_clk_enable(ATMEL_ID_PIOA);
  121. at91_periph_clk_enable(ATMEL_ID_PIOB);
  122. at91_periph_clk_enable(ATMEL_ID_PIOC);
  123. /* Set adress of boot parameters. */
  124. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  125. /* Initialize UARTs and power management. */
  126. ethernut5_power_init();
  127. #ifdef CONFIG_CMD_NAND
  128. ethernut5_nand_hw_init();
  129. #endif
  130. return 0;
  131. }
  132. #ifdef CONFIG_MACB
  133. /*
  134. * This is optionally called last during late initialization.
  135. */
  136. int board_eth_init(bd_t *bis)
  137. {
  138. const char *devname;
  139. unsigned short mode;
  140. at91_periph_clk_enable(ATMEL_ID_EMAC0);
  141. /* Need to reset PHY via power management. */
  142. ethernut5_phy_reset();
  143. /* Set peripheral pins. */
  144. at91_macb_hw_init();
  145. /* Basic EMAC initialization. */
  146. if (macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, CONFIG_PHY_ID))
  147. return -1;
  148. /*
  149. * Early board revisions have a pull-down at the PHY's MODE0
  150. * strap pin, which forces the PHY into power down. Here we
  151. * switch to all-capable mode.
  152. */
  153. devname = miiphy_get_current_dev();
  154. if (miiphy_read(devname, 0, 18, &mode) == 0) {
  155. /* Set mode[2:0] to 0b111. */
  156. mode |= 0x00E0;
  157. miiphy_write(devname, 0, 18, mode);
  158. /* Soft reset overrides strap pins. */
  159. miiphy_write(devname, 0, MII_BMCR, BMCR_RESET);
  160. }
  161. /* Sync environment with network devices, needed for nfsroot. */
  162. return eth_init();
  163. }
  164. #endif
  165. #ifdef CONFIG_GENERIC_ATMEL_MCI
  166. int board_mmc_init(bd_t *bd)
  167. {
  168. at91_periph_clk_enable(ATMEL_ID_MCI);
  169. /* Initialize MCI hardware. */
  170. at91_mci_hw_init();
  171. /* Register the device. */
  172. return atmel_mci_init((void *)ATMEL_BASE_MCI);
  173. }
  174. int board_mmc_getcd(struct mmc *mmc)
  175. {
  176. return !at91_get_pio_value(CONFIG_SYS_MMC_CD_PIN);
  177. }
  178. #endif