miiphybb.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 <miiphy.h>
  25. #include <asm/io.h>
  26. struct io_bb_pinset {
  27. int mdio;
  28. int mdc;
  29. };
  30. static int io_bb_mii_init(struct bb_miiphy_bus *bus)
  31. {
  32. return 0;
  33. }
  34. static int io_bb_mdio_active(struct bb_miiphy_bus *bus)
  35. {
  36. struct io_bb_pinset *pins = bus->priv;
  37. out_be32((void *)GPIO0_TCR,
  38. in_be32((void *)GPIO0_TCR) | pins->mdio);
  39. return 0;
  40. }
  41. static int io_bb_mdio_tristate(struct bb_miiphy_bus *bus)
  42. {
  43. struct io_bb_pinset *pins = bus->priv;
  44. out_be32((void *)GPIO0_TCR,
  45. in_be32((void *)GPIO0_TCR) & ~pins->mdio);
  46. return 0;
  47. }
  48. static int io_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
  49. {
  50. struct io_bb_pinset *pins = bus->priv;
  51. if (v)
  52. out_be32((void *)GPIO0_OR,
  53. in_be32((void *)GPIO0_OR) | pins->mdio);
  54. else
  55. out_be32((void *)GPIO0_OR,
  56. in_be32((void *)GPIO0_OR) & ~pins->mdio);
  57. return 0;
  58. }
  59. static int io_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
  60. {
  61. struct io_bb_pinset *pins = bus->priv;
  62. *v = ((in_be32((void *)GPIO0_IR) & pins->mdio) != 0);
  63. return 0;
  64. }
  65. static int io_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
  66. {
  67. struct io_bb_pinset *pins = bus->priv;
  68. if (v)
  69. out_be32((void *)GPIO0_OR,
  70. in_be32((void *)GPIO0_OR) | pins->mdc);
  71. else
  72. out_be32((void *)GPIO0_OR,
  73. in_be32((void *)GPIO0_OR) & ~pins->mdc);
  74. return 0;
  75. }
  76. static int io_bb_delay(struct bb_miiphy_bus *bus)
  77. {
  78. udelay(1);
  79. return 0;
  80. }
  81. struct io_bb_pinset io_bb_pinsets[] = {
  82. {
  83. .mdio = CONFIG_SYS_MDIO_PIN,
  84. .mdc = CONFIG_SYS_MDC_PIN,
  85. },
  86. #ifdef CONFIG_SYS_GBIT_MII1_BUSNAME
  87. {
  88. .mdio = CONFIG_SYS_MDIO1_PIN,
  89. .mdc = CONFIG_SYS_MDC1_PIN,
  90. },
  91. #endif
  92. };
  93. struct bb_miiphy_bus bb_miiphy_buses[] = {
  94. {
  95. .name = CONFIG_SYS_GBIT_MII_BUSNAME,
  96. .init = io_bb_mii_init,
  97. .mdio_active = io_bb_mdio_active,
  98. .mdio_tristate = io_bb_mdio_tristate,
  99. .set_mdio = io_bb_set_mdio,
  100. .get_mdio = io_bb_get_mdio,
  101. .set_mdc = io_bb_set_mdc,
  102. .delay = io_bb_delay,
  103. .priv = &io_bb_pinsets[0],
  104. },
  105. #ifdef CONFIG_SYS_GBIT_MII1_BUSNAME
  106. {
  107. .name = CONFIG_SYS_GBIT_MII1_BUSNAME,
  108. .init = io_bb_mii_init,
  109. .mdio_active = io_bb_mdio_active,
  110. .mdio_tristate = io_bb_mdio_tristate,
  111. .set_mdio = io_bb_set_mdio,
  112. .get_mdio = io_bb_get_mdio,
  113. .set_mdc = io_bb_set_mdc,
  114. .delay = io_bb_delay,
  115. .priv = &io_bb_pinsets[1],
  116. },
  117. #endif
  118. };
  119. int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
  120. sizeof(bb_miiphy_buses[0]);