mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-07 13:43:51 +00:00
net: dsa: Add helper function to obtain PHY device of a given port
In preparation for having more call sites attempting to obtain a reference against a PHY device corresponding to a particular port, introduce a helper function for that purpose. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
89f0904834
commit
6207a78c09
@ -273,24 +273,37 @@ int dsa_port_vlan_del(struct dsa_port *dp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp)
|
||||
{
|
||||
struct device_node *phy_dn;
|
||||
struct phy_device *phydev;
|
||||
|
||||
phy_dn = of_parse_phandle(dp->dn, "phy-handle", 0);
|
||||
if (!phy_dn)
|
||||
return NULL;
|
||||
|
||||
phydev = of_phy_find_device(phy_dn);
|
||||
if (!phydev) {
|
||||
of_node_put(phy_dn);
|
||||
return ERR_PTR(-EPROBE_DEFER);
|
||||
}
|
||||
|
||||
return phydev;
|
||||
}
|
||||
|
||||
static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable)
|
||||
{
|
||||
struct device_node *port_dn = dp->dn;
|
||||
struct device_node *phy_dn;
|
||||
struct dsa_switch *ds = dp->ds;
|
||||
struct phy_device *phydev;
|
||||
int port = dp->index;
|
||||
int err = 0;
|
||||
|
||||
phy_dn = of_parse_phandle(port_dn, "phy-handle", 0);
|
||||
if (!phy_dn)
|
||||
phydev = dsa_port_get_phy_device(dp);
|
||||
if (!phydev)
|
||||
return 0;
|
||||
|
||||
phydev = of_phy_find_device(phy_dn);
|
||||
if (!phydev) {
|
||||
err = -EPROBE_DEFER;
|
||||
goto err_put_of;
|
||||
}
|
||||
if (IS_ERR(phydev))
|
||||
return PTR_ERR(phydev);
|
||||
|
||||
if (enable) {
|
||||
err = genphy_config_init(phydev);
|
||||
@ -317,8 +330,6 @@ static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable)
|
||||
|
||||
err_put_dev:
|
||||
put_device(&phydev->mdio.dev);
|
||||
err_put_of:
|
||||
of_node_put(phy_dn);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user