From: "luhua.xu" <luhua.xu@xxxxxxxxxxxx> Use runtime PM to power spi when set_cs As set_cs may be called from interrupt context, set runtime PM IRQ safe for spi. Signed-off-by: luhua.xu <luhua.xu@xxxxxxxxxxxx> --- drivers/spi/spi-mt65xx.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 6888a4d..039b67d 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -262,8 +262,16 @@ static int mtk_spi_prepare_message(struct spi_master *master, static void mtk_spi_set_cs(struct spi_device *spi, bool enable) { u32 reg_val; + int ret; struct mtk_spi *mdata = spi_master_get_devdata(spi->master); + ret = pm_runtime_get_sync(spi->master->dev.parent); + if (ret < 0) { + pm_runtime_put_noidle(spi->master->dev.parent); + dev_err(&spi->dev, "failed to power device(%d)\n", ret); + return; + } + reg_val = readl(mdata->base + SPI_CMD_REG); if (!enable) { reg_val |= SPI_CMD_PAUSE_EN; @@ -274,6 +282,9 @@ static void mtk_spi_set_cs(struct spi_device *spi, bool enable) mdata->state = MTK_SPI_IDLE; mtk_spi_reset(mdata); } + + pm_runtime_mark_last_busy(spi->master->dev.parent); + pm_runtime_put_autosuspend(spi->master->dev.parent); } static void mtk_spi_prepare_transfer(struct spi_master *master, @@ -749,6 +760,7 @@ static int mtk_spi_probe(struct platform_device *pdev) clk_disable_unprepare(mdata->spi_clk); pm_runtime_enable(&pdev->dev); + pm_runtime_irq_safe(&pdev->dev); ret = devm_spi_register_master(&pdev->dev, master); if (ret) { -- 2.6.4