io.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * (C) Copyright 2010
  3. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <asm/processor.h>
  10. #include <asm/io.h>
  11. #include <asm/ppc4xx-gpio.h>
  12. #include <dtt.h>
  13. #include <miiphy.h>
  14. #include "405ep.h"
  15. #include <gdsys_fpga.h>
  16. #define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
  17. #define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
  18. #define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
  19. #define PHYREG_CONTROL 0
  20. #define PHYREG_PAGE_ADDRESS 22
  21. #define PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1 16
  22. #define PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2 26
  23. enum {
  24. UNITTYPE_CCD_SWITCH = 1,
  25. };
  26. enum {
  27. HWVER_100 = 0,
  28. HWVER_110 = 1,
  29. HWVER_121 = 2,
  30. HWVER_122 = 3,
  31. };
  32. struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
  33. int misc_init_r(void)
  34. {
  35. /* startup fans */
  36. dtt_init();
  37. return 0;
  38. }
  39. int configure_gbit_phy(unsigned char addr)
  40. {
  41. unsigned short value;
  42. /* select page 2 */
  43. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  44. PHYREG_PAGE_ADDRESS, 0x0002))
  45. goto err_out;
  46. /* disable SGMII autonegotiation */
  47. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  48. PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2, 0x800a))
  49. goto err_out;
  50. /* select page 0 */
  51. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  52. PHYREG_PAGE_ADDRESS, 0x0000))
  53. goto err_out;
  54. /* switch from powerdown to normal operation */
  55. if (miiphy_read(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  56. PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, &value))
  57. goto err_out;
  58. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  59. PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, value & ~0x0004))
  60. goto err_out;
  61. /* reset phy so settings take effect */
  62. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  63. PHYREG_CONTROL, 0x9140))
  64. goto err_out;
  65. return 0;
  66. err_out:
  67. printf("Error writing to the PHY addr=%02x\n", addr);
  68. return -1;
  69. }
  70. /*
  71. * Check Board Identity:
  72. */
  73. int checkboard(void)
  74. {
  75. char *s = getenv("serial#");
  76. puts("Board: CATCenter Io");
  77. if (s != NULL) {
  78. puts(", serial# ");
  79. puts(s);
  80. }
  81. puts("\n");
  82. return 0;
  83. }
  84. static void print_fpga_info(void)
  85. {
  86. u16 versions;
  87. u16 fpga_version;
  88. u16 fpga_features;
  89. unsigned unit_type;
  90. unsigned hardware_version;
  91. unsigned feature_channels;
  92. unsigned feature_expansion;
  93. FPGA_GET_REG(0, versions, &versions);
  94. FPGA_GET_REG(0, fpga_version, &fpga_version);
  95. FPGA_GET_REG(0, fpga_features, &fpga_features);
  96. unit_type = (versions & 0xf000) >> 12;
  97. hardware_version = versions & 0x000f;
  98. feature_channels = fpga_features & 0x007f;
  99. feature_expansion = fpga_features & (1<<15);
  100. puts("FPGA: ");
  101. switch (unit_type) {
  102. case UNITTYPE_CCD_SWITCH:
  103. printf("CCD-Switch");
  104. break;
  105. default:
  106. printf("UnitType %d(not supported)", unit_type);
  107. break;
  108. }
  109. switch (hardware_version) {
  110. case HWVER_100:
  111. printf(" HW-Ver 1.00\n");
  112. break;
  113. case HWVER_110:
  114. printf(" HW-Ver 1.10\n");
  115. break;
  116. case HWVER_121:
  117. printf(" HW-Ver 1.21\n");
  118. break;
  119. case HWVER_122:
  120. printf(" HW-Ver 1.22\n");
  121. break;
  122. default:
  123. printf(" HW-Ver %d(not supported)\n",
  124. hardware_version);
  125. break;
  126. }
  127. printf(" FPGA V %d.%02d, features:",
  128. fpga_version / 100, fpga_version % 100);
  129. printf(" %d channel(s)", feature_channels);
  130. printf(", expansion %ssupported\n", feature_expansion ? "" : "un");
  131. }
  132. /*
  133. * setup Gbit PHYs
  134. */
  135. int last_stage_init(void)
  136. {
  137. unsigned int k;
  138. print_fpga_info();
  139. int retval;
  140. struct mii_dev *mdiodev = mdio_alloc();
  141. if (!mdiodev)
  142. return -ENOMEM;
  143. strncpy(mdiodev->name, CONFIG_SYS_GBIT_MII_BUSNAME, MDIO_NAME_LEN);
  144. mdiodev->read = bb_miiphy_read;
  145. mdiodev->write = bb_miiphy_write;
  146. retval = mdio_register(mdiodev);
  147. if (retval < 0)
  148. return retval;
  149. for (k = 0; k < 32; ++k)
  150. configure_gbit_phy(k);
  151. /* take fpga serdes blocks out of reset */
  152. FPGA_SET_REG(0, quad_serdes_reset, 0);
  153. return 0;
  154. }
  155. void gd405ep_init(void)
  156. {
  157. }
  158. void gd405ep_set_fpga_reset(unsigned state)
  159. {
  160. if (state) {
  161. out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
  162. out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
  163. } else {
  164. out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
  165. out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
  166. }
  167. }
  168. void gd405ep_setup_hw(void)
  169. {
  170. /*
  171. * set "startup-finished"-gpios
  172. */
  173. gpio_write_bit(21, 0);
  174. gpio_write_bit(22, 1);
  175. }
  176. int gd405ep_get_fpga_done(unsigned fpga)
  177. {
  178. return in_le16((void *)LATCH2_BASE) & CONFIG_SYS_FPGA_DONE(fpga);
  179. }