blob: 8e507cd7a68584098ed45e937dab075e6e80062f [file] [log] [blame]
Andy Flemingaecf6fc2011-04-08 02:10:27 -05001/*
2 * Copyright 2011 Freescale Semiconductor, Inc.
Andy Flemingb36a4d42014-07-25 17:39:08 -05003 * Andy Fleming <afleming@gmail.com>
Andy Flemingaecf6fc2011-04-08 02:10:27 -05004 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Andy Flemingaecf6fc2011-04-08 02:10:27 -05006 *
7 * This file pretty much stolen from Linux's mii.h/ethtool.h/phy.h
8 */
9
10#ifndef _PHY_H
11#define _PHY_H
12
13#include <linux/list.h>
14#include <linux/mii.h>
15#include <linux/ethtool.h>
16#include <linux/mdio.h>
17
18#define PHY_MAX_ADDR 32
19
Shaohui Xie62a7b922016-01-28 15:55:46 +080020#define PHY_FLAG_BROKEN_RESET (1 << 0) /* soft reset not supported */
21
Florian Fainelli33bbc242016-01-13 16:59:33 +030022#define PHY_DEFAULT_FEATURES (SUPPORTED_Autoneg | \
Andy Flemingaecf6fc2011-04-08 02:10:27 -050023 SUPPORTED_TP | \
24 SUPPORTED_MII)
25
Florian Fainelli33bbc242016-01-13 16:59:33 +030026#define PHY_10BT_FEATURES (SUPPORTED_10baseT_Half | \
27 SUPPORTED_10baseT_Full)
28
29#define PHY_100BT_FEATURES (SUPPORTED_100baseT_Half | \
30 SUPPORTED_100baseT_Full)
31
32#define PHY_1000BT_FEATURES (SUPPORTED_1000baseT_Half | \
Andy Flemingaecf6fc2011-04-08 02:10:27 -050033 SUPPORTED_1000baseT_Full)
34
Florian Fainelli33bbc242016-01-13 16:59:33 +030035#define PHY_BASIC_FEATURES (PHY_10BT_FEATURES | \
36 PHY_100BT_FEATURES | \
37 PHY_DEFAULT_FEATURES)
38
39#define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \
40 PHY_1000BT_FEATURES)
41
Andy Flemingaecf6fc2011-04-08 02:10:27 -050042#define PHY_10G_FEATURES (PHY_GBIT_FEATURES | \
43 SUPPORTED_10000baseT_Full)
44
Stefan Roeseb6af5572014-10-22 12:13:15 +020045#ifndef PHY_ANEG_TIMEOUT
Andy Flemingaecf6fc2011-04-08 02:10:27 -050046#define PHY_ANEG_TIMEOUT 4000
Stefan Roeseb6af5572014-10-22 12:13:15 +020047#endif
Andy Flemingaecf6fc2011-04-08 02:10:27 -050048
49
50typedef enum {
51 PHY_INTERFACE_MODE_MII,
52 PHY_INTERFACE_MODE_GMII,
53 PHY_INTERFACE_MODE_SGMII,
Shengzhou Liu95403682014-10-23 17:20:57 +080054 PHY_INTERFACE_MODE_SGMII_2500,
Shaohui Xieaab42572013-03-25 07:39:31 +000055 PHY_INTERFACE_MODE_QSGMII,
Andy Flemingaecf6fc2011-04-08 02:10:27 -050056 PHY_INTERFACE_MODE_TBI,
57 PHY_INTERFACE_MODE_RMII,
58 PHY_INTERFACE_MODE_RGMII,
59 PHY_INTERFACE_MODE_RGMII_ID,
60 PHY_INTERFACE_MODE_RGMII_RXID,
61 PHY_INTERFACE_MODE_RGMII_TXID,
62 PHY_INTERFACE_MODE_RTBI,
63 PHY_INTERFACE_MODE_XGMII,
Stefan Roesef8c8cc12017-02-23 11:58:26 +010064 PHY_INTERFACE_MODE_XAUI,
65 PHY_INTERFACE_MODE_RXAUI,
66 PHY_INTERFACE_MODE_SFI,
Simon Glassdbad3462015-04-05 16:07:39 -060067 PHY_INTERFACE_MODE_NONE, /* Must be last */
68
69 PHY_INTERFACE_MODE_COUNT,
Andy Flemingaecf6fc2011-04-08 02:10:27 -050070} phy_interface_t;
71
72static const char *phy_interface_strings[] = {
73 [PHY_INTERFACE_MODE_MII] = "mii",
74 [PHY_INTERFACE_MODE_GMII] = "gmii",
75 [PHY_INTERFACE_MODE_SGMII] = "sgmii",
Shengzhou Liu95403682014-10-23 17:20:57 +080076 [PHY_INTERFACE_MODE_SGMII_2500] = "sgmii-2500",
Shaohui Xieaab42572013-03-25 07:39:31 +000077 [PHY_INTERFACE_MODE_QSGMII] = "qsgmii",
Andy Flemingaecf6fc2011-04-08 02:10:27 -050078 [PHY_INTERFACE_MODE_TBI] = "tbi",
79 [PHY_INTERFACE_MODE_RMII] = "rmii",
80 [PHY_INTERFACE_MODE_RGMII] = "rgmii",
81 [PHY_INTERFACE_MODE_RGMII_ID] = "rgmii-id",
82 [PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
83 [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
84 [PHY_INTERFACE_MODE_RTBI] = "rtbi",
85 [PHY_INTERFACE_MODE_XGMII] = "xgmii",
Stefan Roesef8c8cc12017-02-23 11:58:26 +010086 [PHY_INTERFACE_MODE_XAUI] = "xaui",
87 [PHY_INTERFACE_MODE_RXAUI] = "rxaui",
88 [PHY_INTERFACE_MODE_SFI] = "sfi",
Andy Flemingaecf6fc2011-04-08 02:10:27 -050089 [PHY_INTERFACE_MODE_NONE] = "",
90};
91
92static inline const char *phy_string_for_interface(phy_interface_t i)
93{
94 /* Default to unknown */
95 if (i > PHY_INTERFACE_MODE_NONE)
96 i = PHY_INTERFACE_MODE_NONE;
97
98 return phy_interface_strings[i];
99}
100
101
102struct phy_device;
103
104#define MDIO_NAME_LEN 32
105
106struct mii_dev {
107 struct list_head link;
108 char name[MDIO_NAME_LEN];
109 void *priv;
110 int (*read)(struct mii_dev *bus, int addr, int devad, int reg);
111 int (*write)(struct mii_dev *bus, int addr, int devad, int reg,
112 u16 val);
113 int (*reset)(struct mii_dev *bus);
114 struct phy_device *phymap[PHY_MAX_ADDR];
115 u32 phy_mask;
116};
117
118/* struct phy_driver: a structure which defines PHY behavior
119 *
120 * uid will contain a number which represents the PHY. During
121 * startup, the driver will poll the PHY to find out what its
122 * UID--as defined by registers 2 and 3--is. The 32-bit result
123 * gotten from the PHY will be masked to
124 * discard any bits which may change based on revision numbers
125 * unimportant to functionality
126 *
127 */
128struct phy_driver {
129 char *name;
130 unsigned int uid;
131 unsigned int mask;
132 unsigned int mmds;
133
134 u32 features;
135
136 /* Called to do any driver startup necessities */
137 /* Will be called during phy_connect */
138 int (*probe)(struct phy_device *phydev);
139
140 /* Called to configure the PHY, and modify the controller
141 * based on the results. Should be called after phy_connect */
142 int (*config)(struct phy_device *phydev);
143
144 /* Called when starting up the controller */
145 int (*startup)(struct phy_device *phydev);
146
147 /* Called when bringing down the controller */
148 int (*shutdown)(struct phy_device *phydev);
149
Stefano Babic6b8c5972013-09-02 15:42:30 +0200150 int (*readext)(struct phy_device *phydev, int addr, int devad, int reg);
151 int (*writeext)(struct phy_device *phydev, int addr, int devad, int reg,
152 u16 val);
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500153 struct list_head list;
154};
155
156struct phy_device {
157 /* Information about the PHY type */
158 /* And management functions */
159 struct mii_dev *bus;
160 struct phy_driver *drv;
161 void *priv;
162
Simon Glassdbad3462015-04-05 16:07:39 -0600163#ifdef CONFIG_DM_ETH
164 struct udevice *dev;
165#else
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500166 struct eth_device *dev;
Simon Glassdbad3462015-04-05 16:07:39 -0600167#endif
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500168
169 /* forced speed & duplex (no autoneg)
170 * partner speed & duplex & pause (autoneg)
171 */
172 int speed;
173 int duplex;
174
175 /* The most recently read link state */
176 int link;
177 int port;
178 phy_interface_t interface;
179
180 u32 advertising;
181 u32 supported;
182 u32 mmds;
183
184 int autoneg;
185 int addr;
186 int pause;
187 int asym_pause;
188 u32 phy_id;
189 u32 flags;
190};
191
Shaohui Xieb48127f2013-11-14 19:00:31 +0800192struct fixed_link {
193 int phy_id;
194 int duplex;
195 int link_speed;
196 int pause;
197 int asym_pause;
198};
199
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500200static inline int phy_read(struct phy_device *phydev, int devad, int regnum)
201{
202 struct mii_dev *bus = phydev->bus;
203
204 return bus->read(bus, phydev->addr, devad, regnum);
205}
206
207static inline int phy_write(struct phy_device *phydev, int devad, int regnum,
208 u16 val)
209{
210 struct mii_dev *bus = phydev->bus;
211
212 return bus->write(bus, phydev->addr, devad, regnum, val);
213}
214
215#ifdef CONFIG_PHYLIB_10G
216extern struct phy_driver gen10g_driver;
217
218/* For now, XGMII is the only 10G interface */
219static inline int is_10g_interface(phy_interface_t interface)
220{
221 return interface == PHY_INTERFACE_MODE_XGMII;
222}
223
224#endif
225
226int phy_init(void);
227int phy_reset(struct phy_device *phydev);
Troy Kisky9519bc52012-10-22 16:40:43 +0000228struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask,
229 phy_interface_t interface);
Simon Glassdbad3462015-04-05 16:07:39 -0600230#ifdef CONFIG_DM_ETH
231void phy_connect_dev(struct phy_device *phydev, struct udevice *dev);
232struct phy_device *phy_connect(struct mii_dev *bus, int addr,
233 struct udevice *dev,
234 phy_interface_t interface);
235#else
Troy Kisky9519bc52012-10-22 16:40:43 +0000236void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev);
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500237struct phy_device *phy_connect(struct mii_dev *bus, int addr,
238 struct eth_device *dev,
239 phy_interface_t interface);
Simon Glassdbad3462015-04-05 16:07:39 -0600240#endif
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500241int phy_startup(struct phy_device *phydev);
242int phy_config(struct phy_device *phydev);
243int phy_shutdown(struct phy_device *phydev);
244int phy_register(struct phy_driver *drv);
Alexey Brodkine476bb22016-01-13 16:59:34 +0300245int phy_set_supported(struct phy_device *phydev, u32 max_speed);
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500246int genphy_config_aneg(struct phy_device *phydev);
Troy Kisky80b6b092012-02-07 14:08:48 +0000247int genphy_restart_aneg(struct phy_device *phydev);
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500248int genphy_update_link(struct phy_device *phydev);
Yegor Yefremovc40f5d32012-11-28 11:15:17 +0100249int genphy_parse_link(struct phy_device *phydev);
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500250int genphy_config(struct phy_device *phydev);
251int genphy_startup(struct phy_device *phydev);
252int genphy_shutdown(struct phy_device *phydev);
253int gen10g_config(struct phy_device *phydev);
254int gen10g_startup(struct phy_device *phydev);
255int gen10g_shutdown(struct phy_device *phydev);
256int gen10g_discover_mmds(struct phy_device *phydev);
257
Kevin Smith87b2c4e2016-03-31 19:33:12 +0000258int phy_mv88e61xx_init(void);
Shaohui Xie0e548d72014-12-30 18:32:04 +0800259int phy_aquantia_init(void);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500260int phy_atheros_init(void);
261int phy_broadcom_init(void);
Shengzhou Liuc878bdb2014-11-10 18:32:29 +0800262int phy_cortina_init(void);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500263int phy_davicom_init(void);
Matt Porter3bbeb792013-03-20 05:38:13 +0000264int phy_et1011c_init(void);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500265int phy_lxt_init(void);
266int phy_marvell_init(void);
267int phy_micrel_init(void);
268int phy_natsemi_init(void);
269int phy_realtek_init(void);
Vladimir Zapolskiyaf9605f2011-12-29 15:18:37 +0000270int phy_smsc_init(void);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500271int phy_teranetics_init(void);
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700272int phy_ti_init(void);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500273int phy_vitesse_init(void);
Siva Durga Prasad Paladugudd6cbd32016-02-05 13:22:10 +0530274int phy_xilinx_init(void);
John Haechtenee253f92016-12-09 22:15:17 +0000275int phy_mscc_init(void);
Timur Tabi856f32f2011-10-18 18:44:34 -0500276
Fabio Estevam55e0f192014-02-15 14:52:00 -0200277int board_phy_config(struct phy_device *phydev);
Shengzhou Liu072b0fa2015-04-07 18:46:32 +0800278int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id);
Fabio Estevam55e0f192014-02-15 14:52:00 -0200279
Simon Glassdbad3462015-04-05 16:07:39 -0600280/**
281 * phy_get_interface_by_name() - Look up a PHY interface name
282 *
283 * @str: PHY interface name, e.g. "mii"
284 * @return PHY_INTERFACE_MODE_... value, or -1 if not found
285 */
286int phy_get_interface_by_name(const char *str);
287
Dan Murphy63e3cde2016-05-02 15:46:00 -0500288/**
289 * phy_interface_is_rgmii - Convenience function for testing if a PHY interface
290 * is RGMII (all variants)
291 * @phydev: the phy_device struct
292 */
293static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
294{
295 return phydev->interface >= PHY_INTERFACE_MODE_RGMII &&
296 phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID;
297}
298
Dan Murphy07cf56a2016-05-02 15:46:01 -0500299/**
300 * phy_interface_is_sgmii - Convenience function for testing if a PHY interface
301 * is SGMII (all variants)
302 * @phydev: the phy_device struct
303 */
304static inline bool phy_interface_is_sgmii(struct phy_device *phydev)
305{
306 return phydev->interface >= PHY_INTERFACE_MODE_SGMII &&
307 phydev->interface <= PHY_INTERFACE_MODE_QSGMII;
308}
309
Timur Tabi856f32f2011-10-18 18:44:34 -0500310/* PHY UIDs for various PHYs that are referenced in external code */
Shengzhou Liuc878bdb2014-11-10 18:32:29 +0800311#define PHY_UID_CS4340 0x13e51002
Timur Tabi856f32f2011-10-18 18:44:34 -0500312#define PHY_UID_TN2020 0x00a19410
313
Andy Flemingaecf6fc2011-04-08 02:10:27 -0500314#endif