netspace_v2.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <asm/arch/kirkwood.h>
  27. #include <asm/arch/mpp.h>
  28. #include <asm/arch/gpio.h>
  29. #include "netspace_v2.h"
  30. DECLARE_GLOBAL_DATA_PTR;
  31. int board_early_init_f(void)
  32. {
  33. /* Gpio configuration */
  34. kw_config_gpio(NETSPACE_V2_OE_VAL_LOW, NETSPACE_V2_OE_VAL_HIGH,
  35. NETSPACE_V2_OE_LOW, NETSPACE_V2_OE_HIGH);
  36. /* Multi-Purpose Pins Functionality configuration */
  37. u32 kwmpp_config[] = {
  38. MPP0_SPI_SCn,
  39. MPP1_SPI_MOSI,
  40. MPP2_SPI_SCK,
  41. MPP3_SPI_MISO,
  42. MPP4_NF_IO6,
  43. MPP5_NF_IO7,
  44. MPP6_SYSRST_OUTn,
  45. MPP7_GPO, /* Fan speed (bit 1) */
  46. MPP8_TW_SDA,
  47. MPP9_TW_SCK,
  48. MPP10_UART0_TXD,
  49. MPP11_UART0_RXD,
  50. MPP12_GPO, /* Red led */
  51. MPP14_GPIO, /* USB fuse */
  52. MPP16_GPIO, /* SATA 0 power */
  53. MPP17_GPIO, /* SATA 1 power */
  54. MPP18_NF_IO0,
  55. MPP19_NF_IO1,
  56. MPP20_SATA1_ACTn,
  57. MPP21_SATA0_ACTn,
  58. MPP22_GPIO, /* Fan speed (bit 0) */
  59. MPP23_GPIO, /* Fan power */
  60. MPP24_GPIO, /* USB mode select */
  61. MPP25_GPIO, /* Fan rotation fail */
  62. MPP26_GPIO, /* USB vbus-in detection */
  63. MPP28_GPIO, /* USB enable vbus-out */
  64. MPP29_GPIO, /* Blue led (slow register) */
  65. MPP30_GPIO, /* Blue led (command register) */
  66. MPP31_GPIO, /* Board power off */
  67. MPP32_GPIO, /* Button (0 = Released, 1 = Pushed) */
  68. MPP33_GPIO, /* Fan speed (bit 2) */
  69. 0
  70. };
  71. kirkwood_mpp_conf(kwmpp_config);
  72. return 0;
  73. }
  74. int board_init(void)
  75. {
  76. /* Machine number */
  77. gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
  78. /* Boot parameters address */
  79. gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
  80. return 0;
  81. }
  82. void mv_phy_88e1116_init(char *name)
  83. {
  84. u16 reg;
  85. u16 devadr;
  86. if (miiphy_set_current_dev(name))
  87. return;
  88. /* command to read PHY dev address */
  89. if (miiphy_read(name, 0xEE, 0xEE, (u16 *) &devadr)) {
  90. printf("Err..(%s) could not read PHY dev address\n", __func__);
  91. return;
  92. }
  93. /*
  94. * Enable RGMII delay on Tx and Rx for CPU port
  95. * Ref: sec 4.7.2 of chip datasheet
  96. */
  97. miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2);
  98. miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, &reg);
  99. reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
  100. miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg);
  101. miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0);
  102. /* reset the phy */
  103. if (miiphy_read(name, devadr, MII_BMCR, &reg) != 0) {
  104. printf("Err..(%s) PHY status read failed\n", __func__);
  105. return;
  106. }
  107. if (miiphy_write(name, devadr, MII_BMCR, reg | 0x8000) != 0) {
  108. printf("Err..(%s) PHY reset failed\n", __func__);
  109. return;
  110. }
  111. debug("88E1116 Initialized on %s\n", name);
  112. }
  113. /* Configure and initialize PHY */
  114. void reset_phy(void)
  115. {
  116. mv_phy_88e1116_init("egiga0");
  117. }
  118. /* Return GPIO button status */
  119. static int
  120. do_read_button(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  121. {
  122. return kw_gpio_get_value(NETSPACE_V2_GPIO_BUTTON);
  123. }
  124. U_BOOT_CMD(button, 1, 1, do_read_button,
  125. "Return GPIO button status 0=off 1=on", "");