From 3c863792e9b882c9256b4396742a4b257fb9c557 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Thu, 3 Sep 2015 22:38:46 +0200 Subject: spi: s3c64xx: clean up runtime PM if driver registration fails Fix missing runtime PM cleanup if driver registration fails. Signed-off-by: Heiner Kallweit Reviewed-by: Krzysztof Kozlowski Signed-off-by: Mark Brown --- drivers/spi/spi-s3c64xx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index cd1cfac0447f..8a6ab880601a 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1186,7 +1186,7 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) ret = devm_spi_register_master(&pdev->dev, master); if (ret != 0) { dev_err(&pdev->dev, "cannot register SPI master: %d\n", ret); - goto err3; + goto err4; } dev_dbg(&pdev->dev, "Samsung SoC SPI Driver loaded for Bus SPI-%d with %d Slaves attached\n", @@ -1197,6 +1197,9 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) return 0; +err4: + pm_runtime_disable(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); err3: clk_disable_unprepare(sdd->src_clk); err2: -- cgit v1.2.3 From 483867ee2070e045eb0a18fb7bb2f79d2433339f Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Thu, 3 Sep 2015 22:39:36 +0200 Subject: spi: s3c64xx: extend driver to make full use of runtime PM autosuspend Extend the driver to make full use of runtime PM autosuspend. Before only the SPI core was instructed to use autosuspend by setting master->auto_runtime_pm. Nevertheless due to the missing pm_runtime_use_autosuspend call autosuspend wasn't active. Signed-off-by: Heiner Kallweit Reviewed-by: Krzysztof Kozlowski Signed-off-by: Mark Brown --- drivers/spi/spi-s3c64xx.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 8a6ab880601a..d117fa638ee3 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -32,6 +32,7 @@ #define MAX_SPI_PORTS 6 #define S3C64XX_SPI_QUIRK_POLL (1 << 0) #define S3C64XX_SPI_QUIRK_CS_AUTO (1 << 1) +#define AUTOSUSPEND_TIMEOUT 2000 /* Registers and bit-fields */ @@ -859,13 +860,15 @@ static int s3c64xx_spi_setup(struct spi_device *spi) } } - pm_runtime_put(&sdd->pdev->dev); + pm_runtime_mark_last_busy(&sdd->pdev->dev); + pm_runtime_put_autosuspend(&sdd->pdev->dev); if (!(sdd->port_conf->quirks & S3C64XX_SPI_QUIRK_CS_AUTO)) writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL); return 0; setup_exit: - pm_runtime_put(&sdd->pdev->dev); + pm_runtime_mark_last_busy(&sdd->pdev->dev); + pm_runtime_put_autosuspend(&sdd->pdev->dev); /* setup() returns with device de-selected */ if (!(sdd->port_conf->quirks & S3C64XX_SPI_QUIRK_CS_AUTO)) writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL); @@ -1162,6 +1165,12 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) goto err2; } + pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT); + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); + /* Setup Deufult Mode */ s3c64xx_spi_hwinit(sdd, sdd->port_id); @@ -1180,13 +1189,10 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) S3C64XX_SPI_INT_TX_OVERRUN_EN | S3C64XX_SPI_INT_TX_UNDERRUN_EN, sdd->regs + S3C64XX_SPI_INT_EN); - pm_runtime_set_active(&pdev->dev); - pm_runtime_enable(&pdev->dev); - ret = devm_spi_register_master(&pdev->dev, master); if (ret != 0) { dev_err(&pdev->dev, "cannot register SPI master: %d\n", ret); - goto err4; + goto err3; } dev_dbg(&pdev->dev, "Samsung SoC SPI Driver loaded for Bus SPI-%d with %d Slaves attached\n", @@ -1195,12 +1201,16 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) mem_res, (FIFO_LVL_MASK(sdd) >> 1) + 1, sdd->rx_dma.dmach, sdd->tx_dma.dmach); + pm_runtime_mark_last_busy(&pdev->dev); + pm_runtime_put_autosuspend(&pdev->dev); + return 0; -err4: +err3: + pm_runtime_put_noidle(&pdev->dev); pm_runtime_disable(&pdev->dev); pm_runtime_set_suspended(&pdev->dev); -err3: + clk_disable_unprepare(sdd->src_clk); err2: clk_disable_unprepare(sdd->clk); -- cgit v1.2.3 From 4fcd9b9e06d43b93d00bf02c767d578e7cf8b25c Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Thu, 3 Sep 2015 22:40:11 +0200 Subject: spi: s3c64xx: simplify suspend / resume handlers The runtime PM suspend / resume handlers take care of the enabling/ disabling the clocks already. Therefore replace the duplicated clock handling with pm_runtime_force_suspend/resume. Signed-off-by: Heiner Kallweit Reviewed-by: Krzysztof Kozlowski Signed-off-by: Mark Brown --- drivers/spi/spi-s3c64xx.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index d117fa638ee3..4e5931cabfa2 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1246,10 +1246,9 @@ static int s3c64xx_spi_suspend(struct device *dev) if (ret) return ret; - if (!pm_runtime_suspended(dev)) { - clk_disable_unprepare(sdd->clk); - clk_disable_unprepare(sdd->src_clk); - } + ret = pm_runtime_force_suspend(dev); + if (ret < 0) + return ret; sdd->cur_speed = 0; /* Output Clock is stopped */ @@ -1261,14 +1260,14 @@ static int s3c64xx_spi_resume(struct device *dev) struct spi_master *master = dev_get_drvdata(dev); struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); struct s3c64xx_spi_info *sci = sdd->cntrlr_info; + int ret; if (sci->cfg_gpio) sci->cfg_gpio(); - if (!pm_runtime_suspended(dev)) { - clk_prepare_enable(sdd->src_clk); - clk_prepare_enable(sdd->clk); - } + ret = pm_runtime_force_resume(dev); + if (ret < 0) + return ret; s3c64xx_spi_hwinit(sdd, sdd->port_id); -- cgit v1.2.3 From 8ebe9d163e93e10458f3fd7522f29f9149e58632 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Thu, 3 Sep 2015 22:40:53 +0200 Subject: spi: s3c64xx: replace clock disabling with runtime PM suspend call in remove function Simplify s3c64xx_spi_remove by replacing the clock disabling with calling runtime PM suspend which does the same. Waking up the device if it was suspended wouldn't be strictly needed for this driver but using pm_runtime_get_sync is cleaner and makes s3c64xx_spi_remove more consistent with the runtime PM handling in s3c64xx_spi_setup. pm_runtime_force_suspend does most of the work for us: disabling the clocks, disabling runtime PM and setting it to "suspended" state. Signed-off-by: Heiner Kallweit Reviewed-by: Krzysztof Kozlowski Signed-off-by: Mark Brown --- drivers/spi/spi-s3c64xx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 4e5931cabfa2..dee82e1ae65d 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1225,7 +1225,7 @@ static int s3c64xx_spi_remove(struct platform_device *pdev) struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); - pm_runtime_disable(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); writel(0, sdd->regs + S3C64XX_SPI_INT_EN); @@ -1233,6 +1233,10 @@ static int s3c64xx_spi_remove(struct platform_device *pdev) clk_disable_unprepare(sdd->clk); + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); + return 0; } -- cgit v1.2.3 From fc306de9b54e94a2949fee452741c00259d7dd4a Mon Sep 17 00:00:00 2001 From: Jarkko Nikula Date: Tue, 15 Sep 2015 16:26:13 +0300 Subject: spi: txx9: Use transfer speed unconditionally SPI core validates the transfer speed and defaults to spi->max_speed_hz in case the transfer speed is not set. Signed-off-by: Jarkko Nikula Signed-off-by: Mark Brown --- drivers/spi/spi-txx9.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-txx9.c b/drivers/spi/spi-txx9.c index 9190124b6d90..d69f8f8f3fa6 100644 --- a/drivers/spi/spi-txx9.c +++ b/drivers/spi/spi-txx9.c @@ -181,7 +181,7 @@ static void txx9spi_work_one(struct txx9spi *c, struct spi_message *m) u32 data; unsigned int len = t->len; unsigned int wsize; - u32 speed_hz = t->speed_hz ? : spi->max_speed_hz; + u32 speed_hz = t->speed_hz; u8 bits_per_word = t->bits_per_word; wsize = bits_per_word >> 3; /* in bytes */ -- cgit v1.2.3 From 88d4a7440e51754bd44f58fe1f8c6e6fe050e929 Mon Sep 17 00:00:00 2001 From: Jarkko Nikula Date: Tue, 15 Sep 2015 16:26:14 +0300 Subject: spi: s3c64xx: Use transfer speed unconditionally SPI core validates the transfer speed and defaults to spi->max_speed_hz in case the transfer speed is not set. Signed-off-by: Jarkko Nikula Signed-off-by: Mark Brown --- drivers/spi/spi-s3c64xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index dee82e1ae65d..8e86e7f6663a 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -683,7 +683,7 @@ static int s3c64xx_spi_transfer_one(struct spi_master *master, /* Only BPW and Speed may change across transfers */ bpw = xfer->bits_per_word; - speed = xfer->speed_hz ? : spi->max_speed_hz; + speed = xfer->speed_hz; if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) { sdd->cur_bpw = bpw; -- cgit v1.2.3 From 57c2ecd9bf971946ea0c6ae90a79c90a22159c73 Mon Sep 17 00:00:00 2001 From: Vignesh R Date: Tue, 13 Oct 2015 15:51:05 +0530 Subject: spi: spi-ti-qspi: switch to polling mode for better r/w performance Currently word completion interrupt is fired for transfer of every word(8bit to 128bit in size). This adds a lot of overhead, and decreases r/w throughput. It hardly takes 3us(@48MHz) for 128bit r/w to complete, hence its better to poll on word complete bit to be set in QSPI_SPI_STATUS_REG instead of using interrupts. This increases the throughput by 30% in both read and write case. So, switch to polling mode instead of interrupts to determine completion of word transfer. Signed-off-by: Vignesh R Signed-off-by: Mark Brown --- drivers/spi/spi-ti-qspi.c | 74 +++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 54 deletions(-) diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c index aa6d284131e0..89cf0c821524 100644 --- a/drivers/spi/spi-ti-qspi.c +++ b/drivers/spi/spi-ti-qspi.c @@ -39,8 +39,6 @@ struct ti_qspi_regs { }; struct ti_qspi { - struct completion transfer_complete; - /* list synchronization */ struct mutex list_lock; @@ -62,10 +60,6 @@ struct ti_qspi { #define QSPI_PID (0x0) #define QSPI_SYSCONFIG (0x10) -#define QSPI_INTR_STATUS_RAW_SET (0x20) -#define QSPI_INTR_STATUS_ENABLED_CLEAR (0x24) -#define QSPI_INTR_ENABLE_SET_REG (0x28) -#define QSPI_INTR_ENABLE_CLEAR_REG (0x2c) #define QSPI_SPI_CLOCK_CNTRL_REG (0x40) #define QSPI_SPI_DC_REG (0x44) #define QSPI_SPI_CMD_REG (0x48) @@ -97,7 +91,6 @@ struct ti_qspi { #define QSPI_RD_DUAL (3 << 16) #define QSPI_RD_QUAD (7 << 16) #define QSPI_INVAL (4 << 16) -#define QSPI_WC_CMD_INT_EN (1 << 14) #define QSPI_FLEN(n) ((n - 1) << 0) #define QSPI_WLEN_MAX_BITS 128 #define QSPI_WLEN_MAX_BYTES 16 @@ -106,10 +99,6 @@ struct ti_qspi { #define BUSY 0x01 #define WC 0x02 -/* INTERRUPT REGISTER */ -#define QSPI_WC_INT_EN (1 << 1) -#define QSPI_WC_INT_DISABLE (1 << 1) - /* Device Control */ #define QSPI_DD(m, n) (m << (3 + n * 8)) #define QSPI_CKPHA(n) (1 << (2 + n * 8)) @@ -217,6 +206,24 @@ static inline u32 qspi_is_busy(struct ti_qspi *qspi) return stat & BUSY; } +static inline int ti_qspi_poll_wc(struct ti_qspi *qspi) +{ + u32 stat; + unsigned long timeout = jiffies + QSPI_COMPLETION_TIMEOUT; + + do { + stat = ti_qspi_read(qspi, QSPI_SPI_STATUS_REG); + if (stat & WC) + return 0; + cpu_relax(); + } while (time_after(timeout, jiffies)); + + stat = ti_qspi_read(qspi, QSPI_SPI_STATUS_REG); + if (stat & WC) + return 0; + return -ETIMEDOUT; +} + static int qspi_write_msg(struct ti_qspi *qspi, struct spi_transfer *t) { int wlen, count, xfer_len; @@ -275,8 +282,7 @@ static int qspi_write_msg(struct ti_qspi *qspi, struct spi_transfer *t) } ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG); - if (!wait_for_completion_timeout(&qspi->transfer_complete, - QSPI_COMPLETION_TIMEOUT)) { + if (ti_qspi_poll_wc(qspi)) { dev_err(qspi->dev, "write timed out\n"); return -ETIMEDOUT; } @@ -315,8 +321,7 @@ static int qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t) return -EBUSY; ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG); - if (!wait_for_completion_timeout(&qspi->transfer_complete, - QSPI_COMPLETION_TIMEOUT)) { + if (ti_qspi_poll_wc(qspi)) { dev_err(qspi->dev, "read timed out\n"); return -ETIMEDOUT; } @@ -388,9 +393,7 @@ static int ti_qspi_start_transfer_one(struct spi_master *master, qspi->cmd = 0; qspi->cmd |= QSPI_EN_CS(spi->chip_select); qspi->cmd |= QSPI_FLEN(frame_length); - qspi->cmd |= QSPI_WC_CMD_INT_EN; - ti_qspi_write(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG); ti_qspi_write(qspi, qspi->dc, QSPI_SPI_DC_REG); mutex_lock(&qspi->list_lock); @@ -418,31 +421,6 @@ static int ti_qspi_start_transfer_one(struct spi_master *master, return status; } -static irqreturn_t ti_qspi_isr(int irq, void *dev_id) -{ - struct ti_qspi *qspi = dev_id; - u16 int_stat; - u32 stat; - - irqreturn_t ret = IRQ_HANDLED; - - int_stat = ti_qspi_read(qspi, QSPI_INTR_STATUS_ENABLED_CLEAR); - stat = ti_qspi_read(qspi, QSPI_SPI_STATUS_REG); - - if (!int_stat) { - dev_dbg(qspi->dev, "No IRQ triggered\n"); - ret = IRQ_NONE; - goto out; - } - - ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, - QSPI_INTR_STATUS_ENABLED_CLEAR); - if (stat & WC) - complete(&qspi->transfer_complete); -out: - return ret; -} - static int ti_qspi_runtime_resume(struct device *dev) { struct ti_qspi *qspi; @@ -551,22 +529,12 @@ static int ti_qspi_probe(struct platform_device *pdev) } } - ret = devm_request_irq(&pdev->dev, irq, ti_qspi_isr, 0, - dev_name(&pdev->dev), qspi); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n", - irq); - goto free_master; - } - qspi->fclk = devm_clk_get(&pdev->dev, "fck"); if (IS_ERR(qspi->fclk)) { ret = PTR_ERR(qspi->fclk); dev_err(&pdev->dev, "could not get clk: %d\n", ret); } - init_completion(&qspi->transfer_complete); - pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, QSPI_AUTOSUSPEND_TIMEOUT); pm_runtime_enable(&pdev->dev); @@ -596,8 +564,6 @@ static int ti_qspi_remove(struct platform_device *pdev) return ret; } - ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, QSPI_INTR_ENABLE_CLEAR_REG); - pm_runtime_put(qspi->dev); pm_runtime_disable(&pdev->dev); -- cgit v1.2.3 From e6b5140b706689a38aaeabd9de8fb3e1531cf9cb Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 29 Oct 2015 08:57:30 -0500 Subject: spi: ti-qspi: improve ->remove() callback there's no need to call pm_runtime_get_sync() followed by pm_runtime_put(). We should, instead, just call pm_runtime_put_sync() and pm_runtime_disable(). Signed-off-by: Felipe Balbi Signed-off-by: Mark Brown --- drivers/spi/spi-ti-qspi.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c index 89cf0c821524..432bcc374d50 100644 --- a/drivers/spi/spi-ti-qspi.c +++ b/drivers/spi/spi-ti-qspi.c @@ -555,16 +555,7 @@ free_master: static int ti_qspi_remove(struct platform_device *pdev) { - struct ti_qspi *qspi = platform_get_drvdata(pdev); - int ret; - - ret = pm_runtime_get_sync(qspi->dev); - if (ret < 0) { - dev_err(qspi->dev, "pm_runtime_get_sync() failed\n"); - return ret; - } - - pm_runtime_put(qspi->dev); + pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); return 0; -- cgit v1.2.3