]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
spi: omap2-mcspi: Restore context always in runtime_resume
authorTony Lindgren <tony@atomide.com>
Wed, 25 Apr 2018 14:08:43 +0000 (07:08 -0700)
committerMark Brown <broonie@kernel.org>
Tue, 1 May 2018 21:05:53 +0000 (06:05 +0900)
We can have the SoC enter off mode also during idle, not just
during suspend. Currently we are handling the CS restore properly
for unused CS only for resume and not for runtime resume.

Let's just move all the context related restore to runtime_resume().

Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-omap2-mcspi.c

index 9bf64e6eca9ba706b64e46a34fa9d0763680433d..e8af5a7ccc5ccc1d661c22c216464657da1bf7d6 100644 (file)
@@ -350,20 +350,6 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi,
        mcspi->fifo_depth = 0;
 }
 
-static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
-{
-       struct spi_master       *spi_cntrl = mcspi->master;
-       struct omap2_mcspi_regs *ctx = &mcspi->ctx;
-       struct omap2_mcspi_cs   *cs;
-
-       /* McSPI: context restore */
-       mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_MODULCTRL, ctx->modulctrl);
-       mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_WAKEUPENABLE, ctx->wakeupenable);
-
-       list_for_each_entry(cs, &ctx->cs, node)
-               writel_relaxed(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0);
-}
-
 static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit)
 {
        unsigned long timeout;
@@ -1297,14 +1283,39 @@ static int omap2_mcspi_master_setup(struct omap2_mcspi *mcspi)
        return 0;
 }
 
+/*
+ * When SPI wake up from off-mode, CS is in activate state. If it was in
+ * inactive state when driver was suspend, then force it to inactive state at
+ * wake up.
+ */
 static int omap_mcspi_runtime_resume(struct device *dev)
 {
-       struct omap2_mcspi      *mcspi;
-       struct spi_master       *master;
+       struct spi_master *master = dev_get_drvdata(dev);
+       struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
+       struct omap2_mcspi_regs *ctx = &mcspi->ctx;
+       struct omap2_mcspi_cs *cs;
 
-       master = dev_get_drvdata(dev);
-       mcspi = spi_master_get_devdata(master);
-       omap2_mcspi_restore_ctx(mcspi);
+       /* McSPI: context restore */
+       mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, ctx->modulctrl);
+       mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE, ctx->wakeupenable);
+
+       list_for_each_entry(cs, &ctx->cs, node) {
+               /*
+                * We need to toggle CS state for OMAP take this
+                * change in account.
+                */
+               if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE) == 0) {
+                       cs->chconf0 |= OMAP2_MCSPI_CHCONF_FORCE;
+                       writel_relaxed(cs->chconf0,
+                                      cs->base + OMAP2_MCSPI_CHCONF0);
+                       cs->chconf0 &= ~OMAP2_MCSPI_CHCONF_FORCE;
+                       writel_relaxed(cs->chconf0,
+                                      cs->base + OMAP2_MCSPI_CHCONF0);
+               } else {
+                       writel_relaxed(cs->chconf0,
+                                      cs->base + OMAP2_MCSPI_CHCONF0);
+               }
+       }
 
        return 0;
 }
@@ -1447,34 +1458,8 @@ static int omap2_mcspi_remove(struct platform_device *pdev)
 MODULE_ALIAS("platform:omap2_mcspi");
 
 #ifdef CONFIG_SUSPEND
-/*
- * When SPI wake up from off-mode, CS is in activate state. If it was in
- * unactive state when driver was suspend, then force it to unactive state at
- * wake up.
- */
 static int omap2_mcspi_resume(struct device *dev)
 {
-       struct spi_master       *master = dev_get_drvdata(dev);
-       struct omap2_mcspi      *mcspi = spi_master_get_devdata(master);
-       struct omap2_mcspi_regs *ctx = &mcspi->ctx;
-       struct omap2_mcspi_cs   *cs;
-
-       pm_runtime_get_sync(mcspi->dev);
-       list_for_each_entry(cs, &ctx->cs, node) {
-               if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE) == 0) {
-                       /*
-                        * We need to toggle CS state for OMAP take this
-                        * change in account.
-                        */
-                       cs->chconf0 |= OMAP2_MCSPI_CHCONF_FORCE;
-                       writel_relaxed(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0);
-                       cs->chconf0 &= ~OMAP2_MCSPI_CHCONF_FORCE;
-                       writel_relaxed(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0);
-               }
-       }
-       pm_runtime_mark_last_busy(mcspi->dev);
-       pm_runtime_put_autosuspend(mcspi->dev);
-
        return pinctrl_pm_select_default_state(dev);
 }