spi: new feature and fix for Marvell Orion driver
v2 cover spi: new feature and fix for Marvell Orion driver
From: Konstantin Porotchkin <[email protected]>
This patch set contains the following changes:
- support for switching CS for every transferred byte
- fix for the clock by enabling it for every call to spi_setup()
v2:
- remove DTS entry for single byte CS, use existing SPI_CS_WORD flag
- drop changes to core SPI driver
- fix the wrong first patch signature
Marcin Wojtas (2):
spi: orion: enable clocks before spi_setup
spi: orion: enable support for switching CS every transferred byte
drivers/spi/spi-orion.c | 34 +++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
PATCH v2 1/2 spi: orion: enable clocks before spi_setup
From: Marcin Wojtas <[email protected]>
The spi-orion driver disables its clocks whenever it is not used. In usual case during boot (i.e. using SPI flash) it is not a problem, as the child device driver is present and probed along with spi_register_master() execution.
However in case the child device driver is not ready (e.g. when its type is module_spi_driver) the spi_setup() callback can be called after the spi-orion probe. It may happen, that as a result there will be an attempt to access controller's registers with the clocks disabled.
Prevent such situations and make sure the clocks are on, each time the spi_setup() is called.
--- drivers/spi/spi-orion.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/spi/spi-orion.c +10 -0
@@ -507,6 +507,16 @@ static int orion_spi_transfer_one(struct spi_master *master,static int orion_spi_setup (struct spi_device *spi) { +struct orion_spi *orion_spi =spi_master_get_devdata (spi->master); + +/* +* Make sure the clocks are enabled before +* configuring the SPI controller. +*/ +clk_prepare_enable (orion_spi->clk); +if (!IS_ERR (orion_spi->axi_clk)) +clk_prepare_enable (orion_spi->axi_clk); +return orion_spi_setup_transfer (spi,NULL ); }
Signature · 1 line
2.17.1
Mark Brown
maintainerRe: [PATCH v2 1/2] spi: orion: enable clocks before spi_setup
drivers/spi/spi-orion.c static int orion_spi_transfer_one(struct spi_master *master, · line 521
Quoted 10 lines · On Thu, Dec 17, 2020 at 07:09:31PM +0200, [email protected] wrote:
drivers/spi/spi-orion.c +8
-0+/* +* Make sure the clocks are enabled before +* configuring the SPI controller. +*/ +clk_prepare_enable (orion_spi->clk); +if (!IS_ERR (orion_spi->axi_clk)) +clk_prepare_enable (orion_spi->axi_clk); +return orion_spi_setup_transfer (spi,NULL ); }
There's no matching disable here so we'll leak the enables every time setup() is called - we should unwind the enables after calling _setup_transfer(). It may be more sensible to just take a runtime PM reference rather than do the raw clock API stuff, one less call and means if anything else gets added to runtime PM it'll be handled.
RE: [EXT] Re: [PATCH v2 1/2] spi: orion: enable clocks before spi_setup
Hi, Mark,
Quoted 18 lines
-----Original Message-----
From: Mark Brown <[email protected]>drivers/spi/spi-orion.c static int orion_spi_transfer_one(struct spi_master *master,
Quoted 9 lines
drivers/spi/spi-orion.c +8
-0+/* +* Make sure the clocks are enabled before +* configuring the SPI controller. +*/ +clk_prepare_enable (orion_spi->clk); +if (!IS_ERR (orion_spi->axi_clk)) +clk_prepare_enable (orion_spi->axi_clk); +return orion_spi_setup_transfer (spi,NULL ); }There's no matching disable here so we'll leak the enables every time
setup()is called - we should unwind the enables after calling_setup_transfer(). It may be more sensible to just take a runtime PM reference rather than do the raw clock API stuff, one less call and means if anything else gets added to runtime PM it'll be handled.
[KP] You mean we should call here to orion_spi_runtime_resume() instead of clk_prepare_enable() and make this PM function available regardless the CONFIG_PM option?
Thanks
Kosta
Mark Brown
maintainerRe: [EXT] Re: [PATCH v2 1/2] spi: orion: enable clocks before spi_setup
On Tue, Dec 22, 2020 at 12:46:01PM +0000, Kostya Porotchkin wrote:
Please fix your mail client to word wrap within paragraphs at something substantially less than 80 columns. Doing this makes your messages much easier to read and reply to.
Quoted 9 lines
Quoted 5 lines
There's no matching disable here so we'll leak the enables every time
setup()is called - we should unwind the enables after calling_setup_transfer(). It may be more sensible to just take a runtime PM reference rather than do the raw clock API stuff, one less call and means if anything else gets added to runtime PM it'll be handled.[KP] You mean we should call here to
orion_spi_runtime_resume()instead ofclk_prepare_enable()and make this PM function available regardless theCONFIG_PMoption?
That's one part of the suggestion, yes - the other part is that you need to have a disable matching the enable here.
PATCH v2 2/2 spi: orion: enable support for switching CS every transferred byte
In reply to [email protected]From: Marcin Wojtas <[email protected]>
Some SPI devices, require toggling the CS every transferred byte. Enable such possibility in the spi-orion driver.
Note that in order to use it, in the driver of a secondary device attached to this controller, the SPI bus 'mode' field must be updated with SPI_CS_WORD flag before calling spi_setup() routine.
In addition to that include a work-around - some devices, such as certain models of SLIC (Subscriber Line Interface Card), may require extra delay after CS toggling, so add a minimal timing relaxation in relevant places.
--- drivers/spi/spi-orion.c | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/spi/spi-orion.c +23 -1
@@ -369,8 +369,15 @@ orion_spi_write_read_8bit(struct spi_device *spi, {void __iomem *tx_reg, *rx_reg, *int_reg;struct orion_spi *orion_spi; +bool cs_single_byte; + + cs_single_byte = spi->mode &SPI_CS_WORD ; orion_spi =spi_master_get_devdata (spi->master); + +if (cs_single_byte) +orion_spi_set_cs (spi,0 ); + tx_reg =spi_reg (orion_spi,ORION_SPI_DATA_OUT_REG ); rx_reg =spi_reg (orion_spi,ORION_SPI_DATA_IN_REG ); int_reg =spi_reg (orion_spi,ORION_SPI_INT_CAUSE_REG );
@@ -384,6 +391,11 @@ orion_spi_write_read_8bit(struct spi_device *spi,writel (0 , tx_reg);if (orion_spi_wait_till_ready (orion_spi) <0 ) { +if (cs_single_byte) { +orion_spi_set_cs (spi,1 ); +/* Satisfy some SLIC devices requirements */ +udelay (4 ); + }dev_err (&spi->dev,"TXS timed out\n" );return -1 ; }
@@ -391,6 +403,16 @@ orion_spi_write_read_8bit(struct spi_device *spi,if (rx_buf && *rx_buf) *(*rx_buf)++ =readl (rx_reg); +if (cs_single_byte) { +orion_spi_set_cs (spi,1 ); +/* +* Some devices, such as certain models of SLIC +* (Subscriber Line Interface Card) +* may require extra delay after CS toggling. +*/ +udelay (4 ); + } +return 1 ; }
@@ -626,7 +648,7 @@ static int orion_spi_probe(struct platform_device *pdev) }/* we support all 4 SPI modes and LSB first option */ - master->mode_bits =SPI_CPHA |SPI_CPOL |SPI_LSB_FIRST ; + master->mode_bits =SPI_CPHA |SPI_CPOL |SPI_LSB_FIRST |SPI_CS_WORD ; master->set_cs = orion_spi_set_cs; master->transfer_one = orion_spi_transfer_one; master->num_chipselect =ORION_NUM_CHIPSELECTS ;
Signature · 1 line
2.17.1
Mark Brown
maintainerRe: [PATCH v2 2/2] spi: orion: enable support for switching CS every transferred byte
Review orion_spi_write_read_8bit(struct spi_device *spi, · line 369
Quoted 3 lines · On Thu, Dec 17, 2020 at 07:09:32PM +0200, [email protected] wrote:
+++
b/drivers/spi/spi-orion.c(quoted diff) +0
-0@@ -369,8 +369,15 @@ orion_spi_write_read_8bit(struct spi_device *spi, {
This is only supporting SPI_CS_WORD for 8 bit operations but the driver also supports 16 bit words, it should at least report an error if there's an attempt to use SPI_CS_WORD for 16 bit transfers. It also looks like this won't work on systems where direct access is supported since those use a separate I/O path, that can be fixed by just adding an additional check when deciding to go down that path.
The driver should also pay attention to SPI_CS_HIGH if it's going to try to control chip select by hand as it does, which is generally frowned upon. TBH I'm wondering if it might not be better to just rely on the core support for implementing SPI_CS_WORD on controllers that can't do it in hardware - it *is* much higher overhead since it needs to split the transfers up but it depends how performance critical and frequent access to such devices is likely to be.
v2 cover spi: new feature and fix for Marvell Orion driver
In reply to [email protected]From: Konstantin Porotchkin <[email protected]>
This patch set contains the following:
- support for switching CS for every transferred byte
- fix for the clock by enabling it for every call to spi_setup()
v2:
- remove DTS entry for single byte CS, use existing SPI_CS_WORD flag
- drop changes to core SPI driver
- fix the wrong first patch signature
Marcin Wojtas (2):
spi: orion: enable clocks before spi_setup
spi: orion: enable support for switching CS every transferred byte
drivers/spi/spi-orion.c | 30 +++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1