2007-08-10 18:26:18 +00:00
|
|
|
/*
|
|
|
|
* Intel LXT971/LXT972 PHY Driver for TI DaVinci
|
|
|
|
* (TMS320DM644x) based boards.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
|
|
|
|
*
|
|
|
|
* --------------------------------------------------------
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <net.h>
|
2008-06-18 16:10:31 +00:00
|
|
|
#include <miiphy.h>
|
2007-08-10 18:26:18 +00:00
|
|
|
#include <lxt971a.h>
|
|
|
|
#include <asm/arch/emac_defs.h>
|
2011-11-28 06:37:29 +00:00
|
|
|
#include "../../../../../drivers/net/davinci_emac.h"
|
2007-08-10 18:26:18 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DRIVER_TI_EMAC
|
|
|
|
|
|
|
|
#ifdef CONFIG_CMD_NET
|
|
|
|
|
|
|
|
int lxt972_is_phy_connected(int phy_addr)
|
|
|
|
{
|
2008-06-18 16:10:33 +00:00
|
|
|
u_int16_t id1, id2;
|
2007-08-10 18:26:18 +00:00
|
|
|
|
2010-12-23 20:40:12 +00:00
|
|
|
if (!davinci_eth_phy_read(phy_addr, MII_PHYSID1, &id1))
|
2007-08-10 18:26:18 +00:00
|
|
|
return(0);
|
2010-12-23 20:40:12 +00:00
|
|
|
if (!davinci_eth_phy_read(phy_addr, MII_PHYSID2, &id2))
|
2007-08-10 18:26:18 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
if ((id1 == (0x0013)) && ((id2 & 0xfff0) == 0x78e0))
|
|
|
|
return(1);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int lxt972_get_link_speed(int phy_addr)
|
|
|
|
{
|
2008-06-18 16:10:33 +00:00
|
|
|
u_int16_t stat1, tmp;
|
|
|
|
volatile emac_regs *emac = (emac_regs *)EMAC_BASE_ADDR;
|
2007-08-10 18:26:18 +00:00
|
|
|
|
2008-08-30 22:39:46 +00:00
|
|
|
if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_STAT2, &stat1))
|
2007-08-10 18:26:18 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link up? */
|
|
|
|
return(0);
|
|
|
|
|
2008-08-30 22:39:46 +00:00
|
|
|
if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
|
2007-08-10 18:26:18 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
tmp |= PHY_LXT971_DIG_CFG_MII_DRIVE;
|
|
|
|
|
2008-08-30 22:39:46 +00:00
|
|
|
davinci_eth_phy_write(phy_addr, PHY_LXT971_DIG_CFG, tmp);
|
2007-08-10 18:26:18 +00:00
|
|
|
/* Read back */
|
2008-08-30 22:39:46 +00:00
|
|
|
if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
|
2007-08-10 18:26:18 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
/* Speed doesn't matter, there is no setting for it in EMAC... */
|
2008-06-18 16:10:33 +00:00
|
|
|
if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
|
|
|
|
/* set DM644x EMAC for Full Duplex */
|
|
|
|
emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE |
|
|
|
|
EMAC_MACCONTROL_FULLDUPLEX_ENABLE;
|
2007-08-10 18:26:18 +00:00
|
|
|
} else {
|
2008-06-18 16:10:33 +00:00
|
|
|
/*set DM644x EMAC for Half Duplex */
|
|
|
|
emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE;
|
2007-08-10 18:26:18 +00:00
|
|
|
}
|
|
|
|
|
2008-06-18 16:10:33 +00:00
|
|
|
return(1);
|
2007-08-10 18:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int lxt972_init_phy(int phy_addr)
|
|
|
|
{
|
2008-06-18 16:10:33 +00:00
|
|
|
int ret = 1;
|
2007-08-10 18:26:18 +00:00
|
|
|
|
|
|
|
if (!lxt972_get_link_speed(phy_addr)) {
|
|
|
|
/* Try another time */
|
|
|
|
ret = lxt972_get_link_speed(phy_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable PHY Interrupts */
|
2008-08-30 22:39:46 +00:00
|
|
|
davinci_eth_phy_write(phy_addr, PHY_LXT971_INT_ENABLE, 0);
|
2007-08-10 18:26:18 +00:00
|
|
|
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int lxt972_auto_negotiate(int phy_addr)
|
|
|
|
{
|
2008-06-18 16:10:33 +00:00
|
|
|
u_int16_t tmp;
|
2007-08-10 18:26:18 +00:00
|
|
|
|
2010-12-23 20:40:12 +00:00
|
|
|
if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp))
|
2007-08-10 18:26:18 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
/* Restart Auto_negotiation */
|
2010-12-23 20:40:12 +00:00
|
|
|
tmp |= BMCR_ANRESTART;
|
|
|
|
davinci_eth_phy_write(phy_addr, MII_BMCR, tmp);
|
2007-08-10 18:26:18 +00:00
|
|
|
|
|
|
|
/*check AutoNegotiate complete */
|
|
|
|
udelay (10000);
|
2010-12-23 20:40:12 +00:00
|
|
|
if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp))
|
2007-08-10 18:26:18 +00:00
|
|
|
return(0);
|
|
|
|
|
2010-12-23 20:40:12 +00:00
|
|
|
if (!(tmp & BMSR_ANEGCOMPLETE))
|
2007-08-10 18:26:18 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
return (lxt972_get_link_speed(phy_addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_CMD_NET */
|
|
|
|
|
|
|
|
#endif /* CONFIG_DRIVER_ETHER */
|