linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] spi-cadence-quadspi: Introduce runtime_pm support
@ 2023-08-18 10:37 Dhruva Gole
  2023-08-18 10:37 ` [PATCH 1/2] arm64: dts: ti: k3-am62-main: PM fixes in the fss node Dhruva Gole
  2023-08-18 10:37 ` [RFT/PATCH 2/2] spi: spi-cadence-quadspi: add runtime pm support Dhruva Gole
  0 siblings, 2 replies; 4+ messages in thread
From: Dhruva Gole @ 2023-08-18 10:37 UTC (permalink / raw)
  To: Mark Brown, Nishanth Menon, Vignesh Raghavendra, Tero Kristo
  Cc: linux-arm-kernel, devicetree, linux-kernel, linux-spi, Dhruva Gole

Abstract
********

This series aims to add runtime_pm [0] functionality to the cadence-qspi
driver/IP. Prior to this, the driver had system suspend resume support
which comes into picture only during system wide low power states like
deep sleep / Suspend-to-RAM.

Now, with runtime_pm support we can finally allow this driver/controller
to be clock gated/ suspended when it's not in active use. This helps the
overall system to reduce it's power consumption without needing to resort
to system wide low power modes.

As it turns out, the system suspend resume functionality that existed so
far can be re-used as is even for runtime suspend resume, hence the
actual implementations of those calls need not change.

Testing
*******

This series has been tested by me on a SK-AM625 [1] EVM by Texas Instruments.

I did a basic test to check if IP suspended by trying to access it's
registers while suspended (got core dump) and then to check resume I
read back data from it. Also used k3conf, a TI tool to check on the
device status in K3 Family of SOCs.

I highly encourage other platforms and users of this driver to test
these changes as it affects all those who use runtime_pm.
For this, I have uploaded these changes on my github branch [2] which
can be cloned and readily used.
For referring to how I tested, please refer to my logs [3]

Runtime PM usage
****************

The auto-suspend delay can be tweaked from the userspace using the
following sysfs entry:

root@am62xx-evm:~# cat /sys/bus/platform/devices/fc40000.spi/power/autosuspend_delay_ms
2000

Other useful information can be obtained from the same folder,

root@am62xx-evm:~# cat /sys/bus/platform/devices/fc40000.spi/power/runtime_*

To disable runtime auto-suspend for this driver one can set autosuspend_delay_ms to -1

Note to maintainers
*******************

* Patch 1/2 should probably go via Nishant's / Vignesh's tree
* Patch 2/2 (RFT) can go via Mark's tree

Reference/Links
***************

[0] https://docs.kernel.org/power/runtime_pm.html
[1] https://www.ti.com/tool/SK-AM62
[2] https://github.com/DhruvaG2000/v-linux/tree/ospi_runtime_pm
[3] https://gist.github.com/DhruvaG2000/6aeeb2196caf8fbbe518c89037cb7548

Dhruva Gole (2):
  arm64: dts: ti: k3-am62-main: PM fixes in the fss node
  spi: spi-cadence-quadspi: add runtime pm support

 arch/arm64/boot/dts/ti/k3-am62-main.dtsi |  3 +-
 drivers/spi/spi-cadence-quadspi.c        | 38 ++++++++++++++++++------
 2 files changed, 31 insertions(+), 10 deletions(-)


base-commit: 47762f08697484cf0c2f2904b8c52375ed26c8cb
-- 
2.34.1


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

* [PATCH 1/2] arm64: dts: ti: k3-am62-main: PM fixes in the fss node
  2023-08-18 10:37 [PATCH 0/2] spi-cadence-quadspi: Introduce runtime_pm support Dhruva Gole
