blob: a7356f9672e51b7324c427264ccaee5c9dc984fa [file] [log] [blame]
Sergey Kubushyne8f39122007-08-10 20:26:18 +02001/*
2 * Intel LXT971/LXT972 PHY Driver for TI DaVinci
3 * (TMS320DM644x) based boards.
4 *
5 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
6 *
7 * --------------------------------------------------------
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Sergey Kubushyne8f39122007-08-10 20:26:18 +020010 */
11
12#include <common.h>
13#include <net.h>
Hugo Villeneuve72c01d32008-06-18 12:10:31 -040014#include <miiphy.h>
Sergey Kubushyne8f39122007-08-10 20:26:18 +020015#include <lxt971a.h>
16#include <asm/arch/emac_defs.h>
Masahiro Yamada36445482015-02-20 17:04:05 +090017#include "../../../drivers/net/davinci_emac.h"
Sergey Kubushyne8f39122007-08-10 20:26:18 +020018
19#ifdef CONFIG_DRIVER_TI_EMAC
20
21#ifdef CONFIG_CMD_NET
22
23int lxt972_is_phy_connected(int phy_addr)
24{
Hugo Villeneuve070911d2008-06-18 12:10:33 -040025 u_int16_t id1, id2;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020026
Mike Frysingerd63ee712010-12-23 15:40:12 -050027 if (!davinci_eth_phy_read(phy_addr, MII_PHYSID1, &id1))
Sergey Kubushyne8f39122007-08-10 20:26:18 +020028 return(0);
Mike Frysingerd63ee712010-12-23 15:40:12 -050029 if (!davinci_eth_phy_read(phy_addr, MII_PHYSID2, &id2))
Sergey Kubushyne8f39122007-08-10 20:26:18 +020030 return(0);
31
32 if ((id1 == (0x0013)) && ((id2 & 0xfff0) == 0x78e0))
33 return(1);
34
35 return(0);
36}
37
38int lxt972_get_link_speed(int phy_addr)
39{
Hugo Villeneuve070911d2008-06-18 12:10:33 -040040 u_int16_t stat1, tmp;
41 volatile emac_regs *emac = (emac_regs *)EMAC_BASE_ADDR;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020042
Sandeep Paulraj4b26f052008-08-31 00:39:46 +020043 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_STAT2, &stat1))
Sergey Kubushyne8f39122007-08-10 20:26:18 +020044 return(0);
45
46 if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link up? */
47 return(0);
48
Sandeep Paulraj4b26f052008-08-31 00:39:46 +020049 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
Sergey Kubushyne8f39122007-08-10 20:26:18 +020050 return(0);
51
52 tmp |= PHY_LXT971_DIG_CFG_MII_DRIVE;
53
Sandeep Paulraj4b26f052008-08-31 00:39:46 +020054 davinci_eth_phy_write(phy_addr, PHY_LXT971_DIG_CFG, tmp);
Sergey Kubushyne8f39122007-08-10 20:26:18 +020055 /* Read back */
Sandeep Paulraj4b26f052008-08-31 00:39:46 +020056 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
Sergey Kubushyne8f39122007-08-10 20:26:18 +020057 return(0);
58
Sergey Kubushyne8f39122007-08-10 20:26:18 +020059 /* Speed doesn't matter, there is no setting for it in EMAC... */
Hugo Villeneuve070911d2008-06-18 12:10:33 -040060 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;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020064 } else {
Hugo Villeneuve070911d2008-06-18 12:10:33 -040065 /*set DM644x EMAC for Half Duplex */
66 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020067 }
68
Hugo Villeneuve070911d2008-06-18 12:10:33 -040069 return(1);
Sergey Kubushyne8f39122007-08-10 20:26:18 +020070}
71
72
73int lxt972_init_phy(int phy_addr)
74{
Hugo Villeneuve070911d2008-06-18 12:10:33 -040075 int ret = 1;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020076
77 if (!lxt972_get_link_speed(phy_addr)) {
78 /* Try another time */
79 ret = lxt972_get_link_speed(phy_addr);
80 }
81
82 /* Disable PHY Interrupts */
Sandeep Paulraj4b26f052008-08-31 00:39:46 +020083 davinci_eth_phy_write(phy_addr, PHY_LXT971_INT_ENABLE, 0);
Sergey Kubushyne8f39122007-08-10 20:26:18 +020084
85 return(ret);
86}
87
88
89int lxt972_auto_negotiate(int phy_addr)
90{
Hugo Villeneuve070911d2008-06-18 12:10:33 -040091 u_int16_t tmp;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020092
Mike Frysingerd63ee712010-12-23 15:40:12 -050093 if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp))
Sergey Kubushyne8f39122007-08-10 20:26:18 +020094 return(0);
95
96 /* Restart Auto_negotiation */
Mike Frysingerd63ee712010-12-23 15:40:12 -050097 tmp |= BMCR_ANRESTART;
98 davinci_eth_phy_write(phy_addr, MII_BMCR, tmp);
Sergey Kubushyne8f39122007-08-10 20:26:18 +020099
100 /*check AutoNegotiate complete */
101 udelay (10000);
Mike Frysingerd63ee712010-12-23 15:40:12 -0500102 if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp))
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200103 return(0);
104
Mike Frysingerd63ee712010-12-23 15:40:12 -0500105 if (!(tmp & BMSR_ANEGCOMPLETE))
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200106 return(0);
107
108 return (lxt972_get_link_speed(phy_addr));
109}
110
111#endif /* CONFIG_CMD_NET */
112
113#endif /* CONFIG_DRIVER_ETHER */