@@ -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;
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 <xiaoning.wang@nxp.com> --- 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(-)