spi: sprd: add runtime pm for transfer message
Subsystems (2)
Chunyan Zhang
reviewerPATCH 1/1 spi: sprd: add runtime pm for transfer message
From: Bangzheng Liu <[email protected]>
Before transfer one message, spi core would set chipselect, sprd spi device should be resumed from runtime suspend, otherwise kernel would crash once access spi registers. The sprd spi device can be suspended until clearing chipselect which would be executed after transfer.
--- drivers/spi/spi-sprd.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/spi/spi-sprd.c +13 -3
@@ -293,15 +293,25 @@ static void sprd_spi_chipselect(struct spi_device *sdev, bool cs)struct spi_controller *sctlr = sdev->controller;struct sprd_spi *ss =spi_controller_get_devdata (sctlr);u32 val; +int ret; - val =readl_relaxed (ss->base +SPRD_SPI_CTL0 );/* The SPI controller will pull down CS pin if cs is 0 */ if (!cs) { - val &= ~SPRD_SPI_CS0_VALID ; + ret =pm_runtime_get_sync (ss->dev); +if (ret <0 ) { +pm_runtime_put_noidle (ss->dev); +dev_err (ss->dev,"Failed to power device: %d\n" , ret); +return ; + } + val =readl_relaxed (ss->base +SPRD_SPI_CTL0 ); + val &= ~SPRD_SPI_CS0_VALID ;/* set cs0 valid */ writel_relaxed (val, ss->base +SPRD_SPI_CTL0 ); }else { - val |=SPRD_SPI_CSN_MASK ; + val =readl_relaxed (ss->base +SPRD_SPI_CTL0 ); + val |=SPRD_SPI_CSN_MASK ;/* set all cs invalid */ writel_relaxed (val, ss->base +SPRD_SPI_CTL0 ); +pm_runtime_mark_last_busy (ss->dev); +pm_runtime_put_autosuspend (ss->dev); } }
Signature · 1 line
2.20.1
Mark Brown
maintainerQuoted 6 lines · Chunyan Zhang
From: Bangzheng Liu <[email protected]>
Before transfer one message, spi core would set chipselect, sprd spi device should be resumed from runtime suspend, otherwise kernel would crash once access spi registers. The sprd spi device can be suspended until clearing chipselect which would be executed after transfer.
The core should be handling runtime PM for normal transfers, if it's not managing to do that then we should fix the core so it's fixed for all drivers not just this one.
Chunyan Zhang
reviewerQuoted 4 lines · Mark Brown
Quoted 2 lines · Chunyan Zhang
From: Bangzheng Liu <[email protected]>
Quoted 8 lines
Quoted 4 lines
Before transfer one message, spi core would set chipselect, sprd spi device should be resumed from runtime suspend, otherwise kernel would crash once access spi registers. The sprd spi device can be suspended until clearing chipselect which would be executed after transfer.
The core should be handling runtime PM for normal transfers, if it's not managing to do that then we should fix the core so it's fixed for all drivers not just this one.
Sure, I will send a new patch.