sffsdr.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  3. *
  4. * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
  5. * Copyright (C) 2008 Philip Balister, OpenSDR <philip@opensdr.com>
  6. *
  7. * Parts are shamelessly stolen from various TI sources, original copyright
  8. * follows:
  9. *
  10. * Copyright (C) 2004 Texas Instruments.
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. */
  29. #include <common.h>
  30. #include <i2c.h>
  31. #include <asm/arch/hardware.h>
  32. #include "../common/misc.h"
  33. #define DAVINCI_A3CR (0x01E00014) /* EMIF-A CS3 config register. */
  34. #define DAVINCI_A3CR_VAL (0x3FFFFFFD) /* EMIF-A CS3 value for FPGA. */
  35. #define INTEGRITY_SYSCFG_OFFSET 0x7E8
  36. #define INTEGRITY_CHECKWORD_OFFSET 0x7F8
  37. #define INTEGRITY_CHECKWORD_VALUE 0x10ADBEEF
  38. DECLARE_GLOBAL_DATA_PTR;
  39. int board_init(void)
  40. {
  41. /* arch number of the board */
  42. gd->bd->bi_arch_number = MACH_TYPE_SFFSDR;
  43. /* address of boot parameters */
  44. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  45. davinci_errata_workarounds();
  46. /* Power on required peripherals */
  47. lpsc_on(DAVINCI_LPSC_GPIO);
  48. #if !defined(CONFIG_SYS_USE_DSPLINK)
  49. /* Powerup the DSP */
  50. dsp_on();
  51. #endif /* CONFIG_SYS_USE_DSPLINK */
  52. davinci_enable_uart0();
  53. davinci_enable_emac();
  54. davinci_enable_i2c();
  55. lpsc_on(DAVINCI_LPSC_TIMER1);
  56. timer_init();
  57. return(0);
  58. }
  59. /* Read ethernet MAC address from Integrity data structure inside EEPROM.
  60. * Returns 1 if found, 0 otherwise.
  61. */
  62. static int sffsdr_read_mac_address(uint8_t *buf)
  63. {
  64. u_int32_t value, mac[2], address;
  65. /* Read Integrity data structure checkword. */
  66. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_CHECKWORD_OFFSET,
  67. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  68. goto err;
  69. if (value != INTEGRITY_CHECKWORD_VALUE)
  70. return 0;
  71. /* Read SYSCFG structure offset. */
  72. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_SYSCFG_OFFSET,
  73. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  74. goto err;
  75. address = 0x800 + (int) value; /* Address of SYSCFG structure. */
  76. /* Read NET CONFIG structure offset. */
  77. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
  78. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  79. goto err;
  80. address = 0x800 + (int) value; /* Address of NET CONFIG structure. */
  81. address += 12; /* Address of NET INTERFACE CONFIG structure. */
  82. /* Read NET INTERFACE CONFIG 2 structure offset. */
  83. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
  84. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  85. goto err;
  86. address = 0x800 + 16 + (int) value; /* Address of NET INTERFACE
  87. * CONFIG 2 structure. */
  88. /* Read MAC address. */
  89. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
  90. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &mac[0], 8))
  91. goto err;
  92. buf[0] = mac[0] >> 24;
  93. buf[1] = mac[0] >> 16;
  94. buf[2] = mac[0] >> 8;
  95. buf[3] = mac[0];
  96. buf[4] = mac[1] >> 24;
  97. buf[5] = mac[1] >> 16;
  98. return 1; /* Found */
  99. err:
  100. printf("Read from EEPROM @ 0x%02x failed\n", CONFIG_SYS_I2C_EEPROM_ADDR);
  101. return 0;
  102. }
  103. /* Platform dependent initialisation. */
  104. int misc_init_r(void)
  105. {
  106. uint8_t i2cbuf;
  107. uint8_t eeprom_enetaddr[6];
  108. /* EMIF-A CS3 configuration for FPGA. */
  109. REG(DAVINCI_A3CR) = DAVINCI_A3CR_VAL;
  110. /* Configure I2C switch (PCA9543) to enable channel 0. */
  111. i2cbuf = CONFIG_SYS_I2C_PCA9543_ENABLE_CH0;
  112. if (i2c_write(CONFIG_SYS_I2C_PCA9543_ADDR, 0,
  113. CONFIG_SYS_I2C_PCA9543_ADDR_LEN, &i2cbuf, 1)) {
  114. printf("Write to MUX @ 0x%02x failed\n", CONFIG_SYS_I2C_PCA9543_ADDR);
  115. return 1;
  116. }
  117. /* Read Ethernet MAC address from EEPROM if available. */
  118. if (sffsdr_read_mac_address(eeprom_enetaddr))
  119. dv_configure_mac_address(eeprom_enetaddr);
  120. if (!eth_hw_init())
  121. printf("Ethernet init failed\n");
  122. return(0);
  123. }