blob: b54f67dbfedbc57f030d355b05e2d1fdaecef1fa [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sergey Kubushync74b2102007-08-10 20:26:18 +02002/*
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 * --------------------------------------------------------
Sergey Kubushync74b2102007-08-10 20:26:18 +02009 */
10
11#include <common.h>
12#include <net.h>
Hugo Villeneuvefec61432008-06-18 12:10:31 -040013#include <miiphy.h>
Sergey Kubushync74b2102007-08-10 20:26:18 +020014#include <lxt971a.h>
15#include <asm/arch/emac_defs.h>
Grygorii Strashkoffad5fa2018-10-31 16:21:39 -050016#include "../../../drivers/net/ti/davinci_emac.h"
Sergey Kubushync74b2102007-08-10 20:26:18 +020017
18#ifdef CONFIG_DRIVER_TI_EMAC
19
20#ifdef CONFIG_CMD_NET
21
22int lxt972_is_phy_connected(int phy_addr)
23{
Hugo Villeneuve63676842008-06-18 12:10:33 -040024 u_int16_t id1, id2;
Sergey Kubushync74b2102007-08-10 20:26:18 +020025
Mike Frysinger8ef583a2010-12-23 15:40:12 -050026 if (!davinci_eth_phy_read(phy_addr, MII_PHYSID1, &id1))
Sergey Kubushync74b2102007-08-10 20:26:18 +020027 return(0);
Mike Frysinger8ef583a2010-12-23 15:40:12 -050028 if (!davinci_eth_phy_read(phy_addr, MII_PHYSID2, &id2))
Sergey Kubushync74b2102007-08-10 20:26:18 +020029 return(0);
30
31 if ((id1 == (0x0013)) && ((id2 & 0xfff0) == 0x78e0))
32 return(1);
33
34 return(0);
35}
36
37int lxt972_get_link_speed(int phy_addr)
38{
Hugo Villeneuve63676842008-06-18 12:10:33 -040039 u_int16_t stat1, tmp;
40 volatile emac_regs *emac = (emac_regs *)EMAC_BASE_ADDR;
Sergey Kubushync74b2102007-08-10 20:26:18 +020041
Sandeep Paulrajfcaac582008-08-31 00:39:46 +020042 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_STAT2, &stat1))
Sergey Kubushync74b2102007-08-10 20:26:18 +020043 return(0);
44
45 if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link up? */
46 return(0);
47
Sandeep Paulrajfcaac582008-08-31 00:39:46 +020048 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
Sergey Kubushync74b2102007-08-10 20:26:18 +020049 return(0);
50
51 tmp |= PHY_LXT971_DIG_CFG_MII_DRIVE;
52
Sandeep Paulrajfcaac582008-08-31 00:39:46 +020053 davinci_eth_phy_write(phy_addr, PHY_LXT971_DIG_CFG, tmp);
Sergey Kubushync74b2102007-08-10 20:26:18 +020054 /* Read back */
Sandeep Paulrajfcaac582008-08-31 00:39:46 +020055 if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp))
Sergey Kubushync74b2102007-08-10 20:26:18 +020056 return(0);
57
Sergey Kubushync74b2102007-08-10 20:26:18 +020058 /* Speed doesn't matter, there is no setting for it in EMAC... */
Hugo Villeneuve63676842008-06-18 12:10:33 -040059 if (stat1 & PHY_LXT971_STAT2_DUPLEX_MODE) {
60 /* set DM644x EMAC for Full Duplex */
61 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE |
62 EMAC_MACCONTROL_FULLDUPLEX_ENABLE;
Sergey Kubushync74b2102007-08-10 20:26:18 +020063 } else {
Hugo Villeneuve63676842008-06-18 12:10:33 -040064 /*set DM644x EMAC for Half Duplex */
65 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE;
Sergey Kubushync74b2102007-08-10 20:26:18 +020066 }
67
Hugo Villeneuve63676842008-06-18 12:10:33 -040068 return(1);
Sergey Kubushync74b2102007-08-10 20:26:18 +020069}
70
71
72int lxt972_init_phy(int phy_addr)
73{
Hugo Villeneuve63676842008-06-18 12:10:33 -040074 int ret = 1;
Sergey Kubushync74b2102007-08-10 20:26:18 +020075
76 if (!lxt972_get_link_speed(phy_addr)) {
77 /* Try another time */
78 ret = lxt972_get_link_speed(phy_addr);
79 }
80
81 /* Disable PHY Interrupts */
Sandeep Paulrajfcaac582008-08-31 00:39:46 +020082 davinci_eth_phy_write(phy_addr, PHY_LXT971_INT_ENABLE, 0);
Sergey Kubushync74b2102007-08-10 20:26:18 +020083
84 return(ret);
85}
86
87
88int lxt972_auto_negotiate(int phy_addr)
89{
Hugo Villeneuve63676842008-06-18 12:10:33 -040090 u_int16_t tmp;
Sergey Kubushync74b2102007-08-10 20:26:18 +020091
Mike Frysinger8ef583a2010-12-23 15:40:12 -050092 if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp))
Sergey Kubushync74b2102007-08-10 20:26:18 +020093 return(0);
94
95 /* Restart Auto_negotiation */
Mike Frysinger8ef583a2010-12-23 15:40:12 -050096 tmp |= BMCR_ANRESTART;
97 davinci_eth_phy_write(phy_addr, MII_BMCR, tmp);
Sergey Kubushync74b2102007-08-10 20:26:18 +020098
99 /*check AutoNegotiate complete */
100 udelay (10000);
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500101 if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp))
Sergey Kubushync74b2102007-08-10 20:26:18 +0200102 return(0);
103
Mike Frysinger8ef583a2010-12-23 15:40:12 -0500104 if (!(tmp & BMSR_ANEGCOMPLETE))
Sergey Kubushync74b2102007-08-10 20:26:18 +0200105 return(0);
106
107 return (lxt972_get_link_speed(phy_addr));
108}
109
110#endif /* CONFIG_CMD_NET */
111
112#endif /* CONFIG_DRIVER_ETHER */