net2big_v2.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2011 Simon Guinot <sguinot@lacie.com>
  3. *
  4. * Based on Kirkwood support:
  5. * (C) Copyright 2009
  6. * Marvell Semiconductor <www.marvell.com>
  7. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. */
  22. #include <common.h>
  23. #include <miiphy.h>
  24. #include <netdev.h>
  25. #include <command.h>
  26. #include <i2c.h>
  27. #include <asm/arch/cpu.h>
  28. #include <asm/arch/kirkwood.h>
  29. #include <asm/arch/mpp.h>
  30. #include <asm/arch/gpio.h>
  31. #include "net2big_v2.h"
  32. DECLARE_GLOBAL_DATA_PTR;
  33. int board_early_init_f(void)
  34. {
  35. /* GPIO configuration */
  36. kw_config_gpio(NET2BIG_V2_OE_VAL_LOW, NET2BIG_V2_OE_VAL_HIGH,
  37. NET2BIG_V2_OE_LOW, NET2BIG_V2_OE_HIGH);
  38. /* Multi-Purpose Pins Functionality configuration */
  39. u32 kwmpp_config[] = {
  40. MPP0_SPI_SCn,
  41. MPP1_SPI_MOSI,
  42. MPP2_SPI_SCK,
  43. MPP3_SPI_MISO,
  44. MPP6_SYSRST_OUTn,
  45. MPP7_GPO, /* Request power-off */
  46. MPP8_TW_SDA,
  47. MPP9_TW_SCK,
  48. MPP10_UART0_TXD,
  49. MPP11_UART0_RXD,
  50. MPP13_GPIO, /* Rear power switch (on|auto) */
  51. MPP14_GPIO, /* USB fuse alarm */
  52. MPP15_GPIO, /* Rear power switch (auto|off) */
  53. MPP16_GPIO, /* SATA HDD1 power */
  54. MPP17_GPIO, /* SATA HDD2 power */
  55. MPP20_SATA1_ACTn,
  56. MPP21_SATA0_ACTn,
  57. MPP24_GPIO, /* USB mode select */
  58. MPP26_GPIO, /* USB device vbus */
  59. MPP28_GPIO, /* USB enable host vbus */
  60. MPP29_GPIO, /* GPIO extension ALE */
  61. MPP34_GPIO, /* Rear Push button 0=on 1=off */
  62. MPP35_GPIO, /* Inhibit switch power-off */
  63. MPP36_GPIO, /* SATA HDD1 presence */
  64. MPP37_GPIO, /* SATA HDD2 presence */
  65. MPP40_GPIO, /* eSATA presence */
  66. MPP44_GPIO, /* GPIO extension (data 0) */
  67. MPP45_GPIO, /* GPIO extension (data 1) */
  68. MPP46_GPIO, /* GPIO extension (data 2) */
  69. MPP47_GPIO, /* GPIO extension (addr 0) */
  70. MPP48_GPIO, /* GPIO extension (addr 1) */
  71. MPP49_GPIO, /* GPIO extension (addr 2) */
  72. 0
  73. };
  74. kirkwood_mpp_conf(kwmpp_config);
  75. return 0;
  76. }
  77. int board_init(void)
  78. {
  79. /* Machine number */
  80. gd->bd->bi_arch_number = MACH_TYPE_NET2BIG_V2;
  81. /* Boot parameters address */
  82. gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
  83. return 0;
  84. }
  85. int misc_init_r(void)
  86. {
  87. #ifdef CONFIG_CMD_I2C
  88. if (!getenv("ethaddr")) {
  89. ushort version;
  90. uchar mac[6];
  91. int ret;
  92. /* I2C-0 for on-board EEPROM */
  93. i2c_set_bus_num(0);
  94. /* Check layout version for EEPROM data */
  95. ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
  96. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  97. (uchar *) &version, 2);
  98. if (ret != 0) {
  99. printf("Error: failed to read I2C EEPROM @%02x\n",
  100. CONFIG_SYS_I2C_EEPROM_ADDR);
  101. return ret;
  102. }
  103. version = be16_to_cpu(version);
  104. if (version < 1 || version > 3) {
  105. printf("Error: unknown version %d for EEPROM data\n",
  106. version);
  107. return -1;
  108. }
  109. /* Read Ethernet MAC address from EEPROM */
  110. ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 2,
  111. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, mac, 6);
  112. if (ret != 0) {
  113. printf("Error: failed to read I2C EEPROM @%02x\n",
  114. CONFIG_SYS_I2C_EEPROM_ADDR);
  115. return ret;
  116. }
  117. eth_setenv_enetaddr("ethaddr", mac);
  118. }
  119. #endif /* CONFIG_CMD_I2C */
  120. return 0;
  121. }
  122. void mv_phy_88e1116_init(char *name)
  123. {
  124. u16 reg;
  125. u16 devadr;
  126. if (miiphy_set_current_dev(name))
  127. return;
  128. /* command to read PHY dev address */
  129. if (miiphy_read(name, 0xEE, 0xEE, (u16 *) &devadr)) {
  130. printf("Err..(%s) could not read PHY dev address\n", __func__);
  131. return;
  132. }
  133. /*
  134. * Enable RGMII delay on Tx and Rx for CPU port
  135. * Ref: sec 4.7.2 of chip datasheet
  136. */
  137. miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2);
  138. miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, &reg);
  139. reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
  140. miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg);
  141. miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0);
  142. /* reset the phy */
  143. if (miiphy_read(name, devadr, MII_BMCR, &reg) != 0) {
  144. printf("Err..(%s) PHY status read failed\n", __func__);
  145. return;
  146. }
  147. if (miiphy_write(name, devadr, MII_BMCR, reg | 0x8000) != 0) {
  148. printf("Err..(%s) PHY reset failed\n", __func__);
  149. return;
  150. }
  151. debug("88E1116 Initialized on %s\n", name);
  152. }
  153. /* Configure and initialize PHY */
  154. void reset_phy(void)
  155. {
  156. mv_phy_88e1116_init("egiga0");
  157. }
  158. /* Return GPIO push button status */
  159. static int
  160. do_read_push_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  161. {
  162. return !kw_gpio_get_value(NET2BIG_V2_GPIO_PUSH_BUTTON);
  163. }
  164. U_BOOT_CMD(button, 1, 1, do_read_push_button,
  165. "Return GPIO push button status 0=off 1=on", "");