Skip to content

Commit fd2ef0b

Browse files
Petri Gyntherdavem330
authored andcommitted
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: Petri Gynther <pgynther@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 02c0fc1 commit fd2ef0b

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

drivers/net/phy/fixed.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ EXPORT_SYMBOL_GPL(fixed_phy_del);
233233
static int phy_fixed_addr;
234234
static DEFINE_SPINLOCK(phy_fixed_addr_lock);
235235

236-
int fixed_phy_register(unsigned int irq,
237-
struct fixed_phy_status *status,
238-
struct device_node *np)
236+
struct phy_device *fixed_phy_register(unsigned int irq,
237+
struct fixed_phy_status *status,
238+
struct device_node *np)
239239
{
240240
struct fixed_mdio_bus *fmb = &platform_fmb;
241241
struct phy_device *phy;
@@ -246,19 +246,19 @@ int fixed_phy_register(unsigned int irq,
246246
spin_lock(&phy_fixed_addr_lock);
247247
if (phy_fixed_addr == PHY_MAX_ADDR) {
248248
spin_unlock(&phy_fixed_addr_lock);
249-
return -ENOSPC;
249+
return ERR_PTR(-ENOSPC);
250250
}
251251
phy_addr = phy_fixed_addr++;
252252
spin_unlock(&phy_fixed_addr_lock);
253253

254254
ret = fixed_phy_add(PHY_POLL, phy_addr, status);
255255
if (ret < 0)
256-
return ret;
256+
return ERR_PTR(ret);
257257

258258
phy = get_phy_device(fmb->mii_bus, phy_addr, false);
259259
if (!phy || IS_ERR(phy)) {
260260
fixed_phy_del(phy_addr);
261-
return -EINVAL;
261+
return ERR_PTR(-EINVAL);
262262
}
263263

264264
of_node_get(np);
@@ -269,10 +269,10 @@ int fixed_phy_register(unsigned int irq,
269269
phy_device_free(phy);
270270
of_node_put(np);
271271
fixed_phy_del(phy_addr);
272-
return ret;
272+
return ERR_PTR(ret);
273273
}
274274

275-
return 0;
275+
return phy;
276276
}
277277

278278
static int __init fixed_mdio_bus_init(void)

drivers/of/of_mdio.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ int of_phy_register_fixed_link(struct device_node *np)
286286
struct device_node *fixed_link_node;
287287
const __be32 *fixed_link_prop;
288288
int len;
289+
struct phy_device *phy;
289290

290291
/* New binding */
291292
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)
299300
status.asym_pause = of_property_read_bool(fixed_link_node,
300301
"asym-pause");
301302
of_node_put(fixed_link_node);
302-
return fixed_phy_register(PHY_POLL, &status, np);
303+
phy = fixed_phy_register(PHY_POLL, &status, np);
304+
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
303305
}
304306

305307
/* Old binding */
@@ -310,7 +312,8 @@ int of_phy_register_fixed_link(struct device_node *np)
310312
status.speed = be32_to_cpu(fixed_link_prop[2]);
311313
status.pause = be32_to_cpu(fixed_link_prop[3]);
312314
status.asym_pause = be32_to_cpu(fixed_link_prop[4]);
313-
return fixed_phy_register(PHY_POLL, &status, np);
315+
phy = fixed_phy_register(PHY_POLL, &status, np);
316+
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
314317
}
315318

316319
return -ENODEV;

include/linux/phy_fixed.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ struct device_node;
1414
#ifdef CONFIG_FIXED_PHY
1515
extern int fixed_phy_add(unsigned int irq, int phy_id,
1616
struct fixed_phy_status *status);
17-
extern int fixed_phy_register(unsigned int irq,
18-
struct fixed_phy_status *status,
19-
struct device_node *np);
17+
extern struct phy_device *fixed_phy_register(unsigned int irq,
18+
struct fixed_phy_status *status,
19+
struct device_node *np);
2020
extern void fixed_phy_del(int phy_addr);
2121
extern int fixed_phy_set_link_update(struct phy_device *phydev,
2222
int (*link_update)(struct net_device *,
@@ -27,11 +27,11 @@ static inline int fixed_phy_add(unsigned int irq, int phy_id,
2727
{
2828
return -ENODEV;
2929
}
30-
static inline int fixed_phy_register(unsigned int irq,
31-
struct fixed_phy_status *status,
32-
struct device_node *np)
30+
static inline struct phy_device *fixed_phy_register(unsigned int irq,
31+
struct fixed_phy_status *status,
32+
struct device_node *np)
3333
{
34-
return -ENODEV;
34+
return ERR_PTR(-ENODEV);
3535
}
3636
static inline int fixed_phy_del(int phy_addr)
3737
{

0 commit comments

Comments
 (0)