linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: imx: remove CLK calculation and check for target mode
@ 2025-10-24  5:52 carlos.song
  2025-10-24 15:32 ` Frank Li
  2025-11-06 23:54 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: carlos.song @ 2025-10-24  5:52 UTC (permalink / raw)
  To: frank.li, broonie, shawnguo, s.hauer, kernel, festevam
  Cc: linux-spi, imx, linux-arm-kernel, linux-kernel

From: Clark Wang <xiaoning.wang@nxp.com>

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>
---
 drivers/spi/spi-imx.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 4ffee6c5d5c4..6eb4bfb7be4a 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -42,6 +42,7 @@ MODULE_PARM_DESC(polling_limit_us,
 		 "time in us to run a transfer in polling mode\n");
 
 #define MXC_RPM_TIMEOUT		2000 /* 2000ms */
+#define MXC_SPI_DEFAULT_SPEED	500000 /* 500KHz */
 
 #define MXC_CSPIRXDATA		0x00
 #define MXC_CSPITXDATA		0x04
@@ -692,8 +693,11 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
 	/* set clock speed */
 	ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET |
 		  0xf << MX51_ECSPI_CTRL_PREDIV_OFFSET);
-	ctrl |= mx51_ecspi_clkdiv(spi_imx, spi_imx->spi_bus_clk, &clk);
-	spi_imx->spi_bus_clk = clk;
+
+	if (!spi_imx->target_mode) {
+		ctrl |= mx51_ecspi_clkdiv(spi_imx, spi_imx->spi_bus_clk, &clk);
+		spi_imx->spi_bus_clk = clk;
+	}
 
 	mx51_configure_cpha(spi_imx, spi);
 
@@ -1316,15 +1320,18 @@ static int spi_imx_setupxfer(struct spi_device *spi,
 	if (!t)
 		return 0;
 
-	if (!t->speed_hz) {
-		if (!spi->max_speed_hz) {
-			dev_err(&spi->dev, "no speed_hz provided!\n");
-			return -EINVAL;
+	if (!spi_imx->target_mode) {
+		if (!t->speed_hz) {
+			if (!spi->max_speed_hz) {
+				dev_err(&spi->dev, "no speed_hz provided!\n");
+				return -EINVAL;
+			}
+			dev_dbg(&spi->dev, "using spi->max_speed_hz!\n");
+			spi_imx->spi_bus_clk = spi->max_speed_hz;
+		} else {
+			spi_imx->spi_bus_clk = t->speed_hz;
 		}
-		dev_dbg(&spi->dev, "using spi->max_speed_hz!\n");
-		spi_imx->spi_bus_clk = spi->max_speed_hz;
-	} else
-		spi_imx->spi_bus_clk = t->speed_hz;
+	}
 
 	spi_imx->bits_per_word = t->bits_per_word;
 	spi_imx->count = t->len;
@@ -1839,6 +1846,7 @@ static int spi_imx_probe(struct platform_device *pdev)
 	controller->prepare_message = spi_imx_prepare_message;
 	controller->unprepare_message = spi_imx_unprepare_message;
 	controller->target_abort = spi_imx_target_abort;
+	spi_imx->spi_bus_clk = MXC_SPI_DEFAULT_SPEED;
 	controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS |
 				SPI_MOSI_IDLE_LOW;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: imx: remove CLK calculation and check for target mode
  2025-10-24  5:52 [PATCH] spi: imx: remove CLK calculation and check for target mode carlos.song
@ 2025-10-24 15:32 ` Frank Li
  2025-11-06 23:54 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2025-10-24 15:32 UTC (permalink / raw)
  To: carlos.song
  Cc: broonie, shawnguo, s.hauer, kernel, festevam, linux-spi, imx,
	linux-arm-kernel, linux-kernel

On Fri, Oct 24, 2025 at 01:52:11PM +0800, carlos.song@nxp.com wrote:
> From: Clark Wang <xiaoning.wang@nxp.com>
>
> 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>

