[PATCH] spi/fsl-espi: Add Power Management support for eSPI controller

Subsystems: spi subsystem, the rest

STALE4653d

2 messages, 2 authors, 2013-12-11 · open the first message on its own page

[PATCH] spi/fsl-espi: Add Power Management support for eSPI controller

From: Hou Zhiqiang <hidden>
Date: 2013-12-11 09:34:44

Add PM support for eSPI controller using callback function suspend
and resume in .driver of platform_driver.

Signed-off-by: Hou Zhiqiang <redacted>
---
 drivers/spi/spi-fsl-espi.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index 8106006..9c3fe70 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -727,6 +727,59 @@ static int of_fsl_espi_remove(struct platform_device *dev)
 	return mpc8xxx_spi_remove(&dev->dev);
 }
 
+#ifdef CONFIG_PM
+static int of_fsl_espi_suspend(struct device *dev, pm_message_t state)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct spi_master *master = platform_get_drvdata(pdev);
+	struct mpc8xxx_spi *mpc8xxx_spi;
+	struct fsl_espi_reg *reg_base;
+	u32 regval;
+
+	mpc8xxx_spi = spi_master_get_devdata(master);
+	reg_base = mpc8xxx_spi->reg_base;
+
+	regval = mpc8xxx_spi_read_reg(&reg_base->mode);
+	regval &= ~(SPMODE_ENABLE);
+	mpc8xxx_spi_write_reg(&reg_base->mode, regval);
+
+	regval = mpc8xxx_spi_read_reg(&reg_base->mode);
+
+	return 0;
+}
+
+static int of_fsl_espi_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct fsl_spi_platform_data *pdata = dev_get_platdata(dev);
+	struct spi_master *master = platform_get_drvdata(pdev);
+	struct mpc8xxx_spi *mpc8xxx_spi;
+	struct fsl_espi_reg *reg_base;
+	u32 regval;
+	int i;
+
+	mpc8xxx_spi = spi_master_get_devdata(master);
+	reg_base = mpc8xxx_spi->reg_base;
+
+	/* SPI controller initializations */
+	mpc8xxx_spi_write_reg(&reg_base->mode, 0);
+	mpc8xxx_spi_write_reg(&reg_base->mask, 0);
+	mpc8xxx_spi_write_reg(&reg_base->command, 0);
+	mpc8xxx_spi_write_reg(&reg_base->event, 0xffffffff);
+
+	/* Init eSPI CS mode register */
+	for (i = 0; i < pdata->max_chipselect; i++)
+		mpc8xxx_spi_write_reg(&reg_base->csmode[i], CSMODE_INIT_VAL);
+
+	/* Enable SPI interface */
+	regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE;
+
+	mpc8xxx_spi_write_reg(&reg_base->mode, regval);
+
+	return 0;
+}
+#endif /* CONFIG_PM */
+
 static const struct of_device_id of_fsl_espi_match[] = {
 	{ .compatible = "fsl,mpc8536-espi" },
 	{}
@@ -738,6 +791,10 @@ static struct platform_driver fsl_espi_driver = {
 		.name = "fsl_espi",
 		.owner = THIS_MODULE,
 		.of_match_table = of_fsl_espi_match,
+#ifdef CONFIG_PM
+		.suspend	= of_fsl_espi_suspend,
+		.resume		= of_fsl_espi_resume,
+#endif
 	},
 	.probe		= of_fsl_espi_probe,
 	.remove		= of_fsl_espi_remove,
-- 
1.8.4.1

Re: [PATCH] spi/fsl-espi: Add Power Management support for eSPI controller

From: Mark Brown <broonie@kernel.org>
Date: 2013-12-11 14:09:37

On Wed, Dec 11, 2013 at 04:11:51PM +0800, Hou Zhiqiang wrote:
+#ifdef CONFIG_PM
+static int of_fsl_espi_suspend(struct device *dev, pm_message_t state)
This should be CONFIG_PM_SLEEP.  I'd also expect to see a call to
spi_master_suspend() here (and similarly for resume) - it won't do
anything yet but it'd better for completeness in case we add extra
behaviour and looking at the driver it ought to be converted to
transfer_one_message anyway.
+#ifdef CONFIG_PM
+		.suspend	= of_fsl_espi_suspend,
+		.resume		= of_fsl_espi_resume,
+#endif
SET_SYSTEM_SLEEP_PM_OPS().
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help