Skip to content

Commit 4edf654

Browse files
petegriffinvinodkoul
authored andcommitted
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>
1 parent 42690b8 commit 4edf654

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

drivers/phy/phy-core.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,31 @@ int phy_notify_disconnect(struct phy *phy, int port)
520520
}
521521
EXPORT_SYMBOL_GPL(phy_notify_disconnect);
522522

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+
523548
/**
524549
* phy_configure() - Changes the phy parameters
525550
* @phy: the phy returned by phy_get()

include/linux/phy/phy.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ enum phy_media {
5353
PHY_MEDIA_DAC,
5454
};
5555

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+
5665
/**
5766
* union phy_configure_opts - Opaque generic phy configuration
5867
*
@@ -83,6 +92,7 @@ union phy_configure_opts {
8392
* @set_speed: set the speed of the phy (optional)
8493
* @reset: resetting the phy
8594
* @calibrate: calibrate the phy
95+
* @notify_phystate: notify and configure the phy for a particular state
8696
* @release: ops to be performed while the consumer relinquishes the PHY
8797
* @owner: the module owner containing the ops
8898
*/
@@ -132,6 +142,7 @@ struct phy_ops {
132142
int (*connect)(struct phy *phy, int port);
133143
int (*disconnect)(struct phy *phy, int port);
134144

145+
int (*notify_phystate)(struct phy *phy, union phy_notify state);
135146
void (*release)(struct phy *phy);
136147
struct module *owner;
137148
};
@@ -255,6 +266,7 @@ int phy_reset(struct phy *phy);
255266
int phy_calibrate(struct phy *phy);
256267
int phy_notify_connect(struct phy *phy, int port);
257268
int phy_notify_disconnect(struct phy *phy, int port);
269+
int phy_notify_state(struct phy *phy, union phy_notify state);
258270
static inline int phy_get_bus_width(struct phy *phy)
259271
{
260272
return phy->attrs.bus_width;
@@ -412,6 +424,13 @@ static inline int phy_notify_disconnect(struct phy *phy, int index)
412424
return -ENOSYS;
413425
}
414426

427+
static inline int phy_notify_state(struct phy *phy, union phy_notify state)
428+
{
429+
if (!phy)
430+
return 0;
431+
return -ENOSYS;
432+
}
433+
415434
static inline int phy_configure(struct phy *phy,
416435
union phy_configure_opts *opts)
417436
{

0 commit comments

Comments
 (0)