2 * Intel LXT971/LXT972 PHY Driver for TI DaVinci
3 * (TMS320DM644x) based boards.
5 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
7 * --------------------------------------------------------
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #include <asm/arch/emac_defs.h>
33 #include "../../../../../drivers/net/davinci_emac.h"
35 #ifdef CONFIG_DRIVER_TI_EMAC
39 int lxt972_is_phy_connected(int phy_addr)
43 if (!davinci_eth_phy_read(phy_addr, MII_PHYSID1, &id1))
45 if (!davinci_eth_phy_read(phy_addr, MII_PHYSID2, &id2))
48 if ((id1 == (0x0013)) && ((id2 & 0xfff0) == 0x78e0))
54 int lxt972_get_link_speed(int phy_addr)
57 volatile emac_regs *emac = (emac_regs *)EMAC_BASE_ADDR;
59 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_STAT2, &stat1))
62 if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link up? */
65 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
68 tmp |= PHY_LXT971_DIG_CFG_MII_DRIVE;
70 davinci_eth_phy_write(phy_addr, PHY_LXT971_DIG_CFG, tmp);
72 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
75 /* Speed doesn't matter, there is no setting for it in EMAC... */
76 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
77 /* set DM644x EMAC for Full Duplex */
78 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE |
79 EMAC_MACCONTROL_FULLDUPLEX_ENABLE;
81 /*set DM644x EMAC for Half Duplex */
82 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE;
89 int lxt972_init_phy(int phy_addr)
93 if (!lxt972_get_link_speed(phy_addr)) {
94 /* Try another time */
95 ret = lxt972_get_link_speed(phy_addr);
98 /* Disable PHY Interrupts */
99 davinci_eth_phy_write(phy_addr, PHY_LXT971_INT_ENABLE, 0);
105 int lxt972_auto_negotiate(int phy_addr)
109 if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp))
112 /* Restart Auto_negotiation */
113 tmp |= BMCR_ANRESTART;
114 davinci_eth_phy_write(phy_addr, MII_BMCR, tmp);
116 /*check AutoNegotiate complete */
118 if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp))
121 if (!(tmp & BMSR_ANEGCOMPLETE))
124 return (lxt972_get_link_speed(phy_addr));
127 #endif /* CONFIG_CMD_NET */
129 #endif /* CONFIG_DRIVER_ETHER */