spi: add flow controll support
Subsystems (3)
RFC PATCH 1/1 spi: add flow controll support
Different HW implement different variants of SPI based flow control (FC). To flexible FC implementation a spited it to fallowing common parts:
Flow control: Request Sequence
Master CS |-------2\_____________________| Slave FC |-----1\_______________________| DATA |-----------3\_________________|
Flow control: Ready Sequence
Master CS |-----1\_______________________| Slave FC |--------2\____________________| DATA |-----------3\_________________|
Flow control: ACK End of Data
Master CS |______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|
Flow control: Pause
Master CS |_______________________/------| Slave FC |_______1/-----\3______/-------| DATA |________2/------\4___/--------|
--- drivers/spi/spi-davinci.c | 10 ++-- drivers/spi/spi-sun4i.c | 3 +- drivers/spi/spi.c | 120 +++++++++++++++++++++++++++++++++++++++++++++- include/linux/spi/spi.h | 51 +++++++++++++++++++- 4 files changed, 175 insertions(+), 9 deletions(-)
drivers/spi/spi-davinci.c +5 -5
@@ -351,8 +351,8 @@ static int davinci_spi_setup_transfer(struct spi_device *spi,* * Version 2 hardware supports an optional handshaking signal, * so it can support two more modes: -* - 5 pin SPI variant is standard SPI plus SPI_READY -* - 4 pin with enable is (SPI_READY | SPI_NO_CS) +* - 5 pin SPI variant is standard SPI plus SPI_FC_READY +* - 4 pin with enable is (SPI_FC_READY | SPI_NO_CS) */ if (dspi->version ==SPI_VERSION_2 ) {
@@ -374,7 +374,7 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, &SPIDELAY_T2CDELAY_MASK ; } -if (spi->mode &SPI_READY ) { +if (spi->mode &SPI_FC_READY ) { spifmt |=SPIFMT_WAITENA_MASK ; delay |= (spicfg->t2edelay <<SPIDELAY_T2EDELAY_SHIFT ) &SPIDELAY_T2EDELAY_MASK ;
@@ -452,7 +452,7 @@ static int davinci_spi_setup(struct spi_device *spi)set_io_bits (dspi->base +SPIPC0 ,1 << spi->chip_select); } -if (spi->mode &SPI_READY ) +if (spi->mode &SPI_FC_READY )set_io_bits (dspi->base +SPIPC0 ,SPIPC0_SPIENA_MASK );if (spi->mode &SPI_LOOP )
@@ -1021,7 +1021,7 @@ static int davinci_spi_probe(struct platform_device *pdev) dspi->bitbang.flags =SPI_NO_CS |SPI_LSB_FIRST |SPI_LOOP ;if (dspi->version ==SPI_VERSION_2 ) - dspi->bitbang.flags |=SPI_READY ; + dspi->bitbang.flags |=SPI_FC_HW_ONLY |SPI_FC_READY |SPI_FC_PAUSE ;if (pdev->dev.of_node) {int i;
drivers/spi/spi-sun4i.c +2 -1
@@ -390,7 +390,8 @@ static int sun4i_spi_probe(struct platform_device *pdev) master->set_cs = sun4i_spi_set_cs; master->transfer_one = sun4i_spi_transfer_one; master->num_chipselect =4 ; - master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH |SPI_LSB_FIRST ; + master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH |SPI_LSB_FIRST | +SPI_FC_REQUEST |SPI_FC_READY |SPI_FC_STOP_ACK ; master->bits_per_word_mask =SPI_BPW_MASK (8 ); master->dev.of_node = pdev->dev.of_node; master->auto_runtime_pm = true;
drivers/spi/spi.c +119 -1
174 lines not on this page · raw message
include/linux/spi/spi.h +49 -2
88 lines not on this page · raw message
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
Hi Oleksij,
Quoted 1 line · Oleksij Rempel
Different HW implement different variants of SPI based flow control (FC).
Thanks for your patch!
Quoted 16 lines
drivers/spi/spi.c +13
-0+/* spi_fc_probe should be called by spi_device driver. */ +int spi_fc_probe (struct spi_device *spi) +{ +struct device_node *np = spi->dev.of_node; +int ret; + +if (!np) +return 0 ; + +if (!(spi->mode &SPI_FC_MASK ) || spi->mode &SPI_FC_HW_ONLY ) +return 0 ; + + spi->fc_gpio =devm_gpiod_get (&spi->dev,"fc" ,GPIOD_IN );
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 470
Quoted 10 lines
drivers/spi/spi.c +10
-0+if (IS_ERR (spi->fc_gpio)) { + ret =PTR_ERR (spi->fc_gpio); +dev_err (&spi->dev,"Failed to request FC GPIO: %d\n" , ret); +return ret; + } + +init_completion (&spi->fc_complete); +snprintf (spi->fc_irq_name,sizeof (spi->fc_irq_name),"spi-fc-%s" , +dev_name (&spi->dev)); + ret = devm_request_irq(&spi->dev, gpiod_to_irq(spi->fc_gpio),
gpiod_to_irq() will return -ENXIO if the GPIO doesn't support interrupts. Granted, devm_request_irq() will fail in that case, but you may want to support polling.
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 473
Quoted 3 lines
drivers/spi/spi.c +3
-0+ spi_fc_rq, +IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING , + spi->fc_irq_name, spi);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
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 16 lines · Oleksij Rempel
Different HW implement different variants of SPI based flow control (FC). To flexible FC implementation a spited it to fallowing common parts:
Flow control: Request SequenceMaster CS |-------2\_____________________| Slave FC |-----1\_______________________| DATA |-----------3\_________________|Flow control: Ready Sequence
Master CS |-----1\_______________________| Slave FC |--------2\____________________| DATA |-----------3\_________________|Flow control: ACK End of Data
Quoted 8 lines
Master CS |______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|Flow control: Pause
Master CS |_______________________/------| Slave FC |_______1/-----\3______/-------| DATA |________2/------\4___/--------|
The MAX187/189 SPI-ADC implements a different kind of flow control that is signaling inline on DATA/MISO:
Master CS |-----1\_______________________| MISO/DATA |------2\____3/----------------| CONV START | ^ | DATA READY | ^ |
So when CS get asserted (1)
MISO/DATA becomes dominant low (2) and the ADC conversion starts
(within 100ns of (1))
When MISO/DATA goes dominant high (3) then the conversion has finished and the transfer may start.
A flow-control interface should also cover similar cases - or at least get designed so that such a case can also get handled by the framework in the future as well.
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 481
Quoted 6 lines
drivers/spi/spi.c +5
-0+ +/* spi_fc_probe should be called by spi_device driver. */ +int spi_fc_probe(struct spi_device *spi) +} +EXPORT_SYMBOL_GPL (spi_fc_probe);
Please add kernel doc to the exported methods
Please put per driver changes into a separate patch.
Also missing from the patch(set) is the dt-bindings documentation - see Documentation/devicetree/bindings/spi/spi-bus.txt.
Martin
--
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
Hi Oleksij,
Quoted 33 lines · fixed-term.Oleksij.Rempel
Quoted 23 lines · Geert Uytterhoeven
Quoted 22 lines · Oleksij Rempel
drivers/spi/spi.c +19
-0+/* spi_fc_probe should be called by spi_device driver. */ +int spi_fc_probe (struct spi_device *spi) +{ +struct device_node *np = spi->dev.of_node; +int ret; + +if (!np) +return 0 ; + +if (!(spi->mode &SPI_FC_MASK ) || spi->mode &SPI_FC_HW_ONLY ) +return 0 ; + + spi->fc_gpio =devm_gpiod_get (&spi->dev,"fc" ,GPIOD_IN ); +if (IS_ERR (spi->fc_gpio)) { + ret =PTR_ERR (spi->fc_gpio); +dev_err (&spi->dev,"Failed to request FC GPIO: %d\n" , ret); +return ret; + } +Quoted 8 lines
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 470
Quoted 4 lines
drivers/spi/spi.c +4
-0+init_completion (&spi->fc_complete); +snprintf (spi->fc_irq_name,sizeof (spi->fc_irq_name),"spi-fc-%s" , +dev_name (&spi->dev)); + ret = devm_request_irq(&spi->dev, gpiod_to_irq(spi->fc_gpio),
gpiod_to_irq()will return-ENXIOif the GPIO doesn't support interrupts. Granted,devm_request_irq()will fail in that case, but you may want to support polling.
Quoted 1 line
Do you mean
IRQF_IRQPOLLor row gpio polling?
I don't mean IRQF_IRQPOLL.
I don't know what you mean by "row gpio polling".
I mean a GPIO without interrupt capability, where you have to read the GPIO state from time to time to detect changes.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
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
PATCH 1/6 spi: add flow controll support
In reply to a message not in the archiveDifferent HW implement different variants of SPI based flow control (FC). To flexible FC implementation a spited it to fallowing common parts:
Flow control: Request Sequence
Master CS |-------2\_____________________| Slave FC |-----1\_______________________| DATA |-----------3\_________________|
Flow control: Ready Sequence
Master CS |-----1\_______________________| Slave FC |--------2\____________________| DATA |-----------3\_________________|
Flow control: ACK End of Data
Master CS |______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|
Flow control: Pause
Master CS |_______________________/------| Slave FC |_______1/-----\3______/-------| DATA |________2/------\4___/--------|
Flow control: Ready signal on MISO
Master CS |-----1\_______________________| MISO/DATA |------2\____3/----------------| CONV START | ^ | DATA READY | ^ |
--- Documentation/devicetree/bindings/spi/spi-bus.txt | 7 + drivers/spi/spi.c | 191 +++++++++++++++++++++- include/linux/spi/spi.h | 68 +++++++- 3 files changed, 261 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/spi/spi-bus.txt +7 -0
@@ -61,6 +61,13 @@ contain the following properties. used for MOSI. Defaults to 1 if not present. - spi-rx-bus-width - (optional) The bus width(number of data wires) that used for MISO. Defaults to 1 if not present. +- spi-fc-ready - (optional) flow control line used for ready signal. +- spi-fc-stop-ack - (optional) flow control line used to ACK end of transfer. +- spi-fc-pause - (optional) flow control line used for to pause transfer + at any time. +- spi-fc-request - (optional) flow control line used for request signal. +- spi-fc-miso-ready - (optional) MISO used for flow control ready signal. +- fc-gpio - (optional) gpio for flow control. Some SPI controllers and devices support Dual and Quad SPI transfer mode. It allows data in the SPI system to be transferred in 2 wires(DUAL) or 4 wires(QUAD).
drivers/spi/spi.c +189 -2
238 lines not on this page · raw message
include/linux/spi/spi.h +65 -3
111 lines not on this page · raw message
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
PATCH 2/6 spi: add add flow control test driver
In reply to a message not in the archiveThis testdriver can be used to test flow control
functionality by using some gpio pins to emulate
slave device.
--- drivers/spi/Kconfig | 12 ++ drivers/spi/Makefile | 1 + drivers/spi/spi_fc_test.c | 273 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 drivers/spi/spi_fc_test.c
drivers/spi/Kconfig +12 -0
@@ -681,6 +681,18 @@ config SPI_DW_MMIO # comment "SPI Protocol Masters" +config SPI_FC_TEST + tristate "Test for SPI flow control functionality" + depends on SPI + default n + help + This option enables test module for flow control SPI + extensions. For testing use debugfs interface with count + of packet wich should be used for testing. For example: + echo 100000 > /sys/kernel/debug/spi_fc_test/spi0/test_fc_request + + If unsure, say N. + config SPI_SPIDEV tristate "User mode SPI device driver support" help
drivers/spi/Makefile +1 -0
@@ -37,6 +37,7 @@ spi-dw-midpci-objs := spi-dw-pci.o spi-dw-mid.o obj-$(CONFIG_SPI_EFM32) += spi-efm32.o obj-$(CONFIG_SPI_EP93XX) += spi-ep93xx.o obj-$(CONFIG_SPI_FALCON) += spi-falcon.o +obj-$(CONFIG_SPI_FC_TEST) += spi_fc_test.o obj-$(CONFIG_SPI_FSL_CPM) += spi-fsl-cpm.o obj-$(CONFIG_SPI_FSL_DSPI) += spi-fsl-dspi.o obj-$(CONFIG_SPI_FSL_LIB) += spi-fsl-lib.o
drivers/spi/spi_fc_test.c new file +273 -0
273 lines not on this page · raw message
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
PATCH 3/6 DT: add documentation for spi-fc-test driver
In reply to a message not in the archive--- .../devicetree/bindings/spi/spi-fc-test.txt | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-fc-test.txt
Documentation/devicetree/bindings/spi/spi-fc-test.txt new file +30 -0
@@ -0,0 +1,30 @@ +SPI-FC-TEST is a test driver to simulate slave +flow control from spi master. + +Required properties: + - compatible: should be set to "spi-fc-test" + - fc-gpio: spi device gpio input for flow control line. + - test-cs-in-gpio: chip select gpio input to emulate slave device + - test-fc-out-gpio: request gpio output to emulate slave device +Fallowing required properties are provided by spi framework. +See spi-bus.txt for more information. + - spi-fc-ready + - spi-fc-stop-ack + - spi-fc-request + +Example: +test-spi@0 { + status = "okay"; + reg = <0>; + compatible = "spi-fc-test"; + spi-max-frequency = <100000>; + spi-fc-ready; + spi-fc-request; + spi-fc-stop-ack; + pinctrl-names = "default"; + pinctrl-0 = <&spi_test_in_pins_bananapi>, <&spi_test_out_pins_bananapi>; + fc-gpio = <&pio 7 20 GPIO_ACTIVE_LOW>; /* request line, in IO-4, (PH20) */ + test-cs-in-gpio = <&pio 7 1 GPIO_ACTIVE_LOW>; /* RXD0, (PH1) */ + test-rq-out-gpio = <&pio 7 21 GPIO_ACTIVE_LOW>; /* IO-5, (PH21) */ +}; +
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
PATCH 4/6 spi: davinci: set new SPI_FC_* flags
In reply to a message not in the archiveto indicate flow control support.
--- drivers/spi/spi-davinci.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/spi/spi-davinci.c +5 -5
@@ -351,8 +351,8 @@ static int davinci_spi_setup_transfer(struct spi_device *spi,* * Version 2 hardware supports an optional handshaking signal, * so it can support two more modes: -* - 5 pin SPI variant is standard SPI plus SPI_READY -* - 4 pin with enable is (SPI_READY | SPI_NO_CS) +* - 5 pin SPI variant is standard SPI plus SPI_FC_READY +* - 4 pin with enable is (SPI_FC_READY | SPI_NO_CS) */ if (dspi->version ==SPI_VERSION_2 ) {
@@ -374,7 +374,7 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, &SPIDELAY_T2CDELAY_MASK ; } -if (spi->mode &SPI_READY ) { +if (spi->mode &SPI_FC_READY ) { spifmt |=SPIFMT_WAITENA_MASK ; delay |= (spicfg->t2edelay <<SPIDELAY_T2EDELAY_SHIFT ) &SPIDELAY_T2EDELAY_MASK ;
@@ -452,7 +452,7 @@ static int davinci_spi_setup(struct spi_device *spi)set_io_bits (dspi->base +SPIPC0 ,1 << spi->chip_select); } -if (spi->mode &SPI_READY ) +if (spi->mode &SPI_FC_READY )set_io_bits (dspi->base +SPIPC0 ,SPIPC0_SPIENA_MASK );if (spi->mode &SPI_LOOP )
@@ -1021,7 +1021,7 @@ static int davinci_spi_probe(struct platform_device *pdev) dspi->bitbang.flags =SPI_NO_CS |SPI_LSB_FIRST |SPI_LOOP ;if (dspi->version ==SPI_VERSION_2 ) - dspi->bitbang.flags |=SPI_READY ; + dspi->bitbang.flags |=SPI_FC_HW_ONLY |SPI_FC_READY |SPI_FC_PAUSE ;if (pdev->dev.of_node) {int i;
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
PATCH 5/6 spi: sun4i: set new SPI_FC_* flags
In reply to a message not in the archiveto indicate flow control support.
--- drivers/spi/spi-sun4i.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-sun4i.c +2 -1
@@ -390,7 +390,8 @@ static int sun4i_spi_probe(struct platform_device *pdev) master->set_cs = sun4i_spi_set_cs; master->transfer_one = sun4i_spi_transfer_one; master->num_chipselect =4 ; - master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH |SPI_LSB_FIRST ; + master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH |SPI_LSB_FIRST | +SPI_FC_REQUEST |SPI_FC_READY |SPI_FC_STOP_ACK ; master->bits_per_word_mask =SPI_BPW_MASK (8 ); master->dev.of_node = pdev->dev.of_node; master->auto_runtime_pm = true;
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
PATCH 6/6 spi: bitbang: set new SPI_FC_* flags
In reply to a message not in the archiveto indicate flow control support
--- drivers/spi/spi-bitbang.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/spi/spi-bitbang.c +3 -1
@@ -363,7 +363,9 @@ int spi_bitbang_start(struct spi_bitbang *bitbang)mutex_init (&bitbang->lock);if (!master->mode_bits) - master->mode_bits =SPI_CPOL |SPI_CPHA | bitbang->flags; + master->mode_bits =SPI_CPOL |SPI_CPHA | +SPI_FC_READY |SPI_FC_STOP_ACK | +SPI_FC_REQUEST | bitbang->flags;if (master->transfer || master->transfer_one_message)return -EINVAL ;
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
Quoted 2 lines · Oleksij Rempel
Different HW implement different variants of SPI based flow control (FC). To flexible FC implementation a spited it to fallowing common parts:
Please don't bury new patches in reply to the middle of some other thread, it makes it really hard to follow what's going on.
Re: [PATCH 4/6] spi: davinci: set new SPI_FC_* flags
In reply to a message not in the archivedrivers/spi/spi-davinci.c static int davinci_spi_setup_transfer(struct spi_device *spi, · line 377
Quoted 2 lines · Oleksij Rempel
drivers/spi/spi-davinci.c +1
-1-if (spi->mode &SPI_READY ) { +if (spi->mode &SPI_FC_READY ) {
This isn't setting new flags, this is replacing old flags with new ones which suggests that the patch renaming the flag needs to rename the flag in all the drivers...
Re: [PATCH 3/6] DT: add documentation for spi-fc-test driver
In reply to a message not in the archiveQuoted 1 line · Oleksij Rempel
.../devicetree/bindings/spi/spi-fc-test.txt | 30 ++++++++++++++++++++++
We should not be supporting DT bindings for a test device that doesn't represent physical hardware, this is an invitation to abuse by people writing bad DT bindings for actual hardware.
On Tue, Mar 01, 2016 at 03:43:15PM +0100, Oleksij Rempel wrote:
At a high level I think this needs splitting up quite a bit - this is defining a new DT binding, a new core interface for controlling flow control and a bitbanging flow control implementation. At least those three bits should probably be separate patches, it may make sense to split up the bitbanging implementation some more too.
Quoted 6 lines
Different HW implement different variants of SPI based flow control (FC). To flexible FC implementation a spited it to fallowing common parts:
Flow control: Request SequenceMaster CS |-------2\_____________________| Slave FC |-----1\_______________________| DATA |-----------3\_________________|
I don't know what these pictures mean since you don't say what "slave FC" is - I'm assuming you mean a separate pin but you need to specify that. It really looks like this would be clearer with words rather than ASCII art.
In the case above this looks like a normal interrupt from a device, I'm not clear what is different here or why this is in the core?
Quoted 4 lines
Flow control: ACK End of Data
Master CS |______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|
Why would anything care about this case and why is it part of the SPI protocol rather than something that the device driver would do?
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 448
Quoted 6 lines
drivers/spi/spi.c +6
-0+if (atomic_read (&spi->active_rq)) { +if (!spi_fc_equal_cs (spi)) +dev_warn (&spi->dev,"Got request, but device is not ready\n" ); +atomic_set (&spi->active_rq,0 ); +return ret; + }
Atomic operations are very hard to use safely, you need to really spell out what you think this is doing from a synchronization point of view and why it's safe.
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 483
Quoted 5 lines
drivers/spi/spi.c +5
-0+if (spi->mode |SPI_FC_REQUEST && + !spi->cs_enabled && fc_enabled) { +atomic_set (&spi->active_rq,1 ); +if (spi->request_cb) + spi->request_cb (spi);
This logic is all too complicated for me to follow. Why are we oring things with spi->mode?
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 513
Quoted 5 lines
drivers/spi/spi.c +5
-0+struct device_node *np = spi->dev.of_node; +int ret; + +if (!np) +return 0 ;
We can't support things only for DT, we need a way for things to be used on other systemms.
Re: [PATCH 3/6] DT: add documentation for spi-fc-test driver
In reply to Mark Brown-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Quoted 9 lines · Mark Brown
Quoted 2 lines · Oleksij Rempel
.../devicetree/bindings/spi/spi-fc-test.txt| 30
++++++++++++++++++++++We should not be supporting DT bindings for a test device that doesn't represent physical hardware, this is an invitation to abuse by people writing bad DT bindings for actual hardware.
Ok, i'll try to reimplement it with module parameters. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iF4EAREIAAYFAlbWhwAACgkQHwImuRkmbWlOOwEAgarzmDA119XNTrZOKDB4OtJW J8j0WM80sbRwK9DvNQkA/2lYbFeQgS2hhcirvxB6vMr6/5C77sm0evfv/UAZrDqA =d2kY
-----END PGP SIGNATURE-----
Re: [PATCH 4/6] spi: davinci: set new SPI_FC_* flags
In reply to Mark Brown-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Quoted 9 lines · Mark Brown
Quoted 2 lines · Oleksij Rempel
(quoted diff) +0
-1- if (spi->mode & SPI_READY) { + if (spi->mode & SPI_FC_READY){
This isn't setting new flags, this is replacing old flags with new ones which suggests that the patch renaming the flag needs to rename the flag in all the drivers...
Only this driver was using this flag SPI_READY. So i assume, i will need only to reword patch comment. Right?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iF4EAREIAAYFAlbWh1QACgkQHwImuRkmbWkcDQEAiRMfYYl+PtT4TLSiilvlcD36 B4j8s+YFxKRHpX8BzgwA/2UXedfndYz2pPeZM+F0pwgNhXiFYKZkzjVfso86SQl6 =2QpT
-----END PGP SIGNATURE-----
Quoted 7 lines · Mark Brown
On Tue, Mar 01, 2016 at 03:43:15PM +0100, Oleksij Rempel wrote:
At a high level I think this needs splitting up quite a bit - this is defining a new DT binding, a new core interface for controlling flow control and a bitbanging flow control implementation. At least those three bits should probably be separate patches, it may make sense to split up the bitbanging implementation some more too.
ok
Quoted 11 lines
Quoted 6 lines
Different HW implement different variants of SPI based flow control (FC). To flexible FC implementation a spited it to fallowing common parts:
Flow control: Request SequenceMaster CS |-------2\_____________________| Slave FC |-----1\_______________________| DATA |-----------3\_________________|I don't know what these pictures mean since you don't say what "slave FC" is - I'm assuming you mean a separate pin but you need to specify that. It really looks like this would be clearer with words rather than ASCII art.
Ok, Slave FC means a flow control line controlled by Slave - MISO
Quoted 3 lines
In the case above this looks like a normal interrupt from a device, I'm not clear what is different here or why this is in the core?
At least our HW use tree different signals for flow control. One of it is Request Signal.
Quoted 7 lines
Quoted 4 lines
Flow control: ACK End of Data
Master CS |______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|Why would anything care about this case and why is it part of the SPI protocol rather than something that the device driver would do?
This case covers real bugs and in our case we need to detect if master or slave stalls under one second. If communication problem is detected, some of recovery scenarios is initiated. Like i said, this protocol is used for automotive industry.
Please see two attached screen shots of Master and Slave initiated transfers.
Quoted 10 lines
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 448
Quoted 6 lines
drivers/spi/spi.c +6
-0+if (atomic_read (&spi->active_rq)) { +if (!spi_fc_equal_cs (spi)) +dev_warn (&spi->dev,"Got request, but device is not ready\n" ); +atomic_set (&spi->active_rq,0 ); +return ret; + }Atomic operations are very hard to use safely, you need to really spell out what you think this is doing from a synchronization point of view and why it's safe.
I'm trying to detect if we are on Master or Slave initiated transfer, which was detected by spi_fc_rq. Normally there should be no other interrupts on FC line and active_rq should not be changed until this transfer was processed. The "if (!spi_fc_equal_cs(spi))" check is in case my assumption is wrong or there is some HW issue. Do you have other suggestions?
Quoted 9 lines
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 483
Quoted 6 lines
drivers/spi/spi.c +5
-0+if (spi->mode |SPI_FC_REQUEST && + !spi->cs_enabled && fc_enabled) { +atomic_set (&spi->active_rq,1 ); +if (spi->request_cb) + spi->request_cb (spi);This logic is all too complicated for me to follow. Why are we oring things with
spi->mode?
I'm trying to checking here if fallowing case is actually expected by slave device. Other suggestions?
Quoted 8 lines
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 513
Quoted 5 lines
drivers/spi/spi.c +5
-0+struct device_node *np = spi->dev.of_node; +int ret; + +if (!np) +return 0 ;We can't support things only for DT, we need a way for things to be used on other systemms.
I have nothing against it, but i even do not have other HW to test if my assumptions are correct. Would you accept untested code? :)
This code was tested on Banana Pi with spi-sun4i and spi-gpio drivers.
Re: [PATCH 4/6] spi: davinci: set new SPI_FC_* flags
In reply to Mark Brown-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Beside, this probably should be done by main patch. In other case this will brake compilation - ware bad for bisecting.
Quoted 9 lines · Mark Brown
Quoted 2 lines · Oleksij Rempel
(quoted diff) +0
-1- if (spi->mode & SPI_READY) { + if (spi->mode & SPI_FC_READY){
This isn't setting new flags, this is replacing old flags with new ones which suggests that the patch renaming the flag needs to rename the flag in all the drivers...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iF4EAREIAAYFAlbWjusACgkQHwImuRkmbWmj6QD/VWneJFfDJb4cq6e4mpM3AjER wA5p8k5RMwBr3/SaETcA/iPDHn1jstR1tgN2lQV4tRBmAVBz8U5cyKefJlmuvwu1 =8TBT
-----END PGP SIGNATURE-----
Re: [PATCH 4/6] spi: davinci: set new SPI_FC_* flags
In reply to a message not in the archiveQuoted 10 lines · fixed-term.Oleksij.Rempel
Quoted 8 lines · Mark Brown
Quoted 2 lines · Oleksij Rempel
(quoted diff) +0
-1- if (spi->mode & SPI_READY) { + if (spi->mode & SPI_FC_READY){
This isn't setting new flags, this is replacing old flags with new ones which suggests that the patch renaming the flag needs to rename the flag in all the drivers...
Quoted 2 lines
Only this driver was using this flag
SPI_READY. So i assume, i will need only to reword patch comment. Right?
No, if this is a rename you need to do it as a rename.
Quoted 8 lines · fixed-term.Oleksij.Rempel
Quoted 4 lines · Mark Brown
On Tue, Mar 01, 2016 at 03:43:15PM +0100, Oleksij Rempel wrote:
In the case above this looks like a normal interrupt from a device, I'm not clear what is different here or why this is in the core?
At least our HW use tree different signals for flow control. One of it is Request Signal.
That's still an interrupt, just on a different line to the main interrupt.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Flow control: ACK End of Data
Master CS |______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|
Quoted 7 lines
Quoted 2 lines
Why would anything care about this case and why is it part of the SPI protocol rather than something that the device driver would do?
This case covers real bugs and in our case we need to detect if master or slave stalls under one second. If communication problem is detected, some of recovery scenarios is initiated. Like i said, this protocol is used for automotive industry.
That doesn't answer the second part of my question. This doesn't seem to be something that's anything to do with SPI, it's just your device signalling things out of band.
Quoted 2 lines
Please see two attached screen shots of Master and Slave initiated transfers.
Those tell me nothing.
Quoted 10 lines
Quoted 3 lines
Atomic operations are very hard to use safely, you need to really spell out what you think this is doing from a synchronization point of view and why it's safe.
I'm trying to detect if we are on Master or Slave initiated transfer, which was detected by
spi_fc_rq. Normally there should be no other interrupts on FC line andactive_rqshould not be changed until this transfer was processed. The "if (!spi_fc_equal_cs(spi))" check is in case my assumption is wrong or there is some HW issue. Do you have other suggestions?
Among other things it really needs to be crystal clear how this update gets propagated to all CPUs in the system with no race conditions.
Quoted 11 lines
Quoted 8 lines
drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 483
Quoted 5 lines
drivers/spi/spi.c +5
-0+if (spi->mode |SPI_FC_REQUEST && + !spi->cs_enabled && fc_enabled) { +atomic_set (&spi->active_rq,1 ); +if (spi->request_cb) + spi->request_cb (spi);This logic is all too complicated for me to follow. Why are we oring things with
spi->mode?I'm trying to checking here if fallowing case is actually expected by slave device. Other suggestions?
In what way are we checking what? The code is incomprehensible.
Again, you're ignoring my specific question about the or.
Quoted 5 lines
Quoted 2 lines
We can't support things only for DT, we need a way for things to be used on other systemms.
I have nothing against it, but i even do not have other HW to test if my assumptions are correct. Would you accept untested code? :)
In general the way we do DT code is that the DT parses into some data structure and then we work with that data structure. This means that everyone's code path is tested.
Quoted 25 lines · Mark Brown
Quoted 10 lines · fixed-term.Oleksij.Rempel
Quoted 6 lines · Mark Brown
On Tue, Mar 01, 2016 at 03:43:15PM +0100, Oleksij Rempel wrote:
In the case above this looks like a normal interrupt from a device, I'm not clear what is different here or why this is in the core?
At least our HW use tree different signals for flow control. One of it is Request Signal.
That's still an interrupt, just on a different line to the main interrupt.
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Flow control: ACK End of Data Master CS
|______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|Why would anything care about this case and why is it part of the SPI protocol rather than something that the device driver would do?
Quoted 8 lines
Quoted 4 lines
This case covers real bugs and in our case we need to detect if master or slave stalls under one second. If communication problem is detected, some of recovery scenarios is initiated. Like i said, this protocol is used for automotive industry.
That doesn't answer the second part of my question. This doesn't seem to be something that's anything to do with SPI, it's just your device signalling things out of band.
Because there are more devices using this protocol, not only this company. Because implementing ACK signal will cost a lot more code then it is needed. Because timing for the driver do explode. Because implementing it for two device on one bus it is horror just to satisfy spi framework.
This is why we needed to reimplement almost complete spi stack insight of our driver.
So, do you feel safe if you know that this shit is implemented in your car? :)
Quoted 45 lines
Quoted 2 lines
Please see two attached screen shots of Master and Slave initiated transfers.
Those tell me nothing.
Quoted 10 lines
Quoted 3 lines
Atomic operations are very hard to use safely, you need to really spell out what you think this is doing from a synchronization point of view and why it's safe.
I'm trying to detect if we are on Master or Slave initiated transfer, which was detected by
spi_fc_rq. Normally there should be no other interrupts on FC line andactive_rqshould not be changed until this transfer was processed. The "if (!spi_fc_equal_cs(spi))" check is in case my assumption is wrong or there is some HW issue. Do you have other suggestions?Among other things it really needs to be crystal clear how this update gets propagated to all CPUs in the system with no race conditions.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
(quoted diff) +1
-0+ if (spi->mode | SPI_FC_REQUEST && + !spi->cs_enabled &&
fc_enabled) { +atomic_set(&spi->active_rq, 1); + if
(spi->request_cb) +spi->request_cb(spi);This logic is all too complicated for me to follow. Why are we oring things with
spi->mode?I'm trying to checking here if fallowing case is actually expected by slave device. Other suggestions?
In what way are we checking what? The code is incomprehensible.
Again, you're ignoring my specific question about the or.
Quoted 6 lines
Quoted 2 lines
We can't support things only for DT, we need a way for things to be used on other systemms.
I have nothing against it, but i even do not have other HW to test if my assumptions are correct. Would you accept untested code? :)
In general the way we do DT code is that the DT parses into some data structure and then we work with that data structure. This means that everyone's code path is tested.
Quoted 22 lines · Oleksij Rempel
Different HW implement different variants of SPI based flow control (FC). To flexible FC implementation a spited it to fallowing common parts:
Flow control: Request SequenceMaster CS |-------2\_____________________| Slave FC |-----1\_______________________| DATA |-----------3\_________________|Flow control: Ready Sequence
Master CS |-----1\_______________________| Slave FC |--------2\____________________| DATA |-----------3\_________________|Flow control: ACK End of Data
Master CS |______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|Flow control: Pause
Master CS |_______________________/------| Slave FC |_______1/-----\3______/-------| DATA |________2/------\4___/--------|
Quoted 5 lines
Flow control: Ready signal on MISO
Master CS |-----1\_______________________| MISO/DATA |------2\____3/----------------| CONV START | ^ | DATA READY | ^ |
One alternative idea:
I guess all of the above could also get implemented without a single framework change like this only in the spi_device driver that requires this:
* spi_bus_lock
* spi_sync_lock (but with cs_change = 1 on the last transfer, so that cs does not get de-asserted - maybe a 0 byte transfer)
* check for your gpio to be of the "expected" level (maybe via interrupt or polling)
* spi_sync_lock (continue your transfer)
* spi_bus_unlock
This could also get wrapped in a generic spi_* method.
Maybe another alternative to this approach could be a generic callback after having finished the processing a specific spi_transfer. (not the specific version that you propose)
E.g:
drivers/spi/spi.c +3 -0
@@ -1001,6 +1001,9 @@ static int spi_transfer_one_message(struct spi_master *master,if (msg->status != -EINPROGRESS ) goto out; +if (xfer->complete) + xfer->complete (xfer->context); +if (xfer->delay_usecs)udelay (xfer->delay_usecs);
include/linux/spi/spi.h +3 -0
@@ -753,6 +753,9 @@ struct spi_transfer {u16 delay_usecs;u32 speed_hz; +void (*complete)(void *context); +void *context; +struct list_head transfer_list; };
Then all that is left is implementing that gpio logic as this callback.
The complete_code could be just waiting for an GPIO-interrupt to wake up the thread - so it could be as simple as:
void spi_transfer_complete_wait_for_completion(void *context)
{
/* possibly enable interrupt */
/* wait for interrupt to wake us up*/
wait_for_completion(context);
/* possibly disable interrupt */
reinit_completion(context);
}The creation of the GPIO interrupt and such could also be spi_* helper methods which then could take some of the required info from the device tree.
This way the whole thing would be orthogonal to the SPI_READY, for which there is no spi_device driver besides spidev. So there would be also no impact to out of tree/userland drivers.
Such an interface actually would allow for other (ab)uses - e.g: read len, then read len bytes becomes easy:
void spi_transfer_complete_read_length_then_read(void *context) {
struct spi_transfer *xfer = context;
struct spi_transfer *next =
list_first_entry(list, typeof(*next), transfer_list);
/* saturate on length given in original transfer */ if (xfer->rx_buf && (xfer->len>0))
/* this may require unmapping the dma-buffer */
next->len = min_t(unsigned, len, ((char*)xfer->rx_buf)[0]);
/* note that if we wanted the ability to abort a transfer,
* then the complete method would need to return a status
*/
}All that is required is that a spi_message is created with 2 transfers, where the first has:
* len = 1
* complete = spi_transfer_complete_read_length_then_read;
* context = xfer[0]
and the second contains:
* len = 16;
Just some ideas of how it could be implemented in a more generic way that would also allow other uses.
Martin
--
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 45 lines · Martin Sperl
Quoted 22 lines · Oleksij Rempel
Different HW implement different variants of SPI based flow control (FC). To flexible FC implementation a spited it to fallowing common parts:
Flow control: Request SequenceMaster CS |-------2\_____________________| Slave FC |-----1\_______________________| DATA |-----------3\_________________|Flow control: Ready Sequence
Master CS |-----1\_______________________| Slave FC |--------2\____________________| DATA |-----------3\_________________|Flow control: ACK End of Data
Master CS |______________________/2------| Slave FC |________________________/3----| DATA |__________________/1----------|Flow control: Pause
Master CS |_______________________/------| Slave FC |_______1/-----\3______/-------| DATA |________2/------\4___/--------|Quoted 5 lines
Flow control: Ready signal on MISO
Master CS |-----1\_______________________| MISO/DATA |------2\____3/----------------| CONV START | ^ | DATA READY | ^ |One alternative idea:
I guess all of the above could also get implemented without a single framework change like this only in the
spi_devicedriver that requires this:*
spi_bus_lock
*spi_sync_lock(but withcs_change= 1 on the last transfer, so that cs does not get de-asserted - maybe a 0 byte transfer)
* check for your gpio to be of the "expected" level (maybe via interrupt or polling)
*spi_sync_lock(continue your transfer)
*spi_bus_unlock
Quoted 5 lines
This could also get wrapped in a generic spi_* method.
Maybe another alternative to this approach could be a generic callback after having finished the processing a specific
spi_transfer. (not the specific version that you propose)
Thank you, it sounds match more cleaner then my variant. I'll try it.
Quoted 82 lines
E.g:
drivers/spi/spi.c +3
-0@@ -1001,6 +1001,9 @@ static int spi_transfer_one_message(struct spi_master *master, if (msg->status != -EINPROGRESS) goto out; +if (xfer->complete) + xfer->complete (xfer->context); +if (xfer->delay_usecs)udelay (xfer->delay_usecs);include/linux/spi/spi.h +3
-0@@ -753,6 +753,9 @@ struct spi_transfer {u16 delay_usecs;u32 speed_hz; +void (*complete)(void *context); +void *context; +struct list_head transfer_list; };Then all that is left is implementing that gpio logic as this callback.
The
complete_codecould be just waiting for an GPIO-interrupt to wake up the thread - so it could be as simple as:void
spi_transfer_complete_wait_for_completion(void *context){ /* possibly enable interrupt */ /* wait for interrupt to wake us up*/ wait_for_completion(context); /* possibly disable interrupt */ reinit_completion(context); }The creation of the GPIO interrupt and such could also be spi_* helper methods which then could take some of the required info from the device tree.
This way the whole thing would be orthogonal to the
SPI_READY, for which there is nospi_devicedriver besides spidev. So there would be also no impact to out of tree/userland drivers.Such an interface actually would allow for other (ab)uses - e.g: read len, then read len bytes becomes easy:
void
spi_transfer_complete_read_length_then_read(void *context){ struct spi_transfer *xfer = context; struct spi_transfer *next = list_first_entry(list, typeof(*next), transfer_list); /* saturate on length given in original transfer */ if (xfer->rx_buf && (xfer->len>0)) /* this may require unmapping the dma-buffer */ next->len = min_t(unsigned, len, ((char*)xfer->rx_buf)[0]); /* note that if we wanted the ability to abort a transfer, * then the complete method would need to return a status */ }All that is required is that a
spi_messageis created with 2 transfers, where the first has:
* len = 1
* complete =spi_transfer_complete_read_length_then_read;
* context = xfer[0]
and the second contains:
* len = 16;Just some ideas of how it could be implemented in a more generic way that would also allow other uses.
Martin