Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: fixed-phy: Drop GPIO from fixed_phy_add()

All users of the fixed_phy_add() pass -1 as GPIO number
to the fixed phy driver, and all users of fixed_phy_register()
pass -1 as GPIO number as well, except for the device
tree MDIO bus.

Any new users should create a proper device and pass the
GPIO as a descriptor associated with the device so delete
the GPIO argument from the calls and drop the code looking
requesting a GPIO in fixed_phy_add().

In fixed phy_register(), investigate the "fixed-link"
node and pick the GPIO descriptor from "link-gpios" if
this property exists. Move the corresponding code out
of of_mdio.c as the fixed phy code anyways requires
OF to be in use.

Tested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Linus Walleij and committed by
David S. Miller
5468e82f fc9c5a4a

+72 -46
+1 -1
Documentation/networking/device_drivers/stmicro/stmmac.txt
··· 267 267 268 268 During the board's device_init we can configure the first 269 269 MAC for fixed_link by calling: 270 - fixed_phy_add(PHY_POLL, 1, &stmmac0_fixed_phy_status, -1); 270 + fixed_phy_add(PHY_POLL, 1, &stmmac0_fixed_phy_status); 271 271 and the second one, with a real PHY device attached to the bus, 272 272 by using the stmmac_mdio_bus_data structure (to provide the id, the 273 273 reset procedure etc).
+1 -1
arch/m68k/coldfire/m5272.c
··· 127 127 static int __init init_BSP(void) 128 128 { 129 129 m5272_uarts_init(); 130 - fixed_phy_add(PHY_POLL, 0, &nettel_fixed_phy_status, -1); 130 + fixed_phy_add(PHY_POLL, 0, &nettel_fixed_phy_status); 131 131 return 0; 132 132 } 133 133
+2 -2
arch/mips/ar7/platform.c
··· 683 683 684 684 if (ar7_has_high_cpmac()) { 685 685 res = fixed_phy_add(PHY_POLL, cpmac_high.id, 686 - &fixed_phy_status, -1); 686 + &fixed_phy_status); 687 687 if (!res) { 688 688 cpmac_get_mac(1, cpmac_high_data.dev_addr); 689 689 ··· 696 696 } else 697 697 cpmac_low_data.phy_mask = 0xffffffff; 698 698 699 - res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status, -1); 699 + res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status); 700 700 if (!res) { 701 701 cpmac_get_mac(0, cpmac_low_data.dev_addr); 702 702 res = platform_device_register(&cpmac_low);
+1 -1
arch/mips/bcm47xx/setup.c
··· 274 274 bcm47xx_leds_register(); 275 275 bcm47xx_workarounds(); 276 276 277 - fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status, -1); 277 + fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status); 278 278 return 0; 279 279 } 280 280 device_initcall(bcm47xx_register_bus_complete);
+1 -1
drivers/net/dsa/dsa_loop.c
··· 343 343 unsigned int i; 344 344 345 345 for (i = 0; i < NUM_FIXED_PHYS; i++) 346 - phydevs[i] = fixed_phy_register(PHY_POLL, &status, -1, NULL); 346 + phydevs[i] = fixed_phy_register(PHY_POLL, &status, NULL); 347 347 348 348 return mdio_driver_register(&dsa_loop_drv); 349 349 }
+1 -1
drivers/net/ethernet/broadcom/bgmac.c
··· 1446 1446 struct phy_device *phy_dev; 1447 1447 int err; 1448 1448 1449 - phy_dev = fixed_phy_register(PHY_POLL, &fphy_status, -1, NULL); 1449 + phy_dev = fixed_phy_register(PHY_POLL, &fphy_status, NULL); 1450 1450 if (!phy_dev || IS_ERR(phy_dev)) { 1451 1451 dev_err(bgmac->dev, "Failed to register fixed PHY device\n"); 1452 1452 return -ENODEV;
+1 -1
drivers/net/ethernet/broadcom/genet/bcmmii.c
··· 525 525 .asym_pause = 0, 526 526 }; 527 527 528 - phydev = fixed_phy_register(PHY_POLL, &fphy_status, -1, NULL); 528 + phydev = fixed_phy_register(PHY_POLL, &fphy_status, NULL); 529 529 if (!phydev || IS_ERR(phydev)) { 530 530 dev_err(kdev, "failed to register fixed PHY device\n"); 531 531 return -ENODEV;
+60 -22
drivers/net/phy/fixed_phy.c
··· 18 18 #include <linux/err.h> 19 19 #include <linux/slab.h> 20 20 #include <linux/of.h> 21 - #include <linux/gpio.h> 21 + #include <linux/gpio/consumer.h> 22 22 #include <linux/seqlock.h> 23 23 #include <linux/idr.h> 24 24 #include <linux/netdevice.h> ··· 38 38 bool no_carrier; 39 39 int (*link_update)(struct net_device *, struct fixed_phy_status *); 40 40 struct list_head node; 41 - int link_gpio; 41 + struct gpio_desc *link_gpiod; 42 42 }; 43 43 44 44 static struct platform_device *pdev; ··· 67 67 68 68 static void fixed_phy_update(struct fixed_phy *fp) 69 69 { 70 - if (!fp->no_carrier && gpio_is_valid(fp->link_gpio)) 71 - fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio); 70 + if (!fp->no_carrier && fp->link_gpiod) 71 + fp->status.link = !!gpiod_get_value_cansleep(fp->link_gpiod); 72 72 } 73 73 74 74 static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num) ··· 133 133 } 134 134 EXPORT_SYMBOL_GPL(fixed_phy_set_link_update); 135 135 136 - int fixed_phy_add(unsigned int irq, int phy_addr, 137 - struct fixed_phy_status *status, 138 - int link_gpio) 136 + static int fixed_phy_add_gpiod(unsigned int irq, int phy_addr, 137 + struct fixed_phy_status *status, 138 + struct gpio_desc *gpiod) 139 139 { 140 140 int ret; 141 141 struct fixed_mdio_bus *fmb = &platform_fmb; ··· 156 156 157 157 fp->addr = phy_addr; 158 158 fp->status = *status; 159 - fp->link_gpio = link_gpio; 160 - 161 - if (gpio_is_valid(fp->link_gpio)) { 162 - ret = gpio_request_one(fp->link_gpio, GPIOF_DIR_IN, 163 - "fixed-link-gpio-link"); 164 - if (ret) 165 - goto err_regs; 166 - } 159 + fp->link_gpiod = gpiod; 167 160 168 161 fixed_phy_update(fp); 169 162 170 163 list_add_tail(&fp->node, &fmb->phys); 171 164 172 165 return 0; 166 + } 173 167 174 - err_regs: 175 - kfree(fp); 176 - return ret; 168 + int fixed_phy_add(unsigned int irq, int phy_addr, 169 + struct fixed_phy_status *status) { 170 + 171 + return fixed_phy_add_gpiod(irq, phy_addr, status, NULL); 177 172 } 178 173 EXPORT_SYMBOL_GPL(fixed_phy_add); 179 174 ··· 182 187 list_for_each_entry_safe(fp, tmp, &fmb->phys, node) { 183 188 if (fp->addr == phy_addr) { 184 189 list_del(&fp->node); 185 - if (gpio_is_valid(fp->link_gpio)) 186 - gpio_free(fp->link_gpio); 190 + if (fp->link_gpiod) 191 + gpiod_put(fp->link_gpiod); 187 192 kfree(fp); 188 193 ida_simple_remove(&phy_fixed_ida, phy_addr); 189 194 return; ··· 191 196 } 192 197 } 193 198 199 + #ifdef CONFIG_OF_GPIO 200 + static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) 201 + { 202 + struct device_node *fixed_link_node; 203 + struct gpio_desc *gpiod; 204 + 205 + if (!np) 206 + return NULL; 207 + 208 + fixed_link_node = of_get_child_by_name(np, "fixed-link"); 209 + if (!fixed_link_node) 210 + return NULL; 211 + 212 + /* 213 + * As the fixed link is just a device tree node without any 214 + * Linux device associated with it, we simply have obtain 215 + * the GPIO descriptor from the device tree like this. 216 + */ 217 + gpiod = gpiod_get_from_of_node(fixed_link_node, "link-gpios", 0, 218 + GPIOD_IN, "mdio"); 219 + of_node_put(fixed_link_node); 220 + if (IS_ERR(gpiod)) { 221 + if (PTR_ERR(gpiod) == -EPROBE_DEFER) 222 + return gpiod; 223 + pr_err("error getting GPIO for fixed link %pOF, proceed without\n", 224 + fixed_link_node); 225 + gpiod = NULL; 226 + } 227 + 228 + return gpiod; 229 + } 230 + #else 231 + static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) 232 + { 233 + return NULL; 234 + } 235 + #endif 236 + 194 237 struct phy_device *fixed_phy_register(unsigned int irq, 195 238 struct fixed_phy_status *status, 196 - int link_gpio, 197 239 struct device_node *np) 198 240 { 199 241 struct fixed_mdio_bus *fmb = &platform_fmb; 242 + struct gpio_desc *gpiod = NULL; 200 243 struct phy_device *phy; 201 244 int phy_addr; 202 245 int ret; ··· 242 209 if (!fmb->mii_bus || fmb->mii_bus->state != MDIOBUS_REGISTERED) 243 210 return ERR_PTR(-EPROBE_DEFER); 244 211 212 + /* Check if we have a GPIO associated with this fixed phy */ 213 + gpiod = fixed_phy_get_gpiod(np); 214 + if (IS_ERR(gpiod)) 215 + return ERR_CAST(gpiod); 216 + 245 217 /* Get the next available PHY address, up to PHY_MAX_ADDR */ 246 218 phy_addr = ida_simple_get(&phy_fixed_ida, 0, PHY_MAX_ADDR, GFP_KERNEL); 247 219 if (phy_addr < 0) 248 220 return ERR_PTR(phy_addr); 249 221 250 - ret = fixed_phy_add(irq, phy_addr, status, link_gpio); 222 + ret = fixed_phy_add_gpiod(irq, phy_addr, status, gpiod); 251 223 if (ret < 0) { 252 224 ida_simple_remove(&phy_fixed_ida, phy_addr); 253 225 return ERR_PTR(ret);
+1 -2
drivers/net/usb/lan78xx.c
··· 2051 2051 phydev = phy_find_first(dev->mdiobus); 2052 2052 if (!phydev) { 2053 2053 netdev_dbg(dev->net, "PHY Not Found!! Registering Fixed PHY\n"); 2054 - phydev = fixed_phy_register(PHY_POLL, &fphy_status, -1, 2055 - NULL); 2054 + phydev = fixed_phy_register(PHY_POLL, &fphy_status, NULL); 2056 2055 if (IS_ERR(phydev)) { 2057 2056 netdev_err(dev->net, "No PHY/fixed_PHY found\n"); 2058 2057 return NULL;
+1 -8
drivers/of/of_mdio.c
··· 16 16 #include <linux/phy.h> 17 17 #include <linux/phy_fixed.h> 18 18 #include <linux/of.h> 19 - #include <linux/of_gpio.h> 20 19 #include <linux/of_irq.h> 21 20 #include <linux/of_mdio.h> 22 21 #include <linux/of_net.h> ··· 462 463 struct device_node *fixed_link_node; 463 464 u32 fixed_link_prop[5]; 464 465 const char *managed; 465 - int link_gpio = -1; 466 466 467 467 if (of_property_read_string(np, "managed", &managed) == 0 && 468 468 strcmp(managed, "in-band-status") == 0) { ··· 483 485 status.pause = of_property_read_bool(fixed_link_node, "pause"); 484 486 status.asym_pause = of_property_read_bool(fixed_link_node, 485 487 "asym-pause"); 486 - link_gpio = of_get_named_gpio_flags(fixed_link_node, 487 - "link-gpios", 0, NULL); 488 488 of_node_put(fixed_link_node); 489 - if (link_gpio == -EPROBE_DEFER) 490 - return -EPROBE_DEFER; 491 489 492 490 goto register_phy; 493 491 } ··· 502 508 return -ENODEV; 503 509 504 510 register_phy: 505 - return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, link_gpio, 506 - np)); 511 + return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, np)); 507 512 } 508 513 EXPORT_SYMBOL(of_phy_register_fixed_link); 509 514
+2 -6
include/linux/phy_fixed.h
··· 15 15 #if IS_ENABLED(CONFIG_FIXED_PHY) 16 16 extern int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier); 17 17 extern int fixed_phy_add(unsigned int irq, int phy_id, 18 - struct fixed_phy_status *status, 19 - int link_gpio); 18 + struct fixed_phy_status *status); 20 19 extern struct phy_device *fixed_phy_register(unsigned int irq, 21 20 struct fixed_phy_status *status, 22 - int link_gpio, 23 21 struct device_node *np); 24 22 extern void fixed_phy_unregister(struct phy_device *phydev); 25 23 extern int fixed_phy_set_link_update(struct phy_device *phydev, ··· 25 27 struct fixed_phy_status *)); 26 28 #else 27 29 static inline int fixed_phy_add(unsigned int irq, int phy_id, 28 - struct fixed_phy_status *status, 29 - int link_gpio) 30 + struct fixed_phy_status *status) 30 31 { 31 32 return -ENODEV; 32 33 } 33 34 static inline struct phy_device *fixed_phy_register(unsigned int irq, 34 35 struct fixed_phy_status *status, 35 - int gpio_link, 36 36 struct device_node *np) 37 37 { 38 38 return ERR_PTR(-ENODEV);