@ 2023-08-18 10:37 ` Dhruva Gole
  2023-08-21 16:28   ` Andrew Davis
  2023-08-18 10:37 ` [RFT/PATCH 2/2] spi: spi-cadence-quadspi: add runtime pm support Dhruva Gole
  1 sibling, 1 reply; 4+ messages in thread
From: Dhruva Gole @ 2023-08-18 10:37 UTC (permalink / raw)
  To: Mark Brown, Nishanth Menon, Vignesh Raghavendra, Tero Kristo
  Cc: linux-arm-kernel, devicetree, linux-kernel, linux-spi,
	Dhruva Gole, Vibhore Vardhan

* Make use of Simple Power-Managed Bus as the fss bus controller is under
the control of a functional clock, and also is part of a PM domain.
* Specify the appropriate k3 pd to the fss node as per tisci docs [0].

[0] https://software-dl.ti.com/tisci/esd/latest/5_soc_doc/am62x/devices.html

Fixes: c37c58fdeb8a ("arm64: dts: ti: k3-am62: Add more peripheral nodes")
Co-developed-by: Vibhore Vardhan <vibhore@ti.com>
Signed-off-by: Vibhore Vardhan <vibhore@ti.com>
Signed-off-by: Dhruva Gole <d-gole@ti.com>
---
 arch/arm64/boot/dts/ti/k3-am62-main.dtsi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/ti/k3-am62-main.dtsi b/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
index 284b90c94da8..b23c9e3d91cd 100644
--- a/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
@@ -640,10 +640,11 @@ usb1: usb@31100000 {
 	};
 
 	fss: bus@fc00000 {
-		compatible = "simple-bus";
+		compatible = "simple-pm-bus";
 		reg = <0x00 0x0fc00000 0x00 0x70000>;
 		#address-cells = <2>;
 		#size-cells = <2>;
+		power-domains = <&k3_pds 74 TI_SCI_PD_EXCLUSIVE>;
 		ranges;
 
 		ospi0: spi@fc40000 {
-- 
2.34.1


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

* [RFT/PATCH 2/2] spi: spi-cadence-quadspi: add runtime pm support
  2023-08-18 10:37 [PATCH 0/2] spi-cadence-quadspi: Introduce runtime_pm support Dhruva Gole
  2023-08-18 10:37 ` [PATCH 1/2] arm64: dts: ti: k3-am62-main: PM fixes in the fss node Dhruva Gole
@ 2023-08-18 10:37 ` Dhruva Gole
  1 sibling, 0 replies; 4+ messages in thread
From: Dhruva Gole @ 2023-08-18 10:37 UTC (permalink / raw)
  To: Mark Brown, Nishanth Menon, Vignesh Raghavendra, Tero Kristo
  Cc: linux-arm-kernel, devicetree, linux-kernel, linux-spi,
	Dhruva Gole, Apurva Nandan, Ramuthevar Vadivel Murugan,
	Sai Krishna Potthuri, Ian Abbott, William Qiu, Brad Larson,
	Pratyush Yadav

Add runtime pm support to cadence-qspi driver, this allows the driver to
suspend whenever it's is not actively being used thus reducing active
power consumed by the system.

Also, with the use of devm_pm_runtime_enable we no longer need the
fallback probe_pm_failed that used to pm_runtime_disable

Co-developed-by: Apurva Nandan <a-nandan@ti.com>
Signed-off-by: Apurva Nandan <a-nandan@ti.com>
Signed-off-by: Dhruva Gole <d-gole@ti.com>
---

Cc: Ramuthevar Vadivel Murugan <vadivel.muruganx.ramuthevar@linux.intel.com>
Cc: Sai Krishna Potthuri <lakshmi.sai.krishna.potthuri@xilinx.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: William Qiu <william.qiu@starfivetech.com>
Cc: Brad Larson <blarson@amd.com>
Cc: Pratyush Yadav <ptyadav@amazon.de>

 drivers/spi/spi-cadence-quadspi.c | 38 +++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index b50db71ac4cc..8b6c2822037e 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -116,6 +116,9 @@ struct cqspi_driver_platdata {
 #define CQSPI_TIMEOUT_MS			500
 #define CQSPI_READ_TIMEOUT_MS			10
 
+/* Runtime_pm autosuspend delay */
+#define CQSPI_AUTOSUSPEND_TIMEOUT		2000
+
 #define CQSPI_DUMMY_CLKS_PER_BYTE		8
 #define CQSPI_DUMMY_BYTES_MAX			4
 #define CQSPI_DUMMY_CLKS_MAX			31
@@ -1407,8 +1410,16 @@ static int cqspi_mem_process(struct spi_mem *mem, const struct spi_mem_op *op)
 static int cqspi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op)
 {
 	int ret;
+	struct cqspi_st *cqspi = spi_master_get_devdata(mem->spi->master);
+	struct device *dev = &cqspi->pdev->dev;
+
+	pm_runtime_resume_and_get(dev);
 
 	ret = cqspi_mem_process(mem, op);
+
+	pm_runtime_mark_last_busy(dev);
+	pm_runtime_put_autosuspend(dev);
+
 	if (ret)
 		dev_err(&mem->spi->dev, "operation failed with %d\n", ret);
 
@@ -1753,10 +1764,10 @@ static int cqspi_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return -ENXIO;
 
-	pm_runtime_enable(dev);
-	ret = pm_runtime_resume_and_get(dev);
-	if (ret < 0)
-		goto probe_pm_failed;
+	ret = pm_runtime_set_active(dev);
+	if (ret)
+		return ret;
+
 
 	ret = clk_prepare_enable(cqspi->clk);
 	if (ret) {
@@ -1862,21 +1873,29 @@ static int cqspi_probe(struct platform_device *pdev)
 			goto probe_setup_failed;
 	}
 
+	ret = devm_pm_runtime_enable(dev);
+	if (ret)
+		return ret;
+
+	pm_runtime_set_autosuspend_delay(dev, CQSPI_AUTOSUSPEND_TIMEOUT);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_get_noresume(dev);
+
 	ret = spi_register_controller(host);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register SPI ctlr %d\n", ret);
 		goto probe_setup_failed;
 	}
 
+	pm_runtime_mark_last_busy(dev);
+	pm_runtime_put_autosuspend(dev);
+
 	return 0;
 probe_setup_failed:
 	cqspi_controller_enable(cqspi, 0);
 probe_reset_failed:
 	clk_disable_unprepare(cqspi->clk);
 probe_clk_failed:
-	pm_runtime_put_sync(dev);
-probe_pm_failed:
-	pm_runtime_disable(dev);
 	return ret;
 }
 
@@ -1928,7 +1947,8 @@ static int cqspi_resume(struct device *dev)
 	return spi_controller_resume(host);
 }
 
-static DEFINE_SIMPLE_DEV_PM_OPS(cqspi_dev_pm_ops, cqspi_suspend, cqspi_resume);
+static DEFINE_RUNTIME_DEV_PM_OPS(cqspi_dev_pm_ops, cqspi_suspend,
+				 cqspi_resume, NULL);
 
 static const struct cqspi_driver_platdata cdns_qspi = {
 	.quirks = CQSPI_DISABLE_DAC_MODE,
@@ -2012,7 +2032,7 @@ static struct platform_driver cqspi_platform_driver = {
 	.remove_new = cqspi_remove,
 	.driver = {
 		.name = CQSPI_NAME,
-		.pm = &cqspi_dev_pm_ops,
+		.pm = pm_ptr(&cqspi_dev_pm_ops),
 		.of_match_table = cqspi_dt_ids,
 	},
 };
-- 
2.34.1


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

* Re: [PATCH 1/2] arm64: dts: ti: k3-am62-main: PM fixes in the fss node
  2023-08-18 10:37 ` [PATCH 1/2] arm64: dts: ti: k3-am62-main: PM fixes in the fss node Dhruva Gole
