Commit 5e82147d authored by Oleksij Rempel's avatar Oleksij Rempel Committed by Jakub Kicinski

net: mdiobus: search for PSE nodes by parsing PHY nodes.

Some PHYs can be linked with PSE (Power Sourcing Equipment), so search
for related nodes and attach it to the phydev.
Signed-off-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent cfaa202a
...@@ -10,10 +10,31 @@ ...@@ -10,10 +10,31 @@
#include <linux/fwnode_mdio.h> #include <linux/fwnode_mdio.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/pse-pd/pse.h>
MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>"); MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static struct pse_control *
fwnode_find_pse_control(struct fwnode_handle *fwnode)
{
struct pse_control *psec;
struct device_node *np;
if (!IS_ENABLED(CONFIG_PSE_CONTROLLER))
return NULL;
np = to_of_node(fwnode);
if (!np)
return NULL;
psec = of_pse_control_get(np);
if (PTR_ERR(psec) == -ENOENT)
return NULL;
return psec;
}
static struct mii_timestamper * static struct mii_timestamper *
fwnode_find_mii_timestamper(struct fwnode_handle *fwnode) fwnode_find_mii_timestamper(struct fwnode_handle *fwnode)
{ {
...@@ -91,14 +112,21 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, ...@@ -91,14 +112,21 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
struct fwnode_handle *child, u32 addr) struct fwnode_handle *child, u32 addr)
{ {
struct mii_timestamper *mii_ts = NULL; struct mii_timestamper *mii_ts = NULL;
struct pse_control *psec = NULL;
struct phy_device *phy; struct phy_device *phy;
bool is_c45 = false; bool is_c45 = false;
u32 phy_id; u32 phy_id;
int rc; int rc;
psec = fwnode_find_pse_control(child);
if (IS_ERR(psec))
return PTR_ERR(psec);
mii_ts = fwnode_find_mii_timestamper(child); mii_ts = fwnode_find_mii_timestamper(child);
if (IS_ERR(mii_ts)) if (IS_ERR(mii_ts)) {
return PTR_ERR(mii_ts); rc = PTR_ERR(mii_ts);
goto clean_pse;
}
rc = fwnode_property_match_string(child, "compatible", rc = fwnode_property_match_string(child, "compatible",
"ethernet-phy-ieee802.3-c45"); "ethernet-phy-ieee802.3-c45");
...@@ -134,18 +162,23 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, ...@@ -134,18 +162,23 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
goto clean_phy; goto clean_phy;
} }
phy->psec = psec;
/* phy->mii_ts may already be defined by the PHY driver. A /* phy->mii_ts may already be defined by the PHY driver. A
* mii_timestamper probed via the device tree will still have * mii_timestamper probed via the device tree will still have
* precedence. * precedence.
*/ */
if (mii_ts) if (mii_ts)
phy->mii_ts = mii_ts; phy->mii_ts = mii_ts;
return 0; return 0;
clean_phy: clean_phy:
phy_device_free(phy); phy_device_free(phy);
clean_mii_ts: clean_mii_ts:
unregister_mii_timestamper(mii_ts); unregister_mii_timestamper(mii_ts);
clean_pse:
pse_control_put(psec);
return rc; return rc;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/phy_led_triggers.h> #include <linux/phy_led_triggers.h>
#include <linux/pse-pd/pse.h>
#include <linux/property.h> #include <linux/property.h>
#include <linux/sfp.h> #include <linux/sfp.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
...@@ -991,6 +992,7 @@ EXPORT_SYMBOL(phy_device_register); ...@@ -991,6 +992,7 @@ EXPORT_SYMBOL(phy_device_register);
void phy_device_remove(struct phy_device *phydev) void phy_device_remove(struct phy_device *phydev)
{ {
unregister_mii_timestamper(phydev->mii_ts); unregister_mii_timestamper(phydev->mii_ts);
pse_control_put(phydev->psec);
device_del(&phydev->mdio.dev); device_del(&phydev->mdio.dev);
......
...@@ -597,6 +597,7 @@ struct macsec_ops; ...@@ -597,6 +597,7 @@ struct macsec_ops;
* @master_slave_get: Current master/slave advertisement * @master_slave_get: Current master/slave advertisement
* @master_slave_state: Current master/slave configuration * @master_slave_state: Current master/slave configuration
* @mii_ts: Pointer to time stamper callbacks * @mii_ts: Pointer to time stamper callbacks
* @psec: Pointer to Power Sourcing Equipment control struct
* @lock: Mutex for serialization access to PHY * @lock: Mutex for serialization access to PHY
* @state_queue: Work queue for state machine * @state_queue: Work queue for state machine
* @shared: Pointer to private data shared by phys in one package * @shared: Pointer to private data shared by phys in one package
...@@ -715,6 +716,7 @@ struct phy_device { ...@@ -715,6 +716,7 @@ struct phy_device {
struct phylink *phylink; struct phylink *phylink;
struct net_device *attached_dev; struct net_device *attached_dev;
struct mii_timestamper *mii_ts; struct mii_timestamper *mii_ts;
struct pse_control *psec;
u8 mdix; u8 mdix;
u8 mdix_ctrl; u8 mdix_ctrl;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment