linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2 RESEND] scsi: ufs-mediatek: add device reset implementation
@ 2019-12-16  3:48 Stanley Chu
  2019-12-16  3:48 ` [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface Stanley Chu
  2019-12-16  3:48 ` [PATCH v2 2/2 RESEND] scsi: ufs-mediatek: add device reset implementation Stanley Chu
  0 siblings, 2 replies; 7+ messages in thread
From: Stanley Chu @ 2019-12-16  3:48 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, avri.altman, alim.akhtar,
	pedrom.sousa, jejb, matthias.bgg, f.fainelli
  Cc: linux-mediatek, linux-arm-kernel, linux-kernel, beanhuo,
	kuohong.wang, peter.wang, chun-hung.wu, andy.teng, leon.chen,
	Stanley Chu

This patchset add implementation of UFS device reset vops in MediaTek UFS driver.

v2:
 - Use definition defined in include/linux/arm-smccc.h instead of "magic definition" (Florian Fainelli)

Stanley Chu (2):
  soc: mediatek: add header for SiP service interface
  scsi: ufs-mediatek: add device reset implementation

 drivers/scsi/ufs/ufs-mediatek.c          | 27 +++++++++++++++++++++
 drivers/scsi/ufs/ufs-mediatek.h          |  7 ++++++
 include/linux/soc/mediatek/mtk_sip_svc.h | 30 ++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
 create mode 100644 include/linux/soc/mediatek/mtk_sip_svc.h

-- 
2.18.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface
  2019-12-16  3:48 [PATCH v2 0/2 RESEND] scsi: ufs-mediatek: add device reset implementation Stanley Chu
@ 2019-12-16  3:48 ` Stanley Chu
  2019-12-16  3:52   ` Stanley Chu
  2019-12-19 18:00   ` Alim Akhtar
  2019-12-16  3:48 ` [PATCH v2 2/2 RESEND] scsi: ufs-mediatek: add device reset implementation Stanley Chu
  1 sibling, 2 replies; 7+ messages in thread
From: Stanley Chu @ 2019-12-16  3:48 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, avri.altman, alim.akhtar,
	pedrom.sousa, jejb, matthias.bgg, f.fainelli
  Cc: linux-mediatek, linux-arm-kernel, linux-kernel, beanhuo,
	kuohong.wang, peter.wang, chun-hung.wu, andy.teng, leon.chen,
	Stanley Chu

Add a header for the SiP service interface in order to access
the UFSHCI controller for secure command handling in MediaTek Chipsets.

Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
 include/linux/soc/mediatek/mtk_sip_svc.h | 29 ++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 include/linux/soc/mediatek/mtk_sip_svc.h

diff --git a/include/linux/soc/mediatek/mtk_sip_svc.h b/include/linux/soc/mediatek/mtk_sip_svc.h
new file mode 100644
index 000000000000..97311959d7d7
--- /dev/null
+++ b/include/linux/soc/mediatek/mtk_sip_svc.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 MediaTek Inc.
+ */
+#ifndef __MTK_SIP_SVC_H
+#define __MTK_SIP_SVC_H
+
+/* Error Code */
+#define SIP_SVC_E_SUCCESS               0
+#define SIP_SVC_E_NOT_SUPPORTED         -1
+#define SIP_SVC_E_INVALID_PARAMS        -2
+#define SIP_SVC_E_INVALID_RANGE         -3
+#define SIP_SVC_E_PERMISSION_DENIED     -4
+
+#ifdef CONFIG_ARM64
+#define MTK_SIP_SMC_CONVENTION          ARM_SMCCC_SMC_64
+#else
+#define MTK_SIP_SMC_CONVENTION          ARM_SMCCC_SMC_32
+#endif
+
+#define MTK_SIP_SMC_CMD(fn_id) \
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, MTK_SIP_SMC_CONVENTION, \
+			   ARM_SMCCC_OWNER_SIP, fn_id)
+
+/* UFS related SMC call */
+#define MTK_SIP_UFS_CONTROL \
+	MTK_SIP_SMC_CMD(0x276)
+
+#endif
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2 RESEND] scsi: ufs-mediatek: add device reset implementation
  2019-12-16  3:48 [PATCH v2 0/2 RESEND] scsi: ufs-mediatek: add device reset implementation Stanley Chu
  2019-12-16  3:48 ` [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface Stanley Chu
@ 2019-12-16  3:48 ` Stanley Chu
  1 sibling, 0 replies; 7+ messages in thread
From: Stanley Chu @ 2019-12-16  3:48 UTC (permalink / raw)
  To: linux-scsi, martin.petersen, avri.altman, alim.akhtar,
	pedrom.sousa, jejb, matthias.bgg, f.fainelli
  Cc: linux-mediatek, linux-arm-kernel, linux-kernel, beanhuo,
	kuohong.wang, peter.wang, chun-hung.wu, andy.teng, leon.chen,
	Stanley Chu

