Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8E17C64EC4 for ; Fri, 3 Mar 2023 07:32:11 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9A7A885CEA; Fri, 3 Mar 2023 08:31:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="PRMzUi48"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 800BB85CDE; Fri, 3 Mar 2023 08:31:52 +0100 (CET) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0944585CE2 for ; Fri, 3 Mar 2023 08:31:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=eugen.hristev@collabora.com Received: from eugen-station.. (unknown [82.76.24.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madras.collabora.co.uk (Postfix) with ESMTPSA id 21BF76602FA9; Fri, 3 Mar 2023 07:31:49 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1677828709; bh=iayzKa+XAWXpFSqbr9AxloQe1xSw0yRJvjbvhXX2PDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PRMzUi48S5J4vEnjHzPxUqLnG2k4cDPoAV0zJQXbWs6CRVQfGkmFOcC/X8ROoZj0z ZADT85H5szT10sxFLdaiKSL9TwnQ9EIrNVxLSQMrD2U5xR3bH1IzhAyvRvPrnkFC8H fygqg8dgD4vPnm46WMKB4bVWgtIex3GRVj6mAgeJsDKERFeZlc/BqtfbuB4NsvHz+Q u5ljgngPutNVCG4DLx1SIrf9J+CCJZ8EUSQKh2xQJLG0YaRCGlYxZMM3Y27t28evKO esGoE/yqSnbadWG7xPyPot3uI3BKPo7Lczvq/RA8yNp0KBeO/QX2VXjwTxAaxp7Vug L3xMfssIzdP3A== From: Eugen Hristev To: kever.yang@rock-chips.com, jagan@edgeble.ai, u-boot@lists.denx.de Cc: Eugen Hristev , Frank Wang Subject: [PATCH 2/3] phy: rockchip-inno-usb2: add initial support for rk3588 PHY Date: Fri, 3 Mar 2023 09:31:33 +0200 Message-Id: <20230303073134.282462-2-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230303073134.282462-1-eugen.hristev@collabora.com> References: <20230303073134.282462-1-eugen.hristev@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Add initial support for the rk3588 PHY variant. The driver now looks for phy-supply and enables/disables the vbus accordingly. The lookup for the host-port reg inside the struct now does a do {} while() instead of a while() {} in order to allow a first check for reg == 0. Co-developed-by: Frank Wang Signed-off-by: Frank Wang Signed-off-by: Eugen Hristev --- drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 109 +++++++++++++++++- 1 file changed, 104 insertions(+), 5 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index 55e1dbcfef7e..0551876436d5 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ struct rockchip_usb2phy_cfg { struct rockchip_usb2phy { void *reg_base; struct clk phyclk; + struct udevice *vbus_supply[USB2PHY_NUM_PORTS]; const struct rockchip_usb2phy_cfg *phy_cfg; }; @@ -86,11 +88,34 @@ struct rockchip_usb2phy_port_cfg *us2phy_get_port(struct phy *phy) return &phy_cfg->port_cfgs[phy->id]; } +static struct udevice *rockchip_usb2phy_check_vbus(struct phy *phy) +{ + struct udevice *parent = phy->dev->parent; + struct rockchip_usb2phy *priv = dev_get_priv(parent); + struct udevice *vbus = NULL; + + if (phy->id == USB2PHY_PORT_HOST) + vbus = priv->vbus_supply[USB2PHY_PORT_HOST]; + + return vbus; +} + static int rockchip_usb2phy_power_on(struct phy *phy) { struct udevice *parent = dev_get_parent(phy->dev); struct rockchip_usb2phy *priv = dev_get_priv(parent); const struct rockchip_usb2phy_port_cfg *port_cfg = us2phy_get_port(phy); + struct udevice *vbus = NULL; + int ret; + + vbus = rockchip_usb2phy_check_vbus(phy); + if (vbus) { + ret = regulator_set_enable(vbus, true); + if (ret) { + dev_err(phy->dev, "vbus enable failed: %d\n", ret); + return ret; + } + } property_enable(priv->reg_base, &port_cfg->phy_sus, false); @@ -105,6 +130,17 @@ static int rockchip_usb2phy_power_off(struct phy *phy) struct udevice *parent = dev_get_parent(phy->dev); struct rockchip_usb2phy *priv = dev_get_priv(parent); const struct rockchip_usb2phy_port_cfg *port_cfg = us2phy_get_port(phy); + struct udevice *vbus = NULL; + int ret; + + vbus = rockchip_usb2phy_check_vbus(phy); + if (vbus) { + ret = regulator_set_enable(vbus, false); + if (ret) { + dev_err(phy->dev, "vbus disable failed: %d\n", ret); + return ret; + } + } property_enable(priv->reg_base, &port_cfg->phy_sus, true); @@ -149,13 +185,20 @@ static int rockchip_usb2phy_of_xlate(struct phy *phy, struct ofnode_phandle_args *args) { const char *name = phy->dev->name; + struct udevice *parent = phy->dev->parent; + struct rockchip_usb2phy *priv = dev_get_priv(parent); - if (!strcasecmp(name, "host-port")) + if (!strcasecmp(name, "host-port")) { phy->id = USB2PHY_PORT_HOST; - else if (!strcasecmp(name, "otg-port")) + device_get_supply_regulator(phy->dev, "phy-supply", + &priv->vbus_supply[USB2PHY_PORT_HOST]); + } else if (!strcasecmp(name, "otg-port")) { phy->id = USB2PHY_PORT_OTG; - else + device_get_supply_regulator(phy->dev, "phy-supply", + &priv->vbus_supply[USB2PHY_PORT_OTG]); + } else { dev_err(phy->dev, "improper %s device\n", name); + } return 0; } @@ -201,14 +244,14 @@ static int rockchip_usb2phy_probe(struct udevice *dev) /* find out a proper config which can be matched with dt. */ index = 0; - while (phy_cfgs[index].reg) { + do { if (phy_cfgs[index].reg == reg) { priv->phy_cfg = &phy_cfgs[index]; break; } ++index; - } + } while (phy_cfgs[index].reg); if (!priv->phy_cfg) { dev_err(dev, "failed find proper phy-cfg\n"); @@ -348,6 +391,58 @@ static const struct rockchip_usb2phy_cfg rk3568_phy_cfgs[] = { { /* sentinel */ } }; +static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = { + { + .reg = 0x0000, + .port_cfgs = { + [USB2PHY_PORT_OTG] = { + .phy_sus = { 0x000c, 11, 11, 0, 1 }, + .ls_det_en = { 0x0080, 0, 0, 0, 1 }, + .ls_det_st = { 0x0084, 0, 0, 0, 1 }, + .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, + .utmi_ls = { 0x00c0, 10, 9, 0, 1 }, + } + }, + }, + { + .reg = 0x4000, + .port_cfgs = { + [USB2PHY_PORT_OTG] = { + .phy_sus = { 0x000c, 11, 11, 0, 0 }, + .ls_det_en = { 0x0080, 0, 0, 0, 1 }, + .ls_det_st = { 0x0084, 0, 0, 0, 1 }, + .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, + .utmi_ls = { 0x00c0, 10, 9, 0, 1 }, + } + }, + }, + { + .reg = 0x8000, + .port_cfgs = { + [USB2PHY_PORT_HOST] = { + .phy_sus = { 0x0008, 2, 2, 0, 1 }, + .ls_det_en = { 0x0080, 0, 0, 0, 1 }, + .ls_det_st = { 0x0084, 0, 0, 0, 1 }, + .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, + .utmi_ls = { 0x00c0, 10, 9, 0, 1 }, + } + }, + }, + { + .reg = 0xc000, + .port_cfgs = { + [USB2PHY_PORT_HOST] = { + .phy_sus = { 0x0008, 2, 2, 0, 1 }, + .ls_det_en = { 0x0080, 0, 0, 0, 1 }, + .ls_det_st = { 0x0084, 0, 0, 0, 1 }, + .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, + .utmi_ls = { 0x00c0, 10, 9, 0, 1 }, + } + }, + }, + { /* sentinel */ } +}; + static const struct udevice_id rockchip_usb2phy_ids[] = { { .compatible = "rockchip,rk3399-usb2phy", @@ -357,6 +452,10 @@ static const struct udevice_id rockchip_usb2phy_ids[] = { .compatible = "rockchip,rk3568-usb2phy", .data = (ulong)&rk3568_phy_cfgs, }, + { + .compatible = "rockchip,rk3588-usb2phy", + .data = (ulong)&rk3588_phy_cfgs, + }, { /* sentinel */ } }; -- 2.34.1