sffsdr.c 4.9 KB

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