scsi: ufs-mediatek: add device reset implementation
authorStanley Chu <stanley.chu@mediatek.com>
Mon, 30 Dec 2019 05:32:26 +0000 (13:32 +0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 3 Jan 2020 02:57:44 +0000 (21:57 -0500)
Add device reset vops implementation in MediaTek UFS driver.

Cc: Alim Akhtar <alim.akhtar@samsung.com>
Cc: Avri Altman <avri.altman@wdc.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Bean Huo <beanhuo@micron.com>
Cc: Can Guo <cang@codeaurora.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Link: https://lore.kernel.org/r/1577683950-1702-3-git-send-email-stanley.chu@mediatek.com
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/ufs/ufs-mediatek.c
drivers/scsi/ufs/ufs-mediatek.h

index 83e28edc3ac5b9408b20ee2c635907cfe2e51281..37e2c91fc452c05f0fec3e62f9c2d0f4735f83ae 100644 (file)
@@ -6,16 +6,25 @@
  *     Peter Wang <peter.wang@mediatek.com>
  */
 
+#include <linux/arm-smccc.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/soc/mediatek/mtk_sip_svc.h>
 
 #include "ufshcd.h"
 #include "ufshcd-pltfrm.h"
 #include "unipro.h"
 #include "ufs-mediatek.h"
 
+#define ufs_mtk_smc(cmd, val, res) \
+       arm_smccc_smc(MTK_SIP_UFS_CONTROL, \
+                     cmd, val, 0, 0, 0, 0, 0, &(res))
+
+#define ufs_mtk_device_reset_ctrl(high, res) \
+       ufs_mtk_smc(UFS_MTK_SIP_DEVICE_RESET, high, res)
+
 static void ufs_mtk_cfg_unipro_cg(struct ufs_hba *hba, bool enable)
 {
        u32 tmp;
@@ -269,6 +278,29 @@ static int ufs_mtk_link_startup_notify(struct ufs_hba *hba,
        return ret;
 }
 
+static void ufs_mtk_device_reset(struct ufs_hba *hba)
+{
+       struct arm_smccc_res res;
+
+       ufs_mtk_device_reset_ctrl(0, res);
+
+       /*
+        * The reset signal is active low. UFS devices shall detect
+        * more than or equal to 1us of positive or negative RST_n
+        * pulse width.
+        *
+        * To be on safe side, keep the reset low for at least 10us.
+        */
+       usleep_range(10, 15);
+
+       ufs_mtk_device_reset_ctrl(1, res);
+
+       /* Some devices may need time to respond to rst_n */
+       usleep_range(10000, 15000);
+
+       dev_info(hba->dev, "device reset done\n");
+}
+
 static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 {
        struct ufs_mtk_host *host = ufshcd_get_variant(hba);
@@ -303,6 +335,7 @@ static struct ufs_hba_variant_ops ufs_hba_mtk_vops = {
        .pwr_change_notify   = ufs_mtk_pwr_change_notify,
        .suspend             = ufs_mtk_suspend,
        .resume              = ufs_mtk_resume,
+       .device_reset        = ufs_mtk_device_reset,
 };
 
 /**
index 19f8c42fe06ff3c363299efc11413f2f1712bd82..ce68ce25fdd73a2fb82340c99d010f0a63777035 100644 (file)
@@ -6,6 +6,9 @@
 #ifndef _UFS_MEDIATEK_H
 #define _UFS_MEDIATEK_H
 
+#include <linux/bitops.h>
+#include <linux/soc/mediatek/mtk_sip_svc.h>
+
 /*
  * Vendor specific pre-defined parameters
  */
 #define VS_SAVEPOWERCONTROL         0xD0A6
 #define VS_UNIPROPOWERDOWNCONTROL   0xD0A8
 
+/*
+ * SiP commands
+ */
+#define MTK_SIP_UFS_CONTROL         MTK_SIP_SMC_CMD(0x276)
+#define UFS_MTK_SIP_DEVICE_RESET    BIT(1)
+
 /*
  * VS_DEBUGCLOCKENABLE
  */