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

phy: add new phy_notify_state() api

Add a new phy_notify_state() api that notifies and configures a phy for a
given state transition.

This is intended to be used by phy drivers which need to do some runtime
configuration of parameters that can't be handled by phy_calibrate() or
phy_power_{on|off}().

The first usage of this API is in the Samsung UFS phy that needs to issue
some register writes when entering and exiting the hibernate link state.

Signed-off-by: Peter Griffin <peter.griffin@linaro.org>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patch.msgid.link/20251112-phy-notify-pmstate-v5-1-39df622d8fcb@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Peter Griffin and committed by
Vinod Koul
4edf654b 42690b8e

+44
+25
drivers/phy/phy-core.c
··· 521 521 EXPORT_SYMBOL_GPL(phy_notify_disconnect); 522 522 523 523 /** 524 + * phy_notify_state() - phy state notification 525 + * @phy: the PHY returned by phy_get() 526 + * @state: the PHY state 527 + * 528 + * Notify the PHY of a state transition. Used to notify and 529 + * configure the PHY accordingly. 530 + * 531 + * Returns: %0 if successful, a negative error code otherwise 532 + */ 533 + int phy_notify_state(struct phy *phy, union phy_notify state) 534 + { 535 + int ret; 536 + 537 + if (!phy || !phy->ops->notify_phystate) 538 + return 0; 539 + 540 + mutex_lock(&phy->mutex); 541 + ret = phy->ops->notify_phystate(phy, state); 542 + mutex_unlock(&phy->mutex); 543 + 544 + return ret; 545 + } 546 + EXPORT_SYMBOL_GPL(phy_notify_state); 547 + 548 + /** 524 549 * phy_configure() - Changes the phy parameters 525 550 * @phy: the phy returned by phy_get() 526 551 * @opts: New configuration to apply
+19
include/linux/phy/phy.h
··· 53 53 PHY_MEDIA_DAC, 54 54 }; 55 55 56 + enum phy_ufs_state { 57 + PHY_UFS_HIBERN8_ENTER, 58 + PHY_UFS_HIBERN8_EXIT, 59 + }; 60 + 61 + union phy_notify { 62 + enum phy_ufs_state ufs_state; 63 + }; 64 + 56 65 /** 57 66 * union phy_configure_opts - Opaque generic phy configuration 58 67 * ··· 92 83 * @set_speed: set the speed of the phy (optional) 93 84 * @reset: resetting the phy 94 85 * @calibrate: calibrate the phy 86 + * @notify_phystate: notify and configure the phy for a particular state 95 87 * @release: ops to be performed while the consumer relinquishes the PHY 96 88 * @owner: the module owner containing the ops 97 89 */ ··· 142 132 int (*connect)(struct phy *phy, int port); 143 133 int (*disconnect)(struct phy *phy, int port); 144 134 135 + int (*notify_phystate)(struct phy *phy, union phy_notify state); 145 136 void (*release)(struct phy *phy); 146 137 struct module *owner; 147 138 }; ··· 266 255 int phy_calibrate(struct phy *phy); 267 256 int phy_notify_connect(struct phy *phy, int port); 268 257 int phy_notify_disconnect(struct phy *phy, int port); 258 + int phy_notify_state(struct phy *phy, union phy_notify state); 269 259 static inline int phy_get_bus_width(struct phy *phy) 270 260 { 271 261 return phy->attrs.bus_width; ··· 418 406 } 419 407 420 408 static inline int phy_notify_disconnect(struct phy *phy, int index) 409 + { 410 + if (!phy) 411 + return 0; 412 + return -ENOSYS; 413 + } 414 + 415 + static inline int phy_notify_state(struct phy *phy, union phy_notify state) 421 416 { 422 417 if (!phy) 423 418 return 0;