km_arm.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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/kirkwood.h>
  37. #include <asm/arch/mpp.h>
  38. #include "../common/common.h"
  39. DECLARE_GLOBAL_DATA_PTR;
  40. /* Multi-Purpose Pins Functionality configuration */
  41. u32 kwmpp_config[] = {
  42. MPP0_NF_IO2,
  43. MPP1_NF_IO3,
  44. MPP2_NF_IO4,
  45. MPP3_NF_IO5,
  46. MPP4_NF_IO6,
  47. MPP5_NF_IO7,
  48. MPP6_SYSRST_OUTn,
  49. MPP7_PEX_RST_OUTn,
  50. #if defined(CONFIG_SOFT_I2C)
  51. MPP8_GPIO, /* SDA */
  52. MPP9_GPIO, /* SCL */
  53. #endif
  54. #if defined(CONFIG_HARD_I2C)
  55. MPP8_TW_SDA,
  56. MPP9_TW_SCK,
  57. #endif
  58. MPP10_UART0_TXD,
  59. MPP11_UART0_RXD,
  60. MPP12_GPO, /* Reserved */
  61. MPP13_UART1_TXD,
  62. MPP14_UART1_RXD,
  63. MPP15_GPIO, /* Not used */
  64. MPP16_GPIO, /* Not used */
  65. MPP17_GPIO, /* Reserved */
  66. MPP18_NF_IO0,
  67. MPP19_NF_IO1,
  68. MPP20_GPIO,
  69. MPP21_GPIO,
  70. MPP22_GPIO,
  71. MPP23_GPIO,
  72. MPP24_GPIO,
  73. MPP25_GPIO,
  74. MPP26_GPIO,
  75. MPP27_GPIO,
  76. MPP28_GPIO,
  77. MPP29_GPIO,
  78. MPP30_GPIO,
  79. MPP31_GPIO,
  80. MPP32_GPIO,
  81. MPP33_GPIO,
  82. MPP34_GPIO, /* CDL1 (input) */
  83. MPP35_GPIO, /* CDL2 (input) */
  84. MPP36_GPIO, /* MAIN_IRQ (input) */
  85. MPP37_GPIO, /* BOARD_LED */
  86. MPP38_GPIO, /* Piggy3 LED[1] */
  87. MPP39_GPIO, /* Piggy3 LED[2] */
  88. MPP40_GPIO, /* Piggy3 LED[3] */
  89. MPP41_GPIO, /* Piggy3 LED[4] */
  90. MPP42_GPIO, /* Piggy3 LED[5] */
  91. MPP43_GPIO, /* Piggy3 LED[6] */
  92. MPP44_GPIO, /* Piggy3 LED[7], BIST_EN_L */
  93. MPP45_GPIO, /* Piggy3 LED[8] */
  94. MPP46_GPIO, /* Reserved */
  95. MPP47_GPIO, /* Reserved */
  96. MPP48_GPIO, /* Reserved */
  97. MPP49_GPIO, /* SW_INTOUTn */
  98. 0
  99. };
  100. int ethernet_present(void)
  101. {
  102. uchar buf;
  103. int ret = 0;
  104. if (i2c_read(0x10, 2, 1, &buf, 1) != 0) {
  105. printf("%s: Error reading Boco\n", __func__);
  106. return -1;
  107. }
  108. if ((buf & 0x40) == 0x40)
  109. ret = 1;
  110. return ret;
  111. }
  112. int initialize_unit_leds(void)
  113. {
  114. /*
  115. * init the unit LEDs
  116. * per default they all are
  117. * ok apart from bootstat
  118. * LED connected through BOCO
  119. * BOCO lies at the address 0x10
  120. * LEDs are in the block CTRL_H (addr 0x02)
  121. * BOOTSTAT LED is the first 0x01
  122. */
  123. #define BOCO 0x10
  124. #define CTRL_H 0x02
  125. #define APPLEDMASK 0x01
  126. uchar buf;
  127. if (i2c_read(BOCO, CTRL_H, 1, &buf, 1) != 0) {
  128. printf("%s: Error reading Boco\n", __func__);
  129. return -1;
  130. }
  131. buf |= APPLEDMASK;
  132. if (i2c_write(BOCO, CTRL_H, 1, &buf, 1) != 0) {
  133. printf("%s: Error writing Boco\n", __func__);
  134. return -1;
  135. }
  136. return 0;
  137. }
  138. int misc_init_r(void)
  139. {
  140. char *str;
  141. int mach_type;
  142. puts("Piggy:");
  143. if (ethernet_present() == 0)
  144. puts (" not");
  145. puts(" present\n");
  146. str = getenv("mach_type");
  147. if (str != NULL) {
  148. mach_type = simple_strtoul(str, NULL, 10);
  149. printf("Overwriting MACH_TYPE with %d!!!\n", mach_type);
  150. gd->bd->bi_arch_number = mach_type;
  151. }
  152. initialize_unit_leds();
  153. return 0;
  154. }
  155. int board_early_init_f(void)
  156. {
  157. u32 tmp;
  158. kirkwood_mpp_conf(kwmpp_config);
  159. /*
  160. * The FLASH_GPIO_PIN switches between using a
  161. * NAND or a SPI FLASH. Set this pin on start
  162. * to NAND mode.
  163. */
  164. tmp = readl(KW_GPIO0_BASE);
  165. writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
  166. tmp = readl(KW_GPIO0_BASE + 4);
  167. writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE + 4);
  168. printf("KM: setting NAND mode\n");
  169. #if defined(CONFIG_SOFT_I2C)
  170. /* init the GPIO for I2C Bitbang driver */
  171. kw_gpio_set_valid(KM_KIRKWOOD_SDA_PIN, 1);
  172. kw_gpio_set_valid(KM_KIRKWOOD_SCL_PIN, 1);
  173. kw_gpio_direction_output(KM_KIRKWOOD_SDA_PIN, 0);
  174. kw_gpio_direction_output(KM_KIRKWOOD_SCL_PIN, 0);
  175. #endif
  176. #if defined(CONFIG_SYS_EEPROM_WREN)
  177. kw_gpio_set_valid(KM_KIRKWOOD_ENV_WP, 38);
  178. kw_gpio_direction_output(KM_KIRKWOOD_ENV_WP, 1);
  179. #endif
  180. return 0;
  181. }
  182. int board_init(void)
  183. {
  184. /*
  185. * arch number of board
  186. */
  187. gd->bd->bi_arch_number = MACH_TYPE_KM_KIRKWOOD;
  188. /* address of boot parameters */
  189. gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
  190. return 0;
  191. }
  192. int last_stage_init(void)
  193. {
  194. set_km_env();
  195. return 0;
  196. }
  197. #if defined(CONFIG_CMD_SF)
  198. int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  199. {
  200. u32 tmp;
  201. if (argc < 2)
  202. return cmd_usage(cmdtp);
  203. if ((strcmp(argv[1], "off") == 0)) {
  204. printf("SPI FLASH disabled, NAND enabled\n");
  205. /* Multi-Purpose Pins Functionality configuration */
  206. kwmpp_config[0] = MPP0_NF_IO2;
  207. kwmpp_config[1] = MPP1_NF_IO3;
  208. kwmpp_config[2] = MPP2_NF_IO4;
  209. kwmpp_config[3] = MPP3_NF_IO5;
  210. kirkwood_mpp_conf(kwmpp_config);
  211. tmp = readl(KW_GPIO0_BASE);
  212. writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
  213. } else if ((strcmp(argv[1], "on") == 0)) {
  214. printf("SPI FLASH enabled, NAND disabled\n");
  215. /* Multi-Purpose Pins Functionality configuration */
  216. kwmpp_config[0] = MPP0_SPI_SCn;
  217. kwmpp_config[1] = MPP1_SPI_MOSI;
  218. kwmpp_config[2] = MPP2_SPI_SCK;
  219. kwmpp_config[3] = MPP3_SPI_MISO;
  220. kirkwood_mpp_conf(kwmpp_config);
  221. tmp = readl(KW_GPIO0_BASE);
  222. writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE);
  223. } else {
  224. return cmd_usage(cmdtp);
  225. }
  226. return 0;
  227. }
  228. U_BOOT_CMD(
  229. spitoggle, 2, 0, do_spi_toggle,
  230. "En-/disable SPI FLASH access",
  231. "<on|off> - Enable (on) or disable (off) SPI FLASH access\n"
  232. );
  233. #endif
  234. int dram_init(void)
  235. {
  236. /* dram_init must store complete ramsize in gd->ram_size */
  237. /* Fix this */
  238. gd->ram_size = get_ram_size((volatile void *)kw_sdram_bar(0),
  239. kw_sdram_bs(0));
  240. return 0;
  241. }
  242. void dram_init_banksize(void)
  243. {
  244. int i;
  245. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  246. gd->bd->bi_dram[i].start = kw_sdram_bar(i);
  247. gd->bd->bi_dram[i].size = get_ram_size((long *)kw_sdram_bar(i),
  248. kw_sdram_bs(i));
  249. }
  250. }
  251. /* Configure and enable MV88E1118 PHY */
  252. void reset_phy(void)
  253. {
  254. char *name = "egiga0";
  255. if (miiphy_set_current_dev(name))
  256. return;
  257. /* reset the phy */
  258. miiphy_reset(name, CONFIG_PHY_BASE_ADR);
  259. }
  260. #if defined(CONFIG_HUSH_INIT_VAR)
  261. int hush_init_var(void)
  262. {
  263. ivm_read_eeprom();
  264. return 0;
  265. }
  266. #endif
  267. #if defined(CONFIG_BOOTCOUNT_LIMIT)
  268. void bootcount_store(ulong a)
  269. {
  270. volatile ulong *save_addr;
  271. volatile ulong size = 0;
  272. int i;
  273. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  274. size += gd->bd->bi_dram[i].size;
  275. }
  276. save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
  277. writel(a, save_addr);
  278. writel(BOOTCOUNT_MAGIC, &save_addr[1]);
  279. }
  280. ulong bootcount_load(void)
  281. {
  282. volatile ulong *save_addr;
  283. volatile ulong size = 0;
  284. int i;
  285. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  286. size += gd->bd->bi_dram[i].size;
  287. }
  288. save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
  289. if (readl(&save_addr[1]) != BOOTCOUNT_MAGIC)
  290. return 0;
  291. else
  292. return readl(save_addr);
  293. }
  294. #endif
  295. #if defined(CONFIG_SOFT_I2C)
  296. void set_sda(int state)
  297. {
  298. I2C_ACTIVE;
  299. I2C_SDA(state);
  300. }
  301. void set_scl(int state)
  302. {
  303. I2C_SCL(state);
  304. }
  305. int get_sda(void)
  306. {
  307. I2C_TRISTATE;
  308. return I2C_READ;
  309. }
  310. int get_scl(void)
  311. {
  312. return kw_gpio_get_value(KM_KIRKWOOD_SCL_PIN) ? 1 : 0;
  313. }
  314. #endif
  315. #if defined(CONFIG_SYS_EEPROM_WREN)
  316. int eeprom_write_enable(unsigned dev_addr, int state)
  317. {
  318. kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state);
  319. return !kw_gpio_get_value(KM_KIRKWOOD_ENV_WP);
  320. }
  321. #endif