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

phylib: add mdiobus_{read,write}

Add mdiobus_{read,write} routines to allow direct reading/writing
of registers on an mii bus without having to go through the PHY
abstraction, and make phy_{read,write} use these primitives.

Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Lennert Buytenhek and committed by
David S. Miller
2e888103 46abc021

+87 -57
+49
drivers/net/phy/mdio_bus.c
··· 211 211 EXPORT_SYMBOL(mdiobus_scan); 212 212 213 213 /** 214 + * mdiobus_read - Convenience function for reading a given MII mgmt register 215 + * @bus: the mii_bus struct 216 + * @addr: the phy address 217 + * @regnum: register number to read 218 + * 219 + * NOTE: MUST NOT be called from interrupt context, 220 + * because the bus read/write functions may wait for an interrupt 221 + * to conclude the operation. 222 + */ 223 + int mdiobus_read(struct mii_bus *bus, int addr, u16 regnum) 224 + { 225 + int retval; 226 + 227 + BUG_ON(in_interrupt()); 228 + 229 + mutex_lock(&bus->mdio_lock); 230 + retval = bus->read(bus, addr, regnum); 231 + mutex_unlock(&bus->mdio_lock); 232 + 233 + return retval; 234 + } 235 + EXPORT_SYMBOL(mdiobus_read); 236 + 237 + /** 238 + * mdiobus_write - Convenience function for writing a given MII mgmt register 239 + * @bus: the mii_bus struct 240 + * @addr: the phy address 241 + * @regnum: register number to write 242 + * @val: value to write to @regnum 243 + * 244 + * NOTE: MUST NOT be called from interrupt context, 245 + * because the bus read/write functions may wait for an interrupt 246 + * to conclude the operation. 247 + */ 248 + int mdiobus_write(struct mii_bus *bus, int addr, u16 regnum, u16 val) 249 + { 250 + int err; 251 + 252 + BUG_ON(in_interrupt()); 253 + 254 + mutex_lock(&bus->mdio_lock); 255 + err = bus->write(bus, addr, regnum, val); 256 + mutex_unlock(&bus->mdio_lock); 257 + 258 + return err; 259 + } 260 + EXPORT_SYMBOL(mdiobus_write); 261 + 262 + /** 214 263 * mdio_bus_match - determine if given PHY driver supports the given PHY device 215 264 * @dev: target PHY device 216 265 * @drv: given PHY driver
-49
drivers/net/phy/phy.c
··· 58 58 59 59 60 60 /** 61 - * phy_read - Convenience function for reading a given PHY register 62 - * @phydev: the phy_device struct 63 - * @regnum: register number to read 64 - * 65 - * NOTE: MUST NOT be called from interrupt context, 66 - * because the bus read/write functions may wait for an interrupt 67 - * to conclude the operation. 68 - */ 69 - int phy_read(struct phy_device *phydev, u16 regnum) 70 - { 71 - int retval; 72 - struct mii_bus *bus = phydev->bus; 73 - 74 - BUG_ON(in_interrupt()); 75 - 76 - mutex_lock(&bus->mdio_lock); 77 - retval = bus->read(bus, phydev->addr, regnum); 78 - mutex_unlock(&bus->mdio_lock); 79 - 80 - return retval; 81 - } 82 - EXPORT_SYMBOL(phy_read); 83 - 84 - /** 85 - * phy_write - Convenience function for writing a given PHY register 86 - * @phydev: the phy_device struct 87 - * @regnum: register number to write 88 - * @val: value to write to @regnum 89 - * 90 - * NOTE: MUST NOT be called from interrupt context, 91 - * because the bus read/write functions may wait for an interrupt 92 - * to conclude the operation. 93 - */ 94 - int phy_write(struct phy_device *phydev, u16 regnum, u16 val) 95 - { 96 - int err; 97 - struct mii_bus *bus = phydev->bus; 98 - 99 - BUG_ON(in_interrupt()); 100 - 101 - mutex_lock(&bus->mdio_lock); 102 - err = bus->write(bus, phydev->addr, regnum, val); 103 - mutex_unlock(&bus->mdio_lock); 104 - 105 - return err; 106 - } 107 - EXPORT_SYMBOL(phy_write); 108 - 109 - /** 110 61 * phy_clear_interrupt - Ack the phy device's interrupt 111 62 * @phydev: the phy_device struct 112 63 *
+38 -8
include/linux/phy.h
··· 122 122 }; 123 123 #define to_mii_bus(d) container_of(d, struct mii_bus, dev) 124 124 125 + struct mii_bus *mdiobus_alloc(void); 126 + int mdiobus_register(struct mii_bus *bus); 127 + void mdiobus_unregister(struct mii_bus *bus); 128 + void mdiobus_free(struct mii_bus *bus); 129 + struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr); 130 + int mdiobus_read(struct mii_bus *bus, int addr, u16 regnum); 131 + int mdiobus_write(struct mii_bus *bus, int addr, u16 regnum, u16 val); 132 + 133 + 125 134 #define PHY_INTERRUPT_DISABLED 0x0 126 135 #define PHY_INTERRUPT_ENABLED 0x80000000 127 136 ··· 408 399 int (*run)(struct phy_device *phydev); 409 400 }; 410 401 411 - int phy_read(struct phy_device *phydev, u16 regnum); 412 - int phy_write(struct phy_device *phydev, u16 regnum, u16 val); 402 + /** 403 + * phy_read - Convenience function for reading a given PHY register 404 + * @phydev: the phy_device struct 405 + * @regnum: register number to read 406 + * 407 + * NOTE: MUST NOT be called from interrupt context, 408 + * because the bus read/write functions may wait for an interrupt 409 + * to conclude the operation. 410 + */ 411 + static inline int phy_read(struct phy_device *phydev, u16 regnum) 412 + { 413 + return mdiobus_read(phydev->bus, phydev->addr, regnum); 414 + } 415 + 416 + /** 417 + * phy_write - Convenience function for writing a given PHY register 418 + * @phydev: the phy_device struct 419 + * @regnum: register number to write 420 + * @val: value to write to @regnum 421 + * 422 + * NOTE: MUST NOT be called from interrupt context, 423 + * because the bus read/write functions may wait for an interrupt 424 + * to conclude the operation. 425 + */ 426 + static inline int phy_write(struct phy_device *phydev, u16 regnum, u16 val) 427 + { 428 + return mdiobus_write(phydev->bus, phydev->addr, regnum, val); 429 + } 430 + 413 431 int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id); 414 432 struct phy_device* get_phy_device(struct mii_bus *bus, int addr); 415 433 int phy_clear_interrupt(struct phy_device *phydev); ··· 451 415 void phy_start(struct phy_device *phydev); 452 416 void phy_stop(struct phy_device *phydev); 453 417 int phy_start_aneg(struct phy_device *phydev); 454 - 455 - struct mii_bus *mdiobus_alloc(void); 456 - int mdiobus_register(struct mii_bus *bus); 457 - void mdiobus_unregister(struct mii_bus *bus); 458 - void mdiobus_free(struct mii_bus *bus); 459 - struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr); 460 418 461 419 void phy_sanitize_settings(struct phy_device *phydev); 462 420 int phy_stop_interrupts(struct phy_device *phydev);