-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Add spi-gpio support #2169
Comments
Have you tried this on a Pi? How well does it work? |
I have tested it on a Raspberry Pi Zero W. |
I'm interested to see the overlay - we'd want to add one to the standard image to make the new driver usable. |
Here it is: |
Current version of the overlay, includes debian packaging: |
If you put the overlay in a Pull Request along with a README patch and the required config updates - see #2252 for a very recent example - it should get merged quickly. |
@BjoernSch Did this PR happen? |
Not yet, but I will take care of it this week. |
Not exactly - we've enabled the required driver in the standard kernel builds, but users will need to modify and build their own overlays. |
@pelwell Is the steps needed to be taken documented anywhere to get this working? |
|
@pelwell is this kernel version available yet in Raspbian Stretch, or is there some nightly kernel repository? My raspberrypi-kernel version is: 1.20180417-1
|
That is the most recent Raspbian release, but you can download 4.14.52 using |
@pelwell That causes the spidev device to disappear. I was hoping to keep using that, just that I want to write to the CS pin to be able to run multiple transfers within one toggle. Seems like the spidev by defaults toggles CS based on transfer() calls. My usecase is that I have a radio data frame I want to read out, but I want to read out the header separately, and the payload to a statically allocated buffer, so I want to call transfer first with the address and enough room for the header, then again, with the API user supplied buffer to read out the payload. If I try that today, I get garbage unless I pass address in the first byte in the argument of the second transfer. Was hoping this would fix that. Any idea? |
The spidev API structure
By carefully setting the cs_change flag on each transfer you can create arbitrary patterns of CS usage. |
@pelwell This is getting slightly off-topic, but what you say does not seem to prevent the CS from changing under my feet according to my experiments. Rust's spidev crate leaves cs_change at 0, and yet it changes (my second transfer needs the same address at buffer[0] as the first transfer to continue the read, which is not expected right?). It kind of sounds like the following issue: https://www.raspberrypi.org/forums/viewtopic.php?t=195600 Any suggestions? Can't find the bug that could have been the output of that thread, and don't feel like I have the knowledge myself to file such a bug myself with meaningful information. |
If you want to keep CS asserted indefinitely you need to set cs_change=1, but only for the last transfer in each message. If that doesn't make sense, read my previous reply again until it does. |
So I do:
I guess this has no affect, and I could just as well have ignored setting the CS pin via GPIO. In other cases I have this:
I have re-read your reply, but to me it sounds odd that changing cs_change the last transfer makes the first transfer not fiddle around with the CS. The reason I mention explicitly setting CS here via GPIO is that I'm using the linux-embedded-hal which is a Linux implementation of the generic embedded-hal. Compiling my library for some embedded target would toggle ports and do the SPI dance there instead without spidev being involved. Is it perhaps impossible to disable automatic CS-stuff on raspberry pi when using spidev? Really just want it to hands-off the CS, as I'm expected to control CS manually if the library is deployed on other platforms than Linux. |
Reading the code, the spi-bcm2835 driver does support SPI_NO_CS, but only when using chip-selects driven by the hardware. As a work-around for a bug in the hardware, the driver automatically converts hardware chip selects into GPIO chip selects which are then managed by the common SPI subsystem. Unfortunately this layer doesn't seem to honour SPI_NO_CS, leaving you in the situation you are in now (unless you manage to make use of the cs_change flags). There are a few options available:
What are your thoughts? |
@pelwell My thoughts are centered around how grateful I am for your help. I applied the |
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
I've pushed a one-line patch that adds SPI_NO_CS support for GPIO chip-selects. Once you have a kernel with that patch you should be able to remove the spi0-hw-cs overlay and still be able to drive the CS line as you wish. |
See: raspberrypi/linux#2614 kernel: vc4: DPI support See: raspberrypi/linux#2429 kernel: spi: Make GPIO CSs honour the SPI_NO_CS flag See: raspberrypi/linux#2169 kernel: overlays: Add addr parameter to i2c-rtc (& -gpio) See: raspberrypi/linux#2611 userland: mmal: Remove unused mmal_metadata header file
See: raspberrypi/linux#2614 kernel: vc4: DPI support See: raspberrypi/linux#2429 kernel: spi: Make GPIO CSs honour the SPI_NO_CS flag See: raspberrypi/linux#2169 kernel: overlays: Add addr parameter to i2c-rtc (& -gpio) See: raspberrypi/linux#2611 userland: mmal: Remove unused mmal_metadata header file
Last night's rpi-update kernel+firmware release includes the SPI_NO_CS patch. |
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: raspberrypi#2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: raspberrypi#2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: raspberrypi/linux#2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: raspberrypi/linux#2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
[ Upstream commit a7755c3 ] Requesting page reqest irq under dmar_global_lock could cause potential lock race condition (caught by lockdep). [ 4.100055] ====================================================== [ 4.100063] WARNING: possible circular locking dependency detected [ 4.100072] 5.1.0-rc4+ #2169 Not tainted [ 4.100078] ------------------------------------------------------ [ 4.100086] swapper/0/1 is trying to acquire lock: [ 4.100094] 000000007dcbe3c3 (dmar_lock){+.+.}, at: dmar_alloc_hwirq+0x35/0x140 [ 4.100112] but task is already holding lock: [ 4.100120] 0000000060bbe946 (dmar_global_lock){++++}, at: intel_iommu_init+0x191/0x1438 [ 4.100136] which lock already depends on the new lock. [ 4.100146] the existing dependency chain (in reverse order) is: [ 4.100155] -> #2 (dmar_global_lock){++++}: [ 4.100169] down_read+0x44/0xa0 [ 4.100178] intel_irq_remapping_alloc+0xb2/0x7b0 [ 4.100186] mp_irqdomain_alloc+0x9e/0x2e0 [ 4.100195] __irq_domain_alloc_irqs+0x131/0x330 [ 4.100203] alloc_isa_irq_from_domain.isra.4+0x9a/0xd0 [ 4.100212] mp_map_pin_to_irq+0x244/0x310 [ 4.100221] setup_IO_APIC+0x757/0x7ed [ 4.100229] x86_late_time_init+0x17/0x1c [ 4.100238] start_kernel+0x425/0x4e3 [ 4.100247] secondary_startup_64+0xa4/0xb0 [ 4.100254] -> #1 (irq_domain_mutex){+.+.}: [ 4.100265] __mutex_lock+0x7f/0x9d0 [ 4.100273] __irq_domain_add+0x195/0x2b0 [ 4.100280] irq_domain_create_hierarchy+0x3d/0x40 [ 4.100289] msi_create_irq_domain+0x32/0x110 [ 4.100297] dmar_alloc_hwirq+0x111/0x140 [ 4.100305] dmar_set_interrupt.part.14+0x1a/0x70 [ 4.100314] enable_drhd_fault_handling+0x2c/0x6c [ 4.100323] apic_bsp_setup+0x75/0x7a [ 4.100330] x86_late_time_init+0x17/0x1c [ 4.100338] start_kernel+0x425/0x4e3 [ 4.100346] secondary_startup_64+0xa4/0xb0 [ 4.100352] -> #0 (dmar_lock){+.+.}: [ 4.100364] lock_acquire+0xb4/0x1c0 [ 4.100372] __mutex_lock+0x7f/0x9d0 [ 4.100379] dmar_alloc_hwirq+0x35/0x140 [ 4.100389] intel_svm_enable_prq+0x61/0x180 [ 4.100397] intel_iommu_init+0x1128/0x1438 [ 4.100406] pci_iommu_init+0x16/0x3f [ 4.100414] do_one_initcall+0x5d/0x2be [ 4.100422] kernel_init_freeable+0x1f0/0x27c [ 4.100431] kernel_init+0xa/0x110 [ 4.100438] ret_from_fork+0x3a/0x50 [ 4.100444] other info that might help us debug this: [ 4.100454] Chain exists of: dmar_lock --> irq_domain_mutex --> dmar_global_lock [ 4.100469] Possible unsafe locking scenario: [ 4.100476] CPU0 CPU1 [ 4.100483] ---- ---- [ 4.100488] lock(dmar_global_lock); [ 4.100495] lock(irq_domain_mutex); [ 4.100503] lock(dmar_global_lock); [ 4.100512] lock(dmar_lock); [ 4.100518] *** DEADLOCK *** Cc: Ashok Raj <[email protected]> Cc: Jacob Pan <[email protected]> Cc: Kevin Tian <[email protected]> Reported-by: Dave Jiang <[email protected]> Fixes: a222a7f ("iommu/vt-d: Implement page request handling") Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
The SPI configuration state includes an SPI_NO_CS flag that disables all CS line manipulation, for applications that want to manage their own chip selects. However, this flag is ignored by the GPIO CS code in the SPI framework. Correct this omission with a trivial patch. See: #2169 Signed-off-by: Phil Elwell <[email protected]>
I have followed your instruction on my Raspberry Pi 0 W (Raspbian Buster Lite), but SPI is not working though...
And the execution result:
After I have copied the .dtbo file to
And the RC522 reader is not working with the new SPI bus... Any idea? Thanks! P.S. I even tried to start the overlay manually:
|
This would require to enable spi-gpio (and spi-bitbang as dependency) as module.
Afterwards you could add additional software SPI devices via device tree overlays on freely choosen GPIOs.
The text was updated successfully, but these errors were encountered: