miiphybb.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. static int io_bb_mii_init(struct bb_miiphy_bus *bus)
  27. {
  28. return 0;
  29. }
  30. static int io_bb_mdio_active(struct bb_miiphy_bus *bus)
  31. {
  32. out_be32((void *)GPIO0_TCR,
  33. in_be32((void *)GPIO0_TCR) | CONFIG_SYS_MDIO_PIN);
  34. return 0;
  35. }
  36. static int io_bb_mdio_tristate(struct bb_miiphy_bus *bus)
  37. {
  38. out_be32((void *)GPIO0_TCR,
  39. in_be32((void *)GPIO0_TCR) & ~CONFIG_SYS_MDIO_PIN);
  40. return 0;
  41. }
  42. static int io_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
  43. {
  44. if (v)
  45. out_be32((void *)GPIO0_OR,
  46. in_be32((void *)GPIO0_OR) | CONFIG_SYS_MDIO_PIN);
  47. else
  48. out_be32((void *)GPIO0_OR,
  49. in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_MDIO_PIN);
  50. return 0;
  51. }
  52. static int io_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
  53. {
  54. *v = ((in_be32((void *)GPIO0_IR) & CONFIG_SYS_MDIO_PIN) != 0);
  55. return 0;
  56. }
  57. static int io_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
  58. {
  59. if (v)
  60. out_be32((void *)GPIO0_OR,
  61. in_be32((void *)GPIO0_OR) | CONFIG_SYS_MDC_PIN);
  62. else
  63. out_be32((void *)GPIO0_OR,
  64. in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_MDC_PIN);
  65. return 0;
  66. }
  67. static int io_bb_delay(struct bb_miiphy_bus *bus)
  68. {
  69. udelay(1);
  70. return 0;
  71. }
  72. struct bb_miiphy_bus bb_miiphy_buses[] = {
  73. {
  74. .name = CONFIG_SYS_GBIT_MII_BUSNAME,
  75. .init = io_bb_mii_init,
  76. .mdio_active = io_bb_mdio_active,
  77. .mdio_tristate = io_bb_mdio_tristate,
  78. .set_mdio = io_bb_set_mdio,
  79. .get_mdio = io_bb_get_mdio,
  80. .set_mdc = io_bb_set_mdc,
  81. .delay = io_bb_delay,
  82. }
  83. };
  84. int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
  85. sizeof(bb_miiphy_buses[0]);