lxt972.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 <lxt971a.h>
  31. #ifdef CONFIG_DRIVER_ETHER
  32. #if (CONFIG_COMMANDS & CFG_CMD_NET)
  33. /*
  34. * Name:
  35. * lxt972_IsPhyConnected
  36. * Description:
  37. * Reads the 2 PHY ID registers
  38. * Arguments:
  39. * p_mac - pointer to AT91S_EMAC struct
  40. * Return value:
  41. * TRUE - if id read successfully
  42. * FALSE- if error
  43. */
  44. unsigned int lxt972_IsPhyConnected (AT91PS_EMAC p_mac)
  45. {
  46. unsigned short Id1, Id2;
  47. at91rm9200_EmacEnableMDIO (p_mac);
  48. at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_ID1, &Id1);
  49. at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_ID2, &Id2);
  50. at91rm9200_EmacDisableMDIO (p_mac);
  51. if ((Id1 == (0x0013)) && ((Id2 & 0xFFF0) == 0x78E0))
  52. return TRUE;
  53. return FALSE;
  54. }
  55. /*
  56. * Name:
  57. * lxt972_GetLinkSpeed
  58. * Description:
  59. * Link parallel detection status of MAC is checked and set in the
  60. * MAC configuration registers
  61. * Arguments:
  62. * p_mac - pointer to MAC
  63. * Return value:
  64. * TRUE - if link status set succesfully
  65. * FALSE - if link status not set
  66. */
  67. UCHAR lxt972_GetLinkSpeed (AT91PS_EMAC p_mac)
  68. {
  69. unsigned short stat1;
  70. if (!at91rm9200_EmacReadPhy (p_mac, PHY_LXT971_STAT2, &stat1))
  71. return FALSE;
  72. if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link status up? */
  73. return FALSE;
  74. if (stat1 & PHY_LXT971_STAT2_100BTX) {
  75. if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
  76. /*set Emac for 100BaseTX and Full Duplex */
  77. p_mac->EMAC_CFG |= AT91C_EMAC_SPD | AT91C_EMAC_FD;
  78. } else {
  79. /*set Emac for 100BaseTX and Half Duplex */
  80. p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
  81. ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
  82. | AT91C_EMAC_SPD;
  83. }
  84. return TRUE;
  85. } else {
  86. if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
  87. /*set MII for 10BaseT and Full Duplex */
  88. p_mac->EMAC_CFG = (p_mac->EMAC_CFG &
  89. ~(AT91C_EMAC_SPD | AT91C_EMAC_FD))
  90. | AT91C_EMAC_FD;
  91. } else {
  92. /*set MII for 10BaseT and Half Duplex */
  93. p_mac->EMAC_CFG &= ~(AT91C_EMAC_SPD | AT91C_EMAC_FD);
  94. }
  95. return TRUE;
  96. }
  97. return FALSE;
  98. }
  99. /*
  100. * Name:
  101. * lxt972_InitPhy
  102. * Description:
  103. * MAC starts checking its link by using parallel detection and
  104. * Autonegotiation and the same is set in the MAC configuration registers
  105. * Arguments:
  106. * p_mac - pointer to struct AT91S_EMAC
  107. * Return value:
  108. * TRUE - if link status set succesfully
  109. * FALSE - if link status not set
  110. */
  111. UCHAR lxt972_InitPhy (AT91PS_EMAC p_mac)
  112. {
  113. UCHAR ret = TRUE;
  114. at91rm9200_EmacEnableMDIO (p_mac);
  115. if (!lxt972_GetLinkSpeed (p_mac)) {
  116. /* Try another time */
  117. ret = lxt972_GetLinkSpeed (p_mac);
  118. }
  119. /* Disable PHY Interrupts */
  120. at91rm9200_EmacWritePhy (p_mac, PHY_LXT971_INT_ENABLE, 0);
  121. at91rm9200_EmacDisableMDIO (p_mac);
  122. return (ret);
  123. }
  124. /*
  125. * Name:
  126. * lxt972_AutoNegotiate
  127. * Description:
  128. * MAC Autonegotiates with the partner status of same is set in the
  129. * MAC configuration registers
  130. * Arguments:
  131. * dev - pointer to struct net_device
  132. * Return value:
  133. * TRUE - if link status set successfully
  134. * FALSE - if link status not set
  135. */
  136. UCHAR lxt972_AutoNegotiate (AT91PS_EMAC p_mac, int *status)
  137. {
  138. unsigned short value;
  139. /* Set lxt972 control register */
  140. if (!at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_CTRL, &value))
  141. return FALSE;
  142. /* Restart Auto_negotiation */
  143. value |= PHY_COMMON_CTRL_RES_AUTO;
  144. if (!at91rm9200_EmacWritePhy (p_mac, PHY_COMMON_CTRL, &value))
  145. return FALSE;
  146. /*check AutoNegotiate complete */
  147. udelay (10000);
  148. at91rm9200_EmacReadPhy (p_mac, PHY_COMMON_STAT, &value);
  149. if (!(value & PHY_COMMON_STAT_AN_COMP))
  150. return FALSE;
  151. return (lxt972_GetLinkSpeed (p_mac));
  152. }
  153. #endif /* CONFIG_COMMANDS & CFG_CMD_NET */
  154. #endif /* CONFIG_DRIVER_ETHER */