Linux-ARM-MSM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3 0/3] Qualcomm UFS device reset support
@ 2019-06-08  5:04 Bjorn Andersson
  2019-06-08  5:04 ` [PATCH v3 1/3] scsi: ufs: Introduce vops for resetting device Bjorn Andersson
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Bjorn Andersson @ 2019-06-08  5:04 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: Rob Herring, Mark Rutland, Andy Gross, Alim Akhtar, Avri Altman,
	Pedro Sousa, James E.J. Bottomley, Martin K. Petersen,
	devicetree, linux-kernel, linux-arm-msm, linux-scsi

This series adds a new ufs vops to allow platform specific methods for
resetting an attached UFS device, then implements this for the Qualcomm driver.

Bjorn Andersson (3):
  scsi: ufs: Introduce vops for resetting device
  scsi: ufs-qcom: Implement device_reset vops
  arm64: dts: qcom: sdm845-mtp: Specify UFS device-reset GPIO

 .../devicetree/bindings/ufs/ufshcd-pltfrm.txt |  2 ++
 arch/arm64/boot/dts/qcom/sdm845-mtp.dts       |  2 ++
 drivers/scsi/ufs/ufs-qcom.c                   | 32 +++++++++++++++++++
 drivers/scsi/ufs/ufs-qcom.h                   |  4 +++
 drivers/scsi/ufs/ufshcd.c                     |  6 ++++
 drivers/scsi/ufs/ufshcd.h                     |  8 +++++
 6 files changed, 54 insertions(+)

-- 
2.18.0


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

* [PATCH v3 1/3] scsi: ufs: Introduce vops for resetting device
  2019-06-08  5:04 [PATCH v3 0/3] Qualcomm UFS device reset support Bjorn Andersson
@ 2019-06-08  5:04 ` Bjorn Andersson
  2019-06-25 12:41   ` Alim Akhtar
  2019-06-08  5:04 ` [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops Bjorn Andersson
  2019-06-08  5:04 ` [PATCH v3 3/3] arm64: dts: qcom: sdm845-mtp: Specify UFS device-reset GPIO Bjorn Andersson
  2 siblings, 1 reply; 9+ messages in thread
From: Bjorn Andersson @ 2019-06-08  5:04 UTC (permalink / raw)
  To: Alim Akhtar, Avri Altman, Pedro Sousa, James E.J. Bottomley,
	Martin K. Petersen
  Cc: Rob Herring, Mark Rutland, Andy Gross, devicetree, linux-kernel,
	linux-arm-msm, linux-scsi

Some UFS memory devices needs their reset line toggled in order to get
them into a good state for initialization. Provide a new vops to allow
the platform driver to implement this operation.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---

Changes since v2:
- New patch, to allow moving implementation to platform driver

 drivers/scsi/ufs/ufshcd.c | 6 ++++++
 drivers/scsi/ufs/ufshcd.h | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 04d3686511c8..ee895a625456 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -6191,6 +6191,9 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba)
 	int retries = MAX_HOST_RESET_RETRIES;
 
 	do {
+		/* Reset the attached device */
+		ufshcd_vops_device_reset(hba);
+
 		err = ufshcd_host_reset_and_restore(hba);
 	} while (err && --retries);
 
@@ -8322,6 +8325,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 		goto exit_gating;
 	}
 
+	/* Reset the attached device */
+	ufshcd_vops_device_reset(hba);
+
 	/* Host controller enable */
 	err = ufshcd_hba_enable(hba);
 	if (err) {
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 994d73d03207..cd8139052ed6 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -298,6 +298,7 @@ struct ufs_pwr_mode_info {
  * @resume: called during host controller PM callback
  * @dbg_register_dump: used to dump controller debug information
  * @phy_initialization: used to initialize phys
+ * @device_reset: called to issue a reset pulse on the UFS device
  */
 struct ufs_hba_variant_ops {
 	const char *name;
@@ -326,6 +327,7 @@ struct ufs_hba_variant_ops {
 	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
 	void	(*dbg_register_dump)(struct ufs_hba *hba);
 	int	(*phy_initialization)(struct ufs_hba *);
+	void	(*device_reset)(struct ufs_hba *);
 };
 
 /* clock gating state  */
@@ -1045,6 +1047,12 @@ static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
 		hba->vops->dbg_register_dump(hba);
 }
 
+static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
+{
+	if (hba->vops && hba->vops->device_reset)
+		hba->vops->device_reset(hba);
+}
+
 extern struct ufs_pm_lvl_states ufs_pm_lvl_states[];
 
 /*
-- 
2.18.0


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

* [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops
  2019-06-08  5:04 [PATCH v3 0/3] Qualcomm UFS device reset support Bjorn Andersson
  2019-06-08  5:04 ` [PATCH v3 1/3] scsi: ufs: Introduce vops for resetting device Bjorn Andersson
@ 2019-06-08  5:04 ` Bjorn Andersson
  2019-06-11 16:08   ` [EXT] " Bean Huo (beanhuo)
  2019-06-08  5:04 ` [PATCH v3 3/3] arm64: dts: qcom: sdm845-mtp: Specify UFS device-reset GPIO Bjorn Andersson
  2 siblings, 1 reply; 9+ messages in thread
From: Bjorn Andersson @ 2019-06-08  5:04 UTC (permalink / raw)
  To: Rob Herring, Mark Rutland, Alim Akhtar, Avri Altman, Pedro Sousa,
	James E.J. Bottomley, Martin K. Petersen
  Cc: Andy Gross, devicetree, linux-kernel, linux-arm-msm, linux-scsi

The UFS_RESET pin on Qualcomm SoCs are controlled by TLMM and exposed
through the GPIO framework. Acquire the device-reset GPIO and use this
to implement the device_reset vops, to allow resetting the attached
memory.

Based on downstream support implemented by Subhash Jadavani
<subhashj@codeaurora.org>.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---

Changes since v2:
- Moved implementation to Qualcomm driver

 .../devicetree/bindings/ufs/ufshcd-pltfrm.txt |  2 ++
 drivers/scsi/ufs/ufs-qcom.c                   | 32 +++++++++++++++++++
 drivers/scsi/ufs/ufs-qcom.h                   |  4 +++
 3 files changed, 38 insertions(+)

diff --git a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
index a74720486ee2..d562d8b4919c 100644
--- a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
+++ b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
@@ -54,6 +54,8 @@ Optional properties:
 			  PHY reset from the UFS controller.
 - resets            : reset node register
 - reset-names       : describe reset node register, the "rst" corresponds to reset the whole UFS IP.
+- device-reset-gpios	: A phandle and gpio specifier denoting the GPIO connected
+			  to the RESET pin of the UFS memory device.
 
 Note: If above properties are not defined it can be assumed that the supply
 regulators or clocks are always on.
diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index ea7219407309..efaf57ba618a 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -16,6 +16,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
+#include <linux/gpio/consumer.h>
 #include <linux/reset-controller.h>
 
 #include "ufshcd.h"
@@ -1141,6 +1142,15 @@ static int ufs_qcom_init(struct ufs_hba *hba)
 		goto out_variant_clear;
 	}
 
+	host->device_reset = devm_gpiod_get_optional(dev, "device-reset",
+						     GPIOD_OUT_HIGH);
+	if (IS_ERR(host->device_reset)) {
+		err = PTR_ERR(host->device_reset);
+		if (err != -EPROBE_DEFER)
+			dev_err(dev, "failed to acquire reset gpio: %d\n", err);
+		goto out_variant_clear;
+	}
+
 	err = ufs_qcom_bus_register(host);
 	if (err)
 		goto out_variant_clear;
@@ -1546,6 +1556,27 @@ static void ufs_qcom_dump_dbg_regs(struct ufs_hba *hba)
 	usleep_range(1000, 1100);
 }
 
+/**
+ * ufs_qcom_device_reset() - toggle the (optional) device reset line
+ * @hba: per-adapter instance
+ *
+ * Toggles the (optional) reset line to reset the attached device.
+ */
+static void ufs_qcom_device_reset(struct ufs_hba *hba)
+{
+	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
+
+	/*
+	 * The UFS device shall detect reset pulses of 1us, sleep for 10us to
+	 * be on the safe side.
+	 */
+	gpiod_set_value_cansleep(host->device_reset, 1);
+	usleep_range(10, 15);
+
+	gpiod_set_value_cansleep(host->device_reset, 0);
+	usleep_range(10, 15);
+}
+
 /**
  * struct ufs_hba_qcom_vops - UFS QCOM specific variant operations
  *
@@ -1566,6 +1597,7 @@ static struct ufs_hba_variant_ops ufs_hba_qcom_vops = {
 	.suspend		= ufs_qcom_suspend,
 	.resume			= ufs_qcom_resume,
 	.dbg_register_dump	= ufs_qcom_dump_dbg_regs,
+	.device_reset		= ufs_qcom_device_reset,
 };
 
 /**
diff --git a/drivers/scsi/ufs/ufs-qcom.h b/drivers/scsi/ufs/ufs-qcom.h
index 68a880185752..b96ffb6804e4 100644
--- a/drivers/scsi/ufs/ufs-qcom.h
+++ b/drivers/scsi/ufs/ufs-qcom.h
@@ -204,6 +204,8 @@ struct ufs_qcom_testbus {
 	u8 select_minor;
 };
 
+struct gpio_desc;
+
 struct ufs_qcom_host {
 	/*
 	 * Set this capability if host controller supports the QUniPro mode
@@ -241,6 +243,8 @@ struct ufs_qcom_host {
 	struct ufs_qcom_testbus testbus;
 
 	struct reset_controller_dev rcdev;
+
+	struct gpio_desc *device_reset;
 };
 
 static inline u32
-- 
2.18.0


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

* [PATCH v3 3/3] arm64: dts: qcom: sdm845-mtp: Specify UFS device-reset GPIO
  2019-06-08  5:04 [PATCH v3 0/3] Qualcomm UFS device reset support Bjorn Andersson
  2019-06-08  5:04 ` [PATCH v3 1/3] scsi: ufs: Introduce vops for resetting device Bjorn Andersson
  2019-06-08  5:04 ` [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops Bjorn Andersson
@ 2019-06-08  5:04 ` Bjorn Andersson
  2 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2019-06-08  5:04 UTC (permalink / raw)
  To: Andy Gross
  Cc: Rob Herring, Mark Rutland, Alim Akhtar, Avri Altman, Pedro Sousa,
	James E.J. Bottomley, Martin K. Petersen, devicetree,
	linux-kernel, linux-arm-msm, linux-scsi

Specify the UFS device-reset gpio, so that the controller will issue a
reset of the UFS device.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---

Changes since v2:
- None

 arch/arm64/boot/dts/qcom/sdm845-mtp.dts | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sdm845-mtp.dts b/arch/arm64/boot/dts/qcom/sdm845-mtp.dts
index 80189807b4e5..441045847e9f 100644
--- a/arch/arm64/boot/dts/qcom/sdm845-mtp.dts
+++ b/arch/arm64/boot/dts/qcom/sdm845-mtp.dts
@@ -467,6 +467,8 @@
 &ufs_mem_hc {
 	status = "okay";
 
+	device-reset-gpios = <&tlmm 150 GPIO_ACTIVE_LOW>;
+
 	vcc-supply = <&vreg_l20a_2p95>;
 	vcc-max-microamp = <600000>;
 };
-- 
2.18.0


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

* RE: [EXT] [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops
  2019-06-08  5:04 ` [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops Bjorn Andersson
@ 2019-06-11 16:08   ` " Bean Huo (beanhuo)
  2019-06-12  6:31     ` Bjorn Andersson
  0 siblings, 1 reply; 9+ messages in thread
From: Bean Huo (beanhuo) @ 2019-06-11 16:08 UTC (permalink / raw)
  To: Bjorn Andersson, Rob Herring, Mark Rutland, Alim Akhtar,
	Avri Altman, Pedro Sousa, James E.J. Bottomley,
	Martin K. Petersen
  Cc: Andy Gross, devicetree, linux-kernel, linux-arm-msm, linux-scsi

Hi, Bjorn
This HW reset is dedicated to QUALCOMM based platform case.
how about adding a SW reset as to be default reset routine if platform doesn't support HW reset?

>-----Original Message-----
>From: linux-scsi-owner@vger.kernel.org <linux-scsi-owner@vger.kernel.org>
>On Behalf Of Bjorn Andersson
>Sent: Saturday, June 8, 2019 7:05 AM
>To: Rob Herring <robh+dt@kernel.org>; Mark Rutland
><mark.rutland@arm.com>; Alim Akhtar <alim.akhtar@samsung.com>; Avri
>Altman <avri.altman@wdc.com>; Pedro Sousa
><pedrom.sousa@synopsys.com>; James E.J. Bottomley <jejb@linux.ibm.com>;
>Martin K. Petersen <martin.petersen@oracle.com>
>Cc: Andy Gross <agross@kernel.org>; devicetree@vger.kernel.org; linux-
>kernel@vger.kernel.org; linux-arm-msm@vger.kernel.org; linux-
>scsi@vger.kernel.org
>Subject: [EXT] [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops
>
>The UFS_RESET pin on Qualcomm SoCs are controlled by TLMM and exposed
>through the GPIO framework. Acquire the device-reset GPIO and use this to
>implement the device_reset vops, to allow resetting the attached memory.
>
>Based on downstream support implemented by Subhash Jadavani
><subhashj@codeaurora.org>.
>
>Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
>---
>
>Changes since v2:
>- Moved implementation to Qualcomm driver
>
> .../devicetree/bindings/ufs/ufshcd-pltfrm.txt |  2 ++
> drivers/scsi/ufs/ufs-qcom.c                   | 32 +++++++++++++++++++
> drivers/scsi/ufs/ufs-qcom.h                   |  4 +++
> 3 files changed, 38 insertions(+)
>
>diff --git a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
>b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
>index a74720486ee2..d562d8b4919c 100644
>--- a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
>+++ b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
>@@ -54,6 +54,8 @@ Optional properties:
> 			  PHY reset from the UFS controller.
> - resets            : reset node register
> - reset-names       : describe reset node register, the "rst" corresponds to
>reset the whole UFS IP.
>+- device-reset-gpios	: A phandle and gpio specifier denoting the GPIO
>connected
>+			  to the RESET pin of the UFS memory device.
>
> Note: If above properties are not defined it can be assumed that the supply
>regulators or clocks are always on.
>diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c index
>ea7219407309..efaf57ba618a 100644
>--- a/drivers/scsi/ufs/ufs-qcom.c
>+++ b/drivers/scsi/ufs/ufs-qcom.c
>@@ -16,6 +16,7 @@
> #include <linux/of.h>
> #include <linux/platform_device.h>
> #include <linux/phy/phy.h>
>+#include <linux/gpio/consumer.h>
> #include <linux/reset-controller.h>
>
> #include "ufshcd.h"
>@@ -1141,6 +1142,15 @@ static int ufs_qcom_init(struct ufs_hba *hba)
> 		goto out_variant_clear;
> 	}
>
>+	host->device_reset = devm_gpiod_get_optional(dev, "device-reset",
>+						     GPIOD_OUT_HIGH);
>+	if (IS_ERR(host->device_reset)) {
>+		err = PTR_ERR(host->device_reset);
>+		if (err != -EPROBE_DEFER)
>+			dev_err(dev, "failed to acquire reset gpio: %d\n", err);
>+		goto out_variant_clear;
>+	}
>+
> 	err = ufs_qcom_bus_register(host);
> 	if (err)
> 		goto out_variant_clear;
>@@ -1546,6 +1556,27 @@ static void ufs_qcom_dump_dbg_regs(struct
>ufs_hba *hba)
> 	usleep_range(1000, 1100);
> }
>
>+/**
>+ * ufs_qcom_device_reset() - toggle the (optional) device reset line
>+ * @hba: per-adapter instance
>+ *
>+ * Toggles the (optional) reset line to reset the attached device.
>+ */
>+static void ufs_qcom_device_reset(struct ufs_hba *hba) {
>+	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
>+
>+	/*
>+	 * The UFS device shall detect reset pulses of 1us, sleep for 10us to
>+	 * be on the safe side.
>+	 */
>+	gpiod_set_value_cansleep(host->device_reset, 1);
>+	usleep_range(10, 15);
>+
>+	gpiod_set_value_cansleep(host->device_reset, 0);
>+	usleep_range(10, 15);
>+}
>+
> /**
>  * struct ufs_hba_qcom_vops - UFS QCOM specific variant operations
>  *
>@@ -1566,6 +1597,7 @@ static struct ufs_hba_variant_ops
>ufs_hba_qcom_vops = {
> 	.suspend		= ufs_qcom_suspend,
> 	.resume			= ufs_qcom_resume,
> 	.dbg_register_dump	= ufs_qcom_dump_dbg_regs,
>+	.device_reset		= ufs_qcom_device_reset,
> };
>
> /**
>diff --git a/drivers/scsi/ufs/ufs-qcom.h b/drivers/scsi/ufs/ufs-qcom.h index
>68a880185752..b96ffb6804e4 100644
>--- a/drivers/scsi/ufs/ufs-qcom.h
>+++ b/drivers/scsi/ufs/ufs-qcom.h
>@@ -204,6 +204,8 @@ struct ufs_qcom_testbus {
> 	u8 select_minor;
> };
>
>+struct gpio_desc;
>+
> struct ufs_qcom_host {
> 	/*
> 	 * Set this capability if host controller supports the QUniPro mode
>@@ -241,6 +243,8 @@ struct ufs_qcom_host {
> 	struct ufs_qcom_testbus testbus;
>
> 	struct reset_controller_dev rcdev;
>+
>+	struct gpio_desc *device_reset;
> };
>
> static inline u32
>--
>2.18.0


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

* Re: [EXT] [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops
  2019-06-11 16:08   ` [EXT] " Bean Huo (beanhuo)
@ 2019-06-12  6:31     ` Bjorn Andersson
  2019-06-14  7:42       ` Bean Huo (beanhuo)
  0 siblings, 1 reply; 9+ messages in thread
From: Bjorn Andersson @ 2019-06-12  6:31 UTC (permalink / raw)
  To: Bean Huo (beanhuo)
  Cc: Rob Herring, Mark Rutland, Alim Akhtar, Avri Altman, Pedro Sousa,
	James E.J. Bottomley, Martin K. Petersen, Andy Gross, devicetree,
	linux-kernel, linux-arm-msm, linux-scsi

On Tue 11 Jun 09:08 PDT 2019, Bean Huo (beanhuo) wrote:

> Hi, Bjorn
> This HW reset is dedicated to QUALCOMM based platform case.
> how about adding a SW reset as to be default reset routine if platform doesn't support HW reset?
> 

Can you please advice how I perform such software reset?

Regards,
Bjorn

> >-----Original Message-----
> >From: linux-scsi-owner@vger.kernel.org <linux-scsi-owner@vger.kernel.org>
> >On Behalf Of Bjorn Andersson
> >Sent: Saturday, June 8, 2019 7:05 AM
> >To: Rob Herring <robh+dt@kernel.org>; Mark Rutland
> ><mark.rutland@arm.com>; Alim Akhtar <alim.akhtar@samsung.com>; Avri
> >Altman <avri.altman@wdc.com>; Pedro Sousa
> ><pedrom.sousa@synopsys.com>; James E.J. Bottomley <jejb@linux.ibm.com>;
> >Martin K. Petersen <martin.petersen@oracle.com>
> >Cc: Andy Gross <agross@kernel.org>; devicetree@vger.kernel.org; linux-
> >kernel@vger.kernel.org; linux-arm-msm@vger.kernel.org; linux-
> >scsi@vger.kernel.org
> >Subject: [EXT] [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops
> >
> >The UFS_RESET pin on Qualcomm SoCs are controlled by TLMM and exposed
> >through the GPIO framework. Acquire the device-reset GPIO and use this to
> >implement the device_reset vops, to allow resetting the attached memory.
> >
> >Based on downstream support implemented by Subhash Jadavani
> ><subhashj@codeaurora.org>.
> >
> >Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> >---
> >
> >Changes since v2:
> >- Moved implementation to Qualcomm driver
> >
> > .../devicetree/bindings/ufs/ufshcd-pltfrm.txt |  2 ++
> > drivers/scsi/ufs/ufs-qcom.c                   | 32 +++++++++++++++++++
> > drivers/scsi/ufs/ufs-qcom.h                   |  4 +++
> > 3 files changed, 38 insertions(+)
> >
> >diff --git a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
> >b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
> >index a74720486ee2..d562d8b4919c 100644
> >--- a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
> >+++ b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
> >@@ -54,6 +54,8 @@ Optional properties:
> > 			  PHY reset from the UFS controller.
> > - resets            : reset node register
> > - reset-names       : describe reset node register, the "rst" corresponds to
> >reset the whole UFS IP.
> >+- device-reset-gpios	: A phandle and gpio specifier denoting the GPIO
> >connected
> >+			  to the RESET pin of the UFS memory device.
> >
> > Note: If above properties are not defined it can be assumed that the supply
> >regulators or clocks are always on.
> >diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c index
> >ea7219407309..efaf57ba618a 100644
> >--- a/drivers/scsi/ufs/ufs-qcom.c
> >+++ b/drivers/scsi/ufs/ufs-qcom.c
> >@@ -16,6 +16,7 @@
> > #include <linux/of.h>
> > #include <linux/platform_device.h>
> > #include <linux/phy/phy.h>
> >+#include <linux/gpio/consumer.h>
> > #include <linux/reset-controller.h>
> >
> > #include "ufshcd.h"
> >@@ -1141,6 +1142,15 @@ static int ufs_qcom_init(struct ufs_hba *hba)
> > 		goto out_variant_clear;
> > 	}
> >
> >+	host->device_reset = devm_gpiod_get_optional(dev, "device-reset",
> >+						     GPIOD_OUT_HIGH);
> >+	if (IS_ERR(host->device_reset)) {
> >+		err = PTR_ERR(host->device_reset);
> >+		if (err != -EPROBE_DEFER)
> >+			dev_err(dev, "failed to acquire reset gpio: %d\n", err);
> >+		goto out_variant_clear;
> >+	}
> >+
> > 	err = ufs_qcom_bus_register(host);
> > 	if (err)
> > 		goto out_variant_clear;
> >@@ -1546,6 +1556,27 @@ static void ufs_qcom_dump_dbg_regs(struct
> >ufs_hba *hba)
> > 	usleep_range(1000, 1100);
> > }
> >
> >+/**
> >+ * ufs_qcom_device_reset() - toggle the (optional) device reset line
> >+ * @hba: per-adapter instance
> >+ *
> >+ * Toggles the (optional) reset line to reset the attached device.
> >+ */
> >+static void ufs_qcom_device_reset(struct ufs_hba *hba) {
> >+	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
> >+
> >+	/*
> >+	 * The UFS device shall detect reset pulses of 1us, sleep for 10us to
> >+	 * be on the safe side.
> >+	 */
> >+	gpiod_set_value_cansleep(host->device_reset, 1);
> >+	usleep_range(10, 15);
> >+
> >+	gpiod_set_value_cansleep(host->device_reset, 0);
> >+	usleep_range(10, 15);
> >+}
> >+
> > /**
> >  * struct ufs_hba_qcom_vops - UFS QCOM specific variant operations
> >  *
> >@@ -1566,6 +1597,7 @@ static struct ufs_hba_variant_ops
> >ufs_hba_qcom_vops = {
> > 	.suspend		= ufs_qcom_suspend,
> > 	.resume			= ufs_qcom_resume,
> > 	.dbg_register_dump	= ufs_qcom_dump_dbg_regs,
> >+	.device_reset		= ufs_qcom_device_reset,
> > };
> >
> > /**
> >diff --git a/drivers/scsi/ufs/ufs-qcom.h b/drivers/scsi/ufs/ufs-qcom.h index
> >68a880185752..b96ffb6804e4 100644
> >--- a/drivers/scsi/ufs/ufs-qcom.h
> >+++ b/drivers/scsi/ufs/ufs-qcom.h
> >@@ -204,6 +204,8 @@ struct ufs_qcom_testbus {
> > 	u8 select_minor;
> > };
> >
> >+struct gpio_desc;
> >+
> > struct ufs_qcom_host {
> > 	/*
> > 	 * Set this capability if host controller supports the QUniPro mode
> >@@ -241,6 +243,8 @@ struct ufs_qcom_host {
> > 	struct ufs_qcom_testbus testbus;
> >
> > 	struct reset_controller_dev rcdev;
> >+
> >+	struct gpio_desc *device_reset;
> > };
> >
> > static inline u32
> >--
> >2.18.0
> 

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

* RE: [EXT] [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops
  2019-06-12  6:31     ` Bjorn Andersson
@ 2019-06-14  7:42       ` Bean Huo (beanhuo)
  0 siblings, 0 replies; 9+ messages in thread
From: Bean Huo (beanhuo) @ 2019-06-14  7:42 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Rob Herring, Mark Rutland, Alim Akhtar, Avri Altman, Pedro Sousa,
	James E.J. Bottomley, Martin K. Petersen, Andy Gross, devicetree,
	linux-kernel, linux-arm-msm, linux-scsi

Hi, Bjorn
Sorry just saw your message.

You can use UIC command^[$B!$^[(Bthrough function ufshcd_send_uic_cmd( ) with UIC_CMD_DME_END_PT_RST command.

DME_ENDPOINTRESET: It is used when UFS host wants the UFS device to perform a reset.

//bean

>On Tue 11 Jun 09:08 PDT 2019, Bean Huo (beanhuo) wrote:
>
>> Hi, Bjorn
>> This HW reset is dedicated to QUALCOMM based platform case.
>> how about adding a SW reset as to be default reset routine if platform
>doesn't support HW reset?
>>
>
>Can you please advice how I perform such software reset?
>
>Regards,
>Bjorn
>
>> >-----Original Message-----
>> >From: linux-scsi-owner@vger.kernel.org
>> ><linux-scsi-owner@vger.kernel.org>
>> >On Behalf Of Bjorn Andersson
>> >Sent: Saturday, June 8, 2019 7:05 AM
>> >To: Rob Herring <robh+dt@kernel.org>; Mark Rutland
>> ><mark.rutland@arm.com>; Alim Akhtar <alim.akhtar@samsung.com>; Avri
>> >Altman <avri.altman@wdc.com>; Pedro Sousa
>> ><pedrom.sousa@synopsys.com>; James E.J. Bottomley
>> ><jejb@linux.ibm.com>; Martin K. Petersen <martin.petersen@oracle.com>
>> >Cc: Andy Gross <agross@kernel.org>; devicetree@vger.kernel.org;
>> >linux- kernel@vger.kernel.org; linux-arm-msm@vger.kernel.org; linux-
>> >scsi@vger.kernel.org
>> >Subject: [EXT] [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset
>> >vops
>> >
>> >The UFS_RESET pin on Qualcomm SoCs are controlled by TLMM and
>exposed
>> >through the GPIO framework. Acquire the device-reset GPIO and use
>> >this to implement the device_reset vops, to allow resetting the attached
>memory.
>> >
>> >Based on downstream support implemented by Subhash Jadavani
>> ><subhashj@codeaurora.org>.
>> >
>> >Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
>> >---
>> >
>> >Changes since v2:
>> >- Moved implementation to Qualcomm driver
>> >
>> > .../devicetree/bindings/ufs/ufshcd-pltfrm.txt |  2 ++
>> > drivers/scsi/ufs/ufs-qcom.c                   | 32 +++++++++++++++++++
>> > drivers/scsi/ufs/ufs-qcom.h                   |  4 +++
>> > 3 files changed, 38 insertions(+)
>> >
>> >diff --git a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
>> >b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
>> >index a74720486ee2..d562d8b4919c 100644
>> >--- a/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
>> >+++ b/Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
>> >@@ -54,6 +54,8 @@ Optional properties:
>> > 			  PHY reset from the UFS controller.
>> > - resets            : reset node register
>> > - reset-names       : describe reset node register, the "rst" corresponds to
>> >reset the whole UFS IP.
>> >+- device-reset-gpios	: A phandle and gpio specifier denoting the
>GPIO
>> >connected
>> >+			  to the RESET pin of the UFS memory device.
>> >
>> > Note: If above properties are not defined it can be assumed that the
>> >supply regulators or clocks are always on.
>> >diff --git a/drivers/scsi/ufs/ufs-qcom.c
>> >b/drivers/scsi/ufs/ufs-qcom.c index ea7219407309..efaf57ba618a 100644
>> >--- a/drivers/scsi/ufs/ufs-qcom.c
>> >+++ b/drivers/scsi/ufs/ufs-qcom.c
>> >@@ -16,6 +16,7 @@
>> > #include <linux/of.h>
>> > #include <linux/platform_device.h>
>> > #include <linux/phy/phy.h>
>> >+#include <linux/gpio/consumer.h>
>> > #include <linux/reset-controller.h>
>> >
>> > #include "ufshcd.h"
>> >@@ -1141,6 +1142,15 @@ static int ufs_qcom_init(struct ufs_hba *hba)
>> > 		goto out_variant_clear;
>> > 	}
>> >
>> >+	host->device_reset = devm_gpiod_get_optional(dev, "device-reset",
>> >+						     GPIOD_OUT_HIGH);
>> >+	if (IS_ERR(host->device_reset)) {
>> >+		err = PTR_ERR(host->device_reset);
>> >+		if (err != -EPROBE_DEFER)
>> >+			dev_err(dev, "failed to acquire reset gpio: %d\n", err);
>> >+		goto out_variant_clear;
>> >+	}
>> >+
>> > 	err = ufs_qcom_bus_register(host);
>> > 	if (err)
>> > 		goto out_variant_clear;
>> >@@ -1546,6 +1556,27 @@ static void ufs_qcom_dump_dbg_regs(struct
>> >ufs_hba *hba)
>> > 	usleep_range(1000, 1100);
>> > }
>> >
>> >+/**
>> >+ * ufs_qcom_device_reset() - toggle the (optional) device reset line
>> >+ * @hba: per-adapter instance
>> >+ *
>> >+ * Toggles the (optional) reset line to reset the attached device.
>> >+ */
>> >+static void ufs_qcom_device_reset(struct ufs_hba *hba) {
>> >+	struct ufs_qcom_host *host = ufshcd_get_variant(hba);
>> >+
>> >+	/*
>> >+	 * The UFS device shall detect reset pulses of 1us, sleep for 10us to
>> >+	 * be on the safe side.
>> >+	 */
>> >+	gpiod_set_value_cansleep(host->device_reset, 1);
>> >+	usleep_range(10, 15);
>> >+
>> >+	gpiod_set_value_cansleep(host->device_reset, 0);
>> >+	usleep_range(10, 15);
>> >+}
>> >+
>> > /**
>> >  * struct ufs_hba_qcom_vops - UFS QCOM specific variant operations
>> >  *
>> >@@ -1566,6 +1597,7 @@ static struct ufs_hba_variant_ops
>> >ufs_hba_qcom_vops = {
>> > 	.suspend		= ufs_qcom_suspend,
>> > 	.resume			= ufs_qcom_resume,
>> > 	.dbg_register_dump	= ufs_qcom_dump_dbg_regs,
>> >+	.device_reset		= ufs_qcom_device_reset,
>> > };
>> >
>> > /**
>> >diff --git a/drivers/scsi/ufs/ufs-qcom.h
>> >b/drivers/scsi/ufs/ufs-qcom.h index
>> >68a880185752..b96ffb6804e4 100644
>> >--- a/drivers/scsi/ufs/ufs-qcom.h
>> >+++ b/drivers/scsi/ufs/ufs-qcom.h
>> >@@ -204,6 +204,8 @@ struct ufs_qcom_testbus {
>> > 	u8 select_minor;
>> > };
>> >
>> >+struct gpio_desc;
>> >+
>> > struct ufs_qcom_host {
>> > 	/*
>> > 	 * Set this capability if host controller supports the QUniPro mode
>> >@@ -241,6 +243,8 @@ struct ufs_qcom_host {
>> > 	struct ufs_qcom_testbus testbus;
>> >
>> > 	struct reset_controller_dev rcdev;
>> >+
>> >+	struct gpio_desc *device_reset;
>> > };
>> >
>> > static inline u32
>> >--
>> >2.18.0
>>

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

* Re: [PATCH v3 1/3] scsi: ufs: Introduce vops for resetting device
  2019-06-08  5:04 ` [PATCH v3 1/3] scsi: ufs: Introduce vops for resetting device Bjorn Andersson
@ 2019-06-25 12:41   ` Alim Akhtar
  2019-06-26  3:45     ` Bjorn Andersson
  0 siblings, 1 reply; 9+ messages in thread
From: Alim Akhtar @ 2019-06-25 12:41 UTC (permalink / raw)
  To: Bjorn Andersson, Avri Altman, Pedro Sousa, James E.J. Bottomley,
	Martin K. Petersen
  Cc: Rob Herring, Mark Rutland, Andy Gross, devicetree, linux-kernel,
	linux-arm-msm, linux-scsi

Hi Bjorn,
Are you planning to address Bean's comment on patch#2 and want to 
re-spin this series?
I am ok with taking this patch as it is and take a Softreset patch as a 
separate patch.

On 6/8/19 10:34 AM, Bjorn Andersson wrote:
> Some UFS memory devices needs their reset line toggled in order to get
> them into a good state for initialization. Provide a new vops to allow
> the platform driver to implement this operation.
> 
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
feel free to add
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
> 
> Changes since v2:
> - New patch, to allow moving implementation to platform driver
> 
>   drivers/scsi/ufs/ufshcd.c | 6 ++++++
>   drivers/scsi/ufs/ufshcd.h | 8 ++++++++
>   2 files changed, 14 insertions(+)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 04d3686511c8..ee895a625456 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -6191,6 +6191,9 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba)
>   	int retries = MAX_HOST_RESET_RETRIES;
>   
>   	do {
> +		/* Reset the attached device */
> +		ufshcd_vops_device_reset(hba);
> +
>   		err = ufshcd_host_reset_and_restore(hba);
>   	} while (err && --retries);
>   
> @@ -8322,6 +8325,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
>   		goto exit_gating;
>   	}
>   
> +	/* Reset the attached device */
> +	ufshcd_vops_device_reset(hba);
> +
>   	/* Host controller enable */
>   	err = ufshcd_hba_enable(hba);
>   	if (err) {
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 994d73d03207..cd8139052ed6 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -298,6 +298,7 @@ struct ufs_pwr_mode_info {
>    * @resume: called during host controller PM callback
>    * @dbg_register_dump: used to dump controller debug information
>    * @phy_initialization: used to initialize phys
> + * @device_reset: called to issue a reset pulse on the UFS device
>    */
>   struct ufs_hba_variant_ops {
>   	const char *name;
> @@ -326,6 +327,7 @@ struct ufs_hba_variant_ops {
>   	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
>   	void	(*dbg_register_dump)(struct ufs_hba *hba);
>   	int	(*phy_initialization)(struct ufs_hba *);
> +	void	(*device_reset)(struct ufs_hba *);
>   };
>   
>   /* clock gating state  */
> @@ -1045,6 +1047,12 @@ static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
>   		hba->vops->dbg_register_dump(hba);
>   }
>   
> +static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
> +{
> +	if (hba->vops && hba->vops->device_reset)
> +		hba->vops->device_reset(hba);
> +}
> +
>   extern struct ufs_pm_lvl_states ufs_pm_lvl_states[];
>   
>   /*
> 

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

* Re: [PATCH v3 1/3] scsi: ufs: Introduce vops for resetting device
  2019-06-25 12:41   ` Alim Akhtar
@ 2019-06-26  3:45     ` Bjorn Andersson
  0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2019-06-26  3:45 UTC (permalink / raw)
  To: Alim Akhtar
  Cc: Avri Altman, Pedro Sousa, James E.J. Bottomley,
	Martin K. Petersen, Rob Herring, Mark Rutland, Andy Gross,
	devicetree, linux-kernel, linux-arm-msm, linux-scsi

On Tue 25 Jun 05:41 PDT 2019, Alim Akhtar wrote:

> Hi Bjorn,
> Are you planning to address Bean's comment on patch#2 and want to 
> re-spin this series?
> I am ok with taking this patch as it is and take a Softreset patch as a 
> separate patch.
> 

I still intend to attempt to implement a softreset "fallback", per
Bean's suggestion - just haven't found the time yet. But I would be
happy to see these patches merged in the meantime, as they do resolve
the issue of failing to being up the UFS link on a significant number of
Qualcomm devices.


I think it's best if you take patch 1 and 2 through your tree and we
take the dts patch through the Qualcomm/arm-soc tree.

Thanks,
Bjorn

> On 6/8/19 10:34 AM, Bjorn Andersson wrote:
> > Some UFS memory devices needs their reset line toggled in order to get
> > them into a good state for initialization. Provide a new vops to allow
> > the platform driver to implement this operation.
> > 
> > Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> > ---
> feel free to add
> Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
> > 
> > Changes since v2:
> > - New patch, to allow moving implementation to platform driver
> > 
> >   drivers/scsi/ufs/ufshcd.c | 6 ++++++
> >   drivers/scsi/ufs/ufshcd.h | 8 ++++++++
> >   2 files changed, 14 insertions(+)
> > 
> > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> > index 04d3686511c8..ee895a625456 100644
> > --- a/drivers/scsi/ufs/ufshcd.c
> > +++ b/drivers/scsi/ufs/ufshcd.c
> > @@ -6191,6 +6191,9 @@ static int ufshcd_reset_and_restore(struct ufs_hba *hba)
> >   	int retries = MAX_HOST_RESET_RETRIES;
> >   
> >   	do {
> > +		/* Reset the attached device */
> > +		ufshcd_vops_device_reset(hba);
> > +
> >   		err = ufshcd_host_reset_and_restore(hba);
> >   	} while (err && --retries);
> >   
> > @@ -8322,6 +8325,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
> >   		goto exit_gating;
> >   	}
> >   
> > +	/* Reset the attached device */
> > +	ufshcd_vops_device_reset(hba);
> > +
> >   	/* Host controller enable */
> >   	err = ufshcd_hba_enable(hba);
> >   	if (err) {
> > diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> > index 994d73d03207..cd8139052ed6 100644
> > --- a/drivers/scsi/ufs/ufshcd.h
> > +++ b/drivers/scsi/ufs/ufshcd.h
> > @@ -298,6 +298,7 @@ struct ufs_pwr_mode_info {
> >    * @resume: called during host controller PM callback
> >    * @dbg_register_dump: used to dump controller debug information
> >    * @phy_initialization: used to initialize phys
> > + * @device_reset: called to issue a reset pulse on the UFS device
> >    */
> >   struct ufs_hba_variant_ops {
> >   	const char *name;
> > @@ -326,6 +327,7 @@ struct ufs_hba_variant_ops {
> >   	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
> >   	void	(*dbg_register_dump)(struct ufs_hba *hba);
> >   	int	(*phy_initialization)(struct ufs_hba *);
> > +	void	(*device_reset)(struct ufs_hba *);
> >   };
> >   
> >   /* clock gating state  */
> > @@ -1045,6 +1047,12 @@ static inline void ufshcd_vops_dbg_register_dump(struct ufs_hba *hba)
> >   		hba->vops->dbg_register_dump(hba);
> >   }
> >   
> > +static inline void ufshcd_vops_device_reset(struct ufs_hba *hba)
> > +{
> > +	if (hba->vops && hba->vops->device_reset)
> > +		hba->vops->device_reset(hba);
> > +}
> > +
> >   extern struct ufs_pm_lvl_states ufs_pm_lvl_states[];
> >   
> >   /*
> > 

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

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-08  5:04 [PATCH v3 0/3] Qualcomm UFS device reset support Bjorn Andersson
2019-06-08  5:04 ` [PATCH v3 1/3] scsi: ufs: Introduce vops for resetting device Bjorn Andersson
2019-06-25 12:41   ` Alim Akhtar
2019-06-26  3:45     ` Bjorn Andersson
2019-06-08  5:04 ` [PATCH v3 2/3] scsi: ufs-qcom: Implement device_reset vops Bjorn Andersson
2019-06-11 16:08   ` [EXT] " Bean Huo (beanhuo)
2019-06-12  6:31     ` Bjorn Andersson
2019-06-14  7:42       ` Bean Huo (beanhuo)
2019-06-08  5:04 ` [PATCH v3 3/3] arm64: dts: qcom: sdm845-mtp: Specify UFS device-reset GPIO Bjorn Andersson

Linux-ARM-MSM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-msm/0 linux-arm-msm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-msm linux-arm-msm/ https://lore.kernel.org/linux-arm-msm \
		linux-arm-msm@vger.kernel.org linux-arm-msm@archiver.kernel.org
	public-inbox-index linux-arm-msm


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-arm-msm


AGPL code for this site: git clone https://public-inbox.org/ public-inbox