mirror of
https://github.com/torvalds/linux.git
synced 2024-11-29 07:31:29 +00:00
fc70d643a2
The current Atmel SPI controller driver (v2) behaves incorrectly when
using two SPI devices with different clock polarities and GPIO CS.
When switching from one device to another, the controller driver first
enables the CS and then applies whatever configuration suits the targeted
device (typically, the polarities). The side effect of such order is the
apparition of a spurious clock edge after enabling the CS when the clock
polarity needs to be inverted wrt. the previous configuration of the
controller.
This parasitic clock edge is problematic when the SPI device uses that edge
for internal processing, which is perfectly legitimate given that its CS
was asserted. Indeed, devices such as HVS8080 driven by driver gpio-sr in
the kernel are shift registers and will process this first clock edge to
perform a first register shift. In this case, the first bit gets lost and
the whole data block that will later be read by the kernel is all shifted
by one.
Current behavior:
The actual switching of the clock polarity only occurs after the CS
when the controller sends the first message:
CLK ------------\ /-\ /-\
| | | | | . . .
\---/ \-/ \
CS -----\
|
\------------------
^ ^ ^
| | |
| | Actual clock of the message sent
| |
| Change of clock polarity, which occurs with the first
| write to the bus. This edge occurs when the CS is
| already asserted, and can be interpreted as
| the first clock edge by the receiver.
|
GPIO CS toggle
This issue is specific to this controller because while the SPI core
performs the operations in the right order, the controller however does
not. In practice, the controller only applies the clock configuration right
before the first transmission.
So this is not a problem when using the controller's dedicated CS, as the
controller does things correctly, but it becomes a problem when you need to
change the clock polarity and use an external GPIO for the CS.
One possible approach to solve this problem is to send a dummy message
before actually activating the CS, so that the controller applies the clock
polarity beforehand.
New behavior:
CLK ------\ /-\ /-\ /-\ /-\
| | | ... | | | | ... | |
\------/ \- -/ \------/ \- -/ \------
CS -\/-----------------------\
|| |
\/ \---------------------
^ ^ ^ ^ ^
| | | | |
| | | | Expected clock cycles when
| | | | sending the message
| | | |
| | | Actual GPIO CS activation, occurs inside
| | | the driver
| | |
| | Dummy message, to trigger clock polarity
| | reconfiguration. This message is not received and
| | processed by the device because CS is low.
| |
| Change of clock polarity, forced by the dummy message. This
| time, the edge is not detected by the receiver.
|
This small spike in CS activation is due to the fact that the
spi-core activates the CS gpio before calling the driver's
set_cs callback, which deactivates this gpio again until the
clock polarity is correct.
To avoid having to systematically send a dummy packet, the driver keeps
track of the clock's current polarity. In this way, it only sends the dummy
packet when necessary, ensuring that the clock will have the correct
polarity when the CS is toggled.
There could be two hardware problems with this patch:
1- Maybe the small CS activation peak can confuse SPI devices
2- If on a design, a single wire is used to select two devices depending
on its state, the dummy message may disturb them.
Fixes:
|
||
---|---|---|
.. | ||
atmel-quadspi.c | ||
internals.h | ||
Kconfig | ||
Makefile | ||
spi-altera-core.c | ||
spi-altera-dfl.c | ||
spi-altera-platform.c | ||
spi-amd.c | ||
spi-amlogic-spifc-a1.c | ||
spi-ar934x.c | ||
spi-armada-3700.c | ||
spi-aspeed-smc.c | ||
spi-at91-usart.c | ||
spi-ath79.c | ||
spi-atmel.c | ||
spi-au1550.c | ||
spi-axi-spi-engine.c | ||
spi-bcm63xx-hsspi.c | ||
spi-bcm63xx.c | ||
spi-bcm2835.c | ||
spi-bcm2835aux.c | ||
spi-bcm-qspi.c | ||
spi-bcm-qspi.h | ||
spi-bcmbca-hsspi.c | ||
spi-bitbang-txrx.h | ||
spi-bitbang.c | ||
spi-brcmstb-qspi.c | ||
spi-butterfly.c | ||
spi-cadence-quadspi.c | ||
spi-cadence-xspi.c | ||
spi-cadence.c | ||
spi-cavium-octeon.c | ||
spi-cavium-thunderx.c | ||
spi-cavium.c | ||
spi-cavium.h | ||
spi-clps711x.c | ||
spi-coldfire-qspi.c | ||
spi-cs42l43.c | ||
spi-davinci.c | ||
spi-dln2.c | ||
spi-dw-bt1.c | ||
spi-dw-core.c | ||
spi-dw-dma.c | ||
spi-dw-mmio.c | ||
spi-dw-pci.c | ||
spi-dw.h | ||
spi-ep93xx.c | ||
spi-falcon.c | ||
spi-fsi.c | ||
spi-fsl-cpm.c | ||
spi-fsl-cpm.h | ||
spi-fsl-dspi.c | ||
spi-fsl-espi.c | ||
spi-fsl-lib.c | ||
spi-fsl-lib.h | ||
spi-fsl-lpspi.c | ||
spi-fsl-qspi.c | ||
spi-fsl-spi.c | ||
spi-fsl-spi.h | ||
spi-geni-qcom.c | ||
spi-gpio.c | ||
spi-gxp.c | ||
spi-hisi-kunpeng.c | ||
spi-hisi-sfc-v3xx.c | ||
spi-img-spfi.c | ||
spi-imx.c | ||
spi-ingenic.c | ||
spi-intel-pci.c | ||
spi-intel-platform.c | ||
spi-intel.c | ||
spi-intel.h | ||
spi-iproc-qspi.c | ||
spi-jcore.c | ||
spi-lantiq-ssc.c | ||
spi-ljca.c | ||
spi-lm70llp.c | ||
spi-loongson-core.c | ||
spi-loongson-pci.c | ||
spi-loongson-plat.c | ||
spi-loongson.h | ||
spi-loopback-test.c | ||
spi-lp8841-rtc.c | ||
spi-mem.c | ||
spi-meson-spicc.c | ||
spi-meson-spifc.c | ||
spi-microchip-core-qspi.c | ||
spi-microchip-core.c | ||
spi-mpc52xx-psc.c | ||
spi-mpc52xx.c | ||
spi-mpc512x-psc.c | ||
spi-mt65xx.c | ||
spi-mt7621.c | ||
spi-mtk-nor.c | ||
spi-mtk-snfi.c | ||
spi-mux.c | ||
spi-mxic.c | ||
spi-mxs.c | ||
spi-npcm-fiu.c | ||
spi-npcm-pspi.c | ||
spi-nxp-fspi.c | ||
spi-oc-tiny.c | ||
spi-omap2-mcspi.c | ||
spi-omap-uwire.c | ||
spi-orion.c | ||
spi-pci1xxxx.c | ||
spi-pic32-sqi.c | ||
spi-pic32.c | ||
spi-pl022.c | ||
spi-ppc4xx.c | ||
spi-pxa2xx-dma.c | ||
spi-pxa2xx-pci.c | ||
spi-pxa2xx.c | ||
spi-pxa2xx.h | ||
spi-qcom-qspi.c | ||
spi-qup.c | ||
spi-rb4xx.c | ||
spi-realtek-rtl.c | ||
spi-rockchip-sfc.c | ||
spi-rockchip.c | ||
spi-rpc-if.c | ||
spi-rspi.c | ||
spi-rzv2m-csi.c | ||
spi-s3c64xx.c | ||
spi-sc18is602.c | ||
spi-sh-hspi.c | ||
spi-sh-msiof.c | ||
spi-sh-sci.c | ||
spi-sh.c | ||
spi-sifive.c | ||
spi-slave-mt27xx.c | ||
spi-slave-system-control.c | ||
spi-slave-time.c | ||
spi-sn-f-ospi.c | ||
spi-sprd-adi.c | ||
spi-sprd.c | ||
spi-st-ssc4.c | ||
spi-stm32-qspi.c | ||
spi-stm32.c | ||
spi-sun4i.c | ||
spi-sun6i.c | ||
spi-sunplus-sp7021.c | ||
spi-synquacer.c | ||
spi-tegra20-sflash.c | ||
spi-tegra20-slink.c | ||
spi-tegra114.c | ||
spi-tegra210-quad.c | ||
spi-test.h | ||
spi-ti-qspi.c | ||
spi-tle62x0.c | ||
spi-topcliff-pch.c | ||
spi-uniphier.c | ||
spi-wpcm-fiu.c | ||
spi-xcomm.c | ||
spi-xilinx.c | ||
spi-xlp.c | ||
spi-xtensa-xtfpga.c | ||
spi-zynq-qspi.c | ||
spi-zynqmp-gqspi.c | ||
spi.c | ||
spidev.c |