km_arm.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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_init(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. /*
  150. * arch number of board
  151. */
  152. gd->bd->bi_arch_number = MACH_TYPE_SUEN3;
  153. /* address of boot parameters */
  154. gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
  155. #if defined(CONFIG_SOFT_I2C)
  156. /* init the GPIO for I2C Bitbang driver */
  157. kw_gpio_set_valid(SUEN3_SDA_PIN, 1);
  158. kw_gpio_set_valid(SUEN3_SCL_PIN, 1);
  159. kw_gpio_direction_output(SUEN3_SDA_PIN, 0);
  160. kw_gpio_direction_output(SUEN3_SCL_PIN, 0);
  161. #endif
  162. #if defined(CONFIG_SYS_EEPROM_WREN)
  163. kw_gpio_set_valid(SUEN3_ENV_WP, 38);
  164. kw_gpio_direction_output(SUEN3_ENV_WP, 1);
  165. #endif
  166. return 0;
  167. }
  168. #if defined(CONFIG_CMD_SF)
  169. int do_spi_toggle(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  170. {
  171. u32 tmp;
  172. if (argc < 2) {
  173. cmd_usage(cmdtp);
  174. return 1;
  175. }
  176. if ((strcmp(argv[1], "off") == 0)) {
  177. printf("SPI FLASH disabled, NAND enabled\n");
  178. /* Multi-Purpose Pins Functionality configuration */
  179. kwmpp_config[0] = MPP0_NF_IO2;
  180. kwmpp_config[1] = MPP1_NF_IO3;
  181. kwmpp_config[2] = MPP2_NF_IO4;
  182. kwmpp_config[3] = MPP3_NF_IO5;
  183. kirkwood_mpp_conf(kwmpp_config);
  184. tmp = readl(KW_GPIO0_BASE);
  185. writel(tmp | FLASH_GPIO_PIN , KW_GPIO0_BASE);
  186. } else if ((strcmp(argv[1], "on") == 0)) {
  187. printf("SPI FLASH enabled, NAND disabled\n");
  188. /* Multi-Purpose Pins Functionality configuration */
  189. kwmpp_config[0] = MPP0_SPI_SCn;
  190. kwmpp_config[1] = MPP1_SPI_MOSI;
  191. kwmpp_config[2] = MPP2_SPI_SCK;
  192. kwmpp_config[3] = MPP3_SPI_MISO;
  193. kirkwood_mpp_conf(kwmpp_config);
  194. tmp = readl(KW_GPIO0_BASE);
  195. writel(tmp & (~FLASH_GPIO_PIN) , KW_GPIO0_BASE);
  196. } else {
  197. cmd_usage(cmdtp);
  198. return 1;
  199. }
  200. return 0;
  201. }
  202. U_BOOT_CMD(
  203. spitoggle, 2, 0, do_spi_toggle,
  204. "En-/disable SPI FLASH access",
  205. "<on|off> - Enable (on) or disable (off) SPI FLASH access\n"
  206. );
  207. #endif
  208. int dram_init(void)
  209. {
  210. int i;
  211. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  212. gd->bd->bi_dram[i].start = kw_sdram_bar(i);
  213. gd->bd->bi_dram[i].size = get_ram_size((long *)kw_sdram_bar(i),
  214. kw_sdram_bs(i));
  215. }
  216. return 0;
  217. }
  218. /* Configure and enable MV88E1118 PHY */
  219. void reset_phy(void)
  220. {
  221. char *name = "egiga0";
  222. if (miiphy_set_current_dev(name))
  223. return;
  224. /* reset the phy */
  225. miiphy_reset(name, CONFIG_PHY_BASE_ADR);
  226. }
  227. #if defined(CONFIG_HUSH_INIT_VAR)
  228. int hush_init_var (void)
  229. {
  230. ivm_read_eeprom ();
  231. return 0;
  232. }
  233. #endif
  234. #if defined(CONFIG_BOOTCOUNT_LIMIT)
  235. void bootcount_store (ulong a)
  236. {
  237. volatile ulong *save_addr;
  238. volatile ulong size = 0;
  239. int i;
  240. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  241. size += gd->bd->bi_dram[i].size;
  242. }
  243. save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
  244. writel(a, save_addr);
  245. writel(BOOTCOUNT_MAGIC, &save_addr[1]);
  246. }
  247. ulong bootcount_load (void)
  248. {
  249. volatile ulong *save_addr;
  250. volatile ulong size = 0;
  251. int i;
  252. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  253. size += gd->bd->bi_dram[i].size;
  254. }
  255. save_addr = (ulong*)(size - BOOTCOUNT_ADDR);
  256. if (readl(&save_addr[1]) != BOOTCOUNT_MAGIC)
  257. return 0;
  258. else
  259. return readl(save_addr);
  260. }
  261. #endif
  262. #if defined(CONFIG_SOFT_I2C)
  263. void set_sda (int state)
  264. {
  265. I2C_ACTIVE;
  266. I2C_SDA(state);
  267. }
  268. void set_scl (int state)
  269. {
  270. I2C_SCL(state);
  271. }
  272. int get_sda (void)
  273. {
  274. I2C_TRISTATE;
  275. return I2C_READ;
  276. }
  277. int get_scl (void)
  278. {
  279. return (kw_gpio_get_value(SUEN3_SCL_PIN) ? 1 : 0);
  280. }
  281. #endif
  282. #if defined(CONFIG_SYS_EEPROM_WREN)
  283. int eeprom_write_enable (unsigned dev_addr, int state)
  284. {
  285. kw_gpio_set_value(SUEN3_ENV_WP, !state);
  286. return !kw_gpio_get_value(SUEN3_ENV_WP);
  287. }
  288. #endif