* [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver
@ 2020-12-17 17:09 kostap
2020-12-17 17:09 ` [PATCH v2 1/2] spi: orion: enable clocks before spi_setup kostap
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: kostap @ 2020-12-17 17:09 UTC (permalink / raw)
To: linux-spi
Cc: devicetree, broonie, robh+dt, mw, jaz, nadavh, bpeled, stefanc,
Konstantin Porotchkin
From: Konstantin Porotchkin <kostap@marvell.com>
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(-)
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 1/2] spi: orion: enable clocks before spi_setup 2020-12-17 17:09 [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver kostap @ 2020-12-17 17:09 ` kostap 2020-12-17 17:25 ` Mark Brown 2020-12-17 17:09 ` [PATCH v2 2/2] spi: orion: enable support for switching CS every transferred byte kostap 2020-12-17 17:09 ` [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver kostap 2 siblings, 1 reply; 8+ messages in thread From: kostap @ 2020-12-17 17:09 UTC (permalink / raw) To: linux-spi Cc: devicetree, broonie, robh+dt, mw, jaz, nadavh, bpeled, stefanc, Konstantin Porotchkin From: Marcin Wojtas <mw@semihalf.com> 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. Signed-off-by: Marcin Wojtas <mw@semihalf.com> Signed-off-by: Konstantin Porotchkin <kostap@marvell.com> --- drivers/spi/spi-orion.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index b57b8b3cc26e..3bfda4225d45 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c @@ -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); } -- 2.17.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] spi: orion: enable clocks before spi_setup 2020-12-17 17:09 ` [PATCH v2 1/2] spi: orion: enable clocks before spi_setup kostap @ 2020-12-17 17:25 ` Mark Brown 2020-12-22 12:46 ` [EXT] " Kostya Porotchkin 0 siblings, 1 reply; 8+ messages in thread From: Mark Brown @ 2020-12-17 17:25 UTC (permalink / raw) To: kostap; +Cc: linux-spi, devicetree, robh+dt, mw, jaz, nadavh, bpeled, stefanc [-- Attachment #1: Type: text/plain, Size: 687 bytes --] On Thu, Dec 17, 2020 at 07:09:31PM +0200, kostap@marvell.com wrote: > + /* > + * 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. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [EXT] Re: [PATCH v2 1/2] spi: orion: enable clocks before spi_setup 2020-12-17 17:25 ` Mark Brown @ 2020-12-22 12:46 ` Kostya Porotchkin 2020-12-22 16:56 ` Mark Brown 0 siblings, 1 reply; 8+ messages in thread From: Kostya Porotchkin @ 2020-12-22 12:46 UTC (permalink / raw) To: Mark Brown Cc: linux-spi@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org, mw@semihalf.com, jaz@semihalf.com, Nadav Haklai, Ben Peled, Stefan Chulski Hi, Mark, > -----Original Message----- > From: Mark Brown <broonie@kernel.org> > > + /* > > + * 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [EXT] Re: [PATCH v2 1/2] spi: orion: enable clocks before spi_setup 2020-12-22 12:46 ` [EXT] " Kostya Porotchkin @ 2020-12-22 16:56 ` Mark Brown 0 siblings, 0 replies; 8+ messages in thread From: Mark Brown @ 2020-12-22 16:56 UTC (permalink / raw) To: Kostya Porotchkin Cc: linux-spi@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org, mw@semihalf.com, jaz@semihalf.com, Nadav Haklai, Ben Peled, Stefan Chulski [-- Attachment #1: Type: text/plain, Size: 890 bytes --] 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. > > 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? That's one part of the suggestion, yes - the other part is that you need to have a disable matching the enable here. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] spi: orion: enable support for switching CS every transferred byte 2020-12-17 17:09 [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver kostap 2020-12-17 17:09 ` [PATCH v2 1/2] spi: orion: enable clocks before spi_setup kostap @ 2020-12-17 17:09 ` kostap 2020-12-17 17:42 ` Mark Brown 2020-12-17 17:09 ` [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver kostap 2 siblings, 1 reply; 8+ messages in thread From: kostap @ 2020-12-17 17:09 UTC (permalink / raw) To: linux-spi Cc: devicetree, broonie, robh+dt, mw, jaz, nadavh, bpeled, stefanc, Konstantin Porotchkin From: Marcin Wojtas <mw@semihalf.com> 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. Signed-off-by: Marcin Wojtas <mw@semihalf.com> Signed-off-by: Konstantin Porotchkin <kostap@marvell.com> --- drivers/spi/spi-orion.c | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index 3bfda4225d45..0f92dd026bee 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c @@ -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; -- 2.17.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] spi: orion: enable support for switching CS every transferred byte 2020-12-17 17:09 ` [PATCH v2 2/2] spi: orion: enable support for switching CS every transferred byte kostap @ 2020-12-17 17:42 ` Mark Brown 0 siblings, 0 replies; 8+ messages in thread From: Mark Brown @ 2020-12-17 17:42 UTC (permalink / raw) To: kostap; +Cc: linux-spi, devicetree, robh+dt, mw, jaz, nadavh, bpeled, stefanc [-- Attachment #1: Type: text/plain, Size: 1050 bytes --] On Thu, Dec 17, 2020 at 07:09:32PM +0200, kostap@marvell.com wrote: > +++ b/drivers/spi/spi-orion.c > @@ -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. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver 2020-12-17 17:09 [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver kostap 2020-12-17 17:09 ` [PATCH v2 1/2] spi: orion: enable clocks before spi_setup kostap 2020-12-17 17:09 ` [PATCH v2 2/2] spi: orion: enable support for switching CS every transferred byte kostap @ 2020-12-17 17:09 ` kostap 2 siblings, 0 replies; 8+ messages in thread From: kostap @ 2020-12-17 17:09 UTC (permalink / raw) To: linux-spi Cc: devicetree, broonie, robh+dt, mw, jaz, nadavh, bpeled, stefanc, Konstantin Porotchkin From: Konstantin Porotchkin <kostap@marvell.com> 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(-) -- 2.17.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-12-22 16:57 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-12-17 17:09 [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver kostap 2020-12-17 17:09 ` [PATCH v2 1/2] spi: orion: enable clocks before spi_setup kostap 2020-12-17 17:25 ` Mark Brown 2020-12-22 12:46 ` [EXT] " Kostya Porotchkin 2020-12-22 16:56 ` Mark Brown 2020-12-17 17:09 ` [PATCH v2 2/2] spi: orion: enable support for switching CS every transferred byte kostap 2020-12-17 17:42 ` Mark Brown 2020-12-17 17:09 ` [PATCH v2 0/2] spi: new feature and fix for Marvell Orion driver kostap
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).