[PATCH v3 06/24] scsi: ufs: mediatek: Rework resets

Nicolas Frattaroli
2025-10-23T19:53:18Z

Rework the reset control getting in the driver's probe function to use
the bulk reset APIs. Use the optional variant instead of defaulting to
NULL if the resets fail, so that absent resets can be distinguished from
erroneous resets.

Also remove all remnants of the MPHY reset ever having lived in this
driver.

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
---
drivers/ufs/host/ufs-mediatek-sip.h | 8 ----
drivers/ufs/host/ufs-mediatek.c | 78 ++++++++++++++++++-------------------
drivers/ufs/host/ufs-mediatek.h | 7 ++--
3 files changed, 42 insertions(+), 51 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 ecbbf52bf734..d1554701793e 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -93,6 +93,12 @@ static const char *const ufs_uic_dl_err_str[] = {
"PA_INIT"
};

+static const char *const ufs_reset_names[] = {
+ "unipro",
+ "crypto",
+ "hci",
+};
+
static bool ufs_mtk_is_boost_crypt_enabled(struct ufs_hba *hba)
{
struct ufs_mtk_host *host = ufshcd_get_variant(hba);
@@ -203,49 +209,45 @@ 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;
-
- 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);
+ int 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);
+ ret = reset_control_bulk_assert(MTK_UFS_NUM_RESETS, host->resets);
+ if (ret)
+ dev_warn(hba->dev, "Host reset assert failed: %pe\n", ERR_PTR(ret));

- /* restore mphy setting aftre mphy reset */
- if (host->mphy_reset)
- ufs_mtk_mphy_ctrl(UFS_MPHY_RESTORE, res);
-}
+ ret = phy_reset(host->mphy);

-static void ufs_mtk_init_reset_control(struct ufs_hba *hba,
- struct reset_control **rc,
- char *str)
-{
- *rc = devm_reset_control_get(hba->dev, str);
- if (IS_ERR(*rc)) {
- dev_info(hba->dev, "Failed to get reset control %s: %ld\n",
- str, PTR_ERR(*rc));
- *rc = NULL;
+ /*
+ * 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));
}
+
+ ret = reset_control_bulk_deassert(MTK_UFS_NUM_RESETS, host->resets);
+ if (ret)
+ dev_warn(hba->dev, "Host reset deassert failed: %pe\n", ERR_PTR(ret));
}

-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, i;
+
+ for (i = 0; i < MTK_UFS_NUM_RESETS; i++)
+ host->resets[i].id = ufs_reset_names[i];

- ufs_mtk_init_reset_control(hba, &host->hci_reset,
- "hci_rst");
- ufs_mtk_init_reset_control(hba, &host->unipro_reset,
- "unipro_rst");
- ufs_mtk_init_reset_control(hba, &host->crypto_reset,
- "crypto_rst");
- ufs_mtk_init_reset_control(hba, &host->mphy_reset,
- "mphy_rst");
+ ret = devm_reset_control_bulk_get_optional_exclusive(hba->dev, MTK_UFS_NUM_RESETS,
+ host->resets);
+ if (ret) {
+ dev_err(hba->dev, "Failed to get resets: %pe\n", ERR_PTR(ret));
+ return ret;
+ }
+
+ return 0;
}

static int ufs_mtk_hce_enable_notify(struct ufs_hba *hba,
@@ -1247,11 +1249,9 @@ static int ufs_mtk_init(struct ufs_hba *hba)
if (err)
goto out_variant_clear;

- ufs_mtk_init_reset(hba);
-
- /* backup mphy setting if mphy can reset */
- if (host->mphy_reset)
- ufs_mtk_mphy_ctrl(UFS_MPHY_BACKUP, res);
+ err = ufs_mtk_init_reset(hba);
+ if (err)
+ goto out_variant_clear;

/* Enable runtime autosuspend */
hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND;
diff --git a/drivers/ufs/host/ufs-mediatek.h b/drivers/ufs/host/ufs-mediatek.h
index 9747277f11e8..4fce29d131d1 100644
--- a/drivers/ufs/host/ufs-mediatek.h
+++ b/drivers/ufs/host/ufs-mediatek.h
@@ -7,12 +7,14 @@
#define _UFS_MEDIATEK_H

#include <linux/bitops.h>
+#include <linux/reset.h>

/*
* MCQ define and struct
*/
#define UFSHCD_MAX_Q_NR 8
#define MTK_MCQ_INVALID_IRQ 0xFFFF
+#define MTK_UFS_NUM_RESETS 3

/* REG_UFS_MMIO_OPT_CTRL_0 160h */
#define EHS_EN BIT(0)
@@ -175,10 +177,7 @@ struct ufs_mtk_mcq_intr_info {
struct ufs_mtk_host {
struct phy *mphy;
struct regulator *reg_va09;
- struct reset_control *hci_reset;
- struct reset_control *unipro_reset;
- struct reset_control *crypto_reset;
- struct reset_control *mphy_reset;
+ struct reset_control_bulk_data resets[MTK_UFS_NUM_RESETS];
struct ufs_hba *hba;
struct ufs_mtk_crypt_cfg *crypt;
struct ufs_mtk_clk mclk;

--
2.51.1.dirty