spi-imx: Add loopback mode support
Subsystems (2)
PATCH 1/1 spi-imx: Add loopback mode support
From: Fabio Estevam <[email protected]>
Loopback mode can be activated by setting bit LBC (LoopBack Control) of register ECSPI_TESTREG.
Add support for it.
--- drivers/spi/spi-imx.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/spi/spi-imx.c +13 -2
@@ -244,6 +244,9 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,#define MX51_ECSPI_STAT 0x18#define MX51_ECSPI_STAT_RR (1 << 3) +#define MX51_ECSPI_TESTREG 0x20 +#define MX51_ECSPI_TESTREG_LBC BIT(31) +/* MX51 eCSPI */ static unsigned int mx51_ecspi_clkdiv (unsigned int fin,unsigned int fspi,unsigned int *fres)
@@ -313,7 +316,7 @@ static int __maybe_unused mx51_ecspi_config(struct spi_imx_data *spi_imx, {u32 ctrl =MX51_ECSPI_CTRL_ENABLE , cfg =0 , dma =0 ;u32 tx_wml_cfg, rx_wml_cfg, rxt_wml_cfg; -u32 clk = config->speed_hz, delay; +u32 clk = config->speed_hz, delay, reg;/* * The hardware seems to have a race condition when changing modes. The
@@ -351,6 +354,13 @@ static int __maybe_unused mx51_ecspi_config(struct spi_imx_data *spi_imx,else cfg &= ~MX51_ECSPI_CONFIG_SSBPOL (config->cs); + reg =readl (spi_imx->base +MX51_ECSPI_TESTREG ); +if (config->mode &SPI_LOOP ) + reg |=MX51_ECSPI_TESTREG_LBC ; +else + reg &= ~MX51_ECSPI_TESTREG_LBC ; +writel (reg, spi_imx->base +MX51_ECSPI_TESTREG ); +writel (ctrl, spi_imx->base +MX51_ECSPI_CTRL );writel (cfg, spi_imx->base +MX51_ECSPI_CONFIG );
@@ -1141,7 +1151,8 @@ static int spi_imx_probe(struct platform_device *pdev) spi_imx->bitbang.master->cleanup = spi_imx_cleanup; spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message; spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message; - spi_imx->bitbang.master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH ; + spi_imx->bitbang.master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH | +SPI_LOOP ;init_completion (&spi_imx->xfer_done);
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1449192204-24877-1-git-send-email-festevam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 50 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Loopback mode can be activated by setting bit LBC (LoopBack Control) of register
ECSPI_TESTREG.Add support for it.
Signed-off-by Fabio Estevam <[email protected]>--- drivers/spi/spi-imx.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/spi/spi-imx.c +11
-1@@ -244,6 +244,9 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,#define MX51_ECSPI_STAT 0x18#define MX51_ECSPI_STAT_RR (1 << 3) +#define MX51_ECSPI_TESTREG 0x20 +#define MX51_ECSPI_TESTREG_LBC BIT(31) +/* MX51 eCSPI */ static unsigned int mx51_ecspi_clkdiv (unsigned int fin,unsigned int fspi,unsigned int *fres)@@ -313,7 +316,7 @@ static int __maybe_unused mx51_ecspi_config(struct spi_imx_data *spi_imx, {u32 ctrl =MX51_ECSPI_CTRL_ENABLE , cfg =0 , dma =0 ;u32 tx_wml_cfg, rx_wml_cfg, rxt_wml_cfg; -u32 clk = config->speed_hz, delay; +u32 clk = config->speed_hz, delay, reg;/* * The hardware seems to have a race condition when changing modes. The @@ -351,6 +354,13 @@ static int __maybe_unused mx51_ecspi_config(struct spi_imx_data *spi_imx,else cfg &= ~MX51_ECSPI_CONFIG_SSBPOL (config->cs); + reg =readl (spi_imx->base +MX51_ECSPI_TESTREG ); +if (config->mode &SPI_LOOP ) + reg |=MX51_ECSPI_TESTREG_LBC ; +else + reg &= ~MX51_ECSPI_TESTREG_LBC ; +writel (reg, spi_imx->base +MX51_ECSPI_TESTREG ); +writel (ctrl, spi_imx->base +MX51_ECSPI_CTRL );writel (cfg, spi_imx->base +MX51_ECSPI_CONFIG );
drivers/spi/spi-imx.c static int spi_imx_probe(struct platform_device *pdev) · line 1155
Quoted 6 lines
drivers/spi/spi-imx.c +2
-1@@ -1141,7 +1151,8 @@ static int spi_imx_probe(struct platform_device *pdev) spi_imx->bitbang.master->cleanup = spi_imx_cleanup; spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message; spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message; - spi_imx->bitbang.master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH ; + spi_imx->bitbang.master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH | +SPI_LOOP ;
The SPI_LOOP should not be added to all spi versions, only for the mx51/mx53/mx6q type.
Just realized that Anton sent the loopback support as part of his series, so please discard this one.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAOMZO5AejRorUv6TKH90t-VpsSGd6NiH9cCTJC5-QuMpiGPOPw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 5 lines · Fabio Estevam
The
SPI_LOOPshould not be added to all spi versions, only for the mx51/mx53/mx6q type.Just realized that Anton sent the loopback support as part of his series, so please discard this one.
I'd already applied this before you sent your mail, sorry.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · Mark Brown
Quoted 5 lines · Fabio Estevam
The
SPI_LOOPshould not be added to all spi versions, only for the mx51/mx53/mx6q type.Just realized that Anton sent the loopback support as part of his series, so please discard this one.
I'd already applied this before you sent your mail, sorry.
I'll rebase my changes on top of topic/imx. Is it OK?
Regards, Anton
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Anton Bondarenko
Quoted 1 line · Mark Brown
I'd already applied this before you sent your mail, sorry.
I'll rebase my changes on top of topic/imx. Is it OK?
Yes, totally fine - please go ahead.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Mark Brown
Quoted 5 lines · Anton Bondarenko
Quoted 1 line · Mark Brown
I'd already applied this before you sent your mail, sorry.
I'll rebase my changes on top of topic/imx. Is it OK?
Yes, totally fine - please go ahead.
Fix for this commit provided in [PATCH v6 01/08].
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Mark Brown
Quoted 5 lines · Fabio Estevam
The
SPI_LOOPshould not be added to all spi versions, only for the mx51/mx53/mx6q type.Just realized that Anton sent the loopback support as part of his series, so please discard this one.
I'd already applied this before you sent your mail, sorry.
No problekm, Mark. I think Anton can move the SPI_LOOP flag from the probe function to only mx51/mx53/mx6 config and all will be fine.
Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAOMZO5BrOgOvupBXRcK=iLYmbViKMjQE6xYi6HwU71Twjt2O0A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 9 lines · Fabio Estevam
Quoted 8 lines · Mark Brown
Quoted 5 lines · Fabio Estevam
The
SPI_LOOPshould not be added to all spi versions, only for the mx51/mx53/mx6q type.Just realized that Anton sent the loopback support as part of his series, so please discard this one.
Quoted 7 lines
Quoted 1 line
I'd already applied this before you sent your mail, sorry.
No problekm, Mark. I think Anton can move the
SPI_LOOPflag from the probe function to only mx51/mx53/mx6 config and all will be fine.Thanks
There is a small problem with this change. Loopback mode not enabled for first transaction in the system. This is happen because TEST reg written before controller taken out from the reset by writing to CTRL reg. The simple fix will be to move TEST reg read/write after write to CTRL reg.
Regards, Anton
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Anton,
Quoted 5 lines · Anton Bondarenko
There is a small problem with this change. Loopback mode not enabled for first transaction in the system. This is happen because TEST reg written before controller taken out from the reset by writing to CTRL reg. The simple fix will be to move TEST reg read/write after write to CTRL reg.
Could you please fix this as part of your series?
Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html