sffsdr.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/psc.h"
  33. #include "../common/misc.h"
  34. #define DAVINCI_A3CR (0x01E00014) /* EMIF-A CS3 config register. */
  35. #define DAVINCI_A3CR_VAL (0x3FFFFFFD) /* EMIF-A CS3 value for FPGA. */
  36. #define INTEGRITY_SYSCFG_OFFSET 0x7E8
  37. #define INTEGRITY_CHECKWORD_OFFSET 0x7F8
  38. #define INTEGRITY_CHECKWORD_VALUE 0x10ADBEEF
  39. DECLARE_GLOBAL_DATA_PTR;
  40. int board_init(void)
  41. {
  42. /* arch number of the board */
  43. gd->bd->bi_arch_number = MACH_TYPE_SFFSDR;
  44. /* address of boot parameters */
  45. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  46. davinci_errata_workarounds();
  47. /* Power on required peripherals */
  48. lpsc_on(DAVINCI_LPSC_GPIO);
  49. #if !defined(CONFIG_SYS_USE_DSPLINK)
  50. /* Powerup the DSP */
  51. dsp_on();
  52. #endif /* CONFIG_SYS_USE_DSPLINK */
  53. davinci_enable_uart0();
  54. davinci_enable_emac();
  55. davinci_enable_i2c();
  56. lpsc_on(DAVINCI_LPSC_TIMER1);
  57. timer_init();
  58. return(0);
  59. }
  60. /* Read ethernet MAC address from Integrity data structure inside EEPROM.
  61. * Returns 1 if found, 0 otherwise.
  62. */
  63. static int sffsdr_read_mac_address(uint8_t *buf)
  64. {
  65. u_int32_t value, mac[2], address;
  66. /* Read Integrity data structure checkword. */
  67. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_CHECKWORD_OFFSET,
  68. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  69. goto err;
  70. if (value != INTEGRITY_CHECKWORD_VALUE)
  71. return 0;
  72. /* Read SYSCFG structure offset. */
  73. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_SYSCFG_OFFSET,
  74. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  75. goto err;
  76. address = 0x800 + (int) value; /* Address of SYSCFG structure. */
  77. /* Read NET CONFIG structure offset. */
  78. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
  79. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  80. goto err;
  81. address = 0x800 + (int) value; /* Address of NET CONFIG structure. */
  82. address += 12; /* Address of NET INTERFACE CONFIG structure. */
  83. /* Read NET INTERFACE CONFIG 2 structure offset. */
  84. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
  85. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  86. goto err;
  87. address = 0x800 + 16 + (int) value; /* Address of NET INTERFACE
  88. * CONFIG 2 structure. */
  89. /* Read MAC address. */
  90. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
  91. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &mac[0], 8))
  92. goto err;
  93. buf[0] = mac[0] >> 24;
  94. buf[1] = mac[0] >> 16;
  95. buf[2] = mac[0] >> 8;
  96. buf[3] = mac[0];
  97. buf[4] = mac[1] >> 24;
  98. buf[5] = mac[1] >> 16;
  99. return 1; /* Found */
  100. err:
  101. printf("Read from EEPROM @ 0x%02x failed\n", CONFIG_SYS_I2C_EEPROM_ADDR);
  102. return 0;
  103. }
  104. /* Platform dependent initialisation. */
  105. int misc_init_r(void)
  106. {
  107. uint8_t i2cbuf;
  108. uint8_t eeprom_enetaddr[6];
  109. /* EMIF-A CS3 configuration for FPGA. */
  110. REG(DAVINCI_A3CR) = DAVINCI_A3CR_VAL;
  111. dv_display_clk_infos();
  112. /* Configure I2C switch (PCA9543) to enable channel 0. */
  113. i2cbuf = CONFIG_SYS_I2C_PCA9543_ENABLE_CH0;
  114. if (i2c_write(CONFIG_SYS_I2C_PCA9543_ADDR, 0,
  115. CONFIG_SYS_I2C_PCA9543_ADDR_LEN, &i2cbuf, 1)) {
  116. printf("Write to MUX @ 0x%02x failed\n", CONFIG_SYS_I2C_PCA9543_ADDR);
  117. return 1;
  118. }
  119. /* Read Ethernet MAC address from EEPROM if available. */
  120. if (sffsdr_read_mac_address(eeprom_enetaddr))
  121. dv_configure_mac_address(eeprom_enetaddr);
  122. if (!eth_hw_init())
  123. printf("Ethernet init failed\n");
  124. return(0);
  125. }