@ 2023-08-21 16:28   ` Andrew Davis
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Davis @ 2023-08-21 16:28 UTC (permalink / raw)
  To: Dhruva Gole, Mark Brown, Nishanth Menon, Vignesh Raghavendra,
	Tero Kristo
  Cc: linux-arm-kernel, devicetree, linux-kernel, linux-spi, Vibhore Vardhan

On 8/18/23 5:37 AM, Dhruva Gole wrote:
> * Make use of Simple Power-Managed Bus as the fss bus controller is under
> the control of a functional clock, and also is part of a PM domain.
> * Specify the appropriate k3 pd to the fss node as per tisci docs [0].
> 
> [0] https://software-dl.ti.com/tisci/esd/latest/5_soc_doc/am62x/devices.html
> 

This doc makes it look like the number should be 73, but you have 74, what is FSAS?

Andrew

> Fixes: c37c58fdeb8a ("arm64: dts: ti: k3-am62: Add more peripheral nodes")
> Co-developed-by: Vibhore Vardhan <vibhore@ti.com>
> Signed-off-by: Vibhore Vardhan <vibhore@ti.com>
> Signed-off-by: Dhruva Gole <d-gole@ti.com>
> ---
>   arch/arm64/boot/dts/ti/k3-am62-main.dtsi | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-am62-main.dtsi b/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
> index 284b90c94da8..b23c9e3d91cd 100644
> --- a/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
> +++ b/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
> @@ -640,10 +640,11 @@ usb1: usb@31100000 {
>   	};
>   
>   	fss: bus@fc00000 {
> -		compatible = "simple-bus";
> +		compatible = "simple-pm-bus";
>   		reg = <0x00 0x0fc00000 0x00 0x70000>;
>   		#address-cells = <2>;
>   		#size-cells = <2>;
> +		power-domains = <&k3_pds 74 TI_SCI_PD_EXCLUSIVE>;
>   		ranges;
>   
>   		ospi0: spi@fc40000 {

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

end of thread, other threads:[~2023-08-21 16:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-18 10:37 [PATCH 0/2] spi-cadence-quadspi: Introduce runtime_pm support Dhruva Gole
2023-08-18 10:37 ` [PATCH 1/2] arm64: dts: ti: k3-am62-main: PM fixes in the fss node Dhruva Gole
2023-08-21 16:28   ` Andrew Davis
2023-08-18 10:37 ` [RFT/PATCH 2/2] spi: spi-cadence-quadspi: add runtime pm support Dhruva Gole

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