lxt972.c 4.8 KB

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