spi: mxc_spi: Set master mode for all channels
Subsystems (2)
Fabio Estevam
reviewerPATCH 1/1 spi: mxc_spi: Set master mode for all channels
From: Fabio Estevam <[email protected]>
The glitch in the SPI clock line, which commit 3cea335c34 (spi: mxc_spi: Fix spi clock glitch durant reset) solved, is back now and itwas re-introduced by commit d36b39bf0d (spi: mxc_spi: Fix ECSPI reset handling).
Actually the glitch is happening due to always toggling between slave mode and master mode by configuring the CHANNEL_MODE bits in this reset function.
Since the spi driver only supports master mode, set the mode for all channels always to master mode in order to have a stable, "glitch-free" SPI clock line.
--- drivers/spi/mxc_spi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/spi/mxc_spi.c +8 -3
@@ -137,9 +137,14 @@ static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs,return -1 ; } -/* Reset spi */ -reg_write (®s->ctrl,0 ); -reg_write (®s->ctrl,MXC_CSPICTRL_EN ); +/* +* Reset SPI and set all CSs to master mode, if toggling +* between slave and master mode we might see a glitch +* on the clock line +*/ +reg_write (®s->ctrl,0x000000F0 ); + reg_ctrl =reg_read (®s->ctrl); +reg_write (®s->ctrl, reg_ctrl |MXC_CSPICTRL_EN ); reg_ctrl =reg_read (®s->ctrl);
Signature · 1 line
1.7.9.5
PATCH 1/1 spi: mxc_spi: Set master mode for all channels
Am 06.04.2013 15:15, schrieb Fabio Estevam:
Quoted 11 lines
From: Fabio Estevam <[email protected]>
The glitch in the SPI clock line, which commit
3cea335c34(spi:mxc_spi: Fix spi clock glitch durant reset) solved, is back now and itwas re-introduced by commitd36b39bf0d(spi:mxc_spi: Fix ECSPI reset handling).Actually the glitch is happening due to always toggling between slave mode and master mode by configuring the
CHANNEL_MODEbits in this reset function.Since the spi driver only supports master mode, set the mode for all channels always to master mode in order to have a stable, "glitch-free" SPI clock line.
Ok, thanks, I wasn't aware of this.
Quoted 10 lines
Signed-off-by Fabio Estevam <[email protected]>--- drivers/spi/mxc_spi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/spi/mxc_spi.c +0
-0
drivers/spi/mxc_spi.c static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs, · line 141
Quoted 8 lines
drivers/spi/mxc_spi.c +2
-3@@ -137,9 +137,14 @@ static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs,return -1 ; } -/* Reset spi */ -reg_write (®s->ctrl,0 ); -reg_write (®s->ctrl,MXC_CSPICTRL_EN ); +/* +* Reset SPI and set all CSs to master mode,
I haven't checked the rest of the driver, but do we touch the CSs bits anywhere else, too? Could that parts dropped with this patch, then. I.e. never touch the bits regs->ctrl[7-4] again?
drivers/spi/mxc_spi.c static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs, · line 145
Quoted 5 lines
drivers/spi/mxc_spi.c +4
-0if toggling +* between slave and master mode we might see a glitch +* on the clock line +*/ +reg_write (®s->ctrl,0x000000F0 );
Do we have a macro for the 0xF?
drivers/spi/mxc_spi.c static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs, · line 146
Quoted 1 line
drivers/spi/mxc_spi.c +1
-0+ reg_ctrl =reg_read (®s->ctrl);
Do we expect reg_ctrl to be 0x000000F0 then? If yes, do we have to really read it here? If we read it here, should we drop the read below, then?
drivers/spi/mxc_spi.c static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs, · line 149
Quoted 3 lines
drivers/spi/mxc_spi.c +1
-0+reg_write (®s->ctrl, reg_ctrl |MXC_CSPICTRL_EN ); reg_ctrl =reg_read (®s->ctrl);
So, as mentioned by Stefano before, I'd propose to either
a) do the reg_read(®s->ctrl); only _once_. E.g.
/*
* Reset SPI and set all CSs to master mode, if toggling
* between slave and master mode we might see a glitch
* on the clock line
*/reg_write(®s->ctrl, 0x000000F0); /* FIXME: use a macro here*/ reg_ctrl = reg_read(®s->ctrl) | MXC_CSPICTRL_EN; /* Reading back the register content is done because we don't get back the value written above */reg_write(®s->ctrl, reg_ctrl);
=> no additional read of reg_ctrl needed here as reg_ctrl contains already the recent register content <=
or
b) _never_ read back the register. E.g.
/*
* Reset SPI and set all CSs to master mode, if toggling
* between slave and master mode we might see a glitch
* on the clock line
*/reg_ctrl = 0x000000F0; /* FIXME: use a macro here*/ reg_write(®s->ctrl, reg_ctrl);reg_ctrl |= MXC_CSPICTRL_EN;reg_write(®s->ctrl, reg_ctrl);
=> no additional read of reg_ctrl needed here as reg_ctrl contains already the recent register content <=
Would one of these options work?
Best regards
Dirk