Re: [RFC/PATCH 2/2] phy: rockchip: usbdp: implement .set_mode

Heiko Stuebner
2025-07-15T10:36:00Z

Hi John,

Am Donnerstag, 10. Juli 2025, 17:22:50 Mitteleuropäische Sommerzeit schrieb John Keeping:
> When the orientation of a type C cable changes, usbdp set the new
> configuration in its internal state but does not write this to the
> hardware.
>
> Make use of phy_ops::set_mode to write this new state. This should be
> called by the USB controller when it is notified of a role change
> (assuming it is acting as the role switch) and will be called at a point
> when the controller does not expect the phy to be operating normally.
>
> Signed-off-by: John Keeping <jkeeping@inmusicbrands.com>

with the comments from Ondrej in [0] the whole thing seems to be
slightly more complex

[0] https://patchwork.kernel.org/project/linux-arm-kernel/patch/20250225184519.3586926-3-heiko@sntech.de/

> ---
> drivers/phy/rockchip/phy-rockchip-usbdp.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> index c066cc0a7b4f1..00368fb09307a 100644
> --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
> +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> @@ -1335,9 +1335,23 @@ static int rk_udphy_usb3_phy_exit(struct phy *phy)
> return 0;
> }
>
> +static int rk_udphy_usb3_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
> +{
> + struct rk_udphy *udphy = phy_get_drvdata(phy);
> + int ret = 0;
> +
> + mutex_lock(&udphy->mutex);
> + if (udphy->mode != UDPHY_MODE_NONE)
> + ret = rk_udphy_init(udphy);
> + mutex_unlock(&udphy->mutex);
> +
> + return ret;
> +}
> +
> static const struct phy_ops rk_udphy_usb3_phy_ops = {
> .init = rk_udphy_usb3_phy_init,
> .exit = rk_udphy_usb3_phy_exit,
> + .set_mode = rk_udphy_usb3_phy_set_mode,
> .owner = THIS_MODULE,
> };
>
>