Skip to contentSkip to conversation

Add simple PM operations to sifive-spi

PATCH In review Andy Chiu 3 participants 7 messages Jun 10, 2022 – Jun 22, 2022

Subsystems (3)
lore
Share & tools
lore

Andy Chiu

author
#0 lore raw

cover Add simple PM operations to sifive-spi

The patch has been tested on Unmatched using pm_test. The Unmatched board uses SD over SPI and it was tested by initiating S2RAM cycles for all devices while reading/writing files at the same time. We found no dropped connection to the card or corrupted filesystem during test cycles.

Andy Chiu (1):
spi: sifive: add PM callbacks to support suspend/resume

 drivers/spi/spi-sifive.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
Signature · 1 line
2.36.0
author
#1 lore raw

PATCH 1/1 spi: sifive: add PM callbacks to support suspend/resume

---
 drivers/spi/spi-sifive.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/spi/spi-sifive.c +39 -0
index f7c1e20432e0..e29e85cee88a 100644
@@ -427,6 +427,44 @@ static int sifive_spi_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int sifive_spi_suspend(struct device *dev)
+{
+	struct spi_master *master = dev_get_drvdata(dev);
+	struct sifive_spi *spi = spi_master_get_devdata(master);
+	int ret;
+
+	ret = spi_master_suspend(master);
+	if (ret)
+		return ret;
+
+	/* Disable all the interrupts just in case */
+	sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
+
+	clk_disable_unprepare(spi->clk);
+
+	return ret;
+}
+
+static int sifive_spi_resume(struct device *dev)
+{
+	struct spi_master *master = dev_get_drvdata(dev);
+	struct sifive_spi *spi = spi_master_get_devdata(master);
+	int ret;
+
+	ret = clk_prepare_enable(spi->clk);
+	if (ret)
+		return ret;
+	ret = spi_master_resume(master);
+	if (ret)
+		clk_disable_unprepare(spi->clk);
+
+	return ret;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(sifive_spi_pm_ops,
+				sifive_spi_suspend, sifive_spi_resume);
+
+
 static const struct of_device_id sifive_spi_of_match[] = {
 	{ .compatible = "sifive,spi0", },
 	{}
@@ -438,6 +476,7 @@ static struct platform_driver sifive_spi_driver = {
 	.remove = sifive_spi_remove,
 	.driver = {
 		.name = SIFIVE_SPI_DRIVER_NAME,
+		.pm = &sifive_spi_pm_ops,
 		.of_match_table = sifive_spi_of_match,
 	},
 };
Signature · 1 line
2.36.0
maintainer
#2 lore raw

Re: [PATCH next 1/1] spi: sifive: add PM callbacks to support suspend/resume

Quoted 4 lines · Andy Chiu
drivers/spi/spi-sifive.c +4 -0
+static int sifive_spi_suspend(struct device *dev)
+{
+	struct spi_master *master = dev_get_drvdata(dev);
+	struct sifive_spi *spi = spi_master_get_devdata(master);

drivers/spi/spi-sifive.c static int sifive_spi_remove(struct platform_device *pdev) · line 443

Quoted 10 lines
drivers/spi/spi-sifive.c +10 -0
+	int ret;
+
+	ret = spi_master_suspend(master);
+	if (ret)
+		return ret;
+
+	/* Disable all the interrupts just in case */
+	sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
+
+	clk_disable_unprepare(spi->clk);

Seems like the clock managemnet could usefully be done as runtime PM too? In any case, that can be done as an incremental change.

author
#3 lore raw

Re: [PATCH next 1/1] spi: sifive: add PM callbacks to support suspend/resume

Quoted 2 lines

Seems like the clock managemnet could usefully be done as runtime PM too? In any case, that can be done as an incremental change.

Thanks for the suggestion. We will work on it soon in the future.

#4 lore raw

Re: [PATCH next 1/1] spi: sifive: add PM callbacks to support suspend/resume

In reply to Andy Chiu
Quoted 1 line · Andy Chiu

Missed changelog.

Quoted 6 lines

.driver = {
.name = SIFIVE_SPI_DRIVER_NAME,
+ .pm = &sifive_spi_pm_ops,

Missed pm_sleep_ptr(). Have you compiled it with CONFIG_PM_SLEEP=n? Have you got warnings of unused functions?

Quoted 2 lines

.of_match_table = sifive_spi_of_match,
},

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
In reply to Andy Chiu
Quoted 4 lines · Andy Chiu

The patch has been tested on Unmatched using pm_test. The Unmatched board uses SD over SPI and it was tested by initiating S2RAM cycles for all devices while reading/writing files at the same time. We found no dropped connection to the card or corrupted filesystem during test cycles.

Please don't send cover letters for single patches, if there is anything that needs saying put it in the changelog of the patch or after the --- if it's administrative stuff. This reduces mail volume and ensures that any important information is recorded in the changelog rather than being lost.

maintainer
#6 lore raw
In reply to Andy Chiu
Quoted 9 lines · Andy Chiu

The patch has been tested on Unmatched using pm_test. The Unmatched board uses SD over SPI and it was tested by initiating S2RAM cycles for all devices while reading/writing files at the same time. We found no dropped connection to the card or corrupted filesystem during test cycles.

Andy Chiu (1):
spi: sifive: add PM callbacks to support suspend/resume

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: sifive: add PM callbacks to support suspend/resume

      commit: a1f0161eadbd7941c09b5f4c6a210c390d2b86d6

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark