2 * Intel LXT971/LXT972 PHY Driver for TI DaVinci
3 * (TMS320DM644x) based boards.
5 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
7 * --------------------------------------------------------
9 * SPDX-License-Identifier: GPL-2.0+
16 #include <asm/arch/emac_defs.h>
17 #include "../../../drivers/net/davinci_emac.h"
19 #ifdef CONFIG_DRIVER_TI_EMAC
23 int lxt972_is_phy_connected(int phy_addr)
27 if (!davinci_eth_phy_read(phy_addr, MII_PHYSID1, &id1))
29 if (!davinci_eth_phy_read(phy_addr, MII_PHYSID2, &id2))
32 if ((id1 == (0x0013)) && ((id2 & 0xfff0) == 0x78e0))
38 int lxt972_get_link_speed(int phy_addr)
41 volatile emac_regs *emac = (emac_regs *)EMAC_BASE_ADDR;
43 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_STAT2, &stat1))
46 if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link up? */
49 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
52 tmp |= PHY_LXT971_DIG_CFG_MII_DRIVE;
54 davinci_eth_phy_write(phy_addr, PHY_LXT971_DIG_CFG, tmp);
56 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
59 /* Speed doesn't matter, there is no setting for it in EMAC... */
60 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
61 /* set DM644x EMAC for Full Duplex */
62 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE |
63 EMAC_MACCONTROL_FULLDUPLEX_ENABLE;
65 /*set DM644x EMAC for Half Duplex */
66 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE;
73 int lxt972_init_phy(int phy_addr)
77 if (!lxt972_get_link_speed(phy_addr)) {
78 /* Try another time */
79 ret = lxt972_get_link_speed(phy_addr);
82 /* Disable PHY Interrupts */
83 davinci_eth_phy_write(phy_addr, PHY_LXT971_INT_ENABLE, 0);
89 int lxt972_auto_negotiate(int phy_addr)
93 if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp))
96 /* Restart Auto_negotiation */
97 tmp |= BMCR_ANRESTART;
98 davinci_eth_phy_write(phy_addr, MII_BMCR, tmp);
100 /*check AutoNegotiate complete */
102 if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp))
105 if (!(tmp & BMSR_ANEGCOMPLETE))
108 return (lxt972_get_link_speed(phy_addr));
111 #endif /* CONFIG_CMD_NET */
113 #endif /* CONFIG_DRIVER_ETHER */