Commit fd2ef0ba authored by Petri Gynther's avatar Petri Gynther Committed by David S. Miller

net: phy: adjust fixed_phy_register() return value

Adjust fixed_phy_register() to return struct phy_device *, so that
it becomes easy to use fixed PHYs without device tree support:

  phydev = fixed_phy_register(PHY_POLL, &fixed_phy_status, NULL);
  fixed_phy_set_link_update(phydev, fixed_phy_link_update);
  phy_connect_direct(netdev, phydev, handler_fn, phy_interface);

This change is a prerequisite for modifying bcmgenet driver to work
without a device tree on Broadcom's MIPS-based 7xxx platforms.
Signed-off-by: default avatarPetri Gynther <pgynther@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 02c0fc1b
...@@ -233,7 +233,7 @@ EXPORT_SYMBOL_GPL(fixed_phy_del); ...@@ -233,7 +233,7 @@ EXPORT_SYMBOL_GPL(fixed_phy_del);
static int phy_fixed_addr; static int phy_fixed_addr;
static DEFINE_SPINLOCK(phy_fixed_addr_lock); static DEFINE_SPINLOCK(phy_fixed_addr_lock);
int fixed_phy_register(unsigned int irq, struct phy_device *fixed_phy_register(unsigned int irq,
struct fixed_phy_status *status, struct fixed_phy_status *status,
struct device_node *np) struct device_node *np)
{ {
...@@ -246,19 +246,19 @@ int fixed_phy_register(unsigned int irq, ...@@ -246,19 +246,19 @@ int fixed_phy_register(unsigned int irq,
spin_lock(&phy_fixed_addr_lock); spin_lock(&phy_fixed_addr_lock);
if (phy_fixed_addr == PHY_MAX_ADDR) { if (phy_fixed_addr == PHY_MAX_ADDR) {
spin_unlock(&phy_fixed_addr_lock); spin_unlock(&phy_fixed_addr_lock);
return -ENOSPC; return ERR_PTR(-ENOSPC);
} }
phy_addr = phy_fixed_addr++; phy_addr = phy_fixed_addr++;
spin_unlock(&phy_fixed_addr_lock); spin_unlock(&phy_fixed_addr_lock);
ret = fixed_phy_add(PHY_POLL, phy_addr, status); ret = fixed_phy_add(PHY_POLL, phy_addr, status);
if (ret < 0) if (ret < 0)
return ret; return ERR_PTR(ret);
phy = get_phy_device(fmb->mii_bus, phy_addr, false); phy = get_phy_device(fmb->mii_bus, phy_addr, false);
if (!phy || IS_ERR(phy)) { if (!phy || IS_ERR(phy)) {
fixed_phy_del(phy_addr); fixed_phy_del(phy_addr);
return -EINVAL; return ERR_PTR(-EINVAL);
} }
of_node_get(np); of_node_get(np);
...@@ -269,10 +269,10 @@ int fixed_phy_register(unsigned int irq, ...@@ -269,10 +269,10 @@ int fixed_phy_register(unsigned int irq,
phy_device_free(phy); phy_device_free(phy);
of_node_put(np); of_node_put(np);
fixed_phy_del(phy_addr); fixed_phy_del(phy_addr);
return ret; return ERR_PTR(ret);
} }
return 0; return phy;
} }
static int __init fixed_mdio_bus_init(void) static int __init fixed_mdio_bus_init(void)
......
...@@ -286,6 +286,7 @@ int of_phy_register_fixed_link(struct device_node *np) ...@@ -286,6 +286,7 @@ int of_phy_register_fixed_link(struct device_node *np)
struct device_node *fixed_link_node; struct device_node *fixed_link_node;
const __be32 *fixed_link_prop; const __be32 *fixed_link_prop;
int len; int len;
struct phy_device *phy;
/* New binding */ /* New binding */
fixed_link_node = of_get_child_by_name(np, "fixed-link"); fixed_link_node = of_get_child_by_name(np, "fixed-link");
...@@ -299,7 +300,8 @@ int of_phy_register_fixed_link(struct device_node *np) ...@@ -299,7 +300,8 @@ int of_phy_register_fixed_link(struct device_node *np)
status.asym_pause = of_property_read_bool(fixed_link_node, status.asym_pause = of_property_read_bool(fixed_link_node,
"asym-pause"); "asym-pause");
of_node_put(fixed_link_node); of_node_put(fixed_link_node);
return fixed_phy_register(PHY_POLL, &status, np); phy = fixed_phy_register(PHY_POLL, &status, np);
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
} }
/* Old binding */ /* Old binding */
...@@ -310,7 +312,8 @@ int of_phy_register_fixed_link(struct device_node *np) ...@@ -310,7 +312,8 @@ int of_phy_register_fixed_link(struct device_node *np)
status.speed = be32_to_cpu(fixed_link_prop[2]); status.speed = be32_to_cpu(fixed_link_prop[2]);
status.pause = be32_to_cpu(fixed_link_prop[3]); status.pause = be32_to_cpu(fixed_link_prop[3]);
status.asym_pause = be32_to_cpu(fixed_link_prop[4]); status.asym_pause = be32_to_cpu(fixed_link_prop[4]);
return fixed_phy_register(PHY_POLL, &status, np); phy = fixed_phy_register(PHY_POLL, &status, np);
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
} }
return -ENODEV; return -ENODEV;
......
...@@ -14,7 +14,7 @@ struct device_node; ...@@ -14,7 +14,7 @@ struct device_node;
#ifdef CONFIG_FIXED_PHY #ifdef CONFIG_FIXED_PHY
extern int fixed_phy_add(unsigned int irq, int phy_id, extern int fixed_phy_add(unsigned int irq, int phy_id,
struct fixed_phy_status *status); struct fixed_phy_status *status);
extern int fixed_phy_register(unsigned int irq, extern struct phy_device *fixed_phy_register(unsigned int irq,
struct fixed_phy_status *status, struct fixed_phy_status *status,
struct device_node *np); struct device_node *np);
extern void fixed_phy_del(int phy_addr); extern void fixed_phy_del(int phy_addr);
...@@ -27,11 +27,11 @@ static inline int fixed_phy_add(unsigned int irq, int phy_id, ...@@ -27,11 +27,11 @@ static inline int fixed_phy_add(unsigned int irq, int phy_id,
{ {
return -ENODEV; return -ENODEV;
} }
static inline int fixed_phy_register(unsigned int irq, static inline struct phy_device *fixed_phy_register(unsigned int irq,
struct fixed_phy_status *status, struct fixed_phy_status *status,
struct device_node *np) struct device_node *np)
{ {
return -ENODEV; return ERR_PTR(-ENODEV);
} }
static inline int fixed_phy_del(int phy_addr) static inline int fixed_phy_del(int phy_addr)
{ {
......
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