1 // SPDX-License-Identifier: GPL-2.0+
3 * Core PHY library, taken from phy.c
5 #include <linux/export.h>
9 const char *phy_speed_to_str(int speed)
11 BUILD_BUG_ON_MSG(__ETHTOOL_LINK_MODE_MASK_NBITS != 69,
12 "Enum ethtool_link_mode_bit_indices and phylib are out of sync. "
13 "If a speed or mode has been added please update phy_speed_to_str "
14 "and the PHY settings array.\n");
48 return "Unsupported (update phy-core.c)";
51 EXPORT_SYMBOL_GPL(phy_speed_to_str);
53 const char *phy_duplex_to_str(unsigned int duplex)
55 if (duplex == DUPLEX_HALF)
57 if (duplex == DUPLEX_FULL)
59 if (duplex == DUPLEX_UNKNOWN)
61 return "Unsupported (update phy-core.c)";
63 EXPORT_SYMBOL_GPL(phy_duplex_to_str);
65 /* A mapping of all SUPPORTED settings to speed/duplex. This table
66 * must be grouped by speed and sorted in descending match priority
67 * - iow, descending speed. */
69 #define PHY_SETTING(s, d, b) { .speed = SPEED_ ## s, .duplex = DUPLEX_ ## d, \
70 .bit = ETHTOOL_LINK_MODE_ ## b ## _BIT}
72 static const struct phy_setting settings[] = {
74 PHY_SETTING( 200000, FULL, 200000baseCR4_Full ),
75 PHY_SETTING( 200000, FULL, 200000baseKR4_Full ),
76 PHY_SETTING( 200000, FULL, 200000baseLR4_ER4_FR4_Full ),
77 PHY_SETTING( 200000, FULL, 200000baseDR4_Full ),
78 PHY_SETTING( 200000, FULL, 200000baseSR4_Full ),
80 PHY_SETTING( 100000, FULL, 100000baseCR4_Full ),
81 PHY_SETTING( 100000, FULL, 100000baseKR4_Full ),
82 PHY_SETTING( 100000, FULL, 100000baseLR4_ER4_Full ),
83 PHY_SETTING( 100000, FULL, 100000baseSR4_Full ),
84 PHY_SETTING( 100000, FULL, 100000baseCR2_Full ),
85 PHY_SETTING( 100000, FULL, 100000baseKR2_Full ),
86 PHY_SETTING( 100000, FULL, 100000baseLR2_ER2_FR2_Full ),
87 PHY_SETTING( 100000, FULL, 100000baseDR2_Full ),
88 PHY_SETTING( 100000, FULL, 100000baseSR2_Full ),
90 PHY_SETTING( 56000, FULL, 56000baseCR4_Full ),
91 PHY_SETTING( 56000, FULL, 56000baseKR4_Full ),
92 PHY_SETTING( 56000, FULL, 56000baseLR4_Full ),
93 PHY_SETTING( 56000, FULL, 56000baseSR4_Full ),
95 PHY_SETTING( 50000, FULL, 50000baseCR2_Full ),
96 PHY_SETTING( 50000, FULL, 50000baseKR2_Full ),
97 PHY_SETTING( 50000, FULL, 50000baseSR2_Full ),
98 PHY_SETTING( 50000, FULL, 50000baseCR_Full ),
99 PHY_SETTING( 50000, FULL, 50000baseKR_Full ),
100 PHY_SETTING( 50000, FULL, 50000baseLR_ER_FR_Full ),
101 PHY_SETTING( 50000, FULL, 50000baseDR_Full ),
102 PHY_SETTING( 50000, FULL, 50000baseSR_Full ),
104 PHY_SETTING( 40000, FULL, 40000baseCR4_Full ),
105 PHY_SETTING( 40000, FULL, 40000baseKR4_Full ),
106 PHY_SETTING( 40000, FULL, 40000baseLR4_Full ),
107 PHY_SETTING( 40000, FULL, 40000baseSR4_Full ),
109 PHY_SETTING( 25000, FULL, 25000baseCR_Full ),
110 PHY_SETTING( 25000, FULL, 25000baseKR_Full ),
111 PHY_SETTING( 25000, FULL, 25000baseSR_Full ),
113 PHY_SETTING( 20000, FULL, 20000baseKR2_Full ),
114 PHY_SETTING( 20000, FULL, 20000baseMLD2_Full ),
116 PHY_SETTING( 10000, FULL, 10000baseCR_Full ),
117 PHY_SETTING( 10000, FULL, 10000baseER_Full ),
118 PHY_SETTING( 10000, FULL, 10000baseKR_Full ),
119 PHY_SETTING( 10000, FULL, 10000baseKX4_Full ),
120 PHY_SETTING( 10000, FULL, 10000baseLR_Full ),
121 PHY_SETTING( 10000, FULL, 10000baseLRM_Full ),
122 PHY_SETTING( 10000, FULL, 10000baseR_FEC ),
123 PHY_SETTING( 10000, FULL, 10000baseSR_Full ),
124 PHY_SETTING( 10000, FULL, 10000baseT_Full ),
126 PHY_SETTING( 5000, FULL, 5000baseT_Full ),
128 PHY_SETTING( 2500, FULL, 2500baseT_Full ),
129 PHY_SETTING( 2500, FULL, 2500baseX_Full ),
131 PHY_SETTING( 1000, FULL, 1000baseKX_Full ),
132 PHY_SETTING( 1000, FULL, 1000baseT_Full ),
133 PHY_SETTING( 1000, HALF, 1000baseT_Half ),
134 PHY_SETTING( 1000, FULL, 1000baseT1_Full ),
135 PHY_SETTING( 1000, FULL, 1000baseX_Full ),
137 PHY_SETTING( 100, FULL, 100baseT_Full ),
138 PHY_SETTING( 100, FULL, 100baseT1_Full ),
139 PHY_SETTING( 100, HALF, 100baseT_Half ),
141 PHY_SETTING( 10, FULL, 10baseT_Full ),
142 PHY_SETTING( 10, HALF, 10baseT_Half ),
147 * phy_lookup_setting - lookup a PHY setting
148 * @speed: speed to match
149 * @duplex: duplex to match
150 * @mask: allowed link modes
151 * @exact: an exact match is required
153 * Search the settings array for a setting that matches the speed and
154 * duplex, and which is supported.
156 * If @exact is unset, either an exact match or %NULL for no match will
159 * If @exact is set, an exact match, the fastest supported setting at
160 * or below the specified speed, the slowest supported setting, or if
161 * they all fail, %NULL will be returned.
163 const struct phy_setting *
164 phy_lookup_setting(int speed, int duplex, const unsigned long *mask, bool exact)
166 const struct phy_setting *p, *match = NULL, *last = NULL;
169 for (i = 0, p = settings; i < ARRAY_SIZE(settings); i++, p++) {
170 if (p->bit < __ETHTOOL_LINK_MODE_MASK_NBITS &&
171 test_bit(p->bit, mask)) {
173 if (p->speed == speed && p->duplex == duplex) {
174 /* Exact match for speed and duplex */
178 if (!match && p->speed <= speed)
182 if (p->speed < speed)
188 if (!match && !exact)
193 EXPORT_SYMBOL_GPL(phy_lookup_setting);
195 size_t phy_speeds(unsigned int *speeds, size_t size,
201 for (i = 0, count = 0; i < ARRAY_SIZE(settings) && count < size; i++)
202 if (settings[i].bit < __ETHTOOL_LINK_MODE_MASK_NBITS &&
203 test_bit(settings[i].bit, mask) &&
204 (count == 0 || speeds[count - 1] != settings[i].speed))
205 speeds[count++] = settings[i].speed;
210 static int __set_linkmode_max_speed(u32 max_speed, unsigned long *addr)
212 const struct phy_setting *p;
215 for (i = 0, p = settings; i < ARRAY_SIZE(settings); i++, p++) {
216 if (p->speed > max_speed)
217 linkmode_clear_bit(p->bit, addr);
225 static int __set_phy_supported(struct phy_device *phydev, u32 max_speed)
227 return __set_linkmode_max_speed(max_speed, phydev->supported);
230 int phy_set_max_speed(struct phy_device *phydev, u32 max_speed)
234 err = __set_phy_supported(phydev, max_speed);
238 phy_advertise_supported(phydev);
242 EXPORT_SYMBOL(phy_set_max_speed);
244 void of_set_phy_supported(struct phy_device *phydev)
246 struct device_node *node = phydev->mdio.dev.of_node;
249 if (!IS_ENABLED(CONFIG_OF_MDIO))
255 if (!of_property_read_u32(node, "max-speed", &max_speed))
256 __set_phy_supported(phydev, max_speed);
259 void of_set_phy_eee_broken(struct phy_device *phydev)
261 struct device_node *node = phydev->mdio.dev.of_node;
264 if (!IS_ENABLED(CONFIG_OF_MDIO))
270 if (of_property_read_bool(node, "eee-broken-100tx"))
271 broken |= MDIO_EEE_100TX;
272 if (of_property_read_bool(node, "eee-broken-1000t"))
273 broken |= MDIO_EEE_1000T;
274 if (of_property_read_bool(node, "eee-broken-10gt"))
275 broken |= MDIO_EEE_10GT;
276 if (of_property_read_bool(node, "eee-broken-1000kx"))
277 broken |= MDIO_EEE_1000KX;
278 if (of_property_read_bool(node, "eee-broken-10gkx4"))
279 broken |= MDIO_EEE_10GKX4;
280 if (of_property_read_bool(node, "eee-broken-10gkr"))
281 broken |= MDIO_EEE_10GKR;
283 phydev->eee_broken_modes = broken;
286 void phy_resolve_aneg_pause(struct phy_device *phydev)
288 if (phydev->duplex == DUPLEX_FULL) {
289 phydev->pause = linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,
290 phydev->lp_advertising);
291 phydev->asym_pause = linkmode_test_bit(
292 ETHTOOL_LINK_MODE_Asym_Pause_BIT,
293 phydev->lp_advertising);
296 EXPORT_SYMBOL_GPL(phy_resolve_aneg_pause);
299 * phy_resolve_aneg_linkmode - resolve the advertisements into phy settings
300 * @phydev: The phy_device struct
302 * Resolve our and the link partner advertisements into their corresponding
303 * speed and duplex. If full duplex was negotiated, extract the pause mode
304 * from the link partner mask.
306 void phy_resolve_aneg_linkmode(struct phy_device *phydev)
308 __ETHTOOL_DECLARE_LINK_MODE_MASK(common);
311 linkmode_and(common, phydev->lp_advertising, phydev->advertising);
313 for (i = 0; i < ARRAY_SIZE(settings); i++)
314 if (test_bit(settings[i].bit, common)) {
315 phydev->speed = settings[i].speed;
316 phydev->duplex = settings[i].duplex;
320 phy_resolve_aneg_pause(phydev);
322 EXPORT_SYMBOL_GPL(phy_resolve_aneg_linkmode);
324 static int phy_resolve_min_speed(struct phy_device *phydev, bool fdx_only)
326 __ETHTOOL_DECLARE_LINK_MODE_MASK(common);
327 int i = ARRAY_SIZE(settings);
329 linkmode_and(common, phydev->lp_advertising, phydev->advertising);
332 if (test_bit(settings[i].bit, common)) {
333 if (fdx_only && settings[i].duplex != DUPLEX_FULL)
335 return settings[i].speed;
339 return SPEED_UNKNOWN;
342 int phy_speed_down_core(struct phy_device *phydev)
344 int min_common_speed = phy_resolve_min_speed(phydev, true);
346 if (min_common_speed == SPEED_UNKNOWN)
349 return __set_linkmode_max_speed(min_common_speed, phydev->advertising);
352 static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
355 /* Write the desired MMD Devad */
356 __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad);
358 /* Write the desired MMD register address */
359 __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum);
361 /* Select the Function : DATA with no post increment */
362 __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
363 devad | MII_MMD_CTRL_NOINCR);
367 * __phy_read_mmd - Convenience function for reading a register
368 * from an MMD on a given PHY.
369 * @phydev: The phy_device struct
370 * @devad: The MMD to read from (0..31)
371 * @regnum: The register on the MMD to read (0..65535)
373 * Same rules as for __phy_read();
375 int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
379 if (regnum > (u16)~0 || devad > 32)
382 if (phydev->drv->read_mmd) {
383 val = phydev->drv->read_mmd(phydev, devad, regnum);
384 } else if (phydev->is_c45) {
385 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
387 val = __mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, addr);
389 struct mii_bus *bus = phydev->mdio.bus;
390 int phy_addr = phydev->mdio.addr;
392 mmd_phy_indirect(bus, phy_addr, devad, regnum);
394 /* Read the content of the MMD's selected register */
395 val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
399 EXPORT_SYMBOL(__phy_read_mmd);
402 * phy_read_mmd - Convenience function for reading a register
403 * from an MMD on a given PHY.
404 * @phydev: The phy_device struct
405 * @devad: The MMD to read from
406 * @regnum: The register on the MMD to read
408 * Same rules as for phy_read();
410 int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
414 mutex_lock(&phydev->mdio.bus->mdio_lock);
415 ret = __phy_read_mmd(phydev, devad, regnum);
416 mutex_unlock(&phydev->mdio.bus->mdio_lock);
420 EXPORT_SYMBOL(phy_read_mmd);
423 * __phy_write_mmd - Convenience function for writing a register
424 * on an MMD on a given PHY.
425 * @phydev: The phy_device struct
426 * @devad: The MMD to read from
427 * @regnum: The register on the MMD to read
428 * @val: value to write to @regnum
430 * Same rules as for __phy_write();
432 int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
436 if (regnum > (u16)~0 || devad > 32)
439 if (phydev->drv->write_mmd) {
440 ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
441 } else if (phydev->is_c45) {
442 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
444 ret = __mdiobus_write(phydev->mdio.bus, phydev->mdio.addr,
447 struct mii_bus *bus = phydev->mdio.bus;
448 int phy_addr = phydev->mdio.addr;
450 mmd_phy_indirect(bus, phy_addr, devad, regnum);
452 /* Write the data into MMD's selected register */
453 __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
459 EXPORT_SYMBOL(__phy_write_mmd);
462 * phy_write_mmd - Convenience function for writing a register
463 * on an MMD on a given PHY.
464 * @phydev: The phy_device struct
465 * @devad: The MMD to read from
466 * @regnum: The register on the MMD to read
467 * @val: value to write to @regnum
469 * Same rules as for phy_write();
471 int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
475 mutex_lock(&phydev->mdio.bus->mdio_lock);
476 ret = __phy_write_mmd(phydev, devad, regnum, val);
477 mutex_unlock(&phydev->mdio.bus->mdio_lock);
481 EXPORT_SYMBOL(phy_write_mmd);
484 * __phy_modify_changed() - Convenience function for modifying a PHY register
485 * @phydev: a pointer to a &struct phy_device
486 * @regnum: register number
487 * @mask: bit mask of bits to clear
488 * @set: bit mask of bits to set
490 * Unlocked helper function which allows a PHY register to be modified as
491 * new register value = (old register value & ~mask) | set
493 * Returns negative errno, 0 if there was no change, and 1 in case of change
495 int __phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask,
500 ret = __phy_read(phydev, regnum);
504 new = (ret & ~mask) | set;
508 ret = __phy_write(phydev, regnum, new);
510 return ret < 0 ? ret : 1;
512 EXPORT_SYMBOL_GPL(__phy_modify_changed);
515 * phy_modify_changed - Function for modifying a PHY register
516 * @phydev: the phy_device struct
517 * @regnum: register number to modify
518 * @mask: bit mask of bits to clear
519 * @set: new value of bits set in mask to write to @regnum
521 * NOTE: MUST NOT be called from interrupt context,
522 * because the bus read/write functions may wait for an interrupt
523 * to conclude the operation.
525 * Returns negative errno, 0 if there was no change, and 1 in case of change
527 int phy_modify_changed(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
531 mutex_lock(&phydev->mdio.bus->mdio_lock);
532 ret = __phy_modify_changed(phydev, regnum, mask, set);
533 mutex_unlock(&phydev->mdio.bus->mdio_lock);
537 EXPORT_SYMBOL_GPL(phy_modify_changed);
540 * __phy_modify - Convenience function for modifying a PHY register
541 * @phydev: the phy_device struct
542 * @regnum: register number to modify
543 * @mask: bit mask of bits to clear
544 * @set: new value of bits set in mask to write to @regnum
546 * NOTE: MUST NOT be called from interrupt context,
547 * because the bus read/write functions may wait for an interrupt
548 * to conclude the operation.
550 int __phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
554 ret = __phy_modify_changed(phydev, regnum, mask, set);
556 return ret < 0 ? ret : 0;
558 EXPORT_SYMBOL_GPL(__phy_modify);
561 * phy_modify - Convenience function for modifying a given PHY register
562 * @phydev: the phy_device struct
563 * @regnum: register number to write
564 * @mask: bit mask of bits to clear
565 * @set: new value of bits set in mask to write to @regnum
567 * NOTE: MUST NOT be called from interrupt context,
568 * because the bus read/write functions may wait for an interrupt
569 * to conclude the operation.
571 int phy_modify(struct phy_device *phydev, u32 regnum, u16 mask, u16 set)
575 mutex_lock(&phydev->mdio.bus->mdio_lock);
576 ret = __phy_modify(phydev, regnum, mask, set);
577 mutex_unlock(&phydev->mdio.bus->mdio_lock);
581 EXPORT_SYMBOL_GPL(phy_modify);
584 * __phy_modify_mmd_changed - Function for modifying a register on MMD
585 * @phydev: the phy_device struct
586 * @devad: the MMD containing register to modify
587 * @regnum: register number to modify
588 * @mask: bit mask of bits to clear
589 * @set: new value of bits set in mask to write to @regnum
591 * Unlocked helper function which allows a MMD register to be modified as
592 * new register value = (old register value & ~mask) | set
594 * Returns negative errno, 0 if there was no change, and 1 in case of change
596 int __phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
601 ret = __phy_read_mmd(phydev, devad, regnum);
605 new = (ret & ~mask) | set;
609 ret = __phy_write_mmd(phydev, devad, regnum, new);
611 return ret < 0 ? ret : 1;
613 EXPORT_SYMBOL_GPL(__phy_modify_mmd_changed);
616 * phy_modify_mmd_changed - Function for modifying a register on MMD
617 * @phydev: the phy_device struct
618 * @devad: the MMD containing register to modify
619 * @regnum: register number to modify
620 * @mask: bit mask of bits to clear
621 * @set: new value of bits set in mask to write to @regnum
623 * NOTE: MUST NOT be called from interrupt context,
624 * because the bus read/write functions may wait for an interrupt
625 * to conclude the operation.
627 * Returns negative errno, 0 if there was no change, and 1 in case of change
629 int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
634 mutex_lock(&phydev->mdio.bus->mdio_lock);
635 ret = __phy_modify_mmd_changed(phydev, devad, regnum, mask, set);
636 mutex_unlock(&phydev->mdio.bus->mdio_lock);
640 EXPORT_SYMBOL_GPL(phy_modify_mmd_changed);
643 * __phy_modify_mmd - Convenience function for modifying a register on MMD
644 * @phydev: the phy_device struct
645 * @devad: the MMD containing register to modify
646 * @regnum: register number to modify
647 * @mask: bit mask of bits to clear
648 * @set: new value of bits set in mask to write to @regnum
650 * NOTE: MUST NOT be called from interrupt context,
651 * because the bus read/write functions may wait for an interrupt
652 * to conclude the operation.
654 int __phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
659 ret = __phy_modify_mmd_changed(phydev, devad, regnum, mask, set);
661 return ret < 0 ? ret : 0;
663 EXPORT_SYMBOL_GPL(__phy_modify_mmd);
666 * phy_modify_mmd - Convenience function for modifying a register on MMD
667 * @phydev: the phy_device struct
668 * @devad: the MMD containing register to modify
669 * @regnum: register number to modify
670 * @mask: bit mask of bits to clear
671 * @set: new value of bits set in mask to write to @regnum
673 * NOTE: MUST NOT be called from interrupt context,
674 * because the bus read/write functions may wait for an interrupt
675 * to conclude the operation.
677 int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
682 mutex_lock(&phydev->mdio.bus->mdio_lock);
683 ret = __phy_modify_mmd(phydev, devad, regnum, mask, set);
684 mutex_unlock(&phydev->mdio.bus->mdio_lock);
688 EXPORT_SYMBOL_GPL(phy_modify_mmd);
690 static int __phy_read_page(struct phy_device *phydev)
692 return phydev->drv->read_page(phydev);
695 static int __phy_write_page(struct phy_device *phydev, int page)
697 return phydev->drv->write_page(phydev, page);
701 * phy_save_page() - take the bus lock and save the current page
702 * @phydev: a pointer to a &struct phy_device
704 * Take the MDIO bus lock, and return the current page number. On error,
705 * returns a negative errno. phy_restore_page() must always be called
706 * after this, irrespective of success or failure of this call.
708 int phy_save_page(struct phy_device *phydev)
710 mutex_lock(&phydev->mdio.bus->mdio_lock);
711 return __phy_read_page(phydev);
713 EXPORT_SYMBOL_GPL(phy_save_page);
716 * phy_select_page() - take the bus lock, save the current page, and set a page
717 * @phydev: a pointer to a &struct phy_device
718 * @page: desired page
720 * Take the MDIO bus lock to protect against concurrent access, save the
721 * current PHY page, and set the current page. On error, returns a
722 * negative errno, otherwise returns the previous page number.
723 * phy_restore_page() must always be called after this, irrespective
724 * of success or failure of this call.
726 int phy_select_page(struct phy_device *phydev, int page)
730 oldpage = ret = phy_save_page(phydev);
734 if (oldpage != page) {
735 ret = __phy_write_page(phydev, page);
742 EXPORT_SYMBOL_GPL(phy_select_page);
745 * phy_restore_page() - restore the page register and release the bus lock
746 * @phydev: a pointer to a &struct phy_device
747 * @oldpage: the old page, return value from phy_save_page() or phy_select_page()
748 * @ret: operation's return code
750 * Release the MDIO bus lock, restoring @oldpage if it is a valid page.
751 * This function propagates the earliest error code from the group of
755 * @oldpage if it was a negative value, otherwise
756 * @ret if it was a negative errno value, otherwise
757 * phy_write_page()'s negative value if it were in error, otherwise
760 int phy_restore_page(struct phy_device *phydev, int oldpage, int ret)
765 r = __phy_write_page(phydev, oldpage);
767 /* Propagate the operation return code if the page write
770 if (ret >= 0 && r < 0)
773 /* Propagate the phy page selection error code */
777 mutex_unlock(&phydev->mdio.bus->mdio_lock);
781 EXPORT_SYMBOL_GPL(phy_restore_page);
784 * phy_read_paged() - Convenience function for reading a paged register
785 * @phydev: a pointer to a &struct phy_device
786 * @page: the page for the phy
787 * @regnum: register number
789 * Same rules as for phy_read().
791 int phy_read_paged(struct phy_device *phydev, int page, u32 regnum)
793 int ret = 0, oldpage;
795 oldpage = phy_select_page(phydev, page);
797 ret = __phy_read(phydev, regnum);
799 return phy_restore_page(phydev, oldpage, ret);
801 EXPORT_SYMBOL(phy_read_paged);
804 * phy_write_paged() - Convenience function for writing a paged register
805 * @phydev: a pointer to a &struct phy_device
806 * @page: the page for the phy
807 * @regnum: register number
808 * @val: value to write
810 * Same rules as for phy_write().
812 int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val)
814 int ret = 0, oldpage;
816 oldpage = phy_select_page(phydev, page);
818 ret = __phy_write(phydev, regnum, val);
820 return phy_restore_page(phydev, oldpage, ret);
822 EXPORT_SYMBOL(phy_write_paged);
825 * phy_modify_paged_changed() - Function for modifying a paged register
826 * @phydev: a pointer to a &struct phy_device
827 * @page: the page for the phy
828 * @regnum: register number
829 * @mask: bit mask of bits to clear
830 * @set: bit mask of bits to set
832 * Returns negative errno, 0 if there was no change, and 1 in case of change
834 int phy_modify_paged_changed(struct phy_device *phydev, int page, u32 regnum,
837 int ret = 0, oldpage;
839 oldpage = phy_select_page(phydev, page);
841 ret = __phy_modify_changed(phydev, regnum, mask, set);
843 return phy_restore_page(phydev, oldpage, ret);
845 EXPORT_SYMBOL(phy_modify_paged_changed);
848 * phy_modify_paged() - Convenience function for modifying a paged register
849 * @phydev: a pointer to a &struct phy_device
850 * @page: the page for the phy
851 * @regnum: register number
852 * @mask: bit mask of bits to clear
853 * @set: bit mask of bits to set
855 * Same rules as for phy_read() and phy_write().
857 int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum,
860 int ret = phy_modify_paged_changed(phydev, page, regnum, mask, set);
862 return ret < 0 ? ret : 0;
864 EXPORT_SYMBOL(phy_modify_paged);