lxt972.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. *
  3. * (C) Copyright 2003
  4. * Author : Hamid Ikdoumi (Atmel)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /*
  25. * Adapted for KwikByte KB920x board: 22APR2005
  26. */
  27. #include <common.h>
  28. #include <at91rm9200_net.h>
  29. #include <net.h>
  30. #include <miiphy.h>
  31. #include <lxt971a.h>
  32. #ifdef CONFIG_DRIVER_ETHER
  33. #if defined(CONFIG_CMD_NET)
  34. /*
  35. * Name:
  36. * lxt972_IsPhyConnected
  37. * Description:
  38. * Reads the 2 PHY ID registers
  39. * Arguments:
  40. * p_mac - pointer to AT91S_EMAC struct
  41. * Return value:
  42. * TRUE - if id read successfully
  43. * FALSE- if error
  44. */
  45. unsigned int lxt972_IsPhyConnected (AT91PS_EMAC p_mac)
  46. {
  47. unsigned short Id1, Id2;
  48. at91rm9200_EmacEnableMDIO (p_mac);
  49. at91rm9200_EmacReadPhy(p_mac, PHY_PHYIDR1, &Id1);
  50. at91rm9200_EmacReadPhy(p_mac, PHY_PHYIDR2, &Id2);
  51. at91rm9200_EmacDisableMDIO (p_mac);
  52. if ((Id1 == (0x0013)) && ((Id2 & 0xFFF0) == 0x78E0))
  53. return TRUE;
  54. return FALSE;
  55. }
  56. /*
  57. * Name:
  58. * lxt972_GetLinkSpeed
  59. * Description:
  60. * Link parallel detection status of MAC is checked and set in the
  61. * MAC configuration registers
  62. * Arguments:
  63. * p_mac - pointer to MAC
  64. * Return value:
  65. * TRUE - if link status set succesfully
  66. * FALSE - if link status not set
  67. */
  68. UCHAR lxt972_GetLinkSpeed (AT91PS_EMAC p_mac)
  69. {
  70. unsigned short stat1;
  71. if (!at91rm9200_EmacReadPhy (p_mac, PHY_LXT971_STAT2, &stat1))
  72. return FALSE;
  73. if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link status up? */
  74. return FALSE;
  75. if (stat1 & PHY_LXT971_STAT2_100BTX) {
  76. if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
  77. /*set Emac for 100BaseTX and Full Duplex */
  78. p_mac->EMAC_CFG |= AT91C_EMAC_SPD | AT91C_EMAC_FD;
  79. } else {
  80. /*set Emac for 100BaseTX and Half Duplex */
  81. p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
  82. ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
  83. | AT91C_EMAC_SPD;
  84. }
  85. return TRUE;
  86. } else {
  87. if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
  88. /*set MII for 10BaseT and Full Duplex */
  89. p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
  90. ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
  91. | AT91C_EMAC_FD;
  92. } else {
  93. /*set MII for 10BaseT and Half Duplex */
  94. p_mac->EMAC_CFG &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
  95. }
  96. return TRUE;
  97. }
  98. return FALSE;
  99. }
  100. /*
  101. * Name:
  102. * lxt972_InitPhy
  103. * Description:
  104. * MAC starts checking its link by using parallel detection and
  105. * Autonegotiation and the same is set in the MAC configuration registers
  106. * Arguments:
  107. * p_mac - pointer to struct AT91S_EMAC
  108. * Return value:
  109. * TRUE - if link status set succesfully
  110. * FALSE - if link status not set
  111. */
  112. UCHAR lxt972_InitPhy (AT91PS_EMAC p_mac)
  113. {
  114. UCHAR ret = TRUE;
  115. at91rm9200_EmacEnableMDIO (p_mac);
  116. if (!lxt972_GetLinkSpeed (p_mac)) {
  117. /* Try another time */
  118. ret = lxt972_GetLinkSpeed (p_mac);
  119. }
  120. /* Disable PHY Interrupts */
  121. at91rm9200_EmacWritePhy (p_mac, PHY_LXT971_INT_ENABLE, 0);
  122. at91rm9200_EmacDisableMDIO (p_mac);
  123. return (ret);
  124. }
  125. /*
  126. * Name:
  127. * lxt972_AutoNegotiate
  128. * Description:
  129. * MAC Autonegotiates with the partner status of same is set in the
  130. * MAC configuration registers
  131. * Arguments:
  132. * dev - pointer to struct net_device
  133. * Return value:
  134. * TRUE - if link status set successfully
  135. * FALSE - if link status not set
  136. */
  137. UCHAR lxt972_AutoNegotiate (AT91PS_EMAC p_mac, int *status)
  138. {
  139. unsigned short value;
  140. /* Set lxt972 control register */
  141. if (!at91rm9200_EmacReadPhy (p_mac, PHY_BMCR, &value))
  142. return FALSE;
  143. /* Restart Auto_negotiation */
  144. value |= PHY_BMCR_RST_NEG;
  145. if (!at91rm9200_EmacWritePhy (p_mac, PHY_BMCR, &value))
  146. return FALSE;
  147. /*check AutoNegotiate complete */
  148. udelay (10000);
  149. at91rm9200_EmacReadPhy(p_mac, PHY_BMSR, &value);
  150. if (!(value & PHY_BMSR_AUTN_COMP))
  151. return FALSE;
  152. return (lxt972_GetLinkSpeed (p_mac));
  153. }
  154. #endif
  155. #endif /* CONFIG_DRIVER_ETHER */