-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpi-4.9.y: spi driver reports bogus maximum frequency #2165
Comments
I can confirm the symptoms, but fortunately the error comes from Device Tree. Since the introduction of Raspberry Pi Device Tree in rpi-3.15.y, the standard spidev nodes have had an I'm slightly nervous that changing the maximum now will cause applications currently passing in zero as a speed (or querying the maximum and using that) to fail because their devices can't run at 125MHz. However, that counts as bad coding, and hopefully the usual gradual rollout (rpi-update, apt-get upgrade, major Raspbian release) would catch at least some of them before the change goes mainstream. I'm inclined to change all of the RPi |
The 500kHz value is clearly wrong so should be changed. |
125MHz is probably out past the realms of sanity from a hardware perspective. For example, the SD card interface (4-bit) can just about run at 100MHz and this is with much shorter PCB traces that don't stretch across the board to a pin header. I'd say sub-100MHz (say 62.5MHz) would be the maximum speed I'd expect to work at all reliably. |
I don't think we should be artificially restricting the range to what is going to be usable. The DT bindings say describe spi-max-frequency as:
But since this device is spidev (a userspace API), the value is effectively the maximum bus speed. The SPI host driver would not restrict a kernel SPI device driver to a lower value, so why should spidev be treated any differently? |
Okay, if max freq is treated as theoretical limit (much like arm_freq=1500), rather than a usable default then I'm happy with the change to 125MHz. |
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: #2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
I've pushed a patch to rpi-4.9.y, and will update the other branches tomorrow unless someone complains. |
kernel: config: Enable CONFIG_BRCMDBG temporarily for debugging See: raspberrypi/linux#1342 kernel: BCM270X_DT: Set spidev spi-max-frequency to 125MHz See: raspberrypi/linux#2165
kernel: config: Enable CONFIG_BRCMDBG temporarily for debugging See: raspberrypi/linux#1342 kernel: BCM270X_DT: Set spidev spi-max-frequency to 125MHz See: raspberrypi/linux#2165
kernel: config: Enable CONFIG_BRCMDBG temporarily for debugging See: raspberrypi/linux#1342 kernel: BCM270X_DT: Set spidev spi-max-frequency to 125MHz See: raspberrypi/linux#2165
Latest rpi-update kernel includes the patch @pelwell pushed earlier. |
Wouldn't it better to add a dtparam to change this? spi-max-frequency specifies the maximum a certain spi client can handle (and in the spidev case we don't know the client), and setting it to 125MHz certainly is a stretch :-) Or better yet, put the spidev node in an overlay and let 'dtparam=spi=on' load it for backwards compatibility. Userspace can also change the spidev speed using SPI_IOC_WR_MAX_SPEED_HZ: |
I'm not keen on expecting the userspace code to know that the default maximum speed isn't actually the maximum - the MRAA check seems sensible - which is why I was happy to increase the default. I would like to change spidev node in the DT to be disabled by default to remove the need for real SPI device overlays to disable the corresponding spidev node (i.e. opt-in to spidev rather than opt-out), but that would require spidev users to also indicate which they want to enable - all or nothing is too coarse, and we can't remove the spidev-disabling fragments until they are guaranteed not to be needed. We could defer the selective spidev enabling, requested by |
The linux-raspberrypi kernel update to 4.9.43 included a change to the default reported max speed of the linux spidev, from 100KHz to 125MHz. kernel: BCM270X_DT: Set spidev spi-max-frequency to 125MHz. See raspberrypi/linux#2165. It appears the reported max speed is used as the default if you don't specify it for the device. The MCP23S17 chip used in the PiFace digital board can only handle 10MHz but we were using the default so it was not working after the recent kernel update. This change explicitly sets the maximum speed after opening the device.
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: #2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
raspberrypi/linux#2165 and piface/pifacecad/issues/24#issuecomment-340642247) since kernel 4.9.43
commit 071bba3 Author: Phil Elwell <phil@raspberrypi.org> Date: Wed Aug 16 16:52:50 2017 +0100 BCM270X_DT: Set spidev spi-max-frequency to 125MHz The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi/linux#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org> Gbp-Pq: Topic rpi Gbp-Pq: Name rpi_1335_071bba328d62a0df87d0b4d94797681c3850ac9a.patch
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: #2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: #2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: #2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: #2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
There has been some fallout, as predicted, from applications that don't specify their own transfer speed, and I'm sure there'll be more as people upgrade, but I'll deal with it as it happens. |
The raspberry linux kernel updated the default spi frequency to 125MHz: kernel: BCM270X_DT: Set spidev spi-max-frequency to 125MHz. See raspberrypi/linux#2165. The WS2801 LEDs can only handle 10 MHz, but when not set the default value is used, which is too much. This commit explicit includes the spi package and sets the max speed for the spidev
commit a670cb1 Author: Phil Elwell <phil@raspberrypi.org> Date: Wed Aug 16 16:52:50 2017 +0100 BCM270X_DT: Set spidev spi-max-frequency to 125MHz The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi/linux#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org> Gbp-Pq: Topic rpi Gbp-Pq: Name rpi_1337_a670cb1ba7a2ff3ae4d56b67107fa94ee72089ff.patch
@pelwell Appears closable...? |
commit a670cb1 Author: Phil Elwell <phil@raspberrypi.org> Date: Wed Aug 16 16:52:50 2017 +0100 BCM270X_DT: Set spidev spi-max-frequency to 125MHz The BCM2835 SPI controllers have a maximum bus clock of half the system clock speed, so with the 250MHz system clock found on Raspberry Pis you get a theoretical maximum bus speed of 125MHz. Note that this speed is unlikely to be reliable, and the maximum usable bus spee will depend on both the attached device and the wiring. See: raspberrypi/linux#2165 Signed-off-by: Phil Elwell <phil@raspberrypi.org> Gbp-Pq: Topic rpi Gbp-Pq: Name rpi_1337_a670cb1ba7a2ff3ae4d56b67107fa94ee72089ff.patch
A bug was reported for the MRAA library that the SPI frequency cannot be set higher than 500kHz:
eclipse/mraa#255
It turns out that this boils down to a potential problem with the Raspberry Pi's SPI driver. In response to the SPI_IOC_RD_MAX_SPEED_HZ ioctl, the kernel driver reports some frequency slightly above 500kHz. MRAA then rounds down any requested frequency to the reported maximum speed.
It is known that the Raspberry Pi support speeds of up to 125MHz. So the value reported by the driver should be incorrect. I suggest that the driver is fixed to report the actual maximum speed obtained when the divisor is equal to 2.
Meanwhile, MRAA has been patched to ignore the maximum speed reported by the Raspberry Pi driver. Yet, I though that I should report the bug here so that the kernel driver is actually fixed.
While I did not test it, the bug may also affect other branches such as rpi-4.10.y, rpi-4.11.y, rpi-4.12.y, and rpi-4.13.y.
The text was updated successfully, but these errors were encountered: