bf518f-ezbrd.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/mach-common/bits/otp.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. int checkboard(void)
  19. {
  20. printf("Board: ADI BF518F EZ-Board board\n");
  21. printf(" Support: http://blackfin.uclinux.org/\n");
  22. return 0;
  23. }
  24. phys_size_t initdram(int board_type)
  25. {
  26. gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  27. gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
  28. return gd->bd->bi_memsize;
  29. }
  30. #if defined(CONFIG_BFIN_MAC)
  31. static void board_init_enetaddr(uchar *mac_addr)
  32. {
  33. bool valid_mac = false;
  34. #if 0
  35. /* the MAC is stored in OTP memory page 0xDF */
  36. uint32_t ret;
  37. uint64_t otp_mac;
  38. ret = bfrom_OtpRead(0xDF, OTP_LOWER_HALF, &otp_mac);
  39. if (!(ret & OTP_MASTER_ERROR)) {
  40. uchar *otp_mac_p = (uchar *)&otp_mac;
  41. for (ret = 0; ret < 6; ++ret)
  42. mac_addr[ret] = otp_mac_p[5 - ret];
  43. if (is_valid_ether_addr(mac_addr))
  44. valid_mac = true;
  45. }
  46. #endif
  47. if (!valid_mac) {
  48. puts("Warning: Generating 'random' MAC address\n");
  49. bfin_gen_rand_mac(mac_addr);
  50. }
  51. eth_setenv_enetaddr("ethaddr", mac_addr);
  52. }
  53. int board_eth_init(bd_t *bis)
  54. {
  55. static bool switch_is_alive = false;
  56. int ret;
  57. if (!switch_is_alive) {
  58. struct spi_slave *slave = spi_setup_slave(0, 1, 5000000, SPI_MODE_3);
  59. if (slave) {
  60. if (!spi_claim_bus(slave)) {
  61. unsigned char dout[3] = { 2, 1, 1, };
  62. unsigned char din[3];
  63. ret = spi_xfer(slave, sizeof(dout) * 8, dout, din, SPI_XFER_BEGIN | SPI_XFER_END);
  64. if (!ret)
  65. switch_is_alive = true;
  66. spi_release_bus(slave);
  67. }
  68. spi_free_slave(slave);
  69. }
  70. }
  71. if (switch_is_alive)
  72. return bfin_EMAC_initialize(bis);
  73. else
  74. return -1;
  75. }
  76. #endif
  77. int misc_init_r(void)
  78. {
  79. #ifdef CONFIG_BFIN_MAC
  80. uchar enetaddr[6];
  81. if (!eth_getenv_enetaddr("ethaddr", enetaddr))
  82. board_init_enetaddr(enetaddr);
  83. #endif
  84. return 0;
  85. }