>  drivers/spi/spi-imx.c | 28 ++++++++++++++++++----------
>  1 file changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index 4ffee6c5d5c4..6eb4bfb7be4a 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -42,6 +42,7 @@ MODULE_PARM_DESC(polling_limit_us,
>  		 "time in us to run a transfer in polling mode\n");
>
>  #define MXC_RPM_TIMEOUT		2000 /* 2000ms */
> +#define MXC_SPI_DEFAULT_SPEED	500000 /* 500KHz */
>
>  #define MXC_CSPIRXDATA		0x00
>  #define MXC_CSPITXDATA		0x04
> @@ -692,8 +693,11 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
>  	/* set clock speed */
>  	ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET |
>  		  0xf << MX51_ECSPI_CTRL_PREDIV_OFFSET);
> -	ctrl |= mx51_ecspi_clkdiv(spi_imx, spi_imx->spi_bus_clk, &clk);
> -	spi_imx->spi_bus_clk = clk;
> +
> +	if (!spi_imx->target_mode) {
> +		ctrl |= mx51_ecspi_clkdiv(spi_imx, spi_imx->spi_bus_clk, &clk);
> +		spi_imx->spi_bus_clk = clk;
> +	}
>
>  	mx51_configure_cpha(spi_imx, spi);
>
> @@ -1316,15 +1320,18 @@ static int spi_imx_setupxfer(struct spi_device *spi,
>  	if (!t)
>  		return 0;
>
> -	if (!t->speed_hz) {
> -		if (!spi->max_speed_hz) {
> -			dev_err(&spi->dev, "no speed_hz provided!\n");
> -			return -EINVAL;
> +	if (!spi_imx->target_mode) {
> +		if (!t->speed_hz) {
> +			if (!spi->max_speed_hz) {
> +				dev_err(&spi->dev, "no speed_hz provided!\n");
> +				return -EINVAL;
> +			}
> +			dev_dbg(&spi->dev, "using spi->max_speed_hz!\n");
> +			spi_imx->spi_bus_clk = spi->max_speed_hz;
> +		} else {
> +			spi_imx->spi_bus_clk = t->speed_hz;
>  		}
> -		dev_dbg(&spi->dev, "using spi->max_speed_hz!\n");
> -		spi_imx->spi_bus_clk = spi->max_speed_hz;
> -	} else
> -		spi_imx->spi_bus_clk = t->speed_hz;
> +	}
>
>  	spi_imx->bits_per_word = t->bits_per_word;
>  	spi_imx->count = t->len;
> @@ -1839,6 +1846,7 @@ static int spi_imx_probe(struct platform_device *pdev)
>  	controller->prepare_message = spi_imx_prepare_message;
>  	controller->unprepare_message = spi_imx_unprepare_message;
>  	controller->target_abort = spi_imx_target_abort;
> +	spi_imx->spi_bus_clk = MXC_SPI_DEFAULT_SPEED;
>  	controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS |
>  				SPI_MOSI_IDLE_LOW;
>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: imx: remove CLK calculation and check for target mode
  2025-10-24  5:52 [PATCH] spi: imx: remove CLK calculation and check for target mode carlos.song
  2025-10-24 15:32 ` Frank Li
@ 2025-11-06 23:54 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2025-11-06 23:54 UTC (permalink / raw)
  To: frank.li, shawnguo, s.hauer, kernel, festevam, carlos.song
  Cc: linux-spi, imx, linux-arm-kernel, linux-kernel

On Fri, 24 Oct 2025 13:52:11 +0800, carlos.song@nxp.com wrote:
> 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.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: imx: remove CLK calculation and check for target mode
      commit: 55d03b5b5bdd04daf9a35ce49db18d8bb488dffb

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-06 23:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-24  5:52 [PATCH] spi: imx: remove CLK calculation and check for target mode carlos.song
2025-10-24 15:32 ` Frank Li
2025-11-06 23:54 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).