ds109.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2009-2012
  3. * Wojciech Dubowik <wojciech.dubowik@neratec.com>
  4. * Luka Perkov <luka@openwrt.org>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <miiphy.h>
  10. #include <asm/arch/cpu.h>
  11. #include <asm/arch/soc.h>
  12. #include <asm/arch/mpp.h>
  13. #include "ds109.h"
  14. DECLARE_GLOBAL_DATA_PTR;
  15. int board_early_init_f(void)
  16. {
  17. /*
  18. * default gpio configuration
  19. * There are maximum 64 gpios controlled through 2 sets of registers
  20. * the below configuration configures mainly initial LED status
  21. */
  22. mvebu_config_gpio(DS109_OE_VAL_LOW,
  23. DS109_OE_VAL_HIGH,
  24. DS109_OE_LOW, DS109_OE_HIGH);
  25. /* Multi-Purpose Pins Functionality configuration */
  26. static const u32 kwmpp_config[] = {
  27. MPP0_SPI_SCn, /* SPI Flash */
  28. MPP1_SPI_MOSI,
  29. MPP2_SPI_SCK,
  30. MPP3_SPI_MISO,
  31. MPP4_GPIO,
  32. MPP5_GPO,
  33. MPP6_SYSRST_OUTn, /* Reset signal */
  34. MPP7_GPO,
  35. MPP8_TW_SDA, /* I2C */
  36. MPP9_TW_SCK, /* I2C */
  37. MPP10_UART0_TXD,
  38. MPP11_UART0_RXD,
  39. MPP12_GPO,
  40. MPP13_UART1_TXD,
  41. MPP14_UART1_RXD,
  42. MPP15_GPIO,
  43. MPP16_GPIO,
  44. MPP17_GPIO,
  45. MPP18_GPO,
  46. MPP19_GPO,
  47. MPP20_SATA1_ACTn,
  48. MPP21_SATA0_ACTn,
  49. MPP22_GPIO, /* HDD2 FAIL LED */
  50. MPP23_GPIO, /* HDD1 FAIL LED */
  51. MPP24_GPIO,
  52. MPP25_GPIO,
  53. MPP26_GPIO,
  54. MPP27_GPIO,
  55. MPP28_GPIO,
  56. MPP29_GPIO,
  57. MPP30_GPIO,
  58. MPP31_GPIO, /* HDD2 */
  59. MPP32_GPIO, /* FAN A */
  60. MPP33_GPIO, /* FAN B */
  61. MPP34_GPIO, /* FAN C */
  62. MPP35_GPIO, /* FAN SENSE */
  63. MPP36_GPIO,
  64. MPP37_GPIO,
  65. MPP38_GPIO,
  66. MPP39_GPIO,
  67. MPP40_GPIO,
  68. MPP41_GPIO,
  69. MPP42_GPIO,
  70. MPP43_GPIO,
  71. MPP44_GPIO,
  72. MPP45_GPIO,
  73. MPP46_GPIO,
  74. MPP47_GPIO,
  75. MPP48_GPIO,
  76. MPP49_GPIO,
  77. 0
  78. };
  79. kirkwood_mpp_conf(kwmpp_config, NULL);
  80. return 0;
  81. }
  82. int board_init(void)
  83. {
  84. /* address of boot parameters */
  85. gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
  86. return 0;
  87. }
  88. /* Synology reset uses UART */
  89. #include <ns16550.h>
  90. #define SOFTWARE_SHUTDOWN 0x31
  91. #define SOFTWARE_REBOOT 0x43
  92. #define CONFIG_SYS_NS16550_COM2 KW_UART1_BASE
  93. void reset_misc(void)
  94. {
  95. int b_d;
  96. printf("Synology reset...");
  97. udelay(50000);
  98. b_d = ns16550_calc_divisor((NS16550_t)CONFIG_SYS_NS16550_COM2,
  99. CONFIG_SYS_NS16550_CLK, 9600);
  100. NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM2, b_d);
  101. NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM2, SOFTWARE_REBOOT);
  102. }
  103. /* Support old kernels */
  104. void setup_board_tags(struct tag **in_params)
  105. {
  106. unsigned int boardId;
  107. struct tag *params;
  108. struct tag_mv_uboot *t;
  109. int i;
  110. printf("Synology board tags...");
  111. params = *in_params;
  112. t = (struct tag_mv_uboot *)&params->u;
  113. t->uboot_version = VER_NUM;
  114. boardId = SYNO_DS109_ID;
  115. t->uboot_version |= boardId;
  116. t->tclk = CONFIG_SYS_TCLK;
  117. t->sysclk = CONFIG_SYS_TCLK*2;
  118. t->isusbhost = 1;
  119. for (i = 0; i < 4; i++) {
  120. memset(t->macaddr[i], 0, sizeof(t->macaddr[i]));
  121. t->mtu[i] = 0;
  122. }
  123. params->hdr.tag = ATAG_MV_UBOOT;
  124. params->hdr.size = tag_size(tag_mv_uboot);
  125. params = tag_next(params);
  126. *in_params = params;
  127. }
  128. #ifdef CONFIG_RESET_PHY_R
  129. /* Configure and enable MV88E1116 PHY */
  130. void reset_phy(void)
  131. {
  132. u16 reg;
  133. u16 devadr;
  134. char *name = "egiga0";
  135. if (miiphy_set_current_dev(name))
  136. return;
  137. /* command to read PHY dev address */
  138. if (miiphy_read(name, 0xEE, 0xEE, (u16 *)&devadr)) {
  139. printf("Error: 88E1116 could not read PHY dev address\n");
  140. return;
  141. }
  142. /*
  143. * Enable RGMII delay on Tx and Rx for CPU port
  144. * Ref: sec 4.7.2 of chip datasheet
  145. */
  146. miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2);
  147. miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, &reg);
  148. reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
  149. miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg);
  150. miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0);
  151. /* reset the phy */
  152. miiphy_reset(name, devadr);
  153. printf("88E1116 Initialized on %s\n", name);
  154. }
  155. #endif /* CONFIG_RESET_PHY_R */