summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Fischer <mdf@kernel.org>2019-02-07 12:52:10 -0500
committerDavid S. Miller <davem@davemloft.net>2019-02-07 21:11:58 -0500
commit71bd106d2567675668e253cba3960e3c4bf2e80e (patch)
treee8f34fc458693dd53076ee2993ddb0402966ef0e
parenta4751093a26c6bbdff86c113e7f76cf4eaf22210 (diff)
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>
-rw-r--r--drivers/net/phy/fixed_phy.c32
-rw-r--r--include/linux/phy_fixed.h15
2 files changed, 40 insertions, 7 deletions
diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
index d810f914aaa4..b0d1368c3400 100644
--- a/drivers/net/phy/fixed_phy.c
+++ b/drivers/net/phy/fixed_phy.c
@@ -229,12 +229,12 @@ static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np)
229} 229}
230#endif 230#endif
231 231
232struct phy_device *fixed_phy_register(unsigned int irq, 232static struct phy_device *__fixed_phy_register(unsigned int irq,
233 struct fixed_phy_status *status, 233 struct fixed_phy_status *status,
234 struct device_node *np) 234 struct device_node *np,
235 struct gpio_desc *gpiod)
235{ 236{
236 struct fixed_mdio_bus *fmb = &platform_fmb; 237 struct fixed_mdio_bus *fmb = &platform_fmb;
237 struct gpio_desc *gpiod = NULL;
238 struct phy_device *phy; 238 struct phy_device *phy;
239 int phy_addr; 239 int phy_addr;
240 int ret; 240 int ret;
@@ -243,9 +243,11 @@ struct phy_device *fixed_phy_register(unsigned int irq,
243 return ERR_PTR(-EPROBE_DEFER); 243 return ERR_PTR(-EPROBE_DEFER);
244 244
245 /* Check if we have a GPIO associated with this fixed phy */ 245 /* Check if we have a GPIO associated with this fixed phy */
246 gpiod = fixed_phy_get_gpiod(np); 246 if (!gpiod) {
247 if (IS_ERR(gpiod)) 247 gpiod = fixed_phy_get_gpiod(np);
248 return ERR_CAST(gpiod); 248 if (IS_ERR(gpiod))
249 return ERR_CAST(gpiod);
250 }
249 251
250 /* Get the next available PHY address, up to PHY_MAX_ADDR */ 252 /* Get the next available PHY address, up to PHY_MAX_ADDR */
251 phy_addr = ida_simple_get(&phy_fixed_ida, 0, PHY_MAX_ADDR, GFP_KERNEL); 253 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,
308 310
309 return phy; 311 return phy;
310} 312}
313
314struct 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}
311EXPORT_SYMBOL_GPL(fixed_phy_register); 320EXPORT_SYMBOL_GPL(fixed_phy_register);
312 321
322struct phy_device *
323fixed_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}
329EXPORT_SYMBOL_GPL(fixed_phy_register_with_gpiod);
330
313void fixed_phy_unregister(struct phy_device *phy) 331void fixed_phy_unregister(struct phy_device *phy)
314{ 332{
315 phy_device_remove(phy); 333 phy_device_remove(phy);
diff --git a/include/linux/phy_fixed.h b/include/linux/phy_fixed.h
index c78fc203db43..1e5d86ebdaeb 100644
--- a/include/linux/phy_fixed.h
+++ b/include/linux/phy_fixed.h
@@ -19,6 +19,12 @@ extern int fixed_phy_add(unsigned int irq, int phy_id,
19extern struct phy_device *fixed_phy_register(unsigned int irq, 19extern struct phy_device *fixed_phy_register(unsigned int irq,
20 struct fixed_phy_status *status, 20 struct fixed_phy_status *status,
21 struct device_node *np); 21 struct device_node *np);
22
23extern struct phy_device *
24fixed_phy_register_with_gpiod(unsigned int irq,
25 struct fixed_phy_status *status,
26 struct gpio_desc *gpiod);
27
22extern void fixed_phy_unregister(struct phy_device *phydev); 28extern void fixed_phy_unregister(struct phy_device *phydev);
23extern int fixed_phy_set_link_update(struct phy_device *phydev, 29extern int fixed_phy_set_link_update(struct phy_device *phydev,
24 int (*link_update)(struct net_device *, 30 int (*link_update)(struct net_device *,
@@ -35,6 +41,15 @@ static inline struct phy_device *fixed_phy_register(unsigned int irq,
35{ 41{
36 return ERR_PTR(-ENODEV); 42 return ERR_PTR(-ENODEV);
37} 43}
44
45static inline struct phy_device *
46fixed_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
38static inline void fixed_phy_unregister(struct phy_device *phydev) 53static inline void fixed_phy_unregister(struct phy_device *phydev)
39{ 54{
40} 55}