io.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * (C) Copyright 2010
  3. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <asm/processor.h>
  26. #include <asm/io.h>
  27. #include <asm/ppc4xx-gpio.h>
  28. #include <dtt.h>
  29. #include <miiphy.h>
  30. #include "405ep.h"
  31. #include <gdsys_fpga.h>
  32. #define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
  33. #define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
  34. #define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
  35. #define PHYREG_CONTROL 0
  36. #define PHYREG_PAGE_ADDRESS 22
  37. #define PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1 16
  38. #define PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2 26
  39. enum {
  40. UNITTYPE_CCD_SWITCH = 1,
  41. };
  42. enum {
  43. HWVER_100 = 0,
  44. HWVER_110 = 1,
  45. HWVER_121 = 2,
  46. HWVER_122 = 3,
  47. };
  48. int misc_init_r(void)
  49. {
  50. /* startup fans */
  51. dtt_init();
  52. return 0;
  53. }
  54. int configure_gbit_phy(unsigned char addr)
  55. {
  56. unsigned short value;
  57. /* select page 2 */
  58. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  59. PHYREG_PAGE_ADDRESS, 0x0002))
  60. goto err_out;
  61. /* disable SGMII autonegotiation */
  62. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  63. PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2, 0x800a))
  64. goto err_out;
  65. /* select page 0 */
  66. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  67. PHYREG_PAGE_ADDRESS, 0x0000))
  68. goto err_out;
  69. /* switch from powerdown to normal operation */
  70. if (miiphy_read(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  71. PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, &value))
  72. goto err_out;
  73. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  74. PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1, value & ~0x0004))
  75. goto err_out;
  76. /* reset phy so settings take effect */
  77. if (miiphy_write(CONFIG_SYS_GBIT_MII_BUSNAME, addr,
  78. PHYREG_CONTROL, 0x9140))
  79. goto err_out;
  80. return 0;
  81. err_out:
  82. printf("Error writing to the PHY addr=%02x\n", addr);
  83. return -1;
  84. }
  85. /*
  86. * Check Board Identity:
  87. */
  88. int checkboard(void)
  89. {
  90. char *s = getenv("serial#");
  91. puts("Board: CATCenter Io");
  92. if (s != NULL) {
  93. puts(", serial# ");
  94. puts(s);
  95. }
  96. puts("\n");
  97. return 0;
  98. }
  99. static void print_fpga_info(void)
  100. {
  101. struct ihs_fpga *fpga = (struct ihs_fpga *) CONFIG_SYS_FPGA_BASE(0);
  102. u16 versions = in_le16(&fpga->versions);
  103. u16 fpga_version = in_le16(&fpga->fpga_version);
  104. u16 fpga_features = in_le16(&fpga->fpga_features);
  105. unsigned unit_type;
  106. unsigned hardware_version;
  107. unsigned feature_channels;
  108. unsigned feature_expansion;
  109. unit_type = (versions & 0xf000) >> 12;
  110. hardware_version = versions & 0x000f;
  111. feature_channels = fpga_features & 0x007f;
  112. feature_expansion = fpga_features & (1<<15);
  113. puts("FPGA: ");
  114. switch (unit_type) {
  115. case UNITTYPE_CCD_SWITCH:
  116. printf("CCD-Switch");
  117. break;
  118. default:
  119. printf("UnitType %d(not supported)", unit_type);
  120. break;
  121. }
  122. switch (hardware_version) {
  123. case HWVER_100:
  124. printf(" HW-Ver 1.00\n");
  125. break;
  126. case HWVER_110:
  127. printf(" HW-Ver 1.10\n");
  128. break;
  129. case HWVER_121:
  130. printf(" HW-Ver 1.21\n");
  131. break;
  132. case HWVER_122:
  133. printf(" HW-Ver 1.22\n");
  134. break;
  135. default:
  136. printf(" HW-Ver %d(not supported)\n",
  137. hardware_version);
  138. break;
  139. }
  140. printf(" FPGA V %d.%02d, features:",
  141. fpga_version / 100, fpga_version % 100);
  142. printf(" %d channel(s)", feature_channels);
  143. printf(", expansion %ssupported\n", feature_expansion ? "" : "un");
  144. }
  145. /*
  146. * setup Gbit PHYs
  147. */
  148. int last_stage_init(void)
  149. {
  150. struct ihs_fpga *fpga = (struct ihs_fpga *) CONFIG_SYS_FPGA_BASE(0);
  151. unsigned int k;
  152. print_fpga_info();
  153. miiphy_register(CONFIG_SYS_GBIT_MII_BUSNAME,
  154. bb_miiphy_read, bb_miiphy_write);
  155. for (k = 0; k < 32; ++k)
  156. configure_gbit_phy(k);
  157. /* take fpga serdes blocks out of reset */
  158. out_le16(&fpga->quad_serdes_reset, 0);
  159. return 0;
  160. }
  161. void gd405ep_init(void)
  162. {
  163. }
  164. void gd405ep_set_fpga_reset(unsigned state)
  165. {
  166. if (state) {
  167. out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
  168. out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
  169. } else {
  170. out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
  171. out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
  172. }
  173. }
  174. void gd405ep_setup_hw(void)
  175. {
  176. /*
  177. * set "startup-finished"-gpios
  178. */
  179. gpio_write_bit(21, 0);
  180. gpio_write_bit(22, 1);
  181. }
  182. int gd405ep_get_fpga_done(unsigned fpga)
  183. {
  184. return in_le16((void *)LATCH2_BASE) & CONFIG_SYS_FPGA_DONE(fpga);
  185. }