2021-04-27 08:52:08

by Clark Wang

[permalink] [raw]
Subject: [PATCH] spi: imx: remove CLK calculation and divider in slave mode

In the slave mode, the clock signal is controlled by the master.
The slave does not need to calculate and configure the clock
frequency division. The slave can directly use the root clock
to sample the SCL signal.
Therefore, remove the calculation and frequency division
function of the clock in the slave mode.

Signed-off-by: Clark Wang <[email protected]>
---
Please remove the patch(4df2f5e1372e spi: imx: add a check for speed_hz before
calculating the clock) first and then apply this patch.
Sorry about this. Thank you!
---
drivers/spi/spi-imx.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 24ba7ab1b05d..68cdd87404f6 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -33,6 +33,7 @@ module_param(use_dma, bool, 0644);
MODULE_PARM_DESC(use_dma, "Enable usage of DMA when available (default)");

#define MXC_RPM_TIMEOUT 2000 /* 2000ms */
+#define MXC_DEFAULT_SPEED 500000 /* 500KHz */

#define MXC_CSPIRXDATA 0x00
#define MXC_CSPITXDATA 0x04
@@ -599,8 +600,10 @@ 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, t->speed_hz, &clk);
- spi_imx->spi_bus_clk = clk;
+ if (!spi_imx->slave_mode) {
+ ctrl |= mx51_ecspi_clkdiv(spi_imx, t->speed_hz, &clk);
+ spi_imx->spi_bus_clk = clk;
+ }

if (spi_imx->usedma)
ctrl |= MX51_ECSPI_CTRL_SMC;
@@ -717,9 +720,11 @@ static int mx31_prepare_transfer(struct spi_imx_data *spi_imx,
unsigned int reg = MX31_CSPICTRL_ENABLE | MX31_CSPICTRL_MASTER;
unsigned int clk;

- reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, t->speed_hz, &clk) <<
- MX31_CSPICTRL_DR_SHIFT;
- spi_imx->spi_bus_clk = clk;
+ if (!spi_imx->slave_mode) {
+ reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, t->speed_hz, &clk) <<
+ MX31_CSPICTRL_DR_SHIFT;
+ spi_imx->spi_bus_clk = clk;
+ }

if (is_imx35_cspi(spi_imx)) {
reg |= (spi_imx->bits_per_word - 1) << MX35_CSPICTRL_BL_SHIFT;
@@ -823,9 +828,11 @@ static int mx21_prepare_transfer(struct spi_imx_data *spi_imx,
unsigned int max = is_imx27_cspi(spi_imx) ? 16 : 18;
unsigned int clk;

- reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, t->speed_hz, max, &clk)
- << MX21_CSPICTRL_DR_SHIFT;
- spi_imx->spi_bus_clk = clk;
+ if (!spi_imx->slave_mode) {
+ reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, t->speed_hz, max, &clk)
+ << MX21_CSPICTRL_DR_SHIFT;
+ spi_imx->spi_bus_clk = clk;
+ }

reg |= spi_imx->bits_per_word - 1;

@@ -898,9 +905,11 @@ static int mx1_prepare_transfer(struct spi_imx_data *spi_imx,
unsigned int reg = MX1_CSPICTRL_ENABLE | MX1_CSPICTRL_MASTER;
unsigned int clk;

- reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, t->speed_hz, &clk) <<
- MX1_CSPICTRL_DR_SHIFT;
- spi_imx->spi_bus_clk = clk;
+ if (!spi_imx->slave_mode) {
+ reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, t->speed_hz, &clk) <<
+ MX1_CSPICTRL_DR_SHIFT;
+ spi_imx->spi_bus_clk = clk;
+ }

reg |= spi_imx->bits_per_word - 1;

@@ -1485,8 +1494,6 @@ static int spi_imx_transfer(struct spi_device *spi,
{
struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);

- transfer->effective_speed_hz = spi_imx->spi_bus_clk;
-
/* flush rxfifo before transfer */
while (spi_imx->devtype_data->rx_available(spi_imx))
readl(spi_imx->base + MXC_CSPIRXDATA);
@@ -1494,6 +1501,8 @@ static int spi_imx_transfer(struct spi_device *spi,
if (spi_imx->slave_mode)
return spi_imx_pio_transfer_slave(spi, transfer);

+ transfer->effective_speed_hz = spi_imx->spi_bus_clk;
+
if (spi_imx->usedma)
return spi_imx_dma_transfer(spi_imx, transfer);

@@ -1593,6 +1602,7 @@ static int spi_imx_probe(struct platform_device *pdev)
spi_imx->bitbang.master = master;
spi_imx->dev = &pdev->dev;
spi_imx->slave_mode = slave_mode;
+ spi_imx->spi_bus_clk = MXC_DEFAULT_SPEED;

spi_imx->devtype_data = devtype_data;

--
2.25.1


2021-04-27 11:23:48

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] spi: imx: remove CLK calculation and divider in slave mode

On Tue, Apr 27, 2021 at 04:52:11PM +0800, Clark Wang wrote:

> ---
> Please remove the patch(4df2f5e1372e spi: imx: add a check for speed_hz before
> calculating the clock) first and then apply this patch.
> Sorry about this. Thank you!
> ---

Please resumbit with a revert (with appropriate changelog) either sent
in a series with this or just squashed into this patch.


Attachments:
(No filename) (381.00 B)
signature.asc (499.00 B)
Download all attachments