km_arm.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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 <asm/io.h>
  36. #include <asm/arch/cpu.h>
  37. #include <asm/arch/kirkwood.h>
  38. #include <asm/arch/mpp.h>
  39. #include "../common/common.h"
  40. DECLARE_GLOBAL_DATA_PTR;
  41. /*
  42. * BOCO FPGA definitions
  43. */
  44. #define BOCO 0x10
  45. #define REG_CTRL_H 0x02
  46. #define MASK_WRL_UNITRUN 0x01
  47. #define MASK_RBX_PGY_PRESENT 0x40
  48. #define REG_IRQ_CIRQ2 0x2d
  49. #define MASK_RBI_DEFECT_16 0x01
  50. /* Multi-Purpose Pins Functionality configuration */
  51. 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. MPP7_PEX_RST_OUTn,
  60. #if defined(CONFIG_SOFT_I2C)
  61. MPP8_GPIO, /* SDA */
  62. MPP9_GPIO, /* SCL */
  63. #endif
  64. #if defined(CONFIG_HARD_I2C)
  65. MPP8_TW_SDA,
  66. MPP9_TW_SCK,
  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. #if defined(CONFIG_MGCOGE3UN)
  111. /*
  112. * Wait for startup OK from mgcoge3ne
  113. */
  114. int startup_allowed(void)
  115. {
  116. unsigned char buf;
  117. /*
  118. * Read CIRQ16 bit (bit 0)
  119. */
  120. if (i2c_read(BOCO, REG_IRQ_CIRQ2, 1, &buf, 1) != 0)
  121. printf("%s: Error reading Boco\n", __func__);
  122. else
  123. if ((buf & MASK_RBI_DEFECT_16) == MASK_RBI_DEFECT_16)
  124. return 1;
  125. return 0;
  126. }
  127. #endif
  128. #if (defined(CONFIG_MGCOGE3UN)|defined(CONFIG_PORTL2))
  129. /*
  130. * These two boards have always ethernet present. Its connected to the mv
  131. * switch.
  132. */
  133. int ethernet_present(void)
  134. {
  135. return 1;
  136. }
  137. #else
  138. int ethernet_present(void)
  139. {
  140. uchar buf;
  141. int ret = 0;
  142. if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
  143. printf("%s: Error reading Boco\n", __func__);
  144. return -1;
  145. }
  146. if ((buf & MASK_RBX_PGY_PRESENT) == MASK_RBX_PGY_PRESENT)
  147. ret = 1;
  148. return ret;
  149. }
  150. #endif
  151. int initialize_unit_leds(void)
  152. {
  153. /*
  154. * Init the unit LEDs per default they all are
  155. * ok apart from bootstat
  156. */
  157. uchar buf;
  158. if (i2c_read(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
  159. printf("%s: Error reading Boco\n", __func__);
  160. return -1;
  161. }
  162. buf |= MASK_WRL_UNITRUN;
  163. if (i2c_write(BOCO, REG_CTRL_H, 1, &buf, 1) != 0) {
  164. printf("%s: Error writing Boco\n", __func__);
  165. return -1;
  166. }
  167. return 0;
  168. }
  169. #if defined(CONFIG_BOOTCOUNT_LIMIT)
  170. 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. setenv("bootcountaddr", (char *)buf);
  177. }
  178. #endif
  179. int misc_init_r(void)
  180. {
  181. char *str;
  182. int mach_type;
  183. str = getenv("mach_type");
  184. if (str != NULL) {
  185. mach_type = simple_strtoul(str, NULL, 10);
  186. printf("Overwriting MACH_TYPE with %d!!!\n", mach_type);
  187. gd->bd->bi_arch_number = mach_type;
  188. }
  189. #if defined(CONFIG_MGCOGE3UN)
  190. char *wait_for_ne;
  191. wait_for_ne = getenv("waitforne");
  192. if (wait_for_ne != NULL) {
  193. if (strcmp(wait_for_ne, "true") == 0) {
  194. int cnt = 0;
  195. int abort = 0;
  196. puts("NE go: ");
  197. while (startup_allowed() == 0) {
  198. if (tstc()) {
  199. (void) getc(); /* consume input */
  200. abort = 1;
  201. break;
  202. }
  203. udelay(200000);
  204. cnt++;
  205. if (cnt == 5)
  206. puts("wait\b\b\b\b");
  207. if (cnt == 10) {
  208. cnt = 0;
  209. puts(" \b\b\b\b");
  210. }
  211. }
  212. if (abort == 1)
  213. printf("\nAbort waiting for ne\n");
  214. else
  215. puts("OK\n");
  216. }
  217. }
  218. #endif
  219. initialize_unit_leds();
  220. set_km_env();
  221. #if defined(CONFIG_BOOTCOUNT_LIMIT)
  222. set_bootcount_addr();
  223. #endif
  224. return 0;
  225. }
  226. int board_early_init_f(void)
  227. {
  228. u32 tmp;
  229. kirkwood_mpp_conf(kwmpp_config);
  230. /*
  231. * The FLASH_GPIO_PIN switches between using a
  232. * NAND or a SPI FLASH. Set this pin on start
  233. * to NAND mode.
  234. */
  235. tmp = readl(KW_GPIO0_BASE);
  236. writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
  237. tmp = readl(KW_GPIO0_BASE + 4);
  238. writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
  239. #if defined(CONFIG_SOFT_I2C)
  240. /* init the GPIO for I2C Bitbang driver */
  241. kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
  242. kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
  243. kw_gpio_direction_output(KM_KIRKWOOD_SDA_PIN, 0);
  244. kw_gpio_direction_output(KM_KIRKWOOD_SCL_PIN, 0);
  245. #endif
  246. #if defined(CONFIG_SYS_EEPROM_WREN)
  247. kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
  248. kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
  249. #endif
  250. return 0;
  251. }
  252. int board_init(void)
  253. {
  254. /* address of boot parameters */
  255. gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
  256. return 0;
  257. }
  258. #if defined(CONFIG_CMD_SF)
  259. int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  260. {
  261. u32 tmp;
  262. if (argc < 2)
  263. return cmd_usage(cmdtp);
  264. if ((strcmp(argv[1], "off") == 0)) {
  265. printf("SPI FLASH disabled, NAND enabled\n");
  266. /* Multi-Purpose Pins Functionality configuration */
  267. kwmpp_config[0] = MPP0_NF_IO2;
  268. kwmpp_config[1] = MPP1_NF_IO3;
  269. kwmpp_config[2] = MPP2_NF_IO4;
  270. kwmpp_config[3] = MPP3_NF_IO5;
  271. kirkwood_mpp_conf(kwmpp_config);
  272. tmp = readl(KW_GPIO0_BASE);
  273. writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
  274. } else if ((strcmp(argv[1], "on") == 0)) {
  275. printf("SPI FLASH enabled, NAND disabled\n");
  276. /* Multi-Purpose Pins Functionality configuration */
  277. kwmpp_config[0] = MPP0_SPI_SCn;
  278. kwmpp_config[1] = MPP1_SPI_MOSI;
  279. kwmpp_config[2] = MPP2_SPI_SCK;
  280. kwmpp_config[3] = MPP3_SPI_MISO;
  281. kirkwood_mpp_conf(kwmpp_config);
  282. tmp = readl(KW_GPIO0_BASE);
  283. writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE);
  284. } else {
  285. return cmd_usage(cmdtp);
  286. }
  287. return 0;
  288. }
  289. U_BOOT_CMD(
  290. spitoggle, 2, 0, do_spi_toggle,
  291. "En-/disable SPI FLASH access",
  292. "<on|off> - Enable (on) or disable (off) SPI FLASH access\n"
  293. );
  294. #endif
  295. int dram_init(void)
  296. {
  297. /* dram_init must store complete ramsize in gd->ram_size */
  298. /* Fix this */
  299. gd->ram_size = get_ram_size((void *)kw_sdram_bar(0),
  300. kw_sdram_bs(0));
  301. return 0;
  302. }
  303. void dram_init_banksize(void)
  304. {
  305. int i;
  306. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  307. gd->bd->bi_dram[i].start = kw_sdram_bar(i);
  308. gd->bd->bi_dram[i].size = get_ram_size((long *)kw_sdram_bar(i),
  309. kw_sdram_bs(i));
  310. }
  311. }
  312. #if (defined(CONFIG_MGCOGE3UN)|defined(CONFIG_PORTL2))
  313. #define PHY_LED_SEL 0x18
  314. #define PHY_LED0_LINK (0x5)
  315. #define PHY_LED1_ACT (0x8<<4)
  316. #define PHY_LED2_INT (0xe<<8)
  317. #define PHY_SPEC_CTRL 0x1c
  318. #define PHY_RGMII_CLK_STABLE (0x1<<10)
  319. #define PHY_CLSA (0x1<<1)
  320. /* Configure and enable MV88E3018 PHY */
  321. void reset_phy(void)
  322. {
  323. char *name = "egiga0";
  324. unsigned short reg;
  325. if (miiphy_set_current_dev(name))
  326. return;
  327. /* RGMII clk transition on data stable */
  328. if (miiphy_read(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL, &reg) != 0)
  329. printf("Error reading PHY spec ctrl reg\n");
  330. if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_SPEC_CTRL,
  331. reg | PHY_RGMII_CLK_STABLE | PHY_CLSA) != 0)
  332. printf("Error writing PHY spec ctrl reg\n");
  333. /* leds setup */
  334. if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_LED_SEL,
  335. PHY_LED0_LINK | PHY_LED1_ACT | PHY_LED2_INT) != 0)
  336. printf("Error writing PHY LED reg\n");
  337. /* reset the phy */
  338. miiphy_reset(name, CONFIG_PHY_BASE_ADR);
  339. }
  340. #else
  341. /* Configure and enable MV88E1118 PHY on the piggy*/
  342. void reset_phy(void)
  343. {
  344. char *name = "egiga0";
  345. if (miiphy_set_current_dev(name))
  346. return;
  347. /* reset the phy */
  348. miiphy_reset(name, CONFIG_PHY_BASE_ADR);
  349. }
  350. #endif
  351. #if defined(CONFIG_HUSH_INIT_VAR)
  352. int hush_init_var(void)
  353. {
  354. ivm_read_eeprom();
  355. return 0;
  356. }
  357. #endif
  358. #if defined(CONFIG_BOOTCOUNT_LIMIT)
  359. void bootcount_store(ulong a)
  360. {
  361. volatile ulong *save_addr;
  362. volatile ulong size = 0;
  363. int i;
  364. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  365. size += gd->bd->bi_dram[i].size;
  366. }
  367. save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
  368. writel(a, save_addr);
  369. writel(BOOTCOUNT_MAGIC, &save_addr[1]);
  370. }
  371. ulong bootcount_load(void)
  372. {
  373. volatile ulong *save_addr;
  374. volatile ulong size = 0;
  375. int i;
  376. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  377. size += gd->bd->bi_dram[i].size;
  378. }
  379. save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
  380. if (readl(&save_addr[1]) != BOOTCOUNT_MAGIC)
  381. return 0;
  382. else
  383. return readl(save_addr);
  384. }
  385. #endif
  386. #if defined(CONFIG_SOFT_I2C)
  387. void set_sda(int state)
  388. {
  389. I2C_ACTIVE;
  390. I2C_SDA(state);
  391. }
  392. void set_scl(int state)
  393. {
  394. I2C_SCL(state);
  395. }
  396. int get_sda(void)
  397. {
  398. I2C_TRISTATE;
  399. return I2C_READ;
  400. }
  401. int get_scl(void)
  402. {
  403. return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
  404. }
  405. #endif
  406. #if defined(CONFIG_POST)
  407. #define KM_POST_EN_L 44
  408. #define POST_WORD_OFF 8
  409. int post_hotkeys_pressed(void)
  410. {
  411. return !kw_gpio_get_value(KM_POST_EN_L);
  412. }
  413. ulong post_word_load(void)
  414. {
  415. volatile void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
  416. return in_le32(addr);
  417. }
  418. void post_word_store(ulong value)
  419. {
  420. volatile void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF);
  421. out_le32(addr, value);
  422. }
  423. int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
  424. {
  425. *vstart = CONFIG_SYS_SDRAM_BASE;
  426. /* we go up to relocation plus a 1 MB margin */
  427. *size = CONFIG_SYS_TEXT_BASE - (1<<20);
  428. return 0;
  429. }
  430. #endif
  431. #if defined(CONFIG_SYS_EEPROM_WREN)
  432. int eeprom_write_enable(unsigned dev_addr, int state)
  433. {
  434. kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
  435. return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
  436. }
  437. #endif