km_arm.c 7.2 KB

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