sffsdr.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. #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. extern void timer_init(void);
  40. extern int eth_hw_init(void);
  41. extern phy_t phy;
  42. /* Works on Always On power domain only (no PD argument) */
  43. void lpsc_on(unsigned int id)
  44. {
  45. dv_reg_p mdstat, mdctl;
  46. if (id >= DAVINCI_LPSC_GEM)
  47. return; /* Don't work on DSP Power Domain */
  48. mdstat = REG_P(PSC_MDSTAT_BASE + (id * 4));
  49. mdctl = REG_P(PSC_MDCTL_BASE + (id * 4));
  50. while (REG(PSC_PTSTAT) & 0x01);
  51. if ((*mdstat & 0x1f) == 0x03)
  52. return; /* Already on and enabled */
  53. *mdctl |= 0x03;
  54. /* Special treatment for some modules as for sprue14 p.7.4.2 */
  55. switch (id) {
  56. case DAVINCI_LPSC_VPSSSLV:
  57. case DAVINCI_LPSC_EMAC:
  58. case DAVINCI_LPSC_EMAC_WRAPPER:
  59. case DAVINCI_LPSC_MDIO:
  60. case DAVINCI_LPSC_USB:
  61. case DAVINCI_LPSC_ATA:
  62. case DAVINCI_LPSC_VLYNQ:
  63. case DAVINCI_LPSC_UHPI:
  64. case DAVINCI_LPSC_DDR_EMIF:
  65. case DAVINCI_LPSC_AEMIF:
  66. case DAVINCI_LPSC_MMC_SD:
  67. case DAVINCI_LPSC_MEMSTICK:
  68. case DAVINCI_LPSC_McBSP:
  69. case DAVINCI_LPSC_GPIO:
  70. *mdctl |= 0x200;
  71. break;
  72. }
  73. REG(PSC_PTCMD) = 0x01;
  74. while (REG(PSC_PTSTAT) & 0x03);
  75. while ((*mdstat & 0x1f) != 0x03); /* Probably an overkill... */
  76. }
  77. #if !defined(CFG_USE_DSPLINK)
  78. void dsp_on(void)
  79. {
  80. int i;
  81. if (REG(PSC_PDSTAT1) & 0x1f)
  82. return; /* Already on */
  83. REG(PSC_GBLCTL) |= 0x01;
  84. REG(PSC_PDCTL1) |= 0x01;
  85. REG(PSC_PDCTL1) &= ~0x100;
  86. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) |= 0x03;
  87. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) &= 0xfffffeff;
  88. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) |= 0x03;
  89. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) &= 0xfffffeff;
  90. REG(PSC_PTCMD) = 0x02;
  91. for (i = 0; i < 100; i++) {
  92. if (REG(PSC_EPCPR) & 0x02)
  93. break;
  94. }
  95. REG(PSC_CHP_SHRTSW) = 0x01;
  96. REG(PSC_PDCTL1) |= 0x100;
  97. REG(PSC_EPCCR) = 0x02;
  98. for (i = 0; i < 100; i++) {
  99. if (!(REG(PSC_PTSTAT) & 0x02))
  100. break;
  101. }
  102. REG(PSC_GBLCTL) &= ~0x1f;
  103. }
  104. #endif /* CFG_USE_DSPLINK */
  105. int board_init(void)
  106. {
  107. /* arch number of the board */
  108. gd->bd->bi_arch_number = MACH_TYPE_SFFSDR;
  109. /* address of boot parameters */
  110. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  111. /* Workaround for TMS320DM6446 errata 1.3.22 */
  112. REG(PSC_SILVER_BULLET) = 0;
  113. /* Power on required peripherals */
  114. lpsc_on(DAVINCI_LPSC_EMAC);
  115. lpsc_on(DAVINCI_LPSC_EMAC_WRAPPER);
  116. lpsc_on(DAVINCI_LPSC_MDIO);
  117. lpsc_on(DAVINCI_LPSC_I2C);
  118. lpsc_on(DAVINCI_LPSC_UART0);
  119. lpsc_on(DAVINCI_LPSC_TIMER1);
  120. lpsc_on(DAVINCI_LPSC_GPIO);
  121. #if !defined(CFG_USE_DSPLINK)
  122. /* Powerup the DSP */
  123. dsp_on();
  124. #endif /* CFG_USE_DSPLINK */
  125. /* Bringup UART0 out of reset */
  126. REG(UART0_PWREMU_MGMT) = 0x0000e003;
  127. /* Enable GIO3.3V cells used for EMAC */
  128. REG(VDD3P3V_PWDN) = 0;
  129. /* Enable UART0 MUX lines */
  130. REG(PINMUX1) |= 1;
  131. /* Enable EMAC and AEMIF pins */
  132. REG(PINMUX0) = 0x80000c1f;
  133. /* Enable I2C pin Mux */
  134. REG(PINMUX1) |= (1 << 7);
  135. /* Set the Bus Priority Register to appropriate value */
  136. REG(VBPR) = 0x20;
  137. timer_init();
  138. return(0);
  139. }
  140. /* Read ethernet MAC address from Integrity data structure inside EEPROM. */
  141. int read_mac_address(uint8_t *buf)
  142. {
  143. u_int32_t value, mac[2], address;
  144. /* Read Integrity data structure checkword. */
  145. if (i2c_read(CFG_I2C_EEPROM_ADDR, INTEGRITY_CHECKWORD_OFFSET,
  146. CFG_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  147. goto err;
  148. if (value != INTEGRITY_CHECKWORD_VALUE)
  149. return 1;
  150. /* Read SYSCFG structure offset. */
  151. if (i2c_read(CFG_I2C_EEPROM_ADDR, INTEGRITY_SYSCFG_OFFSET,
  152. CFG_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  153. goto err;
  154. address = 0x800 + (int) value; /* Address of SYSCFG structure. */
  155. /* Read NET CONFIG structure offset. */
  156. if (i2c_read(CFG_I2C_EEPROM_ADDR, address,
  157. CFG_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  158. goto err;
  159. address = 0x800 + (int) value; /* Address of NET CONFIG structure. */
  160. address += 12; /* Address of NET INTERFACE CONFIG structure. */
  161. /* Read NET INTERFACE CONFIG 2 structure offset. */
  162. if (i2c_read(CFG_I2C_EEPROM_ADDR, address,
  163. CFG_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
  164. goto err;
  165. address = 0x800 + 16 + (int) value; /* Address of NET INTERFACE
  166. * CONFIG 2 structure. */
  167. /* Read MAC address. */
  168. if (i2c_read(CFG_I2C_EEPROM_ADDR, address,
  169. CFG_I2C_EEPROM_ADDR_LEN, (uint8_t *) &mac[0], 8))
  170. goto err;
  171. buf[0] = mac[0] >> 24;
  172. buf[1] = mac[0] >> 16;
  173. buf[2] = mac[0] >> 8;
  174. buf[3] = mac[0];
  175. buf[4] = mac[1] >> 24;
  176. buf[5] = mac[1] >> 16;
  177. return 0;
  178. err:
  179. printf("Read from EEPROM @ 0x%02x failed\n", CFG_I2C_EEPROM_ADDR);
  180. return 1;
  181. }
  182. /* Platform dependent initialisation. */
  183. int misc_init_r(void)
  184. {
  185. int i;
  186. u_int8_t i2cbuf;
  187. u_int8_t env_enetaddr[6], eeprom_enetaddr[6];
  188. char *tmp = getenv("ethaddr");
  189. char *end;
  190. int clk;
  191. /* EMIF-A CS3 configuration for FPGA. */
  192. REG(DAVINCI_A3CR) = DAVINCI_A3CR_VAL;
  193. clk = ((REG(PLL2_PLLM) + 1) * 27) / ((REG(PLL2_DIV2) & 0x1f) + 1);
  194. printf("ARM Clock: %dMHz\n", ((REG(PLL1_PLLM) + 1) * 27) / 2);
  195. printf("DDR Clock: %dMHz\n", (clk / 2));
  196. /* Configure I2C switch (PCA9543) to enable channel 0. */
  197. i2cbuf = CFG_I2C_PCA9543_ENABLE_CH0;
  198. if (i2c_write(CFG_I2C_PCA9543_ADDR, 0,
  199. CFG_I2C_PCA9543_ADDR_LEN, &i2cbuf, 1)) {
  200. printf("Write to MUX @ 0x%02x failed\n", CFG_I2C_PCA9543_ADDR);
  201. return 1;
  202. }
  203. /* Read Ethernet MAC address from the U-Boot environment. */
  204. for (i = 0; i < 6; i++) {
  205. env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
  206. if (tmp)
  207. tmp = (*end) ? end+1 : end;
  208. }
  209. /* Read Ethernet MAC address from EEPROM. */
  210. if (read_mac_address(eeprom_enetaddr) == 0) {
  211. if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6) != 0 &&
  212. memcmp(env_enetaddr, eeprom_enetaddr, 6) != 0) {
  213. printf("\nWarning: MAC addresses don't match:\n");
  214. printf("\tHW MAC address: "
  215. "%02X:%02X:%02X:%02X:%02X:%02X\n",
  216. eeprom_enetaddr[0], eeprom_enetaddr[1],
  217. eeprom_enetaddr[2], eeprom_enetaddr[3],
  218. eeprom_enetaddr[4], eeprom_enetaddr[5]);
  219. printf("\t\"ethaddr\" value: "
  220. "%02X:%02X:%02X:%02X:%02X:%02X\n",
  221. env_enetaddr[0], env_enetaddr[1],
  222. env_enetaddr[2], env_enetaddr[3],
  223. env_enetaddr[4], env_enetaddr[5]) ;
  224. debug("### Set MAC addr from environment\n");
  225. memcpy(eeprom_enetaddr, env_enetaddr, 6);
  226. }
  227. if (!tmp) {
  228. char ethaddr[20];
  229. sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
  230. eeprom_enetaddr[0], eeprom_enetaddr[1],
  231. eeprom_enetaddr[2], eeprom_enetaddr[3],
  232. eeprom_enetaddr[4], eeprom_enetaddr[5]) ;
  233. debug("### Set environment from HW MAC addr = \"%s\"\n",
  234. ethaddr);
  235. setenv("ethaddr", ethaddr);
  236. }
  237. }
  238. if (!eth_hw_init()) {
  239. printf("Ethernet init failed\n");
  240. } else {
  241. printf("ETH PHY: %s\n", phy.name);
  242. }
  243. /* On this platform, U-Boot is copied in RAM by the UBL,
  244. * so we are always in the relocated state. */
  245. gd->flags |= GD_FLG_RELOC;
  246. return(0);
  247. }
  248. int dram_init(void)
  249. {
  250. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  251. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  252. return(0);
  253. }