Skip to content

Commit 55d03b5

Browse files
wangxiaoningnxpbroonie
authored andcommitted
spi: imx: remove CLK calculation and check for target mode
In target mode, the clock signal is controlled by the master. Target does not need to check, calculate and configure the clock frequency division. The target can directly use the root clock to sample the SCL signal. Therefore, remove check, calculation and frequency division function of the clock for target mode. Signed-off-by: Carlos Song <carlos.song@nxp.com> Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20251024055211.408440-1-carlos.song@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2f538ef commit 55d03b5

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

drivers/spi/spi-imx.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ MODULE_PARM_DESC(polling_limit_us,
4242
"time in us to run a transfer in polling mode\n");
4343

4444
#define MXC_RPM_TIMEOUT 2000 /* 2000ms */
45+
#define MXC_SPI_DEFAULT_SPEED 500000 /* 500KHz */
4546

4647
#define MXC_CSPIRXDATA 0x00
4748
#define MXC_CSPITXDATA 0x04
@@ -684,8 +685,11 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
684685
/* set clock speed */
685686
ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET |
686687
0xf << MX51_ECSPI_CTRL_PREDIV_OFFSET);
687-
ctrl |= mx51_ecspi_clkdiv(spi_imx, spi_imx->spi_bus_clk, &clk);
688-
spi_imx->spi_bus_clk = clk;
688+
689+
if (!spi_imx->target_mode) {
690+
ctrl |= mx51_ecspi_clkdiv(spi_imx, spi_imx->spi_bus_clk, &clk);
691+
spi_imx->spi_bus_clk = clk;
692+
}
689693

690694
mx51_configure_cpha(spi_imx, spi);
691695

@@ -1308,15 +1312,18 @@ static int spi_imx_setupxfer(struct spi_device *spi,
13081312
if (!t)
13091313
return 0;
13101314

1311-
if (!t->speed_hz) {
1312-
if (!spi->max_speed_hz) {
1313-
dev_err(&spi->dev, "no speed_hz provided!\n");
1314-
return -EINVAL;
1315+
if (!spi_imx->target_mode) {
1316+
if (!t->speed_hz) {
1317+
if (!spi->max_speed_hz) {
1318+
dev_err(&spi->dev, "no speed_hz provided!\n");
1319+
return -EINVAL;
1320+
}
1321+
dev_dbg(&spi->dev, "using spi->max_speed_hz!\n");
1322+
spi_imx->spi_bus_clk = spi->max_speed_hz;
1323+
} else {
1324+
spi_imx->spi_bus_clk = t->speed_hz;
13151325
}
1316-
dev_dbg(&spi->dev, "using spi->max_speed_hz!\n");
1317-
spi_imx->spi_bus_clk = spi->max_speed_hz;
1318-
} else
1319-
spi_imx->spi_bus_clk = t->speed_hz;
1326+
}
13201327

13211328
spi_imx->bits_per_word = t->bits_per_word;
13221329
spi_imx->count = t->len;
@@ -1831,6 +1838,7 @@ static int spi_imx_probe(struct platform_device *pdev)
18311838
controller->prepare_message = spi_imx_prepare_message;
18321839
controller->unprepare_message = spi_imx_unprepare_message;
18331840
controller->target_abort = spi_imx_target_abort;
1841+
spi_imx->spi_bus_clk = MXC_SPI_DEFAULT_SPEED;
18341842
controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS |
18351843
SPI_MOSI_IDLE_LOW;
18361844

0 commit comments

Comments
 (0)