1
2
3
4
5
6
7
8
9#ifndef _PHY_H
10#define _PHY_H
11
12#include <dm.h>
13#include <linux/list.h>
14#include <linux/mii.h>
15#include <linux/ethtool.h>
16#include <linux/mdio.h>
17#include <phy_interface.h>
18
19#define PHY_FIXED_ID 0xa5a55a5a
20
21
22
23
24#define PHY_GMII2RGMII_ID 0x5a5a5a5a
25
26#define PHY_MAX_ADDR 32
27
28#define PHY_FLAG_BROKEN_RESET (1 << 0)
29
30#define PHY_DEFAULT_FEATURES (SUPPORTED_Autoneg | \
31 SUPPORTED_TP | \
32 SUPPORTED_MII)
33
34#define PHY_10BT_FEATURES (SUPPORTED_10baseT_Half | \
35 SUPPORTED_10baseT_Full)
36
37#define PHY_100BT_FEATURES (SUPPORTED_100baseT_Half | \
38 SUPPORTED_100baseT_Full)
39
40#define PHY_1000BT_FEATURES (SUPPORTED_1000baseT_Half | \
41 SUPPORTED_1000baseT_Full)
42
43#define PHY_BASIC_FEATURES (PHY_10BT_FEATURES | \
44 PHY_100BT_FEATURES | \
45 PHY_DEFAULT_FEATURES)
46
47#define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \
48 PHY_1000BT_FEATURES)
49
50#define PHY_10G_FEATURES (PHY_GBIT_FEATURES | \
51 SUPPORTED_10000baseT_Full)
52
53#ifndef PHY_ANEG_TIMEOUT
54#define PHY_ANEG_TIMEOUT 4000
55#endif
56
57
58struct phy_device;
59
60#define MDIO_NAME_LEN 32
61
62struct mii_dev {
63 struct list_head link;
64 char name[MDIO_NAME_LEN];
65 void *priv;
66 int (*read)(struct mii_dev *bus, int addr, int devad, int reg);
67 int (*write)(struct mii_dev *bus, int addr, int devad, int reg,
68 u16 val);
69 int (*reset)(struct mii_dev *bus);
70 struct phy_device *phymap[PHY_MAX_ADDR];
71 u32 phy_mask;
72};
73
74
75
76
77
78
79
80
81
82
83
84struct phy_driver {
85 char *name;
86 unsigned int uid;
87 unsigned int mask;
88 unsigned int mmds;
89
90 u32 features;
91
92
93
94 int (*probe)(struct phy_device *phydev);
95
96
97
98 int (*config)(struct phy_device *phydev);
99
100
101 int (*startup)(struct phy_device *phydev);
102
103
104 int (*shutdown)(struct phy_device *phydev);
105
106 int (*readext)(struct phy_device *phydev, int addr, int devad, int reg);
107 int (*writeext)(struct phy_device *phydev, int addr, int devad, int reg,
108 u16 val);
109 struct list_head list;
110};
111
112struct phy_device {
113
114
115 struct mii_dev *bus;
116 struct phy_driver *drv;
117 void *priv;
118
119#ifdef CONFIG_DM_ETH
120 struct udevice *dev;
121 ofnode node;
122#else
123 struct eth_device *dev;
124#endif
125
126
127
128
129 int speed;
130 int duplex;
131
132
133 int link;
134 int port;
135 phy_interface_t interface;
136
137 u32 advertising;
138 u32 supported;
139 u32 mmds;
140
141 int autoneg;
142 int addr;
143 int pause;
144 int asym_pause;
145 u32 phy_id;
146 u32 flags;
147};
148
149struct fixed_link {
150 int phy_id;
151 int duplex;
152 int link_speed;
153 int pause;
154 int asym_pause;
155};
156
157static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
158{
159 struct mii_dev *bus = phydev->bus;
160
161 return bus->read(bus, phydev->addr, devad, regnum);
162}
163
164static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
165 u16 val)
166{
167 struct mii_dev *bus = phydev->bus;
168
169 return bus->write(bus, phydev->addr, devad, regnum, val);
170}
171
172#ifdef CONFIG_PHYLIB_10G
173extern struct phy_driver gen10g_driver;
174
175
176static inline int is_10g_interface(phy_interface_t interface)
177{
178 return interface == PHY_INTERFACE_MODE_XGMII;
179}
180
181#endif
182
183int phy_init(void);
184int phy_reset(struct phy_device *phydev);
185struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask,
186 phy_interface_t interface);
187#ifdef CONFIG_DM_ETH
188void phy_connect_dev(struct phy_device *phydev, struct udevice *dev);
189struct phy_device *phy_connect(struct mii_dev *bus, int addr,
190 struct udevice *dev,
191 phy_interface_t interface);
192static inline ofnode phy_get_ofnode(struct phy_device *phydev)
193{
194 if (ofnode_valid(phydev->node))
195 return phydev->node;
196 else
197 return dev_ofnode(phydev->dev);
198}
199#else
200void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev);
201struct phy_device *phy_connect(struct mii_dev *bus, int addr,
202 struct eth_device *dev,
203 phy_interface_t interface);
204static inline ofnode phy_get_ofnode(struct phy_device *phydev)
205{
206 return ofnode_null();
207}
208#endif
209int phy_startup(struct phy_device *phydev);
210int phy_config(struct phy_device *phydev);
211int phy_shutdown(struct phy_device *phydev);
212int phy_register(struct phy_driver *drv);
213int phy_set_supported(struct phy_device *phydev, u32 max_speed);
214int genphy_config_aneg(struct phy_device *phydev);
215int genphy_restart_aneg(struct phy_device *phydev);
216int genphy_update_link(struct phy_device *phydev);
217int genphy_parse_link(struct phy_device *phydev);
218int genphy_config(struct phy_device *phydev);
219int genphy_startup(struct phy_device *phydev);
220int genphy_shutdown(struct phy_device *phydev);
221int gen10g_config(struct phy_device *phydev);
222int gen10g_startup(struct phy_device *phydev);
223int gen10g_shutdown(struct phy_device *phydev);
224int gen10g_discover_mmds(struct phy_device *phydev);
225
226int phy_b53_init(void);
227int phy_mv88e61xx_init(void);
228int phy_aquantia_init(void);
229int phy_atheros_init(void);
230int phy_broadcom_init(void);
231int phy_cortina_init(void);
232int phy_davicom_init(void);
233int phy_et1011c_init(void);
234int phy_lxt_init(void);
235int phy_marvell_init(void);
236int phy_micrel_ksz8xxx_init(void);
237int phy_micrel_ksz90x1_init(void);
238int phy_meson_gxl_init(void);
239int phy_natsemi_init(void);
240int phy_realtek_init(void);
241int phy_smsc_init(void);
242int phy_teranetics_init(void);
243int phy_ti_init(void);
244int phy_vitesse_init(void);
245int phy_xilinx_init(void);
246int phy_mscc_init(void);
247int phy_fixed_init(void);
248int phy_xilinx_gmii2rgmii_init(void);
249
250int board_phy_config(struct phy_device *phydev);
251int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id);
252
253
254
255
256
257
258
259int phy_get_interface_by_name(const char *str);
260
261
262
263
264
265
266static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
267{
268 return phydev->interface >= PHY_INTERFACE_MODE_RGMII &&
269 phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID;
270}
271
272
273
274
275
276
277static inline bool phy_interface_is_sgmii(struct phy_device *phydev)
278{
279 return phydev->interface >= PHY_INTERFACE_MODE_SGMII &&
280 phydev->interface <= PHY_INTERFACE_MODE_QSGMII;
281}
282
283
284#define PHY_UID_CS4340 0x13e51002
285#define PHY_UID_CS4223 0x03e57003
286#define PHY_UID_TN2020 0x00a19410
287#define PHY_UID_IN112525_S03 0x02107440
288
289#endif
290