Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 2 | /* |
| 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 Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <net.h> |
Hugo Villeneuve | 72c01d3 | 2008-06-18 12:10:31 -0400 | [diff] [blame] | 13 | #include <miiphy.h> |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 14 | #include <lxt971a.h> |
| 15 | #include <asm/arch/emac_defs.h> |
Grygorii Strashko | 5693dee | 2018-10-31 16:21:39 -0500 | [diff] [blame] | 16 | #include "../../../drivers/net/ti/davinci_emac.h" |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 17 | |
| 18 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 19 | |
| 20 | #ifdef CONFIG_CMD_NET |
| 21 | |
| 22 | int lxt972_is_phy_connected(int phy_addr) |
| 23 | { |
Hugo Villeneuve | 070911d | 2008-06-18 12:10:33 -0400 | [diff] [blame] | 24 | u_int16_t id1, id2; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 25 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 26 | if (!davinci_eth_phy_read(phy_addr, MII_PHYSID1, &id1)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 27 | return(0); |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 28 | if (!davinci_eth_phy_read(phy_addr, MII_PHYSID2, &id2)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 29 | return(0); |
| 30 | |
| 31 | if ((id1 == (0x0013)) && ((id2 & 0xfff0) == 0x78e0)) |
| 32 | return(1); |
| 33 | |
| 34 | return(0); |
| 35 | } |
| 36 | |
| 37 | int lxt972_get_link_speed(int phy_addr) |
| 38 | { |
Hugo Villeneuve | 070911d | 2008-06-18 12:10:33 -0400 | [diff] [blame] | 39 | u_int16_t stat1, tmp; |
| 40 | volatile emac_regs *emac = (emac_regs *)EMAC_BASE_ADDR; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 41 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 42 | if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_STAT2, &stat1)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 43 | return(0); |
| 44 | |
| 45 | if (!(stat1 & PHY_LXT971_STAT2_LINK)) /* link up? */ |
| 46 | return(0); |
| 47 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 48 | if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 49 | return(0); |
| 50 | |
| 51 | tmp |= PHY_LXT971_DIG_CFG_MII_DRIVE; |
| 52 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 53 | davinci_eth_phy_write(phy_addr, PHY_LXT971_DIG_CFG, tmp); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 54 | /* Read back */ |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 55 | if (!davinci_eth_phy_read(phy_addr, PHY_LXT971_DIG_CFG, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 56 | return(0); |
| 57 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 58 | /* Speed doesn't matter, there is no setting for it in EMAC... */ |
Hugo Villeneuve | 070911d | 2008-06-18 12:10:33 -0400 | [diff] [blame] | 59 | 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 Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 63 | } else { |
Hugo Villeneuve | 070911d | 2008-06-18 12:10:33 -0400 | [diff] [blame] | 64 | /*set DM644x EMAC for Half Duplex */ |
| 65 | emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Hugo Villeneuve | 070911d | 2008-06-18 12:10:33 -0400 | [diff] [blame] | 68 | return(1); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | |
| 72 | int lxt972_init_phy(int phy_addr) |
| 73 | { |
Hugo Villeneuve | 070911d | 2008-06-18 12:10:33 -0400 | [diff] [blame] | 74 | int ret = 1; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 75 | |
| 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 Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 82 | davinci_eth_phy_write(phy_addr, PHY_LXT971_INT_ENABLE, 0); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 83 | |
| 84 | return(ret); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | int lxt972_auto_negotiate(int phy_addr) |
| 89 | { |
Hugo Villeneuve | 070911d | 2008-06-18 12:10:33 -0400 | [diff] [blame] | 90 | u_int16_t tmp; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 91 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 92 | if (!davinci_eth_phy_read(phy_addr, MII_BMCR, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 93 | return(0); |
| 94 | |
| 95 | /* Restart Auto_negotiation */ |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 96 | tmp |= BMCR_ANRESTART; |
| 97 | davinci_eth_phy_write(phy_addr, MII_BMCR, tmp); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 98 | |
| 99 | /*check AutoNegotiate complete */ |
| 100 | udelay (10000); |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 101 | if (!davinci_eth_phy_read(phy_addr, MII_BMSR, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 102 | return(0); |
| 103 | |
Mike Frysinger | d63ee71 | 2010-12-23 15:40:12 -0500 | [diff] [blame] | 104 | if (!(tmp & BMSR_ANEGCOMPLETE)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 105 | return(0); |
| 106 | |
| 107 | return (lxt972_get_link_speed(phy_addr)); |
| 108 | } |
| 109 | |
| 110 | #endif /* CONFIG_CMD_NET */ |
| 111 | |
| 112 | #endif /* CONFIG_DRIVER_ETHER */ |