bf518f-ezbrd.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * U-boot - main board file
  3. *
  4. * Copyright (c) 2008-2009 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <common.h>
  9. #include <config.h>
  10. #include <command.h>
  11. #include <net.h>
  12. #include <netdev.h>
  13. #include <spi.h>
  14. #include <asm/blackfin.h>
  15. #include <asm/net.h>
  16. #include <asm/portmux.h>
  17. #include <asm/mach-common/bits/otp.h>
  18. #include <asm/sdh.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. int checkboard(void)
  21. {
  22. printf("Board: ADI BF518F EZ-Board board\n");
  23. printf(" Support: http://blackfin.uclinux.org/\n");
  24. return 0;
  25. }
  26. #if defined(CONFIG_BFIN_MAC)
  27. static void board_init_enetaddr(uchar *mac_addr)
  28. {
  29. #ifdef CONFIG_SYS_NO_FLASH
  30. # define USE_MAC_IN_FLASH 0
  31. #else
  32. # define USE_MAC_IN_FLASH 1
  33. #endif
  34. bool valid_mac = false;
  35. if (USE_MAC_IN_FLASH) {
  36. /* we cram the MAC in the last flash sector */
  37. uchar *board_mac_addr = (uchar *)0x203F0096;
  38. if (is_valid_ether_addr(board_mac_addr)) {
  39. memcpy(mac_addr, board_mac_addr, 6);
  40. valid_mac = true;
  41. }
  42. }
  43. if (!valid_mac) {
  44. puts("Warning: Generating 'random' MAC address\n");
  45. bfin_gen_rand_mac(mac_addr);
  46. }
  47. eth_setenv_enetaddr("ethaddr", mac_addr);
  48. }
  49. /* Only the first run of boards had a KSZ switch */
  50. #if defined(CONFIG_BFIN_SPI) && __SILICON_REVISION__ == 0
  51. # define KSZ_POSSIBLE 1
  52. #else
  53. # define KSZ_POSSIBLE 0
  54. #endif
  55. #define KSZ_MAX_HZ 5000000
  56. #define KSZ_WRITE 0x02
  57. #define KSZ_READ 0x03
  58. #define KSZ_REG_CHID 0x00 /* Register 0: Chip ID0 */
  59. #define KSZ_REG_STPID 0x01 /* Register 1: Chip ID1 / Start Switch */
  60. #define KSZ_REG_GC9 0x0b /* Register 11: Global Control 9 */
  61. #define KSZ_REG_P3C0 0x30 /* Register 48: Port 3 Control 0 */
  62. static int ksz8893m_transfer(struct spi_slave *slave, uchar dir, uchar reg,
  63. uchar data, uchar result[3])
  64. {
  65. unsigned char dout[3] = { dir, reg, data, };
  66. return spi_xfer(slave, sizeof(dout) * 8, dout, result, SPI_XFER_BEGIN | SPI_XFER_END);
  67. }
  68. static int ksz8893m_reg_set(struct spi_slave *slave, uchar reg, uchar data)
  69. {
  70. unsigned char din[3];
  71. return ksz8893m_transfer(slave, KSZ_WRITE, reg, data, din);
  72. }
  73. static int ksz8893m_reg_read(struct spi_slave *slave, uchar reg)
  74. {
  75. int ret;
  76. unsigned char din[3];
  77. ret = ksz8893m_transfer(slave, KSZ_READ, reg, 0, din);
  78. return ret ? ret : din[2];
  79. }
  80. static int ksz8893m_reg_clear(struct spi_slave *slave, uchar reg, uchar mask)
  81. {
  82. return ksz8893m_reg_set(slave, reg, ksz8893m_reg_read(slave, reg) & mask);
  83. }
  84. static int ksz8893m_reset(struct spi_slave *slave)
  85. {
  86. int ret = 0;
  87. /* Disable STPID mode */
  88. ret |= ksz8893m_reg_clear(slave, KSZ_REG_GC9, 0x01);
  89. /* Disable VLAN tag insert on Port3 */
  90. ret |= ksz8893m_reg_clear(slave, KSZ_REG_P3C0, 0x04);
  91. /* Start switch */
  92. ret |= ksz8893m_reg_set(slave, KSZ_REG_STPID, 0x01);
  93. return ret;
  94. }
  95. static bool board_ksz_init(void)
  96. {
  97. static bool switch_is_alive = false;
  98. if (!switch_is_alive) {
  99. struct spi_slave *slave = spi_setup_slave(0, 1, KSZ_MAX_HZ, SPI_MODE_3);
  100. if (slave) {
  101. if (!spi_claim_bus(slave)) {
  102. bool phy_is_ksz = (ksz8893m_reg_read(slave, KSZ_REG_CHID) == 0x88);
  103. int ret = phy_is_ksz ? ksz8893m_reset(slave) : 0;
  104. switch_is_alive = (ret == 0);
  105. spi_release_bus(slave);
  106. }
  107. spi_free_slave(slave);
  108. }
  109. }
  110. return switch_is_alive;
  111. }
  112. int board_eth_init(bd_t *bis)
  113. {
  114. if (KSZ_POSSIBLE) {
  115. if (!board_ksz_init())
  116. return 0;
  117. }
  118. return bfin_EMAC_initialize(bis);
  119. }
  120. #endif
  121. int misc_init_r(void)
  122. {
  123. #ifdef CONFIG_BFIN_MAC
  124. uchar enetaddr[6];
  125. if (!eth_getenv_enetaddr("ethaddr", enetaddr))
  126. board_init_enetaddr(enetaddr);
  127. #endif
  128. #ifndef CONFIG_SYS_NO_FLASH
  129. /* we use the last sector for the MAC address / POST LDR */
  130. extern flash_info_t flash_info[];
  131. flash_protect(FLAG_PROTECT_SET, 0x203F0000, 0x203FFFFF, &flash_info[0]);
  132. #endif
  133. return 0;
  134. }
  135. int board_early_init_f(void)
  136. {
  137. /* connect async banks by default */
  138. const unsigned short pins[] = {
  139. P_AMS2, P_AMS3, 0,
  140. };
  141. return peripheral_request_list(pins, "async");
  142. }
  143. #ifdef CONFIG_BFIN_SDH
  144. int board_mmc_init(bd_t *bis)
  145. {
  146. return bfin_mmc_init(bis);
  147. }
  148. #endif