[PATCH 3/3] phy: k1-usb: k3: add USB2 PHY support
Yao Zi
me at ziyao.cc
Thu Feb 12 03:30:39 PST 2026
On Thu, Feb 12, 2026 at 09:38:56AM +0800, Yixun Lan wrote:
> Add USB2 PHY support for SpacemiT K3 SoC.
>
> Register layout of handling USB disconnect operation has been changed,
> So introducing a platform data to distinguish the different SoCs.
Would it be clearer and simpler if you define separate phy_ops for
k1 and k3, and point of_device_id.data directly to the corresponding
phy_ops? Then there's no need to introduce either spacemit_usb2phy_data
structure, or spacemit_usb2phy_disconnect wrapper.
Best regards,
Yao Zi
> Signed-off-by: Yixun Lan <dlan at kernel.org>
> ---
> drivers/phy/spacemit/phy-k1-usb2.c | 40 ++++++++++++++++++++++++++++++++++++--
> 1 file changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/phy/spacemit/phy-k1-usb2.c b/drivers/phy/spacemit/phy-k1-usb2.c
> index 959bf79c7a72..b0ce0a92861e 100644
> --- a/drivers/phy/spacemit/phy-k1-usb2.c
> +++ b/drivers/phy/spacemit/phy-k1-usb2.c
> @@ -51,6 +51,9 @@
> #define PHY_K1_HS_HOST_DISC 0x40
> #define PHY_K1_HS_HOST_DISC_CLR BIT(0)
>
> +#define PHY_K3_HS_HOST_DISC 0x20
> +#define PHY_K3_HS_HOST_DISC_CLR BIT(8)
> +
> #define PHY_PLL_DIV_CFG 0x98
> #define PHY_FDIV_FRACT_8_15 GENMASK(7, 0)
> #define PHY_FDIV_FRACT_16_19 GENMASK(11, 8)
> @@ -74,10 +77,15 @@
>
> #define K1_USB2PHY_RESET_TIME_MS 50
>
> +struct spacemit_usb2phy_data {
> + int (*disconnect)(struct phy *phy, int port);
> +};
> +
> struct spacemit_usb2phy {
> struct phy *phy;
> struct clk *clk;
> struct regmap *regmap_base;
> + const struct spacemit_usb2phy_data *data;
> };
>
> static const struct regmap_config phy_regmap_config = {
> @@ -145,7 +153,7 @@ static int spacemit_usb2phy_exit(struct phy *phy)
> return 0;
> }
>
> -static int spacemit_usb2phy_disconnect(struct phy *phy, int port)
> +static int spacemit_k1_usb2phy_disconnect(struct phy *phy, int port)
> {
> struct spacemit_usb2phy *sphy = phy_get_drvdata(phy);
>
> @@ -155,6 +163,23 @@ static int spacemit_usb2phy_disconnect(struct phy *phy, int port)
> return 0;
> }
>
> +static int spacemit_k3_usb2phy_disconnect(struct phy *phy, int port)
> +{
> + struct spacemit_usb2phy *sphy = phy_get_drvdata(phy);
> +
> + regmap_update_bits(sphy->regmap_base, PHY_K3_HS_HOST_DISC,
> + PHY_K3_HS_HOST_DISC_CLR, PHY_K3_HS_HOST_DISC_CLR);
> +
> + return 0;
> +}
> +
> +static int spacemit_usb2phy_disconnect(struct phy *phy, int port)
> +{
> + struct spacemit_usb2phy *sphy = phy_get_drvdata(phy);
> +
> + return sphy->data->disconnect(phy, port);
> +}
> +
> static const struct phy_ops spacemit_usb2phy_ops = {
> .init = spacemit_usb2phy_init,
> .exit = spacemit_usb2phy_exit,
> @@ -173,6 +198,8 @@ static int spacemit_usb2phy_probe(struct platform_device *pdev)
> if (!sphy)
> return -ENOMEM;
>
> + sphy->data = device_get_match_data(dev);
> +
> sphy->clk = devm_clk_get_prepared(&pdev->dev, NULL);
> if (IS_ERR(sphy->clk))
> return dev_err_probe(dev, PTR_ERR(sphy->clk), "Failed to get clock\n");
> @@ -195,8 +222,17 @@ static int spacemit_usb2phy_probe(struct platform_device *pdev)
> return PTR_ERR_OR_ZERO(phy_provider);
> }
>
> +static const struct spacemit_usb2phy_data k1_usb2phy_data = {
> + .disconnect = spacemit_k1_usb2phy_disconnect,
> +};
> +
> +static const struct spacemit_usb2phy_data k3_usb2phy_data = {
> + .disconnect = spacemit_k3_usb2phy_disconnect,
> +};
> +
> static const struct of_device_id spacemit_usb2phy_dt_match[] = {
> - { .compatible = "spacemit,k1-usb2-phy", },
> + { .compatible = "spacemit,k1-usb2-phy", .data = &k1_usb2phy_data },
> + { .compatible = "spacemit,k3-usb2-phy", .data = &k3_usb2phy_data },
> { /* sentinel */ }
> };
> MODULE_DEVICE_TABLE(of, spacemit_usb2phy_dt_match);
>
> --
> 2.52.0
>
>
More information about the linux-riscv
mailing list