15#include <drivers/core/driver.h>
20#include <general_phy.h>
21#define RT_PHY_FIXED_ID 0xa5a55a5a
22#define RT_PHY_NCSI_ID 0xbeefcafe
26#define RT_SUPPORTED_10baseT_Half (1 << 0)
27#define RT_SUPPORTED_10baseT_Full (1 << 1)
28#define RT_SUPPORTED_100baseT_Half (1 << 2)
29#define RT_SUPPORTED_100baseT_Full (1 << 3)
30#define RT_SUPPORTED_1000baseT_Half (1 << 4)
31#define RT_SUPPORTED_1000baseT_Full (1 << 5)
32#define RT_SUPPORTED_Autoneg (1 << 6)
33#define RT_SUPPORTED_TP (1 << 7)
34#define RT_SUPPORTED_AUI (1 << 8)
35#define RT_SUPPORTED_MII (1 << 9)
36#define RT_SUPPORTED_FIBRE (1 << 10)
37#define RT_SUPPORTED_BNC (1 << 11)
38#define RT_SUPPORTED_10000baseT_Full (1 << 12)
39#define RT_SUPPORTED_Pause (1 << 13)
40#define RT_SUPPORTED_Asym_Pause (1 << 14)
41#define RT_SUPPORTED_2500baseX_Full (1 << 15)
42#define RT_SUPPORTED_Backplane (1 << 16)
43#define RT_SUPPORTED_1000baseKX_Full (1 << 17)
44#define RT_SUPPORTED_10000baseKX4_Full (1 << 18)
45#define RT_SUPPORTED_10000baseKR_Full (1 << 19)
46#define RT_SUPPORTED_10000baseR_FEC (1 << 20)
47#define RT_SUPPORTED_1000baseX_Half (1 << 21)
48#define RT_SUPPORTED_1000baseX_Full (1 << 22)
50#define RT_PHY_FLAG_BROKEN_RESET (1 << 0)
51#define RT_PHY_DEFAULT_FEATURES (RT_SUPPORTED_Autoneg | RT_SUPPORTED_TP | RT_SUPPORTED_MII)
53#define RT_PHY_10BT_FEATURES (RT_SUPPORTED_10baseT_Half | RT_SUPPORTED_10baseT_Full)
55#define RT_PHY_100BT_FEATURES (RT_SUPPORTED_100baseT_Half | RT_SUPPORTED_100baseT_Full)
57#define RT_PHY_1000BT_FEATURES (RT_SUPPORTED_1000baseT_Half | RT_SUPPORTED_1000baseT_Full)
59#define RT_PHY_BASIC_FEATURES (RT_PHY_10BT_FEATURES | RT_PHY_100BT_FEATURES | RT_PHY_DEFAULT_FEATURES)
61#define RT_PHY_GBIT_FEATURES (RT_PHY_BASIC_FEATURES | RT_PHY_1000BT_FEATURES)
63#define RT_PHY_10G_FEATURES (RT_PHY_GBIT_FEATURES | RT_SUPPORTED_10000baseT_Full)
66 struct rt_device parent;
68 struct rt_phy_driver *drv;
82 rt_phy_interface interface;
85 struct rt_ofw_node *node;
92 struct rt_driver parent;
93 char name[RT_NAME_MAX];
99 int (*probe)(
struct rt_phy_device *phydev);
100 int (*config)(
struct rt_phy_device *phydev);
101 int (*startup)(
struct rt_phy_device *phydev);
102 int (*shutdown)(
struct rt_phy_device *phydev);
103 int (*
read)(
struct rt_phy_device *phydev,
int addr,
int devad,
int reg);
104 int (*
write)(
struct rt_phy_device *phydev,
int addr,
int devad,
int reg,
106 int (*read_mmd)(
struct rt_phy_device *phydev,
int devad,
int reg);
107 int (*write_mmd)(
struct rt_phy_device *phydev,
int devad,
int reg,
114int rt_phy_read(
struct rt_phy_device *phydev,
int devad,
int regnum);
115int rt_phy_write(
struct rt_phy_device *phydev,
int devad,
int regnum,
rt_uint16_t val);
116int rt_phy_read_mmd(
struct rt_phy_device *phydev,
int devad,
int regnum);
117int rt_phy_write_mmd(
struct rt_phy_device *phydev,
int devad,
int regnum,
rt_uint16_t val);
118int rt_phy_reset(
struct rt_phy_device *phydev);
119int rt_phy_startup(
struct rt_phy_device *phydev);
120int rt_phy_config(
struct rt_phy_device *phydev);
121int rt_phy_shutdown(
struct rt_phy_device *phydev);
122int rt_phy_read_mmd(
struct rt_phy_device *phydev,
int devad,
int regnum);
123int rt_phy_set_supported(
struct rt_phy_device *phydev,
rt_uint32_t max_speed);
125void rt_phy_mmd_start_indirect(
struct rt_phy_device *phydev,
int devad,
int regnum);
127rt_err_t rt_phy_device_register(
struct rt_phy_device *pdev);
128rt_err_t rt_phy_driver_register(
struct rt_phy_driver *pdrv);
131struct rt_phy_device *rt_phy_device_create(
struct mii_bus *bus,
int addr,
rt_uint32_t phy_id,
rt_bool_t is_c45);
132struct rt_phy_device *rt_phy_find_by_mask(
struct mii_bus *bus,
unsigned int phy_mask);
133struct rt_phy_device *rt_ofw_create_phy(
struct mii_bus *bus,
struct rt_ofw_node *np,
int phyaddr);
134struct rt_phy_device *rt_phy_get_device(
struct mii_bus *bus,
struct rt_ofw_node *np,
int addr, rt_phy_interface interface);
136#define RT_PHY_DEVICE_REGISTER(phy_dev) \
137static int rt_##phy_dev##_register(void) \
139 rt_phy_device_register(&phy_dev); \
142INIT_PREV_EXPORT(rt_##phy_dev##_register);
144#define RT_PHY_DRIVER_REGISTER(phy_drv) \
145static int rt_##phy_drv##_register(void) \
147 rt_phy_driver_register(&phy_drv); \
150INIT_PREV_EXPORT(rt_##phy_drv##_register);
159struct rt_mdio_bus_ops
171 struct rt_mdio_bus_ops *ops;
174typedef struct rt_mdio_bus rt_mdio_t;
177#define PHY_SPEED_10M 0U
178#define PHY_SPEED_100M 1U
179#define PHY_SPEED_1000M 2U
182#define PHY_HALF_DUPLEX 0U
183#define PHY_FULL_DUPLEX 1U
186#define PHY_LOCAL_LOOP 0U
187#define PHY_REMOTE_LOOP 1U
189#define PHY_STATUS_OK 0U
190#define PHY_STATUS_FAIL 1U
191#define PHY_STATUS_TIMEOUT 2U
193typedef struct rt_phy_msg
199typedef struct rt_phy_device
201 struct rt_device parent;
202 struct rt_mdio_bus *bus;
204 struct rt_phy_ops *ops;
215 rt_phy_status (*get_link_status)(rt_phy_t *phy,
rt_bool_t *status);
219rt_err_t rt_hw_phy_register(
struct rt_phy_device *phy,
const char *name);
ssize_t write(int fd, const void *buf, size_t len)
ssize_t read(int fd, void *buf, size_t len)
unsigned short rt_uint16_t
unsigned long long rt_uint64_t