diff mbox series

[v5,10/11] scsi: ufs-mediatek: Support multiple VCC sources

Message ID 20220616053725.5681-11-stanley.chu@mediatek.com (mailing list archive)
State Accepted
Headers show
Series scsi: ufs: Fix PMC and low-power mode on MediaTek UFS platforms | expand

Commit Message

Stanley Chu June 16, 2022, 5:37 a.m. UTC
Support multiple VCC source in MediaTek UFS platforms.

Two options are provided and distinguished by specific
device tree attributes as below examples,

[Option 1: By numbering]
mediatek,ufs-vcc-by-num;
vcc-opt1-supply = <&mt6373_vbuck4_ufs>;
vcc-opt2-supply = <&mt6363_vemc>;

[Option 2: By UFS version]
mediatek,ufs-vcc-by-ver;
vcc-ufs3-supply = <&mt6373_vbuck4_ufs>;

Signed-off-by: Alice Chao <alice.chao@mediatek.com>
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
 drivers/ufs/host/ufs-mediatek.c | 46 ++++++++++++++++++++++++++++++++-
 drivers/ufs/host/ufs-mediatek.h | 14 ++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)

Comments

Anders Roxell June 20, 2022, 9:24 a.m. UTC | #1
On 2022-06-16 13:37, Stanley Chu wrote:
> Support multiple VCC source in MediaTek UFS platforms.
> 
> Two options are provided and distinguished by specific
> device tree attributes as below examples,
> 
> [Option 1: By numbering]
> mediatek,ufs-vcc-by-num;
> vcc-opt1-supply = <&mt6373_vbuck4_ufs>;
> vcc-opt2-supply = <&mt6363_vemc>;
> 
> [Option 2: By UFS version]
> mediatek,ufs-vcc-by-ver;
> vcc-ufs3-supply = <&mt6373_vbuck4_ufs>;
> 
> Signed-off-by: Alice Chao <alice.chao@mediatek.com>
> Signed-off-by: Peter Wang <peter.wang@mediatek.com>
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> ---
>  drivers/ufs/host/ufs-mediatek.c | 46 ++++++++++++++++++++++++++++++++-
>  drivers/ufs/host/ufs-mediatek.h | 14 ++++++++++
>  2 files changed, 59 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
> index e756aba45acd..34e51c094366 100755
> --- a/drivers/ufs/host/ufs-mediatek.c
> +++ b/drivers/ufs/host/ufs-mediatek.c
> @@ -669,6 +669,49 @@ static u32 ufs_mtk_get_ufs_hci_version(struct ufs_hba *hba)
>  	return hba->ufs_version;
>  }
>  
> +#define MAX_VCC_NAME 30
> +static int ufs_mtk_vreg_fix_vcc(struct ufs_hba *hba)
> +{
> +	struct ufs_vreg_info *info = &hba->vreg_info;
> +	struct device_node *np = hba->dev->of_node;
> +	struct device *dev = hba->dev;
> +	char vcc_name[MAX_VCC_NAME];
> +	struct arm_smccc_res res;
> +	int err, ver;
> +
> +	if (hba->vreg_info.vcc)
> +		return 0;
> +
> +	if (of_property_read_bool(np, "mediatek,ufs-vcc-by-num")) {
> +		ufs_mtk_get_vcc_num(res);
> +		if (res.a1 > UFS_VCC_NONE && res.a1 < UFS_VCC_MAX)
> +			snprintf(vcc_name, MAX_VCC_NAME, "vcc-opt%u", res.a1);

Building this showes the following build warning/error

drivers/ufs/host/ufs-mediatek.c: In function 'ufs_mtk_vreg_fix_vcc':
drivers/ufs/host/ufs-mediatek.c:688:67: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'long unsigned int' [-Werror=format=]
  688 |                         snprintf(vcc_name, MAX_VCC_NAME, "vcc-opt%u", res.a1);
      |                                                                  ~^   ~~~~~~
      |                                                                   |      |
      |                                                                   |      long unsigned int
      |                                                                   unsigned int
      |                                                                  %lu
cc1: all warnings being treated as errors


Cheers,
Anders
diff mbox series

Patch

diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index e756aba45acd..34e51c094366 100755
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -669,6 +669,49 @@  static u32 ufs_mtk_get_ufs_hci_version(struct ufs_hba *hba)
 	return hba->ufs_version;
 }
 
+#define MAX_VCC_NAME 30
+static int ufs_mtk_vreg_fix_vcc(struct ufs_hba *hba)
+{
+	struct ufs_vreg_info *info = &hba->vreg_info;
+	struct device_node *np = hba->dev->of_node;
+	struct device *dev = hba->dev;
+	char vcc_name[MAX_VCC_NAME];
+	struct arm_smccc_res res;
+	int err, ver;
+
+	if (hba->vreg_info.vcc)
+		return 0;
+
+	if (of_property_read_bool(np, "mediatek,ufs-vcc-by-num")) {
+		ufs_mtk_get_vcc_num(res);
+		if (res.a1 > UFS_VCC_NONE && res.a1 < UFS_VCC_MAX)
+			snprintf(vcc_name, MAX_VCC_NAME, "vcc-opt%u", res.a1);
+		else
+			return -ENODEV;
+	} else if (of_property_read_bool(np, "mediatek,ufs-vcc-by-ver")) {
+		ver = (hba->dev_info.wspecversion & 0xF00) >> 8;
+		snprintf(vcc_name, MAX_VCC_NAME, "vcc-ufs%u", ver);
+	} else {
+		return 0;
+	}
+
+	err = ufshcd_populate_vreg(dev, vcc_name, &info->vcc);
+	if (err)
+		return err;
+
+	err = ufshcd_get_vreg(dev, info->vcc);
+	if (err)
+		return err;
+
+	err = regulator_enable(info->vcc->reg);
+	if (!err) {
+		info->vcc->enabled = true;
+		dev_info(dev, "%s: %s enabled\n", __func__, vcc_name);
+	}
+
+	return err;
+}
+
 /**
  * ufs_mtk_init - find other essential mmio bases
  * @hba: host controller instance
@@ -1179,7 +1222,6 @@  static int ufs_mtk_apply_dev_quirks(struct ufs_hba *hba)
 	else
 		ufs_mtk_setup_ref_clk_wait_us(hba,
 					      REFCLK_DEFAULT_WAIT_US);
-
 	return 0;
 }
 
@@ -1197,6 +1239,8 @@  static void ufs_mtk_fixup_dev_quirks(struct ufs_hba *hba)
 		hba->dev_quirks &= ~(UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM |
 			UFS_DEVICE_QUIRK_DELAY_AFTER_LPM);
 	}
+
+	ufs_mtk_vreg_fix_vcc(hba);
 }
 
 static void ufs_mtk_event_notify(struct ufs_hba *hba,
diff --git a/drivers/ufs/host/ufs-mediatek.h b/drivers/ufs/host/ufs-mediatek.h
index 5c6101ac518f..49a2137fb251 100755
--- a/drivers/ufs/host/ufs-mediatek.h
+++ b/drivers/ufs/host/ufs-mediatek.h
@@ -83,6 +83,7 @@  enum {
 #define UFS_MTK_SIP_DEVICE_RESET          BIT(1)
 #define UFS_MTK_SIP_CRYPTO_CTRL           BIT(2)
 #define UFS_MTK_SIP_REF_CLK_NOTIFICATION  BIT(3)
+#define UFS_MTK_SIP_GET_VCC_NUM           BIT(6)
 #define UFS_MTK_SIP_DEVICE_PWR_CTRL       BIT(7)
 
 /*
@@ -144,6 +145,16 @@  struct ufs_mtk_host {
 	u32 ip_ver;
 };
 
+/*
+ * Multi-VCC by Numbering
+ */
+enum ufs_mtk_vcc_num {
+	UFS_VCC_NONE = 0,
+	UFS_VCC_1,
+	UFS_VCC_2,
+	UFS_VCC_MAX
+};
+
 /*
  * SMC call wrapper function
  */
@@ -183,6 +194,9 @@  static void _ufs_mtk_smc(struct ufs_mtk_smc_arg s)
 #define ufs_mtk_device_reset_ctrl(high, res) \
 	ufs_mtk_smc(UFS_MTK_SIP_DEVICE_RESET, &(res), high)
 
+#define ufs_mtk_get_vcc_num(res) \
+	ufs_mtk_smc(UFS_MTK_SIP_GET_VCC_NUM, &(res))
+
 #define ufs_mtk_device_pwr_ctrl(on, ufs_ver, res) \
 	ufs_mtk_smc(UFS_MTK_SIP_DEVICE_PWR_CTRL, &(res), on, ufs_ver)