Skip to content

Commit 632556d

Browse files
leilkliubroonie
authored andcommitted
spi: mt65xx: add PM QoS support
Enable Quality of Service(QoS) support to speed up interrupt service routine handle. Sometimes, a gic interrupt will be generated after SPI transmission, but at this time the CPU is in an idle state and the processing handler will be very slow. It takes time to exit the idle state and then become active. This will cause the SPI handler to execute slowly and cause SPI transfer timeouts. Signed-off-by: Leilk Liu <leilk.liu@mediatek.com> Link: https://patch.msgid.link/20250304024045.7788-1-leilk.liu@mediatek.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 02a838b commit 632556d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/spi/spi-mt65xx.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/spi/spi.h>
2121
#include <linux/spi/spi-mem.h>
2222
#include <linux/dma-mapping.h>
23+
#include <linux/pm_qos.h>
2324

2425
#define SPI_CFG0_REG 0x0000
2526
#define SPI_CFG1_REG 0x0004
@@ -147,6 +148,7 @@ struct mtk_spi_compatible {
147148
* @tx_sgl_len: Size of TX DMA transfer
148149
* @rx_sgl_len: Size of RX DMA transfer
149150
* @dev_comp: Device data structure
151+
* @qos_request: QoS request
150152
* @spi_clk_hz: Current SPI clock in Hz
151153
* @spimem_done: SPI-MEM operation completion
152154
* @use_spimem: Enables SPI-MEM
@@ -166,6 +168,7 @@ struct mtk_spi {
166168
struct scatterlist *tx_sgl, *rx_sgl;
167169
u32 tx_sgl_len, rx_sgl_len;
168170
const struct mtk_spi_compatible *dev_comp;
171+
struct pm_qos_request qos_request;
169172
u32 spi_clk_hz;
170173
struct completion spimem_done;
171174
bool use_spimem;
@@ -356,6 +359,7 @@ static int mtk_spi_hw_init(struct spi_controller *host,
356359
struct mtk_chip_config *chip_config = spi->controller_data;
357360
struct mtk_spi *mdata = spi_controller_get_devdata(host);
358361

362+
cpu_latency_qos_update_request(&mdata->qos_request, 500);
359363
cpha = spi->mode & SPI_CPHA ? 1 : 0;
360364
cpol = spi->mode & SPI_CPOL ? 1 : 0;
361365

@@ -459,6 +463,15 @@ static int mtk_spi_prepare_message(struct spi_controller *host,
459463
return mtk_spi_hw_init(host, msg->spi);
460464
}
461465

466+
static int mtk_spi_unprepare_message(struct spi_controller *host,
467+
struct spi_message *message)
468+
{
469+
struct mtk_spi *mdata = spi_controller_get_devdata(host);
470+
471+
cpu_latency_qos_update_request(&mdata->qos_request, PM_QOS_DEFAULT_VALUE);
472+
return 0;
473+
}
474+
462475
static void mtk_spi_set_cs(struct spi_device *spi, bool enable)
463476
{
464477
u32 reg_val;
@@ -1143,6 +1156,7 @@ static int mtk_spi_probe(struct platform_device *pdev)
11431156

11441157
host->set_cs = mtk_spi_set_cs;
11451158
host->prepare_message = mtk_spi_prepare_message;
1159+
host->unprepare_message = mtk_spi_unprepare_message;
11461160
host->transfer_one = mtk_spi_transfer_one;
11471161
host->can_dma = mtk_spi_can_dma;
11481162
host->setup = mtk_spi_setup;
@@ -1249,6 +1263,8 @@ static int mtk_spi_probe(struct platform_device *pdev)
12491263
clk_disable_unprepare(mdata->spi_hclk);
12501264
}
12511265

1266+
cpu_latency_qos_add_request(&mdata->qos_request, PM_QOS_DEFAULT_VALUE);
1267+
12521268
if (mdata->dev_comp->need_pad_sel) {
12531269
if (mdata->pad_num != host->num_chipselect)
12541270
return dev_err_probe(dev, -EINVAL,
@@ -1292,6 +1308,7 @@ static void mtk_spi_remove(struct platform_device *pdev)
12921308
struct mtk_spi *mdata = spi_controller_get_devdata(host);
12931309
int ret;
12941310

1311+
cpu_latency_qos_remove_request(&mdata->qos_request);
12951312
if (mdata->use_spimem && !completion_done(&mdata->spimem_done))
12961313
complete(&mdata->spimem_done);
12971314

0 commit comments

Comments
 (0)