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 A40B6C76196 for ; Fri, 31 Mar 2023 09:41:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BC49085F6F; Fri, 31 Mar 2023 11:41:29 +0200 (CEST) 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="h7tv/tJj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5BF9485F85; Fri, 31 Mar 2023 11:41:20 +0200 (CEST) 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 5801785F5F for ; Fri, 31 Mar 2023 11:41:14 +0200 (CEST) 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 659F16603130; Fri, 31 Mar 2023 10:41:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680255674; bh=rO4UBB4W8Dpkn+y98YRbnuvlOZ/Hx30sRGUmT5x4VjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h7tv/tJjYPik1iEQfx1ulvGStfZHLTbGXldnIPO5WP+norKvJO27PDmndRtsQdDC4 CwkZisTRudEELaTOjC/0j2nE3Dm0nhK9CHNLli8TT96R8Uu4wOIVJS913fP19ZnstS L/ccLJ8Kh2eUPSg/iMWVyKIoqUzYhTpo7XakEC8NUUdbv1E3LiaVt9VKHjFgmQAKPP B93PxSPS1hWXwwPo9ywepPhnHh+uVQ4HKkkYmxzHJhrMZwBx/ppshoaWb3zRda+YyD RLwW1H2E1s4UrwFpsoZv1I2C+/i8KMAmZ/VJQh3ojwGYGHxV+/NW+ceTcX45Gvltfq 63M/rul0bvd3A== From: Eugen Hristev To: u-boot@lists.denx.de, kever.yang@rock-chips.com Cc: jagan@edgeble.ai, jonas@kwiboo.se, Eugen Hristev , Frank Wang , Vasily Khoruzhick , Xavier Drudis Ferran Subject: [PATCH v3 2/3] phy: rockchip-inno-usb2: add initial support for rk3588 PHY Date: Fri, 31 Mar 2023 12:40:49 +0300 Message-Id: <20230331094050.149867-2-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230331094050.149867-1-eugen.hristev@collabora.com> References: <20230331094050.149867-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.8 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 Tested-by: Vasily Khoruzhick # rk3568-based board Tested-by: Xavier Drudis Ferran # rk3399 rock pi 4B+ --- Changes in v3: - add handling of -EBUSY and -EALREADY for regulator return Changes in v2: - add handling of -EACCES 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..75c50670524e 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 && ret != -EALREADY) { + 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 && ret != -EACCES && ret != -EBUSY) { + dev_info(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