Add device reset vops implementation in MediaTek UFS driver.

Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
---
 drivers/scsi/ufs/ufs-mediatek.c | 27 +++++++++++++++++++++++++++
 drivers/scsi/ufs/ufs-mediatek.h |  7 +++++++
 2 files changed, 34 insertions(+)

diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c
index 83e28edc3ac5..6a3ec11b16db 100644
--- a/drivers/scsi/ufs/ufs-mediatek.c
+++ b/drivers/scsi/ufs/ufs-mediatek.c
@@ -6,10 +6,12 @@
  *	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"
@@ -269,6 +271,30 @@ 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;
+
+	arm_smccc_smc(MTK_SIP_UFS_CONTROL, UFS_MTK_SIP_DEVICE_RESET,
+		      0, 0, 0, 0, 0, 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);
+
+	arm_smccc_smc(MTK_SIP_UFS_CONTROL, UFS_MTK_SIP_DEVICE_RESET,
+		      1, 0, 0, 0, 0, 0, &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 +329,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,
 };
 
 /**
diff --git a/drivers/scsi/ufs/ufs-mediatek.h b/drivers/scsi/ufs/ufs-mediatek.h
index 19f8c42fe06f..b03f601d3a9e 100644
--- a/drivers/scsi/ufs/ufs-mediatek.h
+++ b/drivers/scsi/ufs/ufs-mediatek.h
@@ -6,6 +6,8 @@
 #ifndef _UFS_MEDIATEK_H
 #define _UFS_MEDIATEK_H
 
+#include <linux/bitops.h>
+
 /*
  * Vendor specific pre-defined parameters
  */
@@ -29,6 +31,11 @@
 #define VS_SAVEPOWERCONTROL         0xD0A6
 #define VS_UNIPROPOWERDOWNCONTROL   0xD0A8
 
