sffsdr.c 8.1 KB

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