lxt972.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Intel LXT971/LXT972 PHY Driver for TI DaVinci
  4. * (TMS320DM644x) based boards.
  5. *
  6. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  7. *
  8. * --------------------------------------------------------
  9. */
  10. #include <common.h>
  11. #include <net.h>
  12. #include <miiphy.h>
  13. #include <lxt971a.h>
  14. #include <asm/arch/emac_defs.h>
  15. #include "../../../drivers/net/ti/davinci_emac.h"
  16. #ifdef CONFIG_DRIVER_TI_EMAC
  17. #ifdef CONFIG_CMD_NET
  18. int lxt972_is_phy_connected(int phy_addr)
  19. {
  20. u_int16_t id1, id2;
  21. if (!davinci_eth_phy_read(phy_addr, MII_PHYSID1, &id1))
  22. return(0);
  23. if (!davinci_eth_phy_read(phy_addr, MII_PHYSID2, &id2))
  24. return(0);
  25. if ((id1 == (0x0013)) && ((id2 & 0xfff0) == 0x78e0))
  26. return(1);
  27. return(0);
  28. }
  29. int lxt972_get_link_speed(int phy_addr)
  30. {
  31. u_int16_t stat1, tmp;
  32. volatile emac_regs *emac = (emac_regs *)EMAC_BASE_ADDR;
  33. if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_STAT2, &stat1))
  34. return(0);
  35. if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link up? */
  36. return(0);
  37. if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
  38. return(0);
  39. tmp |= PHY_LXT971_DIG_CFG_MII_DRIVE;
  40. davinci_eth_phy_write(phy_addr, PHY_LXT971_DIG_CFG, tmp);
  41. /* Read back */
  42. if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
  43. return(0);
  44. /* Speed doesn't matter, there is no setting for it in EMAC... */
  45. if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
  46. /* set DM644x EMAC for Full Duplex */
  47. emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE |
  48. EMAC_MACCONTROL_FULLDUPLEX_ENABLE;
  49. } else {
  50. /*set DM644x EMAC for Half Duplex */
  51. emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE;
  52. }
  53. return(1);
  54. }
  55. int lxt972_init_phy(int phy_addr)
  56. {
  57. int ret = 1;
  58. if (!lxt972_get_link_speed(phy_addr)) {
  59. /* Try another time */
  60. ret = lxt972_get_link_speed(phy_addr);
  61. }
  62. /* Disable PHY Interrupts */
  63. davinci_eth_phy_write(phy_addr, PHY_LXT971_INT_ENABLE, 0);
  64. return(ret);
  65. }
  66. int lxt972_auto_negotiate(int phy_addr)
  67. {
  68. u_int16_t tmp;
  69. if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp))
  70. return(0);
  71. /* Restart Auto_negotiation */
  72. tmp |= BMCR_ANRESTART;
  73. davinci_eth_phy_write(phy_addr, MII_BMCR, tmp);
  74. /*check AutoNegotiate complete */
  75. udelay (10000);
  76. if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp))
  77. return(0);
  78. if (!(tmp & BMSR_ANEGCOMPLETE))
  79. return(0);
  80. return (lxt972_get_link_speed(phy_addr));
  81. }
  82. #endif /* CONFIG_CMD_NET */
  83. #endif /* CONFIG_DRIVER_ETHER */