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 | * National Semiconductor DP83848 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> |
| 13 | #include <dp83848.h> |
| 14 | #include <asm/arch/emac_defs.h> |
Masahiro Yamada | 3644548 | 2015-02-20 17:04:05 +0900 | [diff] [blame] | 15 | #include "../../../drivers/net/davinci_emac.h" |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 16 | |
| 17 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 18 | |
| 19 | #ifdef CONFIG_CMD_NET |
| 20 | |
| 21 | int dp83848_is_phy_connected(int phy_addr) |
| 22 | { |
| 23 | u_int16_t id1, id2; |
| 24 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 25 | if (!davinci_eth_phy_read(phy_addr, DP83848_PHYID1_REG, &id1)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 26 | return(0); |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 27 | if (!davinci_eth_phy_read(phy_addr, DP83848_PHYID2_REG, &id2)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 28 | return(0); |
| 29 | |
| 30 | if ((id1 == DP83848_PHYID1_OUI) && (id2 == DP83848_PHYID2_OUI)) |
| 31 | return(1); |
| 32 | |
| 33 | return(0); |
| 34 | } |
| 35 | |
| 36 | int dp83848_get_link_speed(int phy_addr) |
| 37 | { |
| 38 | u_int16_t tmp; |
| 39 | volatile emac_regs* emac = (emac_regs *)EMAC_BASE_ADDR; |
| 40 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 41 | if (!davinci_eth_phy_read(phy_addr, DP83848_STAT_REG, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 42 | return(0); |
| 43 | |
| 44 | if (!(tmp & DP83848_LINK_STATUS)) /* link up? */ |
| 45 | return(0); |
| 46 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 47 | if (!davinci_eth_phy_read(phy_addr, DP83848_PHY_STAT_REG, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 48 | return(0); |
| 49 | |
| 50 | /* Speed doesn't matter, there is no setting for it in EMAC... */ |
Hugo Villeneuve | 6281221 | 2008-09-12 02:20:47 +0200 | [diff] [blame] | 51 | if (tmp & DP83848_DUPLEX) { |
| 52 | /* set DM644x EMAC for Full Duplex */ |
| 53 | emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE | |
| 54 | EMAC_MACCONTROL_FULLDUPLEX_ENABLE; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 55 | } else { |
Hugo Villeneuve | 6281221 | 2008-09-12 02:20:47 +0200 | [diff] [blame] | 56 | /*set DM644x EMAC for Half Duplex */ |
| 57 | emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE; |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 58 | } |
| 59 | |
Hugo Villeneuve | 6281221 | 2008-09-12 02:20:47 +0200 | [diff] [blame] | 60 | return(1); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | |
| 64 | int dp83848_init_phy(int phy_addr) |
| 65 | { |
| 66 | int ret = 1; |
| 67 | |
| 68 | if (!dp83848_get_link_speed(phy_addr)) { |
| 69 | /* Try another time */ |
| 70 | udelay(100000); |
| 71 | ret = dp83848_get_link_speed(phy_addr); |
| 72 | } |
| 73 | |
| 74 | /* Disable PHY Interrupts */ |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 75 | davinci_eth_phy_write(phy_addr, DP83848_PHY_INTR_CTRL_REG, 0); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 76 | |
| 77 | return(ret); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | int dp83848_auto_negotiate(int phy_addr) |
| 82 | { |
| 83 | u_int16_t tmp; |
| 84 | |
| 85 | |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 86 | if (!davinci_eth_phy_read(phy_addr, DP83848_CTL_REG, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 87 | return(0); |
| 88 | |
| 89 | /* Restart Auto_negotiation */ |
| 90 | tmp &= ~DP83848_AUTONEG; /* remove autonegotiation enable */ |
| 91 | tmp |= DP83848_ISOLATE; /* Electrically isolate PHY */ |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 92 | davinci_eth_phy_write(phy_addr, DP83848_CTL_REG, tmp); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 93 | |
| 94 | /* Set the Auto_negotiation Advertisement Register |
| 95 | * MII advertising for Next page, 100BaseTxFD and HD, |
| 96 | * 10BaseTFD and HD, IEEE 802.3 |
| 97 | */ |
| 98 | tmp = DP83848_NP | DP83848_TX_FDX | DP83848_TX_HDX | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 99 | DP83848_10_FDX | DP83848_10_HDX | DP83848_AN_IEEE_802_3; |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 100 | davinci_eth_phy_write(phy_addr, DP83848_ANA_REG, tmp); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 101 | |
| 102 | |
| 103 | /* Read Control Register */ |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 104 | if (!davinci_eth_phy_read(phy_addr, DP83848_CTL_REG, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 105 | return(0); |
| 106 | |
| 107 | tmp |= DP83848_SPEED_SELECT | DP83848_AUTONEG | DP83848_DUPLEX_MODE; |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 108 | davinci_eth_phy_write(phy_addr, DP83848_CTL_REG, tmp); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 109 | |
| 110 | /* Restart Auto_negotiation */ |
| 111 | tmp |= DP83848_RESTART_AUTONEG; |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 112 | davinci_eth_phy_write(phy_addr, DP83848_CTL_REG, tmp); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 113 | |
| 114 | /*check AutoNegotiate complete */ |
| 115 | udelay(10000); |
Sandeep Paulraj | 4b26f05 | 2008-08-31 00:39:46 +0200 | [diff] [blame] | 116 | if (!davinci_eth_phy_read(phy_addr, DP83848_STAT_REG, &tmp)) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 117 | return(0); |
| 118 | |
| 119 | if (!(tmp & DP83848_AUTONEG_COMP)) |
| 120 | return(0); |
| 121 | |
| 122 | return (dp83848_get_link_speed(phy_addr)); |
| 123 | } |
| 124 | |
| 125 | #endif /* CONFIG_CMD_NET */ |
| 126 | |
| 127 | #endif /* CONFIG_DRIVER_ETHER */ |