linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend
@ 2019-01-11 23:01 Evan Green
  2019-01-11 23:01 ` [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset Evan Green
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Evan Green @ 2019-01-11 23:01 UTC (permalink / raw)
  To: Andy Gross, Rob Herring, Kishon Vijay Abraham I
  Cc: Can Guo, Douglas Anderson, Asutosh Das, Stephen Boyd,
	Vivek Gautam, Evan Green, devicetree, Arnd Bergmann,
	Grygorii Strashko, linux-scsi, Bjorn Andersson, linux-arm-msm,
	linux-kernel, Vinayak Holikatti, Manu Gautam, David Brown,
	Mark Rutland, James E.J. Bottomley, Martin K. Petersen

The goal with this series is to enable shutting off regulators that power
UFS during system suspend.

In "the good life" version of this, we'd just disable the regulators
in phy_poweroff and be done with it. Unfortunately, that's not symmetric,
as regulators are not enabled during phy_poweron. Ok, so you might think
we could just move the regulator enable and anything else that needs to
come along into phy_poweron, so that we can then undo it all in
phy_poweroff. That's where things get tricky.

The qcom-qmp-phy overloaded the phy_init and phy_poweron callbacks,
basically to mean "init phase 1" and "init phase 2". There are two phases
because they have this phy_reset bit outside of the phy (in the UFS
controller registers), and they need to make sure this bit is toggled at
specific points in the phy init sequence. So there's this implicit
sequence in the init dance between ufs-qcom.c and phy-qcom-qmp.c:
1) ufs-qcom asserts the PHY reset bit.
2) phy-qcom-qmp phy_init does most of its initialization, but exits early.
3) ufs-qcom deasserts the PHY reset bit.
4) phy-qcom-qmp phy_poweron finishes its initialization.

This init dance is very difficult to follow in the code (since it's split
between two drivers and not spelled out well), and arguably represents a
deficiency in the hardware description of these devices.

In this series I'm proposing tweaking the bindings for the Qualcomm
UFS controller and PHY. In it we expose a reset controller from the
UFS controller, that is then picked up and used from the PHY code.
With this, the phy code can be reorganized to complete its initialization
in a single function, removing the implicit two-phase overloading.

Then I can move most of the phy initialization, including enabling
the regulators, into phy_poweron. Now, when phy_poweroff is called,
the phy actually powers off. This finally disables the regulators
and allows me to save power in system suspend.

Because the UFS PHY reset bit is now toggled in the PHY, rather
than in ufs-qcom, this also percolated to all other PHYs using
ufs-qcom, which from what I can see is just 8996.

There are a couple of tradeoffs in this series that I'd welcome feedback
on. First, it breaks compatibility with device trees that don't expose
this new reset controller. Making this work with older device trees
would be pretty ugly in the code, and given that the SDM845 UFS DT nodes
aren't accepted upstream yet, the breakage seemed worth it. I'm not as
sure about 8996.

Second, I removed the calls to phy_poweroff during clock gating. This
was originally dialing down a clock or two, while leaving the phy powered.
I've now changed the semantics of phy_poweroff to, well, actually power off.
This works great for userlands that have set UFS's spm_lvl to 5 (off) like
I have, but maybe changes power consumption for devices that have spm_lvl
set to 3. I could try to use phy_init and phy_poweron as the two different
possible transitions (fully off, and clocks off respectively), but I'm not
sure if it actually matters, and I like the idea that phy_poweroff really
does power the thing off.

Also, I don't have an 8996 device to test. If someone is able to test this
out and perhaps point out any (hopefully obvious) bugs in the 8996 portion,
I'd be grateful.

This patch is based atop phy-next, plus the UFS DT nodes, which are now
patch 3, 4, 5 of [1].

[1] https://lore.kernel.org/lkml/20181210192826.241350-1-evgreen@chromium.org/


Evan Green (8):
  dt-bindings: phy-qcom-qmp: Add UFS PHY reset
  dt-bindings: phy: qcom-ufs: Add resets property
  arm64: dts: sdm845: Add UFS PHY reset
  arm64: dts: msm8996: Add UFS PHY reset controller
  scsi: ufs: qcom: Expose the reset controller for PHY
  phy: qcom-qmp: Utilize UFS reset controller
  phy: qcom-qmp: Move UFS phy to phy_poweron/off
  phy: qcom-ufs: Refactor all init steps into phy_poweron

 .../devicetree/bindings/phy/qcom-qmp-phy.txt  |   6 +-
 .../devicetree/bindings/ufs/ufs-qcom.txt      |   1 +
 arch/arm64/boot/dts/qcom/msm8996.dtsi         |   4 +-
 arch/arm64/boot/dts/qcom/sdm845.dtsi          |   3 +
 drivers/phy/qualcomm/phy-qcom-qmp.c           | 123 ++++++++++--------
 drivers/phy/qualcomm/phy-qcom-ufs-i.h         |   5 +-
 drivers/phy/qualcomm/phy-qcom-ufs-qmp-14nm.c  |  25 +---
 drivers/phy/qualcomm/phy-qcom-ufs-qmp-20nm.c  |  25 +---
 drivers/phy/qualcomm/phy-qcom-ufs.c           |  57 ++++++--
 drivers/scsi/ufs/Kconfig                      |   1 +
 drivers/scsi/ufs/ufs-qcom.c                   | 110 +++++++++-------
 drivers/scsi/ufs/ufs-qcom.h                   |   4 +
 12 files changed, 197 insertions(+), 167 deletions(-)

-- 
2.18.1

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

* [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset
  2019-01-11 23:01 [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend Evan Green
@ 2019-01-11 23:01 ` Evan Green
  2019-01-18 22:20   ` Stephen Boyd
  2019-01-22  0:25   ` Rob Herring
  2019-01-11 23:01 ` [PATCH v1 4/8] arm64: dts: msm8996: Add UFS PHY reset controller Evan Green
  2019-01-16 22:32 ` [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend Stephen Boyd
  2 siblings, 2 replies; 8+ messages in thread
From: Evan Green @ 2019-01-11 23:01 UTC (permalink / raw)
  To: Andy Gross, Rob Herring, Kishon Vijay Abraham I
  Cc: Can Guo, Douglas Anderson, Asutosh Das, Stephen Boyd,
	Vivek Gautam, Evan Green, devicetree, linux-arm-msm,
	linux-kernel, David Brown, Mark Rutland

Wire up the reset controller in the Qcom UFS controller for the PHY.
This will be used to toggle PHY reset during initialization of the PHY.

Signed-off-by: Evan Green <evgreen@chromium.org>
---
This commit is based atop the series at [1]. Patches 1 and 2 of that
series have landed, but 3, 4, and 5 are still outstanding.

[1] https://lore.kernel.org/lkml/20181210192826.241350-1-evgreen@chromium.org/

 arch/arm64/boot/dts/qcom/sdm845.dtsi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sdm845.dtsi b/arch/arm64/boot/dts/qcom/sdm845.dtsi
index b29332b265d9e..029ab66405cf4 100644
--- a/arch/arm64/boot/dts/qcom/sdm845.dtsi
+++ b/arch/arm64/boot/dts/qcom/sdm845.dtsi
@@ -990,6 +990,7 @@
 			phy-names = "ufsphy";
 			lanes-per-direction = <2>;
 			power-domains = <&gcc UFS_PHY_GDSC>;
+			#reset-cells = <1>;
 
 			clock-names =
 				"core_clk",
@@ -1033,6 +1034,8 @@
 			clocks = <&gcc GCC_UFS_MEM_CLKREF_CLK>,
 				 <&gcc GCC_UFS_PHY_PHY_AUX_CLK>;
 
+			resets = <&ufs_mem_hc 0>;
+			reset-names = "ufsphy";
 			status = "disabled";
 
 			ufs_mem_phy_lanes: lanes@1d87400 {
-- 
2.18.1

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

* [PATCH v1 4/8] arm64: dts: msm8996: Add UFS PHY reset controller
  2019-01-11 23:01 [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend Evan Green
  2019-01-11 23:01 ` [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset Evan Green
@ 2019-01-11 23:01 ` Evan Green
  2019-01-18 22:20   ` Stephen Boyd
  2019-01-16 22:32 ` [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend Stephen Boyd
  2 siblings, 1 reply; 8+ messages in thread
From: Evan Green @ 2019-01-11 23:01 UTC (permalink / raw)
  To: Andy Gross, Rob Herring, Kishon Vijay Abraham I
  Cc: Can Guo, Douglas Anderson, Asutosh Das, Stephen Boyd,
	Vivek Gautam, Evan Green, devicetree, linux-arm-msm,
	linux-kernel, David Brown, Mark Rutland

Add the reset controller for the UFS controller, and wire it up
so that the UFS PHY can initialize itself without relying on
implicit sequencing between the two drivers.

Signed-off-by: Evan Green <evgreen@chromium.org>
---

 arch/arm64/boot/dts/qcom/msm8996.dtsi | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/qcom/msm8996.dtsi b/arch/arm64/boot/dts/qcom/msm8996.dtsi
index 99b7495455a62..179f1988d45c5 100644
--- a/arch/arm64/boot/dts/qcom/msm8996.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8996.dtsi
@@ -663,10 +663,11 @@
 			clock-names = "ref_clk_src", "ref_clk";
 			clocks = <&rpmcc RPM_SMD_LN_BB_CLK>,
 				 <&gcc GCC_UFS_CLKREF_CLK>;
+			resets = <&ufshc 0>;
 			status = "disabled";
 		};
 
-		ufshc@624000 {
+		ufshc: ufshc@624000 {
 			compatible = "qcom,ufshc";
 			reg = <0x624000 0x2500>;
 			interrupts = <GIC_SPI 265 IRQ_TYPE_LEVEL_HIGH>;
@@ -722,6 +723,7 @@
 				<0 0>;
 
 			lanes-per-direction = <1>;
+			#reset-cells = <1>;
 			status = "disabled";
 
 			ufs_variant {
-- 
2.18.1

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

* Re: [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend
  2019-01-11 23:01 [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend Evan Green
  2019-01-11 23:01 ` [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset Evan Green
  2019-01-11 23:01 ` [PATCH v1 4/8] arm64: dts: msm8996: Add UFS PHY reset controller Evan Green
@ 2019-01-16 22:32 ` Stephen Boyd
  2 siblings, 0 replies; 8+ messages in thread
From: Stephen Boyd @ 2019-01-16 22:32 UTC (permalink / raw)
  To: Andy Gross, Kishon Vijay Abraham I, Rob Herring
  Cc: Can Guo, Douglas Anderson, Asutosh Das, Vivek Gautam, Evan Green,
	devicetree, Arnd Bergmann, Grygorii Strashko, linux-scsi,
	Bjorn Andersson, linux-arm-msm, linux-kernel, Vinayak Holikatti,
	Manu Gautam, David Brown, Mark Rutland, James E.J. Bottomley,
	Martin K. Petersen

Quoting Evan Green (2019-01-11 15:01:21)
> 
> Because the UFS PHY reset bit is now toggled in the PHY, rather
> than in ufs-qcom, this also percolated to all other PHYs using
> ufs-qcom, which from what I can see is just 8996.
> 
> There are a couple of tradeoffs in this series that I'd welcome feedback
> on. First, it breaks compatibility with device trees that don't expose
> this new reset controller. Making this work with older device trees
> would be pretty ugly in the code, and given that the SDM845 UFS DT nodes
> aren't accepted upstream yet, the breakage seemed worth it. I'm not as
> sure about 8996.

It may take some minor surgery to the reset framework, but it should be
possible to register a reset lookup that can be used if nothing matches
in DT. Right now the reset code looks to only want to use DT if it's
there for the device requesting the reset. If there isn't a DT node for
the device it will look in the global lookup list. That could be changed
to fallback to the global lookup that uses device names (similar to clk
framework) when the DT lookup fails. Then it's just a matter of
registering the lookup for this reset with the handful of device names
that need the non-DT way of finding the reset.

Of course, that's another change and if breaking DT is simpler and
acceptable then I would say go for the path of least resistance and
don't try to modify reset framework for this.

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

* Re: [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset
  2019-01-11 23:01 ` [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset Evan Green
@ 2019-01-18 22:20   ` Stephen Boyd
  2019-01-22  0:25   ` Rob Herring
  1 sibling, 0 replies; 8+ messages in thread
From: Stephen Boyd @ 2019-01-18 22:20 UTC (permalink / raw)
  To: Andy Gross, Kishon Vijay Abraham I, Rob Herring
  Cc: Can Guo, Douglas Anderson, Asutosh Das, Vivek Gautam, Evan Green,
	devicetree, linux-arm-msm, linux-kernel, David Brown,
	Mark Rutland

Quoting Evan Green (2019-01-11 15:01:24)
> Wire up the reset controller in the Qcom UFS controller for the PHY.
> This will be used to toggle PHY reset during initialization of the PHY.
> 
> Signed-off-by: Evan Green <evgreen@chromium.org>
> ---

Reviewed-by: Stephen Boyd <swboyd@chromium.org>

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

* Re: [PATCH v1 4/8] arm64: dts: msm8996: Add UFS PHY reset controller
  2019-01-11 23:01 ` [PATCH v1 4/8] arm64: dts: msm8996: Add UFS PHY reset controller Evan Green
@ 2019-01-18 22:20   ` Stephen Boyd
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Boyd @ 2019-01-18 22:20 UTC (permalink / raw)
  To: Andy Gross, Kishon Vijay Abraham I, Rob Herring
  Cc: Can Guo, Douglas Anderson, Asutosh Das, Vivek Gautam, Evan Green,
	devicetree, linux-arm-msm, linux-kernel, David Brown,
	Mark Rutland

Quoting Evan Green (2019-01-11 15:01:25)
> Add the reset controller for the UFS controller, and wire it up
> so that the UFS PHY can initialize itself without relying on
> implicit sequencing between the two drivers.
> 
> Signed-off-by: Evan Green <evgreen@chromium.org>
> ---

Reviewed-by: Stephen Boyd <swboyd@chromium.org>

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

* Re: [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset
  2019-01-11 23:01 ` [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset Evan Green
  2019-01-18 22:20   ` Stephen Boyd
@ 2019-01-22  0:25   ` Rob Herring
  2019-01-22 18:13     ` Evan Green
  1 sibling, 1 reply; 8+ messages in thread
From: Rob Herring @ 2019-01-22  0:25 UTC (permalink / raw)
  To: Evan Green
  Cc: Andy Gross, Kishon Vijay Abraham I, Can Guo, Douglas Anderson,
	Asutosh Das, Stephen Boyd, Vivek Gautam, devicetree,
	linux-arm-msm, linux-kernel, David Brown, Mark Rutland

On Fri, Jan 11, 2019 at 03:01:24PM -0800, Evan Green wrote:
> Wire up the reset controller in the Qcom UFS controller for the PHY.
> This will be used to toggle PHY reset during initialization of the PHY.
> 
> Signed-off-by: Evan Green <evgreen@chromium.org>
> ---
> This commit is based atop the series at [1]. Patches 1 and 2 of that
> series have landed, but 3, 4, and 5 are still outstanding.
> 
> [1] https://lore.kernel.org/lkml/20181210192826.241350-1-evgreen@chromium.org/
> 
>  arch/arm64/boot/dts/qcom/sdm845.dtsi | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/qcom/sdm845.dtsi b/arch/arm64/boot/dts/qcom/sdm845.dtsi
> index b29332b265d9e..029ab66405cf4 100644
> --- a/arch/arm64/boot/dts/qcom/sdm845.dtsi
> +++ b/arch/arm64/boot/dts/qcom/sdm845.dtsi
> @@ -990,6 +990,7 @@
>  			phy-names = "ufsphy";
>  			lanes-per-direction = <2>;
>  			power-domains = <&gcc UFS_PHY_GDSC>;
> +			#reset-cells = <1>;

Is this documented?

>  
>  			clock-names =
>  				"core_clk",
> @@ -1033,6 +1034,8 @@
>  			clocks = <&gcc GCC_UFS_MEM_CLKREF_CLK>,
>  				 <&gcc GCC_UFS_PHY_PHY_AUX_CLK>;
>  
> +			resets = <&ufs_mem_hc 0>;
> +			reset-names = "ufsphy";
>  			status = "disabled";
>  
>  			ufs_mem_phy_lanes: lanes@1d87400 {
> -- 
> 2.18.1
> 

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

* Re: [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset
  2019-01-22  0:25   ` Rob Herring
@ 2019-01-22 18:13     ` Evan Green
  0 siblings, 0 replies; 8+ messages in thread
From: Evan Green @ 2019-01-22 18:13 UTC (permalink / raw)
  To: Rob Herring
  Cc: Andy Gross, Kishon Vijay Abraham I, Can Guo, Douglas Anderson,
	Asutosh Das, Stephen Boyd, Vivek Gautam, devicetree,
	linux-arm-msm, LKML, David Brown, Mark Rutland

On Mon, Jan 21, 2019 at 4:25 PM Rob Herring <robh@kernel.org> wrote:
>
> On Fri, Jan 11, 2019 at 03:01:24PM -0800, Evan Green wrote:
> > Wire up the reset controller in the Qcom UFS controller for the PHY.
> > This will be used to toggle PHY reset during initialization of the PHY.
> >
> > Signed-off-by: Evan Green <evgreen@chromium.org>
> > ---
> > This commit is based atop the series at [1]. Patches 1 and 2 of that
> > series have landed, but 3, 4, and 5 are still outstanding.
> >
> > [1] https://lore.kernel.org/lkml/20181210192826.241350-1-evgreen@chromium.org/
> >
> >  arch/arm64/boot/dts/qcom/sdm845.dtsi | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/arch/arm64/boot/dts/qcom/sdm845.dtsi b/arch/arm64/boot/dts/qcom/sdm845.dtsi
> > index b29332b265d9e..029ab66405cf4 100644
> > --- a/arch/arm64/boot/dts/qcom/sdm845.dtsi
> > +++ b/arch/arm64/boot/dts/qcom/sdm845.dtsi
> > @@ -990,6 +990,7 @@
> >                       phy-names = "ufsphy";
> >                       lanes-per-direction = <2>;
> >                       power-domains = <&gcc UFS_PHY_GDSC>;
> > +                     #reset-cells = <1>;
>
> Is this documented?
>

No, I'll add this in my next spin. Thanks.
-Evan

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

end of thread, other threads:[~2019-01-22 18:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 23:01 [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend Evan Green
2019-01-11 23:01 ` [PATCH v1 3/8] arm64: dts: sdm845: Add UFS PHY reset Evan Green
2019-01-18 22:20   ` Stephen Boyd
2019-01-22  0:25   ` Rob Herring
2019-01-22 18:13     ` Evan Green
2019-01-11 23:01 ` [PATCH v1 4/8] arm64: dts: msm8996: Add UFS PHY reset controller Evan Green
2019-01-18 22:20   ` Stephen Boyd
2019-01-16 22:32 ` [PATCH v1 0/8] phy: qcom-ufs: Enable regulators to be off in suspend Stephen Boyd

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