km_arm.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2009
  4. * Marvell Semiconductor <www.marvell.com>
  5. * Prafulla Wadaskar <prafulla@marvell.com>
  6. *
  7. * (C) Copyright 2009
  8. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  9. *
  10. * (C) Copyright 2010
  11. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  12. */
  13. #include <common.h>
  14. #include <i2c.h>
  15. #include <nand.h>
  16. #include <netdev.h>
  17. #include <miiphy.h>
  18. #include <spi.h>
  19. #include <asm/io.h>
  20. #include <asm/arch/cpu.h>
  21. #include <asm/arch/soc.h>
  22. #include <asm/arch/mpp.h>
  23. #include "../common/common.h"
  24. DECLARE_GLOBAL_DATA_PTR;
  25. /*
  26. * BOCO FPGA definitions
  27. */
  28. #define BOCO 0x10
  29. #define REG_CTRL_H 0x02
  30. #define MASK_WRL_UNITRUN 0x01
  31. #define MASK_RBX_PGY_PRESENT 0x40
  32. #define REG_IRQ_CIRQ2 0x2d
  33. #define MASK_RBI_DEFECT_16 0x01
  34. /*
  35. * PHY registers definitions
  36. */
  37. #define PHY_MARVELL_OUI 0x5043
  38. #define PHY_MARVELL_88E1118_MODEL 0x0022
  39. #define PHY_MARVELL_88E1118R_MODEL 0x0024
  40. #define PHY_MARVELL_PAGE_REG 0x0016
  41. #define PHY_MARVELL_DEFAULT_PAGE 0x0000
  42. #define PHY_MARVELL_88E1118R_LED_CTRL_PAGE 0x0003
  43. #define PHY_MARVELL_88E1118R_LED_CTRL_REG 0x0010
  44. #define PHY_MARVELL_88E1118R_LED_CTRL_RESERVED 0x1000
  45. #define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7<<0)
  46. #define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3<<4)
  47. #define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0<<8)
  48. /* I/O pin to erase flash RGPP09 = MPP43 */
  49. #define KM_FLASH_ERASE_ENABLE 43
  50. /* Multi-Purpose Pins Functionality configuration */
  51. static const u32 kwmpp_config[] = {
  52. MPP0_NF_IO2,
  53. MPP1_NF_IO3,
  54. MPP2_NF_IO4,
  55. MPP3_NF_IO5,
  56. MPP4_NF_IO6,
  57. MPP5_NF_IO7,
  58. MPP6_SYSRST_OUTn,
  59. #if defined(KM_PCIE_RESET_MPP7)
  60. MPP7_GPO,
  61. #else
  62. MPP7_PEX_RST_OUTn,
  63. #endif
  64. #if defined(CONFIG_SYS_I2C_SOFT)
  65. MPP8_GPIO, /* SDA */
  66. MPP9_GPIO, /* SCL */
  67. #endif
  68. MPP10_UART0_TXD,
  69. MPP11_UART0_RXD,
  70. MPP12_GPO, /* Reserved */
  71. MPP13_UART1_TXD,
  72. MPP14_UART1_RXD,
  73. MPP15_GPIO, /* Not used */
  74. MPP16_GPIO, /* Not used */
  75. MPP17_GPIO, /* Reserved */
  76. MPP18_NF_IO0,
  77. MPP19_NF_IO1,
  78. MPP20_GPIO,
  79. MPP21_GPIO,
  80. MPP22_GPIO,
  81. MPP23_GPIO,
  82. MPP24_GPIO,
  83. MPP25_GPIO,
  84. MPP26_GPIO,
  85. MPP27_GPIO,
  86. MPP28_GPIO,
  87. MPP29_GPIO,
  88. MPP30_GPIO,
  89. MPP31_GPIO,
  90. MPP32_GPIO,
  91. MPP33_GPIO,
  92. MPP34_GPIO, /* CDL1 (input) */
  93. MPP35_GPIO, /* CDL2 (input) */
  94. MPP36_GPIO, /* MAIN_IRQ (input) */
  95. MPP37_GPIO, /* BOARD_LED */
  96. MPP38_GPIO, /* Piggy3 LED[1] */
  97. MPP39_GPIO, /* Piggy3 LED[2] */
  98. MPP40_GPIO, /* Piggy3 LED[3] */
  99. MPP41_GPIO, /* Piggy3 LED[4] */
  100. MPP42_GPIO, /* Piggy3 LED[5] */
  101. MPP43_GPIO, /* Piggy3 LED[6] */
  102. MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */
  103. MPP45_GPIO, /* Piggy3 LED[8] */
  104. MPP46_GPIO, /* Reserved */
  105. MPP47_GPIO, /* Reserved */
  106. MPP48_GPIO, /* Reserved */
  107. MPP49_GPIO, /* SW_INTOUTn */
  108. 0
  109. };
  110. static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
  111. #if defined(CONFIG_KM_MGCOGE3UN)
  112. /*
  113. * Wait for startup OK from mgcoge3ne
  114. */
  115. static int startup_allowed(void)
  116. {
  117. unsigned char buf;
  118. /*
  119. * Read CIRQ16 bit (bit 0)
  120. */
  121. if (i2c_read(BOCO, REG_IRQ_CIRQ2, 1, &buf, 1) != 0)
  122. printf("%s: Error reading Boco\n", __func__);
  123. else
  124. if ((buf & MASK_RBI_DEFECT_16) == MASK_RBI_DEFECT_16)
  125. return 1;
  126. return 0;
  127. }
  128. #endif
  129. #if (defined(CONFIG_KM_PIGGY4_88E6061)|defined(CONFIG_KM_PIGGY4_88E6352))
  130. /*
  131. * All boards with PIGGY4 connected via a simple switch have ethernet always
  132. * present.
  133. */
  134. int ethernet_present(void)
  135. {
  136. return 1;
  137. }
  138. #else
  139. int ethernet_present(void)
  140. {
  141. uchar buf;
  142. int ret = 0;
  143. if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
  144. printf("%s: Error reading Boco\n", __func__);
  145. return -1;
  146. }
  147. if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT)
  148. ret = 1;
  149. return ret;
  150. }
  151. #endif
  152. static int initialize_unit_leds(void)
  153. {
  154. /*
  155. * Init the unit LEDs per default they all are
  156. * ok apart from bootstat
  157. */
  158. uchar buf;
  159. if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
  160. printf("%s: Error reading Boco\n", __func__);
  161. return -1;
  162. }
  163. buf |= MASK_WRL_UNITRUN;
  164. if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
  165. printf("%s: Error writing Boco\n", __func__);
  166. return -1;
  167. }
  168. return 0;
  169. }
  170. static void set_bootcount_addr(void)
  171. {
  172. uchar buf[32];
  173. unsigned int bootcountaddr;
  174. bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
  175. sprintf((char *)buf, "0x%x", bootcountaddr);
  176. env_set("bootcountaddr", (char *)buf);
  177. }
  178. int misc_init_r(void)
  179. {
  180. #if defined(CONFIG_KM_MGCOGE3UN)
  181. char *wait_for_ne;
  182. u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
  183. wait_for_ne = env_get("waitforne");
  184. if ((wait_for_ne != NULL) && (dip_switch == 0)) {
  185. if (strcmp(wait_for_ne, "true") == 0) {
  186. int cnt = 0;
  187. int abort = 0;
  188. puts("NE go: ");
  189. while (startup_allowed() == 0) {
  190. if (tstc()) {
  191. (void) getc(); /* consume input */
  192. abort = 1;
  193. break;
  194. }
  195. udelay(200000);
  196. cnt++;
  197. if (cnt == 5)
  198. puts("wait\b\b\b\b");
  199. if (cnt == 10) {
  200. cnt = 0;
  201. puts(" \b\b\b\b");
  202. }
  203. }
  204. if (abort == 1)
  205. printf("\nAbort waiting for ne\n");
  206. else
  207. puts("OK\n");
  208. }
  209. }
  210. #endif
  211. ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
  212. initialize_unit_leds();
  213. set_km_env();
  214. set_bootcount_addr();
  215. return 0;
  216. }
  217. int board_early_init_f(void)
  218. {
  219. #if defined(CONFIG_SYS_I2C_SOFT)
  220. u32 tmp;
  221. /* set the 2 bitbang i2c pins as output gpios */
  222. tmp = readl(MVEBU_GPIO0_BASE + 4);
  223. writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS) , MVEBU_GPIO0_BASE + 4);
  224. #endif
  225. /* adjust SDRAM size for bank 0 */
  226. mvebu_sdram_size_adjust(0);
  227. kirkwood_mpp_conf(kwmpp_config, NULL);
  228. return 0;
  229. }
  230. int board_init(void)
  231. {
  232. /* address of boot parameters */
  233. gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
  234. /*
  235. * The KM_FLASH_GPIO_PIN switches between using a
  236. * NAND or a SPI FLASH. Set this pin on start
  237. * to NAND mode.
  238. */
  239. kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
  240. kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
  241. #if defined(CONFIG_SYS_I2C_SOFT)
  242. /*
  243. * Reinit the GPIO for I2C Bitbang driver so that the now
  244. * available gpio framework is consistent. The calls to
  245. * direction output in are not necessary, they are already done in
  246. * board_early_init_f
  247. */
  248. kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
  249. kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
  250. #endif
  251. #if defined(CONFIG_SYS_EEPROM_WREN)
  252. kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
  253. kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
  254. #endif
  255. #if defined(CONFIG_KM_FPGA_CONFIG)
  256. trigger_fpga_config();
  257. #endif
  258. return 0;
  259. }
  260. int board_late_init(void)
  261. {
  262. #if (defined(CONFIG_KM_COGE5UN) | defined(CONFIG_KM_MGCOGE3UN))
  263. u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
  264. /* if pin 1 do full erase */
  265. if (dip_switch != 0) {
  266. /* start bootloader */
  267. puts("DIP: Enabled\n");
  268. env_set("actual_bank", "0");
  269. }
  270. #endif
  271. #if defined(CONFIG_KM_FPGA_CONFIG)
  272. wait_for_fpga_config();
  273. fpga_reset();
  274. toggle_eeprom_spi_bus();
  275. #endif
  276. return 0;
  277. }
  278. int board_spi_claim_bus(struct spi_slave *slave)
  279. {
  280. kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0);
  281. return 0;
  282. }
  283. void board_spi_release_bus(struct spi_slave *slave)
  284. {
  285. kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1);
  286. }
  287. #if (defined(CONFIG_KM_PIGGY4_88E6061))
  288. #define PHY_LED_SEL_REG 0x18
  289. #define PHY_LED0_LINK (0x5)
  290. #define PHY_LED1_ACT (0x8<<4)
  291. #define PHY_LED2_INT (0xe<<8)
  292. #define PHY_SPEC_CTRL_REG 0x1c
  293. #define PHY_RGMII_CLK_STABLE (0x1<<10)
  294. #define PHY_CLSA (0x1<<1)
  295. /* Configure and enable MV88E3018 PHY */
  296. void reset_phy(void)
  297. {
  298. char *name = "egiga0";
  299. unsigned short reg;
  300. if (miiphy_set_current_dev(name))
  301. return;
  302. /* RGMII clk transition on data stable */
  303. if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, &reg))
  304. printf("Error reading PHY spec ctrl reg\n");
  305. if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG,
  306. reg | PHY_RGMII_CLK_STABLE | PHY_CLSA))
  307. printf("Error writing PHY spec ctrl reg\n");
  308. /* leds setup */
  309. if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL_REG,
  310. PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT))
  311. printf("Error writing PHY LED reg\n");
  312. /* reset the phy */
  313. miiphy_reset(name, CONFIG_PHY_BASE_ADR);
  314. }
  315. #elif defined(CONFIG_KM_PIGGY4_88E6352)
  316. #include <mv88e6352.h>
  317. #if defined(CONFIG_KM_NUSA)
  318. struct mv88e_sw_reg extsw_conf[] = {
  319. /*
  320. * port 0, PIGGY4, autoneg
  321. * first the fix for the 1000Mbits Autoneg, this is from
  322. * a Marvell errata, the regs are undocumented
  323. */
  324. { PHY(0), PHY_PAGE, AN1000FIX_PAGE },
  325. { PHY(0), PHY_STATUS, AN1000FIX },
  326. { PHY(0), PHY_PAGE, 0 },
  327. /* now the real port and phy configuration */
  328. { PORT(0), PORT_PHY, NO_SPEED_FOR },
  329. { PORT(0), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
  330. { PHY(0), PHY_1000_CTRL, NO_ADV },
  331. { PHY(0), PHY_SPEC_CTRL, AUTO_MDIX_EN },
  332. { PHY(0), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST |
  333. FULL_DUPLEX },
  334. /* port 1, unused */
  335. { PORT(1), PORT_CTRL, PORT_DIS },
  336. { PHY(1), PHY_CTRL, PHY_PWR_DOWN },
  337. { PHY(1), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
  338. /* port 2, unused */
  339. { PORT(2), PORT_CTRL, PORT_DIS },
  340. { PHY(2), PHY_CTRL, PHY_PWR_DOWN },
  341. { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
  342. /* port 3, unused */
  343. { PORT(3), PORT_CTRL, PORT_DIS },
  344. { PHY(3), PHY_CTRL, PHY_PWR_DOWN },
  345. { PHY(3), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
  346. /* port 4, ICNEV, SerDes, SGMII */
  347. { PORT(4), PORT_STATUS, NO_PHY_DETECT },
  348. { PORT(4), PORT_PHY, SPEED_1000_FOR },
  349. { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
  350. { PHY(4), PHY_CTRL, PHY_PWR_DOWN },
  351. { PHY(4), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
  352. /* port 5, CPU_RGMII */
  353. { PORT(5), PORT_PHY, RX_RGMII_TIM | TX_RGMII_TIM | FLOW_CTRL_EN |
  354. FLOW_CTRL_FOR | LINK_VAL | LINK_FOR | FULL_DPX |
  355. FULL_DPX_FOR | SPEED_1000_FOR },
  356. { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
  357. /* port 6, unused, this port has no phy */
  358. { PORT(6), PORT_CTRL, PORT_DIS },
  359. };
  360. #else
  361. struct mv88e_sw_reg extsw_conf[] = {};
  362. #endif
  363. void reset_phy(void)
  364. {
  365. #if defined(CONFIG_KM_MVEXTSW_ADDR)
  366. char *name = "egiga0";
  367. if (miiphy_set_current_dev(name))
  368. return;
  369. mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf,
  370. ARRAY_SIZE(extsw_conf));
  371. mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR);
  372. #endif
  373. }
  374. #else
  375. /* Configure and enable MV88E1118 PHY on the piggy*/
  376. void reset_phy(void)
  377. {
  378. unsigned int oui;
  379. unsigned char model, rev;
  380. char *name = "egiga0";
  381. if (miiphy_set_current_dev(name))
  382. return;
  383. /* reset the phy */
  384. miiphy_reset(name, CONFIG_PHY_BASE_ADR);
  385. /* get PHY model */
  386. if (miiphy_info(name, CONFIG_PHY_BASE_ADR, &oui, &model, &rev))
  387. return;
  388. /* check for Marvell 88E1118R Gigabit PHY (PIGGY3) */
  389. if ((oui == PHY_MARVELL_OUI) &&
  390. (model == PHY_MARVELL_88E1118R_MODEL)) {
  391. /* set page register to 3 */
  392. if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
  393. PHY_MARVELL_PAGE_REG,
  394. PHY_MARVELL_88E1118R_LED_CTRL_PAGE))
  395. printf("Error writing PHY page reg\n");
  396. /*
  397. * leds setup as printed on PCB:
  398. * LED2 (Link): 0x0 (On Link, Off No Link)
  399. * LED1 (Activity): 0x3 (On Activity, Off No Activity)
  400. * LED0 (Speed): 0x7 (On 1000 MBits, Off Else)
  401. */
  402. if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
  403. PHY_MARVELL_88E1118R_LED_CTRL_REG,
  404. PHY_MARVELL_88E1118R_LED_CTRL_RESERVED |
  405. PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB |
  406. PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT |
  407. PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK))
  408. printf("Error writing PHY LED reg\n");
  409. /* set page register back to 0 */
  410. if (miiphy_write(name, CONFIG_PHY_BASE_ADR,
  411. PHY_MARVELL_PAGE_REG,
  412. PHY_MARVELL_DEFAULT_PAGE))
  413. printf("Error writing PHY page reg\n");
  414. }
  415. }
  416. #endif
  417. #if defined(CONFIG_HUSH_INIT_VAR)
  418. int hush_init_var(void)
  419. {
  420. ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
  421. return 0;
  422. }
  423. #endif
  424. #if defined(CONFIG_SYS_I2C_SOFT)
  425. void set_sda(int state)
  426. {
  427. I2C_ACTIVE;
  428. I2C_SDA(state);
  429. }
  430. void set_scl(int state)
  431. {
  432. I2C_SCL(state);
  433. }
  434. int get_sda(void)
  435. {
  436. I2C_TRISTATE;
  437. return I2C_READ;
  438. }
  439. int get_scl(void)
  440. {
  441. return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
  442. }
  443. #endif
  444. #if defined(CONFIG_POST)
  445. #define KM_POST_EN_L 44
  446. #define POST_WORD_OFF 8
  447. int post_hotkeys_pressed(void)
  448. {
  449. #if defined(CONFIG_KM_COGE5UN)
  450. return kw_gpio_get_value(KM_POST_EN_L);
  451. #else
  452. return !kw_gpio_get_value(KM_POST_EN_L);
  453. #endif
  454. }
  455. ulong post_word_load(void)
  456. {
  457. void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
  458. return in_le32(addr);
  459. }
  460. void post_word_store(ulong value)
  461. {
  462. void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
  463. out_le32(addr, value);
  464. }
  465. int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  466. {
  467. *vstart = CONFIG_SYS_SDRAM_BASE;
  468. /* we go up to relocation plus a 1 MB margin */
  469. *size = CONFIG_SYS_TEXT_BASE - (1<<20);
  470. return 0;
  471. }
  472. #endif
  473. #if defined(CONFIG_SYS_EEPROM_WREN)
  474. int eeprom_write_enable(unsigned dev_addr, int state)
  475. {
  476. kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
  477. return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
  478. }
  479. #endif