1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <common.h>
29#include <net.h>
30#include <dp83848.h>
31#include <asm/arch/emac_defs.h>
32#include "../../../../../drivers/net/davinci_emac.h"
33
34#ifdef CONFIG_DRIVER_TI_EMAC
35
36#ifdef CONFIG_CMD_NET
37
38int dp83848_is_phy_connected(int phy_addr)
39{
40 u_int16_t id1, id2;
41
42 if (!davinci_eth_phy_read(phy_addr, DP83848_PHYID1_REG, &id1))
43 return(0);
44 if (!davinci_eth_phy_read(phy_addr, DP83848_PHYID2_REG, &id2))
45 return(0);
46
47 if ((id1 == DP83848_PHYID1_OUI) && (id2 == DP83848_PHYID2_OUI))
48 return(1);
49
50 return(0);
51}
52
53int dp83848_get_link_speed(int phy_addr)
54{
55 u_int16_t tmp;
56 volatile emac_regs* emac = (emac_regs *)EMAC_BASE_ADDR;
57
58 if (!davinci_eth_phy_read(phy_addr, DP83848_STAT_REG, &tmp))
59 return(0);
60
61 if (!(tmp & DP83848_LINK_STATUS))
62 return(0);
63
64 if (!davinci_eth_phy_read(phy_addr, DP83848_PHY_STAT_REG, &tmp))
65 return(0);
66
67
68 if (tmp & DP83848_DUPLEX) {
69
70 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE |
71 EMAC_MACCONTROL_FULLDUPLEX_ENABLE;
72 } else {
73
74 emac->MACCONTROL = EMAC_MACCONTROL_MIIEN_ENABLE;
75 }
76
77 return(1);
78}
79
80
81int dp83848_init_phy(int phy_addr)
82{
83 int ret = 1;
84
85 if (!dp83848_get_link_speed(phy_addr)) {
86
87 udelay(100000);
88 ret = dp83848_get_link_speed(phy_addr);
89 }
90
91
92 davinci_eth_phy_write(phy_addr, DP83848_PHY_INTR_CTRL_REG, 0);
93
94 return(ret);
95}
96
97
98int dp83848_auto_negotiate(int phy_addr)
99{
100 u_int16_t tmp;
101
102
103 if (!davinci_eth_phy_read(phy_addr, DP83848_CTL_REG, &tmp))
104 return(0);
105
106
107 tmp &= ~DP83848_AUTONEG;
108 tmp |= DP83848_ISOLATE;
109 davinci_eth_phy_write(phy_addr, DP83848_CTL_REG, tmp);
110
111
112
113
114
115 tmp = DP83848_NP | DP83848_TX_FDX | DP83848_TX_HDX |
116 DP83848_10_FDX | DP83848_10_HDX | DP83848_AN_IEEE_802_3;
117 davinci_eth_phy_write(phy_addr, DP83848_ANA_REG, tmp);
118
119
120
121 if (!davinci_eth_phy_read(phy_addr, DP83848_CTL_REG, &tmp))
122 return(0);
123
124 tmp |= DP83848_SPEED_SELECT | DP83848_AUTONEG | DP83848_DUPLEX_MODE;
125 davinci_eth_phy_write(phy_addr, DP83848_CTL_REG, tmp);
126
127
128 tmp |= DP83848_RESTART_AUTONEG;
129 davinci_eth_phy_write(phy_addr, DP83848_CTL_REG, tmp);
130
131
132 udelay(10000);
133 if (!davinci_eth_phy_read(phy_addr, DP83848_STAT_REG, &tmp))
134 return(0);
135
136 if (!(tmp & DP83848_AUTONEG_COMP))
137 return(0);
138
139 return (dp83848_get_link_speed(phy_addr));
140}
141
142#endif
143
144#endif
145