Add support for board-level PHY fixups
Subsystems (4)
RFC 1/1 Add support for board-level PHY fixups
Sometimes the specific interaction between the platform and the PHY requires special handling. For instance, to change where the PHY's clock input is, or to add a delay to account for latency issues in the data path. We add a mechanism for registering a callback with the PHY Lib to be called on matching PHYs when they are brought up, or reset.
---
I have some example code for this, it just got swallowed in a particularly egregious git mistake, and I wanted to get this out there sooner rather than later.
Documentation/networking/phy.txt | 38 +++++++++++- drivers/net/phy/mdio_bus.c | 3 + drivers/net/phy/phy.c | 4 +- drivers/net/phy/phy_device.c | 132 ++++++++++++++++++++++++++++++++++---- include/linux/phy.h | 24 ++++++- 5 files changed, 184 insertions(+), 17 deletions(-)
Documentation/networking/phy.txt +37 -1
@@ -1,7 +1,7 @@ ------- PHY Abstraction Layer -(Updated 2006-11-30) +(Updated 2008-04-08) Purpose
@@ -291,3 +291,39 @@ Writing a PHY driver Feel free to look at the Marvell, Cicada, and Davicom drivers in drivers/net/phy/ for examples (the lxt and qsemi drivers have not been tested as of this writing) + +Board Fixups + + Sometimes the specific interaction between the platform and the PHY requires + special handling. For instance, to change where the PHY's clock input is, + or to add a delay to account for latency issues in the data path. In order + to support such contingencies, the PHY Layer allows platform code to register + fixups to be run when the PHY is brought up (or subsequently reset). + + When the PHY Layer brings up a PHY it checks to see if there are any fixups + registered for it, matching based on UID (contained in the PHY device's phy_id + field) and the bus identifier (contained in phydev->dev.bus_id). Both must + match, however two constants, PHY_ANY_ID and PHY_ANY_UID, are provided as + wildcards for the bus ID and UID, respectively. + + When a match is found, the PHY layer will invoke the run function associated + with the fixup. This function is passed a pointer to the phy_device of + interest. It should therefore only operate on that PHY. + + The platform code can either register the fixup using phy_register_fixup(): + + int phy_register_fixup(const char *phy_id, + u32 phy_uid, u32 phy_uid_mask, + int (*run)(struct phy_device *)); + + Or using one of the two stubs, phy_register_fixup_for_uid() and + phy_register_fixup_for_id(): + + int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, + int (*run)(struct phy_device *)); + int phy_register_fixup_for_id(const char *phy_id, + int (*run)(struct phy_device *)); + + The stubs set one of the two matching criteria, and set the other one to + match anything. +
drivers/net/phy/mdio_bus.c +3 -0
@@ -89,6 +89,9 @@ int mdiobus_register(struct mii_bus *bus) phydev->bus = bus; +/* Run all of the fixups for this PHY */ +phy_scan_fixups (phydev); + err =device_register (&phydev->dev);if (err) {
drivers/net/phy/phy.c +3 -1
@@ -406,8 +406,10 @@ int phy_mii_ioctl(struct phy_device *phydev,if (mii_data->reg_num ==MII_BMCR && val &BMCR_RESET - && phydev->drv->config_init) + && phydev->drv->config_init) { +phy_scan_fixups (phydev); phydev->drv->config_init (phydev); + }break ;default :
drivers/net/phy/phy_device.c +119 -13
207 lines not on this page · raw message
include/linux/phy.h +22 -2
@@ -379,14 +379,26 @@ struct phy_driver { };#define to_phy_driver (d) container_of(d, struct phy_driver, driver) +#define PHY_ANY_ID "MATCH ANY PHY" +#define PHY_ANY_UID 0xffffffff + +/* A Structure for boards to register fixups with the PHY Lib */ +struct phy_fixup { +struct list_head list; +char bus_id[BUS_ID_SIZE ]; +u32 phy_uid; +u32 phy_uid_mask; +int (*run)(struct phy_device *phydev); +}; +int phy_read (struct phy_device *phydev,u16 regnum);int phy_write (struct phy_device *phydev,u16 regnum,u16 val);struct phy_device *get_phy_device (struct mii_bus *bus,int addr);int phy_clear_interrupt (struct phy_device *phydev);int phy_config_interrupt (struct phy_device *phydev,u32 interrupts);struct phy_device *phy_attach (struct net_device *dev, -const char *phy_id,u32 flags,phy_interface_t interface); -struct phy_device *phy_connect (struct net_device *dev,const char *phy_id, +const char *bus_id,u32 flags,phy_interface_t interface); +struct phy_device *phy_connect (struct net_device *dev,const char *bus_id,void (*handler)(struct net_device *),u32 flags,phy_interface_t interface);void phy_disconnect (struct phy_device *phydev);
@@ -426,5 +438,13 @@ void phy_print_status(struct phy_device *phydev);struct phy_device *phy_device_create (struct mii_bus *bus,int addr,int phy_id);void phy_device_free (struct phy_device *phydev); +int phy_register_fixup (const char *bus_id,u32 phy_uid,u32 phy_uid_mask, +int (*run)(struct phy_device *)); +int phy_register_fixup_for_id (const char *bus_id, +int (*run)(struct phy_device *)); +int phy_register_fixup_for_uid (u32 phy_uid,u32 phy_uid_mask, +int (*run)(struct phy_device *)); +int phy_scan_fixups (struct phy_device *phydev); +extern struct bus_type mdio_bus_type;#endif /* __PHY_H */
Signature · 1 line
1.5.4.GIT