+/*
+ * SiP commands
+ */
+#define UFS_MTK_SIP_DEVICE_RESET    BIT(1)
+
 /*
  * VS_DEBUGCLOCKENABLE
  */
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface
  2019-12-16  3:48 ` [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface Stanley Chu
@ 2019-12-16  3:52   ` Stanley Chu
  2019-12-19 18:00   ` Alim Akhtar
  1 sibling, 0 replies; 7+ messages in thread
From: Stanley Chu @ 2019-12-16  3:52 UTC (permalink / raw)
  To: linux-scsi, f.fainelli, matthias.bgg
  Cc: martin.petersen, avri.altman, alim.akhtar, pedrom.sousa, jejb,
	matthias.bgg, f.fainelli, linux-mediatek, linux-arm-kernel,
	linux-kernel, beanhuo, Kuohong Wang (王國鴻),
	Peter Wang (王信友),
	Chun-Hung Wu (巫駿宏),
	Andy Teng (鄧如宏),
	Leon Chen (陳文鏘)

Hi Matthias and Florian,

Could you please help review this revised v2 patch ?

Or please advise if any expert could help ?

Thanks so much.
Stanley

On Mon, 2019-12-16 at 11:48 +0800, Stanley Chu wrote:
> Add a header for the SiP service interface in order to access
> the UFSHCI controller for secure command handling in MediaTek Chipsets.
> 
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface
  2019-12-16  3:48 ` [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface Stanley Chu
  2019-12-16  3:52   ` Stanley Chu
@ 2019-12-19 18:00   ` Alim Akhtar
  2019-12-20  1:15     ` Stanley Chu
  1 sibling, 1 reply; 7+ messages in thread
From: Alim Akhtar @ 2019-12-19 18:00 UTC (permalink / raw)
  To: Stanley Chu
  Cc: linux-scsi, Martin K. Petersen, Avri Altman, Alim Akhtar,
	Pedro Sousa, James E.J. Bottomley, Matthias Brugger, f.fainelli,
	linux-mediatek, linux-arm-kernel, open list, Bean Huo (beanhuo),
	Kuohong Wang, peter.wang, chun-hung.wu, andy.teng, leon.chen

Hi

On Mon, Dec 16, 2019 at 9:19 AM Stanley Chu <stanley.chu@mediatek.com> wrote:
>
> Add a header for the SiP service interface in order to access
> the UFSHCI controller for secure command handling in MediaTek Chipsets.
>
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> ---
>  include/linux/soc/mediatek/mtk_sip_svc.h | 29 ++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
>  create mode 100644 include/linux/soc/mediatek/mtk_sip_svc.h
>
> diff --git a/include/linux/soc/mediatek/mtk_sip_svc.h b/include/linux/soc/mediatek/mtk_sip_svc.h
> new file mode 100644
> index 000000000000..97311959d7d7
> --- /dev/null
> +++ b/include/linux/soc/mediatek/mtk_sip_svc.h
> @@ -0,0 +1,29 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2019 MediaTek Inc.
> + */
> +#ifndef __MTK_SIP_SVC_H
> +#define __MTK_SIP_SVC_H
> +
> +/* Error Code */
> +#define SIP_SVC_E_SUCCESS               0
> +#define SIP_SVC_E_NOT_SUPPORTED         -1
> +#define SIP_SVC_E_INVALID_PARAMS        -2
> +#define SIP_SVC_E_INVALID_RANGE         -3
> +#define SIP_SVC_E_PERMISSION_DENIED     -4
> +
> +#ifdef CONFIG_ARM64
> +#define MTK_SIP_SMC_CONVENTION          ARM_SMCCC_SMC_64
> +#else
> +#define MTK_SIP_SMC_CONVENTION          ARM_SMCCC_SMC_32
> +#endif
> +
> +#define MTK_SIP_SMC_CMD(fn_id) \
> +       ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, MTK_SIP_SMC_CONVENTION, \
> +                          ARM_SMCCC_OWNER_SIP, fn_id)
> +
> +/* UFS related SMC call */
> +#define MTK_SIP_UFS_CONTROL \
> +       MTK_SIP_SMC_CMD(0x276)
> +
How about moving UFS specific stuff to MTK UFS driver and include this
header in driver file?
Rest looks fine.
> +#endif
> --
> 2.18.0



-- 
Regards,
Alim

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface
  2019-12-19 18:00   ` Alim Akhtar
@ 2019-12-20  1:15     ` Stanley Chu
  2019-12-25  7:34       ` Stanley Chu
  0 siblings, 1 reply; 7+ messages in thread
From: Stanley Chu @ 2019-12-20  1:15 UTC (permalink / raw)
  To: Alim Akhtar
  Cc: f.fainelli, linux-scsi, Martin K. Petersen,
	Leon Chen (陳文鏘), Andy Teng ( ^[$B{}G!9(^[(B),
	James E.J. Bottomley, Chun-Hung Wu (巫駿宏),
	Kuohong Wang (王國鴻),
	open list, Avri Altman, linux-mediatek,
	Peter Wang (王信友),
	Alim Akhtar, Matthias Brugger, Pedro Sousa, linux-arm-kernel,
	Bean Huo (beanhuo)

Hi Alim,

On Fri, 2019-12-20 at 02:00 +0800, Alim Akhtar wrote:
> > +/* UFS related SMC call */
> > +#define MTK_SIP_UFS_CONTROL \
> > +       MTK_SIP_SMC_CMD(0x276)
> > +
> How about moving UFS specific stuff to MTK UFS driver and include this
> header in driver file?
> Rest looks fine.

Thanks so much for your review.

Our intention is to collect all SMC call command types in MediaTek
Chipsets here for easier management.

This is the first time we show this header thus only UFS related stuff
is present here.

> > +#endif
> > --
> > 2.18.0
> 
> 

Thanks,
Stanley





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface
  2019-12-20  1:15     ` Stanley Chu
@ 2019-12-25  7:34       ` Stanley Chu
  0 siblings, 0 replies; 7+ messages in thread
From: Stanley Chu @ 2019-12-25  7:34 UTC (permalink / raw)
  To: Alim Akhtar
  Cc: f.fainelli, linux-scsi, Martin K. Petersen,
	Leon Chen (陳文鏘), Andy Teng ( ^[$B{}G!9(^[(B),
	James E.J. Bottomley, Chun-Hung Wu (巫駿宏),
	Kuohong Wang (王國鴻),
	open list, Avri Altman, linux-mediatek,
	Peter Wang (王信友),
	Alim Akhtar, Matthias Brugger, Pedro Sousa, linux-arm-kernel,
	Bean Huo (beanhuo)

Hi Alim,

Would you think below explanation is OK to you?

BTW, FYI, this series was combined to the new series "scsi: ufs: add
MediaTek vendor implementations" with this same patch in it.

Thanks,
Stanley


On Fri, 2019-12-20 at 09:15 +0800, Stanley Chu wrote:
> Hi Alim,
> 
> On Fri, 2019-12-20 at 02:00 +0800, Alim Akhtar wrote:
> > > +/* UFS related SMC call */
> > > +#define MTK_SIP_UFS_CONTROL \
> > > +       MTK_SIP_SMC_CMD(0x276)
> > > +
> > How about moving UFS specific stuff to MTK UFS driver and include this
> > header in driver file?
> > Rest looks fine.
> 
> Thanks so much for your review.
> 
> Our intention is to collect all SMC call command types in MediaTek
> Chipsets here for easier management.
> 
> This is the first time we show this header thus only UFS related stuff
> is present here.
> 
> > > +#endif
> > > --
> > > 2.18.0
> > 
> > 
> 
> Thanks,
> Stanley
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-12-25  7:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-16  3:48 [PATCH v2 0/2 RESEND] scsi: ufs-mediatek: add device reset implementation Stanley Chu
2019-12-16  3:48 ` [PATCH v2 1/2 RESEND] soc: mediatek: add header for SiP service interface Stanley Chu
2019-12-16  3:52   ` Stanley Chu
2019-12-19 18:00   ` Alim Akhtar
2019-12-20  1:15     ` Stanley Chu
2019-12-25  7:34       ` Stanley Chu
2019-12-16  3:48 ` [PATCH v2 2/2 RESEND] scsi: ufs-mediatek: add device reset implementation Stanley Chu

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).