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 75D55C88E64 for ; Mon, 14 Sep 2026 11:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type: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=YXHtwGIzenaGus4oYzSlmD/nOIbXMt/gcYmNZRVVe/c=; b=ucv+cJtGRBJ6va9CLEp94kF67J ZmI8X2gvkOYHA+KYsl4Rdd8OV1D+ri9E8uVjAZ5YKF+dY5BomAH9BoVS66ggeqRzZaUZcsgs0fnl0 R7fssJNR4nHB3H0kQ0XgmXdI6OtWWj3WK/geKGKLAy0dIAndPfSM8YCr6L2NoQ/XD3r624sNbmxpk 6IDk9mujKWlW1Qrq9+d/ceyuViNF9PC39Dl6i+ECcUEEpfdF0ApczNpPi/u2qsCAdMhRVhitxB6Jo jvDACIhlZ0ODPP0En+8dK2FD6C4iRrSA3iSeX+sA+BXLcwX+Or38W6ykxuzjjhegpCLy2+7eGNHXK ykoGR8YQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x653C-00000003JeP-1V8G; Mon, 14 Sep 2026 11:40:42 +0000 Received: from bali.collaboradmins.com ([2a01:4f8:201:9162::2]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x6527-00000003Ifo-3tm2; Mon, 14 Sep 2026 11:39:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1789385973; bh=ftBk39qrZhQjOvGrhxC0GRN0oNAwMHykTXlQwjPdQX4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Tss3zOMdMfnoXhdIMEYFbUkcjA+g7lxxq8F8u30dXd6lCTBPvBOKrSSGFNrf5v9V+ yKxURm1UeIq6XVcHJv3st4Ri2DheqvGEylWZdN9b2kQk8N0wZPCGJNT1oHGyBxPuzx RXX6GBZ3rZlOVO+GR/Rr/miYUr28VNlUq0unEo7N+WEbLw97wgeP0B0yd/SrVw+AVo xfKijCDSoKnCy0LrfJPyKuDGXVOVyswUIw8YJwlJDCANEn9Rv7dcEbGz8RLKNZWhrr C7dCquZHPRCL8N6o2QjxG7AVCx0nHu7S96uAix/VRtPc8MEl+Dw/fW+916kpKLE6xj Umnv7tMvCyAeQ== 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 18FC617E07DC; Mon, 14 Sep 2026 13:39:32 +0200 (CEST) From: Louis-Alexis Eyraud Date: Mon, 14 Sep 2026 13:39:00 +0200 Subject: [PATCH v12 14/24] scsi: ufs: mediatek: Use the common PHY framework MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260914-mt8196-ufs-v12-14-9279d7ef814d@collabora.com> References: <20260914-mt8196-ufs-v12-0-9279d7ef814d@collabora.com> In-Reply-To: <20260914-mt8196-ufs-v12-0-9279d7ef814d@collabora.com> To: Chunfeng Yun , Vinod Koul , Neil Armstrong , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Peter Wang , Chaotian Jing , Alim Akhtar , Avri Altman , Bart Van Assche , Stanley Jhu , "James E.J. Bottomley" , Philipp Zabel , Liam Girdwood , Mark Brown , Manivannan Sadhasivam , "Martin K. Petersen" 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=1789385943; l=7542; i=louisalexis.eyraud@collabora.com; s=20250113; h=from:subject:message-id; bh=Aoh+DU0o/8uqBdQ/QrPxSrr1YhdUqc9obDkxu9/ggr4=; b=0kJxaVCr1q8zhFgNvS0ov6aq00MS7/rXlS5+OelqDE+Q4CZQ4ACGHIQ3JXklE4WGiN8OX2FiH TJu0KzfKITJBV9DRc9RAd6HdPgUFXMGCyHmiOf++JZuBDqk+8Mcs23O 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-20260914_043936_134103_9B512D1C X-CRM114-Status: GOOD ( 23.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nicolas Frattaroli There is no need to reinvent the PHY framework, especially not its OF parsing. Change the code to simply use the PHY framework to acquire the device's PHY in the ufshcd init, so that it's device linked to the right device. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Nicolas Frattaroli Reviewed-by: Chaotian Jing Signed-off-by: Louis-Alexis Eyraud --- drivers/ufs/host/ufs-mediatek.c | 134 +++++++++++++--------------------------- drivers/ufs/host/ufs-mediatek.h | 1 - 2 files changed, 42 insertions(+), 93 deletions(-) diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index 3c10a9fd09df..538009e3b1f1 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -296,44 +296,6 @@ static int ufs_mtk_hce_enable_notify(struct ufs_hba *hba, return 0; } -static int ufs_mtk_bind_mphy(struct ufs_hba *hba) -{ - struct ufs_mtk_host *host = ufshcd_get_variant(hba); - struct device *dev = hba->dev; - struct device_node *np = dev->of_node; - int err = 0; - - host->mphy = devm_of_phy_get_by_index(dev, np, 0); - - if (host->mphy == ERR_PTR(-EPROBE_DEFER)) { - /* - * UFS driver might be probed before the phy driver does. - * In that case we would like to return EPROBE_DEFER code. - */ - err = -EPROBE_DEFER; - dev_info(dev, - "%s: required phy hasn't probed yet. err = %d\n", - __func__, err); - } else if (IS_ERR(host->mphy)) { - err = PTR_ERR(host->mphy); - if (err != -ENODEV) { - dev_info(dev, "%s: PHY get failed %d\n", __func__, - err); - } - } - - if (err) - host->mphy = NULL; - /* - * Allow unbound mphy because not every platform needs specific - * mphy control. - */ - if (err == -ENODEV) - err = 0; - - return err; -} - static int ufs_mtk_setup_ref_clk(struct ufs_hba *hba, bool on) { struct ufs_mtk_host *host = ufshcd_get_variant(hba); @@ -1234,13 +1196,21 @@ static int ufs_mtk_init(struct ufs_hba *hba) ufs_mtk_init_mcq_irq(hba); - err = ufs_mtk_bind_mphy(hba); - if (err) + host->mphy = devm_phy_optional_get(dev, NULL); + if (IS_ERR(host->mphy)) { + err = dev_err_probe(dev, PTR_ERR(host->mphy), "Failed to get PHY\n"); + goto out_variant_clear; + } + + err = phy_init(host->mphy); + if (err) { + dev_err_probe(dev, err, "Failed to initialize PHY\n"); goto out_variant_clear; + } err = ufs_mtk_init_reset(hba); if (err) - goto out_variant_clear; + goto out_phy_exit; /* Enable runtime autosuspend */ hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND; @@ -1279,7 +1249,7 @@ static int ufs_mtk_init(struct ufs_hba *hba) err = ufs_mtk_get_supplies(host); if (err) - goto out_variant_clear; + goto out_phy_exit; /* * ufshcd_vops_init() is invoked after @@ -1304,11 +1274,22 @@ static int ufs_mtk_init(struct ufs_hba *hba) return 0; +out_phy_exit: + phy_exit(host->mphy); out_variant_clear: ufshcd_set_variant(hba, NULL); return err; } +static void ufs_mtk_exit(struct ufs_hba *hba) +{ + struct ufs_mtk_host *host = ufshcd_get_variant(hba); + + ufs_mtk_mphy_power_on(hba, false); + + phy_exit(host->mphy); +} + static int ufs_mtk_negotiate_pwr_mode(struct ufs_hba *hba, const struct ufs_pa_layer_attr *dev_max_params, struct ufs_pa_layer_attr *dev_req_params) @@ -2321,6 +2302,7 @@ static void ufs_mtk_config_scsi_dev(struct scsi_device *sdev) static const struct ufs_hba_variant_ops ufs_hba_mtk_vops = { .name = "mediatek.ufshci", .init = ufs_mtk_init, + .exit = ufs_mtk_exit, .get_ufs_hci_version = ufs_mtk_get_ufs_hci_version, .setup_clocks = ufs_mtk_setup_clocks, .hce_enable_notify = ufs_mtk_hce_enable_notify, @@ -2381,48 +2363,15 @@ MODULE_DEVICE_TABLE(of, ufs_mtk_of_match); */ static int ufs_mtk_probe(struct platform_device *pdev) { - int err; + struct device *dev = &pdev->dev; struct ufs_hba *hba; - struct platform_device *phy_pdev = NULL; - struct device *dev = &pdev->dev, *phy_dev = NULL; - struct device_node *phy_node = NULL; - struct ufs_mtk_host *host; - - /* find phy node */ - phy_node = of_parse_phandle(dev->of_node, "phys", 0); - - if (phy_node) { - phy_pdev = of_find_device_by_node(phy_node); - if (!phy_pdev) - goto skip_phy; - phy_dev = &phy_pdev->dev; - - pm_runtime_set_active(phy_dev); - pm_runtime_enable(phy_dev); - pm_runtime_get_sync(phy_dev); - - put_device(phy_dev); - dev_info(dev, "phys node found\n"); - } else { - dev_notice(dev, "phys node not found\n"); - } + int ret; -skip_phy: - /* perform generic probe */ - err = ufshcd_pltfrm_init(pdev, &ufs_hba_mtk_vops); - if (err) { - dev_err(dev, "probe failed %d\n", err); - goto out; - } + ret = ufshcd_pltfrm_init(pdev, &ufs_hba_mtk_vops); + if (ret) + return dev_err_probe(dev, ret, "Generic platform probe failed\n"); hba = platform_get_drvdata(pdev); - if (!hba) - goto out; - - if (phy_node && phy_dev) { - host = ufshcd_get_variant(hba); - host->phy_dev = phy_dev; - } /* * Because the default power setting of VSx (the upper layer of @@ -2431,16 +2380,12 @@ static int ufs_mtk_probe(struct platform_device *pdev) */ ufs_mtk_dev_vreg_set_lpm(hba, false); -out: - of_node_put(phy_node); - return err; + return 0; } /** * ufs_mtk_remove - set driver_data of the device to NULL * @pdev: pointer to platform device handle - * - * Always return 0 */ static void ufs_mtk_remove(struct platform_device *pdev) { @@ -2497,9 +2442,8 @@ static int ufs_mtk_system_resume(struct device *dev) static int ufs_mtk_runtime_suspend(struct device *dev) { struct ufs_hba *hba = dev_get_drvdata(dev); - struct ufs_mtk_host *host = ufshcd_get_variant(hba); struct arm_smccc_res res; - int ret = 0; + int ret; ret = ufshcd_runtime_suspend(dev); if (ret) @@ -2510,8 +2454,11 @@ static int ufs_mtk_runtime_suspend(struct device *dev) if (ufs_mtk_is_rtff_mtcmos(hba)) ufs_mtk_mtcmos_ctrl(false, res); - if (host->phy_dev) - pm_runtime_put_sync(host->phy_dev); + ret = ufs_mtk_mphy_power_on(hba, false); + if (ret) { + dev_err(dev, "Failed to power off PHY: %pe\n", ERR_PTR(ret)); + return ret; + } return 0; } @@ -2519,14 +2466,17 @@ static int ufs_mtk_runtime_suspend(struct device *dev) static int ufs_mtk_runtime_resume(struct device *dev) { struct ufs_hba *hba = dev_get_drvdata(dev); - struct ufs_mtk_host *host = ufshcd_get_variant(hba); struct arm_smccc_res res; + int ret; if (ufs_mtk_is_rtff_mtcmos(hba)) ufs_mtk_mtcmos_ctrl(true, res); - if (host->phy_dev) - pm_runtime_get_sync(host->phy_dev); + ret = ufs_mtk_mphy_power_on(hba, true); + if (ret) { + dev_err(dev, "Failed to power on PHY: %pe\n", ERR_PTR(ret)); + return ret; + } ufs_mtk_dev_vreg_set_lpm(hba, false); diff --git a/drivers/ufs/host/ufs-mediatek.h b/drivers/ufs/host/ufs-mediatek.h index 477fb9e36555..bde2b53f5798 100644 --- a/drivers/ufs/host/ufs-mediatek.h +++ b/drivers/ufs/host/ufs-mediatek.h @@ -196,7 +196,6 @@ struct ufs_mtk_host { bool is_mcq_intr_enabled; int mcq_nr_intr; struct ufs_mtk_mcq_intr_info mcq_intr_info[UFSHCD_MAX_Q_NR]; - struct device *phy_dev; }; /* MTK delay of autosuspend: 500 ms */ -- 2.55.0