Devicetree
 help / color / mirror / Atom feed
From: "Chaotian Jing (井朝天)" <Chaotian.Jing@mediatek.com>
To: "Peter Wang (王信友)" <peter.wang@mediatek.com>,
	"avri.altman@sandisk.com" <avri.altman@sandisk.com>,
	"Chunfeng Yun (云春峰)" <Chunfeng.Yun@mediatek.com>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"bvanassche@acm.org" <bvanassche@acm.org>,
	"Louis-Alexis Eyraud" <louisalexis.eyraud@collabora.com>,
	"broonie@kernel.org" <broonie@kernel.org>,
	"alim.akhtar@samsung.com" <alim.akhtar@samsung.com>,
	"chu.stanley@gmail.com" <chu.stanley@gmail.com>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	"robh@kernel.org" <robh@kernel.org>,
	"James.Bottomley@HansenPartnership.com"
	<James.Bottomley@HansenPartnership.com>,
	"lgirdwood@gmail.com" <lgirdwood@gmail.com>,
	"vkoul@kernel.org" <vkoul@kernel.org>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"neil.armstrong@linaro.org" <neil.armstrong@linaro.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"AngeloGioacchino Del Regno"
	<angelogioacchino.delregno@collabora.com>
Cc: "linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"nicolas.frattaroli@collabora.com"
	<nicolas.frattaroli@collabora.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"kernel@collabora.com" <kernel@collabora.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-phy@lists.infradead.org" <linux-phy@lists.infradead.org>
Subject: Re: [PATCH v10 13/26] scsi: ufs: mediatek: Use the common PHY framework
Date: Fri, 31 Jul 2026 05:51:17 +0000	[thread overview]
Message-ID: <5bd6efe2079ac94a3e39dba3d1f644cb627368da.camel@mediatek.com> (raw)
In-Reply-To: <20260730-mt8196-ufs-v10-13-bc5ecef202dc@collabora.com>

