From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DDB14CCA464 for ; Fri, 16 Oct 2026 12:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mnJbC4j15Y4UM9/n3YJrZaL44MMPLVW8qPtv287zVd4=; b=AHRldH11Hi70vo GwkgyzfbVNjJ3z6nrC+44yej42pJGIMeaw7unUyXdb0Vb37gsIp3hFbOn2oOZ52ZtcrG3AMt8YXhN l3tppqclqvxg7MgFJuhjuM1LMveEQsN9kr7cSr+irg5oelVYvh0oq/XhfKQJdiRjZ/tVEqY04Hi+O R8nH69BT07e98EiLmWeWJA01o6HZtKZbUVQreyMwoIfRzmazR8Cu5PRleE1WTL5f49gmeJUG3Y0TF 1bAoLZPCAHhoy3dqNQgXGJFZ3KE4OgIBlCTs31VvebFjhQXPXTeb+rzaOhwxmjxZrTnNYduqFHTnL ML1TQ4a8gTV+pcWLDZsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xHh8C-00000002tNU-1lo8; Fri, 16 Oct 2026 12:33:52 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xHh84-00000002t9C-3gos; Fri, 16 Oct 2026 12:33:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=l1d7e1p9S3i9mJvC4S8HRqtNNOqXMv0+x232tUTlcFk=; b=WEpiJvXnAeTVl3PR9Mcbmep6xU YKsd0mSWMMTkslBe6L8ike1vDShcCrm81zdwUweZXDid+0fc5XZbw1WTyeJyMuQdeEYSY84zyKLti 2Eo9cyL7U3nEI35p6WlDXXO+wuGkd8dupx8wmrQB5hp0NgJNvlNjC4GvSQaNUmR2UG3GuuxnbdKxB DVdq3l0hMNlz5MFP+uHkNcQYwtWWyyZRkyMadbwgTByEiVcxsOHNs8K8cWwMjlH5KK2t57XfSnYTN 9z6iOyM6wXM6nJvFDAlFslO3g5U4jr8ZBe4Gfj8chIp1xkfgaoZxoU9UeT0oNZHY7yGMxE6ndSQHh ygTCh1Gg==; Received: from bali.collaboradmins.com ([148.251.105.195]) by desiato.infradead.org with esmtps (Exim 4.99.5 #2 (Red Hat Linux)) id 1xHh7x-00000001U9Q-3jst; Fri, 16 Oct 2026 12:33:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1792154016; bh=+KaVZGEBBzDtS0fcRT+2HvW3uSiC7/ZH2k2oI6EB5iM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LssM1lQMDKBr84TU72AOo8O/88mNpIRKo4Ulpv7ZScVYtXKt43gntycvFjMgU9RHJ gF+IpdsH+PSBTGWPljzUISBEhy3vSn5P/iCGgfY0LJwVzgwu6HiILk/VC7vxyBxsr+ McUIPJCLw8OjqMkubX7ua//V8sfM9ei8giWxNJBFP8h0taJy5rPFRaRxhYg3VN+mUH RCo/Il9E4/7fwhxge+jhawbzHPVQr0bbxCSxs6jbRpCh0zOBhrBCqZB1V9WNFrKGp8 XF4w7BjOyQKzJnAE1mT7lG+YUSAz/FCiXCS1uMLg4tbrAetteBMrOQqanB3HLbEXqj Os2b4TrF+Nolg== Received: from yukiji.home (unknown [100.64.0.131]) (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: laeyraud) by bali.collaboradmins.com (Postfix) with ESMTPSA id 5FE4717E153B; Fri, 16 Oct 2026 14:33:35 +0200 (CEST) From: Louis-Alexis Eyraud Date: Fri, 16 Oct 2026 14:32:57 +0200 Subject: [PATCH v14 05/23] phy: mediatek: ufs: Add support for resets MIME-Version: 1.0 Message-Id: <20261016-mt8196-ufs-v14-5-e8d565e0cd45@collabora.com> References: <20261016-mt8196-ufs-v14-0-e8d565e0cd45@collabora.com> In-Reply-To: <20261016-mt8196-ufs-v14-0-e8d565e0cd45@collabora.com> To: Chunfeng Yun , Vinod Koul , Neil Armstrong , Manivannan Sadhasivam , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Peter Wang , Chaotian Jing , Alim Akhtar , Bart Van Assche , Bean Huo , Stanley Jhu , Stanley Jhu , "James E.J. Bottomley" , "Martin K. Petersen" , Philipp Zabel , Liam Girdwood , Mark Brown Cc: kernel@collabora.com, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Nicolas Frattaroli , Louis-Alexis Eyraud X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1792154009; l=4162; i=louisalexis.eyraud@collabora.com; s=20250113; h=from:subject:message-id; bh=n6fnaH5W2rNRma377J+VqS6SrwtXMaxCbfvdDhgnwk0=; b=tvMv363Z9EN7VcBXtC9zILFnWwV6YlX6FN4COH8BqFgrm3iLDzn4gmGf5KTqyiCsV+RqGhPe5 Qu7Y3LX4nDoBf3U3LyWVn8zSl7NAsWiIkvObDyds8uqZqPQbjHTu81O X-Developer-Key: i=louisalexis.eyraud@collabora.com; a=ed25519; pk=CHFBDB2Kqh4EHc6JIqFn69GhxJJAzc0Zr4e8QxtumuM= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261016_133341_423212_7472CD38 X-CRM114-Status: GOOD ( 20.56 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Nicolas Frattaroli The MediaTek UFS PHY supports PHY resets. Until now, they've been implemented in the UFS host driver. Since they were never documented in the UFS HCI node's DT bindings, and no mainline DT uses it, it's fine if it's moved to the correct location, which is the PHY driver. Implement the MPHY reset logic in this driver and expose it through the phy subsystem's reset op. The reset itself is optional, as judging by other mainline devices that use this hardware, it's not required for the device to function. If no reset is present, the reset op returns -EOPNOTSUPP, which means that the ufshci driver can detect it's present and not double sleep in its own reset function, where it will call the phy reset. Reviewed-by: Philipp Zabel Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Peter Wang Acked-by: Vinod Koul Signed-off-by: Nicolas Frattaroli Signed-off-by: Louis-Alexis Eyraud --- drivers/phy/mediatek/phy-mtk-ufs.c | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/phy/mediatek/phy-mtk-ufs.c b/drivers/phy/mediatek/phy-mtk-ufs.c index fc19e0fa8ed5..4439a9eb6b7a 100644 --- a/drivers/phy/mediatek/phy-mtk-ufs.c +++ b/drivers/phy/mediatek/phy-mtk-ufs.c @@ -4,12 +4,15 @@ * Author: Stanley Chu */ +#include #include #include #include #include #include #include +#include +#include #include "phy-mtk-io.h" @@ -35,9 +38,17 @@ #define UFSPHY_CLKS_CNT 2 +#define UFS_MTK_SIP_MPHY_CTRL BIT(8) + +enum ufs_mtk_mphy_op { + UFS_MPHY_BACKUP = 0, + UFS_MPHY_RESTORE +}; + struct ufs_mtk_phy { struct device *dev; void __iomem *mmio; + struct reset_control *reset; struct clk_bulk_data clks[UFSPHY_CLKS_CNT]; }; @@ -140,9 +151,59 @@ static int ufs_mtk_phy_power_off(struct phy *generic_phy) return 0; } +static int ufs_mtk_phy_ctrl(struct ufs_mtk_phy *phy, enum ufs_mtk_mphy_op op) +{ + struct arm_smccc_res res; + + arm_smccc_smc(MTK_SIP_UFS_CONTROL, UFS_MTK_SIP_MPHY_CTRL, op, + 0, 0, 0, 0, 0, &res); + + switch (res.a0) { + case SMCCC_RET_NOT_SUPPORTED: + return -EOPNOTSUPP; + case SMCCC_RET_INVALID_PARAMETER: + return -EINVAL; + default: + return 0; + } +} + +static int ufs_mtk_phy_reset(struct phy *generic_phy) +{ + struct ufs_mtk_phy *phy = get_ufs_mtk_phy(generic_phy); + int ret; + + if (!phy->reset) + return -EOPNOTSUPP; + + ret = reset_control_assert(phy->reset); + if (ret) + return ret; + + usleep_range(100, 110); + + ret = reset_control_deassert(phy->reset); + if (ret) + return ret; + + /* + * To avoid double-sleep and other unintended side-effects in the ufshci + * driver, don't return the phy_ctrl retval here, but just return -EPROTO. + */ + ret = ufs_mtk_phy_ctrl(phy, UFS_MPHY_RESTORE); + if (ret) { + dev_err(phy->dev, "UFS_MPHY_RESTORE SMC command failed: %pe\n", + ERR_PTR(ret)); + return -EPROTO; + } + + return 0; +} + static const struct phy_ops ufs_mtk_phy_ops = { .power_on = ufs_mtk_phy_power_on, .power_off = ufs_mtk_phy_power_off, + .reset = ufs_mtk_phy_reset, .owner = THIS_MODULE, }; @@ -162,8 +223,18 @@ static int ufs_mtk_phy_probe(struct platform_device *pdev) if (IS_ERR(phy->mmio)) return PTR_ERR(phy->mmio); + phy->reset = devm_reset_control_get_optional_exclusive(dev, NULL); + if (IS_ERR(phy->reset)) + return dev_err_probe(dev, PTR_ERR(phy->reset), "Failed to get reset\n"); + phy->dev = dev; + if (phy->reset) { + ret = ufs_mtk_phy_ctrl(phy, UFS_MPHY_BACKUP); + if (ret) + return dev_err_probe(dev, ret, "Failed to back up MPHY\n"); + } + ret = ufs_mtk_phy_clk_init(phy); if (ret) return ret; -- 2.56.0 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy