miiphy.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*-----------------------------------------------------------------------------+
  2. | This source code is dual-licensed. You may use it under the terms of the
  3. | GNU General Public License version 2, or under the license below.
  4. |
  5. | This source code has been made available to you by IBM on an AS-IS
  6. | basis. Anyone receiving this source is licensed under IBM
  7. | copyrights to use it in any way he or she deems fit, including
  8. | copying it, modifying it, compiling it, and redistributing it either
  9. | with or without modifications. No license under IBM patents or
  10. | patent applications is to be implied by the copyright license.
  11. |
  12. | Any user of this software should understand that IBM cannot provide
  13. | technical support for this software and will not be responsible for
  14. | any consequences resulting from the use of this software.
  15. |
  16. | Any person who transfers this source code or any derivative work
  17. | must include the IBM copyright notice, this paragraph, and the
  18. | preceding two paragraphs in the transferred software.
  19. |
  20. | COPYRIGHT I B M CORPORATION 1995
  21. | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  22. +-----------------------------------------------------------------------------*/
  23. /*-----------------------------------------------------------------------------+
  24. |
  25. | File Name: miiphy.c
  26. |
  27. | Function: This module has utilities for accessing the MII PHY through
  28. | the EMAC3 macro.
  29. |
  30. | Author: Mark Wisner
  31. |
  32. | Change Activity-
  33. |
  34. | Date Description of Change BY
  35. | --------- --------------------- ---
  36. | 05-May-99 Created MKW
  37. | 01-Jul-99 Changed clock setting of sta_reg from 66MHz to 50MHz to
  38. | better match OPB speed. Also modified delay times. JWB
  39. | 29-Jul-99 Added Full duplex support MKW
  40. | 24-Aug-99 Removed printf from dp83843_duplex() JWB
  41. | 19-Jul-00 Ported to esd cpci405 sr
  42. | 23-Dec-03 Ported from miiphy.c to 440GX Travis Sawyer TBS
  43. | <travis.sawyer@sandburst.com>
  44. |
  45. +-----------------------------------------------------------------------------*/
  46. #include <common.h>
  47. #include <miiphy.h>
  48. #include "IxOsal.h"
  49. #include "IxEthAcc.h"
  50. #include "IxEthAcc_p.h"
  51. #include "IxEthAccMac_p.h"
  52. #include "IxEthAccMii_p.h"
  53. /***********************************************************/
  54. /* Dump out to the screen PHY regs */
  55. /***********************************************************/
  56. void miiphy_dump (char *devname, unsigned char addr)
  57. {
  58. unsigned long i;
  59. unsigned short data;
  60. for (i = 0; i < 0x1A; i++) {
  61. if (miiphy_read (devname, addr, i, &data)) {
  62. printf ("read error for reg %lx\n", i);
  63. return;
  64. }
  65. printf ("Phy reg %lx ==> %4x\n", i, data);
  66. /* jump to the next set of regs */
  67. if (i == 0x07)
  68. i = 0x0f;
  69. } /* end for loop */
  70. } /* end dump */
  71. /***********************************************************/
  72. /* (Re)start autonegotiation */
  73. /***********************************************************/
  74. int phy_setup_aneg (char *devname, unsigned char addr)
  75. {
  76. unsigned short ctl, adv;
  77. /* Setup standard advertise */
  78. miiphy_read (devname, addr, MII_ADVERTISE, &adv);
  79. adv |= (LPA_LPACK | LPA_RFAULT | LPA_100BASE4 |
  80. LPA_100FULL | LPA_100HALF | LPA_10FULL |
  81. LPA_10HALF);
  82. miiphy_write (devname, addr, MII_ADVERTISE, adv);
  83. /* Start/Restart aneg */
  84. miiphy_read (devname, addr, MII_BMCR, &ctl);
  85. ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
  86. miiphy_write (devname, addr, MII_BMCR, ctl);
  87. return 0;
  88. }
  89. int npe_miiphy_read (const char *devname, unsigned char addr,
  90. unsigned char reg, unsigned short *value)
  91. {
  92. u16 val;
  93. ixEthAccMiiReadRtn(addr, reg, &val);
  94. *value = val;
  95. return 0;
  96. } /* phy_read */
  97. int npe_miiphy_write (const char *devname, unsigned char addr,
  98. unsigned char reg, unsigned short value)
  99. {
  100. ixEthAccMiiWriteRtn(addr, reg, value);
  101. return 0;
  102. } /* phy_write */