Skip to content

Commit 71bd106

Browse files
mfischerdavem330
authored andcommitted
net: fixed-phy: Add fixed_phy_register_with_gpiod() API
Add fixed_phy_register_with_gpiod() API. It lets users create a fixed_phy instance that uses a GPIO descriptor which was obtained externally e.g. through platform data. This enables platform devices (non-DT based) to use GPIOs for link status. Signed-off-by: Moritz Fischer <mdf@kernel.org> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a475109 commit 71bd106

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

drivers/net/phy/fixed_phy.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np)
229229
}
230230
#endif
231231

232-
struct phy_device *fixed_phy_register(unsigned int irq,
233-
struct fixed_phy_status *status,
234-
struct device_node *np)
232+
static struct phy_device *__fixed_phy_register(unsigned int irq,
233+
struct fixed_phy_status *status,
234+
struct device_node *np,
235+
struct gpio_desc *gpiod)
235236
{
236237
struct fixed_mdio_bus *fmb = &platform_fmb;
237-
struct gpio_desc *gpiod = NULL;
238238
struct phy_device *phy;
239239
int phy_addr;
240240
int ret;
@@ -243,9 +243,11 @@ struct phy_device *fixed_phy_register(unsigned int irq,
243243
return ERR_PTR(-EPROBE_DEFER);
244244

245245
/* Check if we have a GPIO associated with this fixed phy */
246-
gpiod = fixed_phy_get_gpiod(np);
247-
if (IS_ERR(gpiod))
248-
return ERR_CAST(gpiod);
246+
if (!gpiod) {
247+
gpiod = fixed_phy_get_gpiod(np);
248+
if (IS_ERR(gpiod))
249+
return ERR_CAST(gpiod);
250+
}
249251

250252
/* Get the next available PHY address, up to PHY_MAX_ADDR */
251253
phy_addr = ida_simple_get(&phy_fixed_ida, 0, PHY_MAX_ADDR, GFP_KERNEL);
@@ -308,8 +310,24 @@ struct phy_device *fixed_phy_register(unsigned int irq,
308310

309311
return phy;
310312
}
313+
314+
struct phy_device *fixed_phy_register(unsigned int irq,
315+
struct fixed_phy_status *status,
316+
struct device_node *np)
317+
{
318+
return __fixed_phy_register(irq, status, np, NULL);
319+
}
311320
EXPORT_SYMBOL_GPL(fixed_phy_register);
312321

322+
struct phy_device *
323+
fixed_phy_register_with_gpiod(unsigned int irq,
324+
struct fixed_phy_status *status,
325+
struct gpio_desc *gpiod)
326+
{
327+
return __fixed_phy_register(irq, status, NULL, gpiod);
328+
}
329+
EXPORT_SYMBOL_GPL(fixed_phy_register_with_gpiod);
330+
313331
void fixed_phy_unregister(struct phy_device *phy)
314332
{
315333
phy_device_remove(phy);

include/linux/phy_fixed.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ extern int fixed_phy_add(unsigned int irq, int phy_id,
1919
extern struct phy_device *fixed_phy_register(unsigned int irq,
2020
struct fixed_phy_status *status,
2121
struct device_node *np);
22+
23+
extern struct phy_device *
24+
fixed_phy_register_with_gpiod(unsigned int irq,
25+
struct fixed_phy_status *status,
26+
struct gpio_desc *gpiod);
27+
2228
extern void fixed_phy_unregister(struct phy_device *phydev);
2329
extern int fixed_phy_set_link_update(struct phy_device *phydev,
2430
int (*link_update)(struct net_device *,
@@ -35,6 +41,15 @@ static inline struct phy_device *fixed_phy_register(unsigned int irq,
3541
{
3642
return ERR_PTR(-ENODEV);
3743
}
44+
45+
static inline struct phy_device *
46+
fixed_phy_register_with_gpiod(unsigned int irq,
47+
struct fixed_phy_status *status,
48+
struct gpio_desc *gpiod)
49+
{
50+
return ERR_PTR(-ENODEV);
51+
}
52+
3853
static inline void fixed_phy_unregister(struct phy_device *phydev)
3954
{
4055
}

0 commit comments

Comments
 (0)