On Thu, 2026-07-30 at 11:49 +0200, Louis-Alexis Eyraud wrote:
> From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
> 
> 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: Chaotian Jing <chaotian.jing@mediatek.com>
> Reviewed-by: AngeloGioacchino Del Regno <
> angelogioacchino.delregno@collabora.com>
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
> Signed-off-by: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com>
> ---
>  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 e5527969a5e6..385f0180b230 100644
> --- a/drivers/ufs/host/ufs-mediatek.c
> +++ b/drivers/ufs/host/ufs-mediatek.c
> @@ -293,44 +293,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);
> @@ -1185,13 +1147,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_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;
> @@ -1230,7 +1200,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
> @@ -1255,11 +1225,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)
> @@ -2272,6 +2253,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,
> @@ -2332,48 +2314,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
> @@ -2382,16 +2331,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)
>  {
> @@ -2448,9 +2393,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)
> @@ -2461,8 +2405,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;
>  }
> @@ -2470,14 +2417,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 c63740b98e85..8b3cd17e6227 100644
> --- a/drivers/ufs/host/ufs-mediatek.h
> +++ b/drivers/ufs/host/ufs-mediatek.h
> @@ -195,7 +195,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 */
> 

  parent reply	other threads:[~2026-07-31  5:51 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  9:48 [PATCH v10 00/26] MediaTek UFS Cleanup and MT8196 Enablement Louis-Alexis Eyraud
2026-07-30  9:48 ` [PATCH v10 01/26] dt-bindings: phy: Add mediatek,mt8196-ufsphy variant Louis-Alexis Eyraud
2026-07-30  9:48 ` [PATCH v10 02/26] dt-bindings: ufs: mediatek,ufs: Complete the binding Louis-Alexis Eyraud
2026-07-30  9:57   ` sashiko-bot
2026-07-31  5:47   ` Chaotian Jing (井朝天)
2026-07-30  9:48 ` [PATCH v10 03/26] dt-bindings: ufs: mediatek,ufs: Add mt8196 variant Louis-Alexis Eyraud
2026-07-30  9:59   ` sashiko-bot
2026-07-31  5:48   ` Chaotian Jing (井朝天)
2026-07-31  8:27   ` Krzysztof Kozlowski
2026-07-30  9:49 ` [PATCH v10 04/26] scsi: ufs: mediatek: Move MTK_SIP_UFS_CONTROL to mtk_sip_svc.h Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 05/26] phy: mediatek: ufs: Add support for resets Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 06/26] scsi: ufs: mediatek: Rework resets Louis-Alexis Eyraud
2026-07-30 10:29   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 07/26] scsi: ufs: mediatek: Rework 0.9V regulator Louis-Alexis Eyraud
2026-07-30 10:13   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 08/26] scsi: ufs: mediatek: Rework init function Louis-Alexis Eyraud
2026-07-30 10:07   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 09/26] scsi: ufs: mediatek: Rework the crypt-boost stuff Louis-Alexis Eyraud
2026-07-30 10:16   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 10/26] scsi: ufs: mediatek: Handle misc host voltage regulators Louis-Alexis Eyraud
2026-07-30 10:29   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 11/26] scsi: ufs: mediatek: Remove undocumented downstream reset cruft Louis-Alexis Eyraud
2026-07-30 10:23   ` sashiko-bot
2026-07-31  5:49   ` Chaotian Jing (井朝天)
2026-07-30  9:49 ` [PATCH v10 12/26] scsi: ufs: mediatek: Remove vendor kernel quirks cruft Louis-Alexis Eyraud
2026-07-30 10:30   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 13/26] scsi: ufs: mediatek: Use the common PHY framework Louis-Alexis Eyraud
2026-07-30 10:40   ` sashiko-bot
2026-07-31  5:51   ` Chaotian Jing (井朝天) [this message]
2026-07-30  9:49 ` [PATCH v10 14/26] scsi: ufs: mediatek: Remove mediatek,ufs-broken-rtc property Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 15/26] scsi: ufs: mediatek: Rework _ufs_mtk_clk_scale error paths Louis-Alexis Eyraud
2026-07-30 10:34   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 16/26] scsi: ufs: mediatek: Clean up logging prints Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 17/26] scsi: ufs: mediatek: Rework ufs_mtk_wait_idle_state Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 18/26] scsi: ufs: mediatek: Don't acquire dvfsrc-vcore twice Louis-Alexis Eyraud
2026-07-30 10:41   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 19/26] scsi: ufs: mediatek: Rework hardware version reading Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 20/26] scsi: ufs: mediatek: Back up idle timer in per-instance struct Louis-Alexis Eyraud
2026-07-30 10:53   ` sashiko-bot
2026-07-30  9:49 ` [PATCH v10 21/26] scsi: ufs: mediatek: Remove ret local from link_startup_notify Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 22/26] scsi: ufs: mediatek: Remove undocumented "clk-scale-up-vcore-min" Louis-Alexis Eyraud
2026-07-30 10:49   ` sashiko-bot
2026-07-31  5:51   ` Chaotian Jing (井朝天)
2026-07-30  9:49 ` [PATCH v10 23/26] scsi: ufs: mediatek: Add MT8196 compatible, update copyright Louis-Alexis Eyraud
2026-07-30  9:49 ` [PATCH v10 24/26] arm64: dts: mediatek: mt8195: Align ufshci node to dt-bindings changes Louis-Alexis Eyraud
2026-07-30 11:13   ` sashiko-bot
2026-07-31  5:52   ` Chaotian Jing (井朝天)
2026-07-31  8:28   ` Krzysztof Kozlowski
2026-07-30  9:49 ` [PATCH v10 25/26] arm64: dts: mediatek: mt8395-genio-1200-evk-ufs: Complete UFS power supplies Louis-Alexis Eyraud
2026-07-31  5:53   ` Chaotian Jing (井朝天)
2026-07-30  9:49 ` [PATCH v10 26/26] arm64: dts: mediatek: mt8395-radxa-nio-12l: " Louis-Alexis Eyraud
2026-07-31  5:54   ` Chaotian Jing (井朝天)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5bd6efe2079ac94a3e39dba3d1f644cb627368da.camel@mediatek.com \
    --to=chaotian.jing@mediatek.com \
    --cc=Chunfeng.Yun@mediatek.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=alim.akhtar@samsung.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=avri.altman@sandisk.com \
    --cc=broonie@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=chu.stanley@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@collabora.com \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=louisalexis.eyraud@collabora.com \
    --cc=martin.petersen@oracle.com \
    --cc=matthias.bgg@gmail.com \
    --cc=neil.armstrong@linaro.org \
    --cc=nicolas.frattaroli@collabora.com \
    --cc=p.zabel@pengutronix.de \
    --cc=peter.wang@mediatek.com \
    --cc=robh@kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox