ucp1020.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * Copyright 2013-2015 Arcturus Networks, Inc.
  3. * http://www.arcturusnetworks.com/products/ucp1020/
  4. * by Oleksandr G Zhadan et al.
  5. * based on board/freescale/p1_p2_rdb_pc/spl.c
  6. * original copyright follows:
  7. * Copyright 2013 Freescale Semiconductor, Inc.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <command.h>
  13. #include <hwconfig.h>
  14. #include <pci.h>
  15. #include <i2c.h>
  16. #include <miiphy.h>
  17. #include <libfdt.h>
  18. #include <fdt_support.h>
  19. #include <fsl_mdio.h>
  20. #include <tsec.h>
  21. #include <ioports.h>
  22. #include <netdev.h>
  23. #include <micrel.h>
  24. #include <spi_flash.h>
  25. #include <mmc.h>
  26. #include <linux/ctype.h>
  27. #include <asm/fsl_serdes.h>
  28. #include <asm/gpio.h>
  29. #include <asm/processor.h>
  30. #include <asm/mmu.h>
  31. #include <asm/cache.h>
  32. #include <asm/immap_85xx.h>
  33. #include <asm/fsl_pci.h>
  34. #include <fsl_ddr_sdram.h>
  35. #include <asm/io.h>
  36. #include <asm/fsl_law.h>
  37. #include <asm/fsl_lbc.h>
  38. #include <asm/mp.h>
  39. #include "ucp1020.h"
  40. void spi_set_speed(struct spi_slave *slave, uint hz)
  41. {
  42. /* TO DO: It's actially have to be in spi/ */
  43. }
  44. /*
  45. * To be compatible with cmd_gpio
  46. */
  47. int name_to_gpio(const char *name)
  48. {
  49. int gpio = 31 - simple_strtoul(name, NULL, 10);
  50. if (gpio < 16)
  51. gpio = -1;
  52. return gpio;
  53. }
  54. void board_gpio_init(void)
  55. {
  56. int i;
  57. char envname[8], *val;
  58. for (i = 0; i < GPIO_MAX_NUM; i++) {
  59. sprintf(envname, "GPIO%d", i);
  60. val = getenv(envname);
  61. if (val) {
  62. char direction = toupper(val[0]);
  63. char level = toupper(val[1]);
  64. if (direction == 'I') {
  65. gpio_direction_input(i);
  66. } else {
  67. if (direction == 'O') {
  68. if (level == '1')
  69. gpio_direction_output(i, 1);
  70. else
  71. gpio_direction_output(i, 0);
  72. }
  73. }
  74. }
  75. }
  76. val = getenv("PCIE_OFF");
  77. if (val) {
  78. gpio_direction_input(GPIO_PCIE1_EN);
  79. gpio_direction_input(GPIO_PCIE2_EN);
  80. } else {
  81. gpio_direction_output(GPIO_PCIE1_EN, 1);
  82. gpio_direction_output(GPIO_PCIE2_EN, 1);
  83. }
  84. val = getenv("SDHC_CDWP_OFF");
  85. if (!val) {
  86. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  87. setbits_be32(&gur->pmuxcr,
  88. (MPC85xx_PMUXCR_SDHC_CD | MPC85xx_PMUXCR_SDHC_WP));
  89. }
  90. }
  91. int board_early_init_f(void)
  92. {
  93. return 0; /* Just in case. Could be disable in config file */
  94. }
  95. int checkboard(void)
  96. {
  97. printf("Board: %s\n", CONFIG_BOARDNAME_LOCAL);
  98. board_gpio_init();
  99. printf("SD/MMC: 4-bit Mode\n");
  100. return 0;
  101. }
  102. #ifdef CONFIG_PCI
  103. void pci_init_board(void)
  104. {
  105. fsl_pcie_init_board(0);
  106. }
  107. #endif
  108. int board_early_init_r(void)
  109. {
  110. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  111. const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
  112. /*
  113. * Remap Boot flash region to caching-inhibited
  114. * so that flash can be erased properly.
  115. */
  116. /* Flush d-cache and invalidate i-cache of any FLASH data */
  117. flush_dcache();
  118. invalidate_icache();
  119. /* invalidate existing TLB entry for flash */
  120. disable_tlb(flash_esel);
  121. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */
  122. MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G, /* perms, wimge */
  123. 0, flash_esel, BOOKE_PAGESZ_64M, 1);/* ts, esel, tsize, iprot */
  124. return 0;
  125. }
  126. int board_phy_config(struct phy_device *phydev)
  127. {
  128. #if defined(CONFIG_PHY_MICREL_KSZ9021)
  129. int regval;
  130. static int cnt;
  131. if (cnt++ == 0)
  132. printf("PHYs address [");
  133. if (phydev->addr == TSEC1_PHY_ADDR || phydev->addr == TSEC3_PHY_ADDR) {
  134. regval =
  135. ksz9021_phy_extended_read(phydev,
  136. MII_KSZ9021_EXT_STRAP_STATUS);
  137. /*
  138. * min rx data delay
  139. */
  140. ksz9021_phy_extended_write(phydev,
  141. MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW,
  142. 0x6666);
  143. /*
  144. * max rx/tx clock delay, min rx/tx control
  145. */
  146. ksz9021_phy_extended_write(phydev,
  147. MII_KSZ9021_EXT_RGMII_CLOCK_SKEW,
  148. 0xf6f6);
  149. printf("0x%x", (regval & 0x1f));
  150. } else {
  151. printf("0x%x", (TSEC2_PHY_ADDR & 0x1f));
  152. }
  153. if (cnt == 3)
  154. printf("] ");
  155. else
  156. printf(",");
  157. #endif
  158. #if defined(CONFIG_PHY_MICREL_KSZ9031_DEBUG)
  159. regval = ksz9031_phy_extended_read(phydev, 2, 0x01, 0x4000);
  160. if (regval >= 0)
  161. printf(" (ADDR 0x%x) ", regval & 0x1f);
  162. #endif
  163. return 0;
  164. }
  165. int last_stage_init(void)
  166. {
  167. static char newkernelargs[256];
  168. static u8 id1[16];
  169. static u8 id2;
  170. struct mmc *mmc;
  171. char *sval, *kval;
  172. if (i2c_read(CONFIG_SYS_I2C_IDT6V49205B, 7, 1, &id1[0], 2) < 0) {
  173. printf("Error reading i2c IDT6V49205B information!\n");
  174. } else {
  175. printf("IDT6V49205B(0x%02x): ready\n", id1[1]);
  176. i2c_read(CONFIG_SYS_I2C_IDT6V49205B, 4, 1, &id1[0], 2);
  177. if (!(id1[1] & 0x02)) {
  178. id1[1] |= 0x02;
  179. i2c_write(CONFIG_SYS_I2C_IDT6V49205B, 4, 1, &id1[0], 2);
  180. asm("nop; nop");
  181. }
  182. }
  183. if (i2c_read(CONFIG_SYS_I2C_NCT72_ADDR, 0xFE, 1, &id2, 1) < 0)
  184. printf("Error reading i2c NCT72 information!\n");
  185. else
  186. printf("NCT72(0x%x): ready\n", id2);
  187. kval = getenv("kernelargs");
  188. mmc = find_mmc_device(0);
  189. if (mmc)
  190. if (!mmc_init(mmc)) {
  191. printf("MMC/SD card detected\n");
  192. if (kval) {
  193. int n = strlen(defkargs);
  194. char *tmp = strstr(kval, defkargs);
  195. *tmp = 0;
  196. strcpy(newkernelargs, kval);
  197. strcat(newkernelargs, " ");
  198. strcat(newkernelargs, mmckargs);
  199. strcat(newkernelargs, " ");
  200. strcat(newkernelargs, &tmp[n]);
  201. setenv("kernelargs", newkernelargs);
  202. } else {
  203. setenv("kernelargs", mmckargs);
  204. }
  205. }
  206. get_arc_info();
  207. if (kval) {
  208. sval = getenv("SERIAL");
  209. if (sval) {
  210. strcpy(newkernelargs, "SN=");
  211. strcat(newkernelargs, sval);
  212. strcat(newkernelargs, " ");
  213. strcat(newkernelargs, kval);
  214. setenv("kernelargs", newkernelargs);
  215. }
  216. } else {
  217. printf("Error reading kernelargs env variable!\n");
  218. }
  219. return 0;
  220. }
  221. int board_eth_init(bd_t *bis)
  222. {
  223. struct fsl_pq_mdio_info mdio_info;
  224. struct tsec_info_struct tsec_info[4];
  225. #ifdef CONFIG_TSEC2
  226. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  227. #endif
  228. int num = 0;
  229. #ifdef CONFIG_TSEC1
  230. SET_STD_TSEC_INFO(tsec_info[num], 1);
  231. num++;
  232. #endif
  233. #ifdef CONFIG_TSEC2
  234. SET_STD_TSEC_INFO(tsec_info[num], 2);
  235. if (is_serdes_configured(SGMII_TSEC2)) {
  236. if (!(in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_SGMII2_DIS)) {
  237. puts("eTSEC2 is in sgmii mode.\n");
  238. tsec_info[num].flags |= TSEC_SGMII;
  239. tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII;
  240. }
  241. }
  242. num++;
  243. #endif
  244. #ifdef CONFIG_TSEC3
  245. SET_STD_TSEC_INFO(tsec_info[num], 3);
  246. num++;
  247. #endif
  248. if (!num) {
  249. printf("No TSECs initialized\n");
  250. return 0;
  251. }
  252. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  253. mdio_info.name = DEFAULT_MII_NAME;
  254. fsl_pq_mdio_init(bis, &mdio_info);
  255. tsec_eth_init(bis, tsec_info, num);
  256. return pci_eth_init(bis);
  257. }
  258. #ifdef CONFIG_OF_BOARD_SETUP
  259. int ft_board_setup(void *blob, bd_t *bd)
  260. {
  261. phys_addr_t base;
  262. phys_size_t size;
  263. const char *soc_usb_compat = "fsl-usb2-dr";
  264. int err, usb1_off, usb2_off;
  265. ft_cpu_setup(blob, bd);
  266. base = getenv_bootm_low();
  267. size = getenv_bootm_size();
  268. fdt_fixup_memory(blob, (u64)base, (u64)size);
  269. FT_FSL_PCI_SETUP;
  270. #if defined(CONFIG_HAS_FSL_DR_USB)
  271. fsl_fdt_fixup_dr_usb(blob, bd);
  272. #endif
  273. #if defined(CONFIG_SDCARD) || defined(CONFIG_SPIFLASH)
  274. /* Delete eLBC node as it is muxed with USB2 controller */
  275. if (hwconfig("usb2")) {
  276. const char *soc_elbc_compat = "fsl,p1020-elbc";
  277. int off = fdt_node_offset_by_compatible(blob, -1,
  278. soc_elbc_compat);
  279. if (off < 0) {
  280. printf
  281. ("WARNING: could not find compatible node %s: %s\n",
  282. soc_elbc_compat, fdt_strerror(off));
  283. return off;
  284. }
  285. err = fdt_del_node(blob, off);
  286. if (err < 0) {
  287. printf("WARNING: could not remove %s: %s\n",
  288. soc_elbc_compat, fdt_strerror(err));
  289. }
  290. return err;
  291. }
  292. #endif
  293. /* Delete USB2 node as it is muxed with eLBC */
  294. usb1_off = fdt_node_offset_by_compatible(blob, -1, soc_usb_compat);
  295. if (usb1_off < 0) {
  296. printf("WARNING: could not find compatible node %s: %s.\n",
  297. soc_usb_compat, fdt_strerror(usb1_off));
  298. return usb1_off;
  299. }
  300. usb2_off =
  301. fdt_node_offset_by_compatible(blob, usb1_off, soc_usb_compat);
  302. if (usb2_off < 0) {
  303. printf("WARNING: could not find compatible node %s: %s.\n",
  304. soc_usb_compat, fdt_strerror(usb2_off));
  305. return usb2_off;
  306. }
  307. err = fdt_del_node(blob, usb2_off);
  308. if (err < 0) {
  309. printf("WARNING: could not remove %s: %s.\n",
  310. soc_usb_compat, fdt_strerror(err));
  311. }
  312. return 0;
  313. }
  314. #endif