From: Philipp Zabel <p.zabel@pengutronix.de>
To: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>,
Alim Akhtar <alim.akhtar@samsung.com>,
Avri Altman <avri.altman@wdc.com>,
Bart Van Assche <bvanassche@acm.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Stanley Chu <stanley.chu@mediatek.com>,
Chunfeng Yun <chunfeng.yun@mediatek.com>,
Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@kernel.org>,
Peter Wang <peter.wang@mediatek.com>,
Stanley Jhu <chu.stanley@gmail.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com>,
kernel@collabora.com, linux-scsi@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-phy@lists.infradead.org
Subject: Re: [PATCH 5/5] scsi: ufs: mediatek: Rework resets
Date: Wed, 15 Oct 2025 12:07:33 +0200 [thread overview]
Message-ID: <6bea63bb14f2be814762fa719d3d7944bad39b6e.camel@pengutronix.de> (raw)
In-Reply-To: <20251014-mt8196-ufs-v1-5-195dceb83bc8@collabora.com>
Hi Nicolas,
On Di, 2025-10-14 at 17:10 +0200, Nicolas Frattaroli wrote:
> Rework the reset control getting in the driver's probe function to use
> the "_optional" function instead of defaulting to NULL on IS_ERR, so
> that actual real errors (as opposed to missing resets) can be handled as
> errors in the probe function.
>
> Also move the MPHY reset into the PHY driver, where it should live, and
> remove all remnants of it ever having been in this driver.
Part of that happened in the previous patch.
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
> ---
> drivers/ufs/host/ufs-mediatek-sip.h | 8 -----
> drivers/ufs/host/ufs-mediatek.c | 67 +++++++++++++++++++++----------------
> drivers/ufs/host/ufs-mediatek.h | 1 -
> 3 files changed, 38 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/ufs/host/ufs-mediatek-sip.h b/drivers/ufs/host/ufs-mediatek-sip.h
> index d627dfb4a766..256598cc3b5b 100644
> --- a/drivers/ufs/host/ufs-mediatek-sip.h
> +++ b/drivers/ufs/host/ufs-mediatek-sip.h
> @@ -31,11 +31,6 @@ enum ufs_mtk_vcc_num {
> UFS_VCC_MAX
> };
>
> -enum ufs_mtk_mphy_op {
> - UFS_MPHY_BACKUP = 0,
> - UFS_MPHY_RESTORE
> -};
> -
> /*
> * SMC call wrapper function
> */
> @@ -84,9 +79,6 @@ static inline void _ufs_mtk_smc(struct ufs_mtk_smc_arg s)
> #define ufs_mtk_device_pwr_ctrl(on, ufs_version, res) \
> ufs_mtk_smc(UFS_MTK_SIP_DEVICE_PWR_CTRL, &(res), on, ufs_version)
>
> -#define ufs_mtk_mphy_ctrl(op, res) \
> - ufs_mtk_smc(UFS_MTK_SIP_MPHY_CTRL, &(res), op)
> -
> #define ufs_mtk_mtcmos_ctrl(op, res) \
> ufs_mtk_smc(UFS_MTK_SIP_MTCMOS_CTRL, &(res), op)
>
> diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
> index 758a393a9de1..ac40d4a3a800 100644
> --- a/drivers/ufs/host/ufs-mediatek.c
> +++ b/drivers/ufs/host/ufs-mediatek.c
> @@ -204,49 +204,60 @@ static void ufs_mtk_crypto_enable(struct ufs_hba *hba)
> static void ufs_mtk_host_reset(struct ufs_hba *hba)
> {
> struct ufs_mtk_host *host = ufshcd_get_variant(hba);
> - struct arm_smccc_res res;
> + int ret;
>
> reset_control_assert(host->hci_reset);
> reset_control_assert(host->crypto_reset);
> reset_control_assert(host->unipro_reset);
> - reset_control_assert(host->mphy_reset);
>
> - usleep_range(100, 110);
> + ret = phy_reset(host->mphy);
> +
> + /*
> + * Only sleep if MPHY doesn't have a reset implemented (which already
> + * sleeps) or the PHY reset function failed somehow, just to be safe
> + */
> + if (ret) {
> + usleep_range(100, 110);
> + if (ret != -EOPNOTSUPP)
> + dev_warn(hba->dev, "PHY reset failed: %pe\n", ERR_PTR(ret));
> + }
>
> reset_control_deassert(host->unipro_reset);
> reset_control_deassert(host->crypto_reset);
> reset_control_deassert(host->hci_reset);
> - reset_control_deassert(host->mphy_reset);
> -
> - /* restore mphy setting aftre mphy reset */
> - if (host->mphy_reset)
> - ufs_mtk_mphy_ctrl(UFS_MPHY_RESTORE, res);
> }
>
> -static void ufs_mtk_init_reset_control(struct ufs_hba *hba,
> - struct reset_control **rc,
> - char *str)
> +static int ufs_mtk_init_reset_control(struct ufs_hba *hba,
> + struct reset_control **rc,
> + const char *str)
> {
> - *rc = devm_reset_control_get(hba->dev, str);
> + *rc = devm_reset_control_get_optional(hba->dev, str);
Please use
devm_reset_control_get_optional_exclusive()
directly, or see below for an alternative suggestion.
> if (IS_ERR(*rc)) {
> - dev_info(hba->dev, "Failed to get reset control %s: %ld\n",
> - str, PTR_ERR(*rc));
> - *rc = NULL;
> + dev_err(hba->dev, "Failed to get reset control %s: %pe\n", str, *rc);
> + return PTR_ERR(*rc);
> }
> +
> + return 0;
> }
>
> -static void ufs_mtk_init_reset(struct ufs_hba *hba)
> +static int ufs_mtk_init_reset(struct ufs_hba *hba)
> {
> struct ufs_mtk_host *host = ufshcd_get_variant(hba);
> + int ret;
> +
> + ret = ufs_mtk_init_reset_control(hba, &host->hci_reset, "hci_rst");
> + if (ret)
> + return ret;
> +
> + ret = ufs_mtk_init_reset_control(hba, &host->unipro_reset, "unipro_rst");
> + if (ret)
> + return ret;
> +
> + ret = ufs_mtk_init_reset_control(hba, &host->crypto_reset, "crypto_rst");
> + if (ret)
> + return ret;
It looks to me like you could combine these into a
devm_reset_control_bulk_get_optional_exclusive()
and operate the three resets with reset_control_bulk_assert/deassert().
regards
Philipp
next prev parent reply other threads:[~2025-10-15 10:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-14 15:10 [PATCH 0/5] MediaTek UFS Cleanup and MT8196 Enablement Nicolas Frattaroli
2025-10-14 15:10 ` [PATCH 1/5] dt-bindings: ufs: mediatek,ufs: Add mt8196-ufshci variant Nicolas Frattaroli
2025-10-16 2:59 ` Peter Wang (王信友)
2025-10-16 3:15 ` Peter Wang (王信友)
2025-10-16 16:53 ` Conor Dooley
2025-10-16 16:54 ` Conor Dooley
2025-10-14 15:10 ` [PATCH 2/5] dt-bindings: phy: Add mediatek,mt8196-ufsphy variant Nicolas Frattaroli
2025-10-17 6:51 ` Peter Wang (王信友)
2025-10-14 15:10 ` [PATCH 3/5] scsi: ufs: mediatek: Move MTK_SIP_UFS_CONTROL to mtk_sip_svc.h Nicolas Frattaroli
2025-10-16 3:42 ` Peter Wang (王信友)
2025-10-14 15:10 ` [PATCH 4/5] phy: mediatek: ufs: Add support for resets Nicolas Frattaroli
2025-10-15 10:07 ` Philipp Zabel
2025-10-14 15:10 ` [PATCH 5/5] scsi: ufs: mediatek: Rework resets Nicolas Frattaroli
2025-10-15 10:07 ` Philipp Zabel [this message]
2025-10-15 8:25 ` [PATCH 0/5] MediaTek UFS Cleanup and MT8196 Enablement AngeloGioacchino Del Regno
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=6bea63bb14f2be814762fa719d3d7944bad39b6e.camel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=avri.altman@wdc.com \
--cc=bvanassche@acm.org \
--cc=chu.stanley@gmail.com \
--cc=chunfeng.yun@mediatek.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kernel@collabora.com \
--cc=kishon@kernel.org \
--cc=krzk+dt@kernel.org \
--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=nicolas.frattaroli@collabora.com \
--cc=peter.wang@mediatek.com \
--cc=robh@kernel.org \
--cc=stanley.chu@mediatek.com \
--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;
as well as URLs for NNTP newsgroup(s).