km_arm.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*
  2. * (C) Copyright 2009
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Prafulla Wadaskar <prafulla@marvell.com>
  5. *
  6. * (C) Copyright 2009
  7. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  8. *
  9. * (C) Copyright 2010
  10. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  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
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (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., 51 Franklin Street, Fifth Floor, Boston,
  28. * MA 02110-1301 USA
  29. */
  30. #include <common.h>
  31. #include <i2c.h>
  32. #include <nand.h>
  33. #include <netdev.h>
  34. #include <miiphy.h>
  35. #include <spi.h>
  36. #include <asm/io.h>
  37. #include <asm/arch/cpu.h>
  38. #include <asm/arch/kirkwood.h>
  39. #include <asm/arch/mpp.h>
  40. #include "../common/common.h"
  41. DECLARE_GLOBAL_DATA_PTR;
  42. /*
  43. * BOCO FPGA definitions
  44. */
  45. #define BOCO 0x10
  46. #define REG_CTRL_H 0x02
  47. #define MASK_WRL_UNITRUN 0x01
  48. #define MASK_RBX_PGY_PRESENT 0x40
  49. #define REG_IRQ_CIRQ2 0x2d
  50. #define MASK_RBI_DEFECT_16 0x01
  51. /* Multi-Purpose Pins Functionality configuration */
  52. u32 kwmpp_config[] = {
  53. MPP0_NF_IO2,
  54. MPP1_NF_IO3,
  55. MPP2_NF_IO4,
  56. MPP3_NF_IO5,
  57. MPP4_NF_IO6,
  58. MPP5_NF_IO7,
  59. MPP6_SYSRST_OUTn,
  60. MPP7_PEX_RST_OUTn,
  61. #if defined(CONFIG_SOFT_I2C)
  62. MPP8_GPIO, /* SDA */
  63. MPP9_GPIO, /* SCL */
  64. #endif
  65. #if defined(CONFIG_HARD_I2C)
  66. MPP8_TW_SDA,
  67. MPP9_TW_SCK,
  68. #endif
  69. MPP10_UART0_TXD,
  70. MPP11_UART0_RXD,
  71. MPP12_GPO, /* Reserved */
  72. MPP13_UART1_TXD,
  73. MPP14_UART1_RXD,
  74. MPP15_GPIO, /* Not used */
  75. MPP16_GPIO, /* Not used */
  76. MPP17_GPIO, /* Reserved */
  77. MPP18_NF_IO0,
  78. MPP19_NF_IO1,
  79. MPP20_GPIO,
  80. MPP21_GPIO,
  81. MPP22_GPIO,
  82. MPP23_GPIO,
  83. MPP24_GPIO,
  84. MPP25_GPIO,
  85. MPP26_GPIO,
  86. MPP27_GPIO,
  87. MPP28_GPIO,
  88. MPP29_GPIO,
  89. MPP30_GPIO,
  90. MPP31_GPIO,
  91. MPP32_GPIO,
  92. MPP33_GPIO,
  93. MPP34_GPIO, /* CDL1 (input) */
  94. MPP35_GPIO, /* CDL2 (input) */
  95. MPP36_GPIO, /* MAIN_IRQ (input) */
  96. MPP37_GPIO, /* BOARD_LED */
  97. MPP38_GPIO, /* Piggy3 LED[1] */
  98. MPP39_GPIO, /* Piggy3 LED[2] */
  99. MPP40_GPIO, /* Piggy3 LED[3] */
  100. MPP41_GPIO, /* Piggy3 LED[4] */
  101. MPP42_GPIO, /* Piggy3 LED[5] */
  102. MPP43_GPIO, /* Piggy3 LED[6] */
  103. MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */
  104. MPP45_GPIO, /* Piggy3 LED[8] */
  105. MPP46_GPIO, /* Reserved */
  106. MPP47_GPIO, /* Reserved */
  107. MPP48_GPIO, /* Reserved */
  108. MPP49_GPIO, /* SW_INTOUTn */
  109. 0
  110. };
  111. #if defined(CONFIG_KM_MGCOGE3UN)
  112. /*
  113. * Wait for startup OK from mgcoge3ne
  114. */
  115. 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. 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. #if defined(CONFIG_BOOTCOUNT_LIMIT)
  171. void set_bootcount_addr(void)
  172. {
  173. uchar buf[32];
  174. unsigned int bootcountaddr;
  175. bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR;
  176. sprintf((char *)buf, "0x%x", bootcountaddr);
  177. setenv("bootcountaddr", (char *)buf);
  178. }
  179. #endif
  180. int misc_init_r(void)
  181. {
  182. char *str;
  183. int mach_type;
  184. str = getenv("mach_type");
  185. if (str != NULL) {
  186. mach_type = simple_strtoul(str, NULL, 10);
  187. printf("Overwriting MACH_TYPE with %d!!!\n", mach_type);
  188. gd->bd->bi_arch_number = mach_type;
  189. }
  190. #if defined(CONFIG_KM_MGCOGE3UN)
  191. char *wait_for_ne;
  192. wait_for_ne = getenv("waitforne");
  193. if (wait_for_ne != NULL) {
  194. if (strcmp(wait_for_ne, "true") == 0) {
  195. int cnt = 0;
  196. int abort = 0;
  197. puts("NE go: ");
  198. while (startup_allowed() == 0) {
  199. if (tstc()) {
  200. (void) getc(); /* consume input */
  201. abort = 1;
  202. break;
  203. }
  204. udelay(200000);
  205. cnt++;
  206. if (cnt == 5)
  207. puts("wait\b\b\b\b");
  208. if (cnt == 10) {
  209. cnt = 0;
  210. puts(" \b\b\b\b");
  211. }
  212. }
  213. if (abort == 1)
  214. printf("\nAbort waiting for ne\n");
  215. else
  216. puts("OK\n");
  217. }
  218. }
  219. #endif
  220. initialize_unit_leds();
  221. set_km_env();
  222. #if defined(CONFIG_BOOTCOUNT_LIMIT)
  223. set_bootcount_addr();
  224. #endif
  225. return 0;
  226. }
  227. int board_early_init_f(void)
  228. {
  229. #if defined(CONFIG_SOFT_I2C)
  230. u32 tmp;
  231. /* set the 2 bitbang i2c pins as output gpios */
  232. tmp = readl(KW_GPIO0_BASE + 4);
  233. writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS) , KW_GPIO0_BASE + 4);
  234. #endif
  235. /* adjust SDRAM size for bank 0 */
  236. kw_sdram_size_adjust(0);
  237. kirkwood_mpp_conf(kwmpp_config, NULL);
  238. return 0;
  239. }
  240. int board_init(void)
  241. {
  242. /*
  243. * arch number of board
  244. */
  245. gd->bd->bi_arch_number = MACH_TYPE_KM_KIRKWOOD;
  246. /* address of boot parameters */
  247. gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
  248. /*
  249. * The KM_FLASH_GPIO_PIN switches between using a
  250. * NAND or a SPI FLASH. Set this pin on start
  251. * to NAND mode.
  252. */
  253. kw_gpio_set_valid(KM_FLASH_GPIO_PIN, 1);
  254. kw_gpio_direction_output(KM_FLASH_GPIO_PIN, 1);
  255. #if defined(CONFIG_SOFT_I2C)
  256. /*
  257. * Reinit the GPIO for I2C Bitbang driver so that the now
  258. * available gpio framework is consistent. The calls to
  259. * direction output in are not necessary, they are already done in
  260. * board_early_init_f
  261. */
  262. kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
  263. kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
  264. #endif
  265. #if defined(CONFIG_SYS_EEPROM_WREN)
  266. kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
  267. kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
  268. #endif
  269. #if defined(CONFIG_KM_FPGA_CONFIG)
  270. trigger_fpga_config();
  271. #endif
  272. return 0;
  273. }
  274. int board_late_init(void)
  275. {
  276. #if defined(CONFIG_KMCOGE5UN)
  277. /* I/O pin to erase flash RGPP09 = MPP43 */
  278. #define KM_FLASH_ERASE_ENABLE 43
  279. u8 dip_switch = kw_gpio_get_value(KM_FLASH_ERASE_ENABLE);
  280. /* if pin 1 do full erase */
  281. if (dip_switch != 0) {
  282. /* start bootloader */
  283. puts("DIP: Enabled\n");
  284. setenv("actual_bank", "0");
  285. }
  286. #endif
  287. #if defined(CONFIG_KM_FPGA_CONFIG)
  288. wait_for_fpga_config();
  289. fpga_reset();
  290. toggle_eeprom_spi_bus();
  291. #endif
  292. return 0;
  293. }
  294. int board_spi_claim_bus(struct spi_slave *slave)
  295. {
  296. kw_gpio_set_value(KM_FLASH_GPIO_PIN, 0);
  297. return 0;
  298. }
  299. void board_spi_release_bus(struct spi_slave *slave)
  300. {
  301. kw_gpio_set_value(KM_FLASH_GPIO_PIN, 1);
  302. }
  303. #if (defined(CONFIG_KM_PIGGY4_88E6061))
  304. #define PHY_LED_SEL_REG 0x18
  305. #define PHY_LED0_LINK (0x5)
  306. #define PHY_LED1_ACT (0x8<<4)
  307. #define PHY_LED2_INT (0xe<<8)
  308. #define PHY_SPEC_CTRL_REG 0x1c
  309. #define PHY_RGMII_CLK_STABLE (0x1<<10)
  310. #define PHY_CLSA (0x1<<1)
  311. /* Configure and enable MV88E3018 PHY */
  312. void reset_phy(void)
  313. {
  314. char *name = "egiga0";
  315. unsigned short reg;
  316. if (miiphy_set_current_dev(name))
  317. return;
  318. /* RGMII clk transition on data stable */
  319. if (!miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG, &reg))
  320. printf("Error reading PHY spec ctrl reg\n");
  321. if (!miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL_REG,
  322. reg | PHY_RGMII_CLK_STABLE | PHY_CLSA))
  323. printf("Error writing PHY spec ctrl reg\n");
  324. /* leds setup */
  325. if (!miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL_REG,
  326. PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT))
  327. printf("Error writing PHY LED reg\n");
  328. /* reset the phy */
  329. miiphy_reset(name, CONFIG_PHY_BASE_ADR);
  330. }
  331. #elif defined(CONFIG_KM_PIGGY4_88E6352)
  332. #include <mv88e6352.h>
  333. #if defined(CONFIG_KM_NUSA)
  334. struct mv88e_sw_reg extsw_conf[] = {
  335. /*
  336. * port 0, PIGGY4, autoneg
  337. * first the fix for the 1000Mbits Autoneg, this is from
  338. * a Marvell errata, the regs are undocumented
  339. */
  340. { PHY(0), PHY_PAGE, AN1000FIX_PAGE },
  341. { PHY(0), PHY_STATUS, AN1000FIX },
  342. { PHY(0), PHY_PAGE, 0 },
  343. /* now the real port and phy configuration */
  344. { PORT(0), PORT_PHY, NO_SPEED_FOR },
  345. { PORT(0), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
  346. { PHY(0), PHY_1000_CTRL, NO_ADV },
  347. { PHY(0), PHY_SPEC_CTRL, AUTO_MDIX_EN },
  348. { PHY(0), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST |
  349. FULL_DUPLEX },
  350. /* port 1, unused */
  351. { PORT(1), PORT_CTRL, PORT_DIS },
  352. { PHY(1), PHY_CTRL, PHY_PWR_DOWN },
  353. { PHY(1), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
  354. /* port 2, unused */
  355. { PORT(2), PORT_CTRL, PORT_DIS },
  356. { PHY(2), PHY_CTRL, PHY_PWR_DOWN },
  357. { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
  358. /* port 3, unused */
  359. { PORT(3), PORT_CTRL, PORT_DIS },
  360. { PHY(3), PHY_CTRL, PHY_PWR_DOWN },
  361. { PHY(3), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
  362. /* port 4, ICNEV, SerDes, SGMII */
  363. { PORT(4), PORT_STATUS, NO_PHY_DETECT },
  364. { PORT(4), PORT_PHY, SPEED_1000_FOR },
  365. { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
  366. { PHY(4), PHY_CTRL, PHY_PWR_DOWN },
  367. { PHY(4), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
  368. /* port 5, CPU_RGMII */
  369. { PORT(5), PORT_PHY, RX_RGMII_TIM | TX_RGMII_TIM | FLOW_CTRL_EN |
  370. FLOW_CTRL_FOR | LINK_VAL | LINK_FOR | FULL_DPX |
  371. FULL_DPX_FOR | SPEED_1000_FOR },
  372. { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
  373. /* port 6, unused, this port has no phy */
  374. { PORT(6), PORT_CTRL, PORT_DIS },
  375. };
  376. #else
  377. struct mv88e_sw_reg extsw_conf[] = {};
  378. #endif
  379. void reset_phy(void)
  380. {
  381. #if defined(CONFIG_KM_MVEXTSW_ADDR)
  382. char *name = "egiga0";
  383. if (miiphy_set_current_dev(name))
  384. return;
  385. mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf,
  386. ARRAY_SIZE(extsw_conf));
  387. mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR);
  388. #endif
  389. }
  390. #else
  391. /* Configure and enable MV88E1118 PHY on the piggy*/
  392. void reset_phy(void)
  393. {
  394. char *name = "egiga0";
  395. if (miiphy_set_current_dev(name))
  396. return;
  397. /* reset the phy */
  398. miiphy_reset(name, CONFIG_PHY_BASE_ADR);
  399. }
  400. #endif
  401. #if defined(CONFIG_HUSH_INIT_VAR)
  402. int hush_init_var(void)
  403. {
  404. ivm_read_eeprom();
  405. return 0;
  406. }
  407. #endif
  408. #if defined(CONFIG_SOFT_I2C)
  409. void set_sda(int state)
  410. {
  411. I2C_ACTIVE;
  412. I2C_SDA(state);
  413. }
  414. void set_scl(int state)
  415. {
  416. I2C_SCL(state);
  417. }
  418. int get_sda(void)
  419. {
  420. I2C_TRISTATE;
  421. return I2C_READ;
  422. }
  423. int get_scl(void)
  424. {
  425. return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
  426. }
  427. #endif
  428. #if defined(CONFIG_POST)
  429. #define KM_POST_EN_L 44
  430. #define POST_WORD_OFF 8
  431. int post_hotkeys_pressed(void)
  432. {
  433. #if defined(CONFIG_KM_COGE5UN)
  434. return kw_gpio_get_value(KM_POST_EN_L);
  435. #else
  436. return !kw_gpio_get_value(KM_POST_EN_L);
  437. #endif
  438. }
  439. ulong post_word_load(void)
  440. {
  441. void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
  442. return in_le32(addr);
  443. }
  444. void post_word_store(ulong value)
  445. {
  446. void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
  447. out_le32(addr, value);
  448. }
  449. int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  450. {
  451. *vstart = CONFIG_SYS_SDRAM_BASE;
  452. /* we go up to relocation plus a 1 MB margin */
  453. *size = CONFIG_SYS_TEXT_BASE - (1<<20);
  454. return 0;
  455. }
  456. #endif
  457. #if defined(CONFIG_SYS_EEPROM_WREN)
  458. int eeprom_write_enable(unsigned dev_addr, int state)
  459. {
  460. kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
  461. return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
  462. }
  463. #endif