Skip to content

New unified hostmot2 SPI driver hm2_spix#3209

Merged
pcw-mesa merged 19 commits intoLinuxCNC:masterfrom
BsAtHome:hm2_spix
Dec 7, 2024
Merged

New unified hostmot2 SPI driver hm2_spix#3209
pcw-mesa merged 19 commits intoLinuxCNC:masterfrom
BsAtHome:hm2_spix

Conversation

@BsAtHome
Copy link
Contributor

@BsAtHome BsAtHome commented Dec 7, 2024

This is the new unified SPI driver for the Mesa cards supporting hostmot2 over SPI. This driver currently supports Raspberry Pi 3, 4 and 5 natively, including compute modules 4 and 5, and will automatically fall back to the kernel's spidev interface if an unsupported board is found. The driver is written for easy addition of new native hardware drivers like future RPi boards or existing other "fruity" pi boards.

The new driver also includes fixes for SPI1 on the RPi3 and RPi4 boards, which was non-functional with the previous driver.

The new hm2_spix driver is easily back-ported if required.
The code body includes some separated source files for future de-duplicating of some routines and constants, which other HM2 drivers should make use of later on. A second PR will be created after integration of this driver to streamline and implement code de-duplication for the other drivers(s).

Don't close ports forcefully at exit, let the driver do that on cleanup.
Fix some text typos.
Don't add isopen to spix_spidev driver. It can be determined from the file descriptor.
Add spi_pull_* arguments for compatibility and warn if they are used.
Use rtapi_open_as_root instead of plain open.
Use variable bit-length mode in SPI1 transfers.
Fix swapping words back to host-order after transfer.
Add more generic forwarding of module arguments when opening a port.
Recalculate min/max frequencies for RPi3/4.
Allow spidev device node path overrides.
Copy errno because following code can alter it.
Reading a 0-byte length file is not a real error. It will lead to a fail later.
Don't fuss, sizeof(uint32_t) = 2 * sizeof(uint16_t) and will never change.
Other manufacturers will have other names, but may share the last portion.
…iver.

Compensate truncated input values by adding one kHz to the rate settings.
@pcw-mesa pcw-mesa merged commit b97d0a8 into LinuxCNC:master Dec 7, 2024
7 of 10 checks passed
@JessieAMorris
Copy link

Amazing work! Thank you for this, this is perfect timing for my project.

@andypugh
Copy link
Collaborator

andypugh commented Dec 7, 2024

Thanks.
If it was just a new driver I would be looking to port it to 2.9, but it touches lots of other files in hm2 and that makes me a little nervous.

@BsAtHome
Copy link
Contributor Author

BsAtHome commented Dec 7, 2024

If it was just a new driver I would be looking to port it to 2.9, but it touches lots of other files in hm2 and that makes me a little nervous.

Actually, it only touches two files from the previous driver: hm2_rpspi.c and spi_common_rpspi.h.
The changes in hm2_rpspi.c are moving the register read/write macros (always inlined function) into a header hwregaccess.h. The changes in spi_common_rpspi.h are moving the __I, __O and __IO macros into the hwregaccess.h header.

A backport to 2.9 would change exactly the same thing as this PR did in HEAD.

Now, HEAD should evolve a bit further, where a cleanup is in order, which I mentioned in the text accompanying this PR. None of the evolution needs to be backported for the hm2_spix driver to function in 2.9.

@ghost
Copy link

ghost commented Dec 15, 2024

Wow Thank You Sir.
Very much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants