-
Notifications
You must be signed in to change notification settings - Fork 7.9k
spi: add spi_acquire
API
#95592
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
base: main
Are you sure you want to change the base?
spi: add spi_acquire
API
#95592
Conversation
f26b155
to
3aba62a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the use case of this? and I didn't understand why the SD card requires locking/acquiring the spi bus
note: the block is over the error codes documentation, I am fine with adding a "symmetrical" API to spi_release
Add a counterpart to the `spi_release` function call that locks the context without needing to initiate a transaction. This is intended to be used when SPI bus access needs to be blocked before the device is accessed. One example of this requirement is power cycling an SD card, where the bus should be kept idle after power up until starting the switch from SD mode to SPI mode. This requires locking the bus before power is applied. Signed-off-by: Jordan Yates <[email protected]>
Add `spi_acquire` implementations for a subset of SPI drivers. Signed-off-by: Jordan Yates <[email protected]>
Document the new SPI API function, `spi_acquire`. Signed-off-by: Jordan Yates <[email protected]>
3aba62a
to
c6a8eeb
Compare
|
I don't see a need for API change for such corner case. A way to do what you want already I think, if you really need to lock a SPI controller to a user (whatever the reason is), will be to just have a temporary spi_config as a copy of your dts based spi_config but with SPI_LOCK_ON bit set, call spi_write with valid spi_buf_set but a spi_buf of length 0. It should be going through the config, setting the ownership and do nothing on the bus (at least not sending any data) and return now with the caller having the lock until calling spi_release with that same temporary config. No? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my previous comment
Maybe in theory, but thats not the case even in the first controller I look at, I agree that its a corner case, but supporting it this way is much lower overhead than looking at every driver and checking how it would have a transaction of length 0. |
Sorry, my comment had it around the wrong way. Yes the CS needs to be high for 74 cycles. The problem is that on actual cards, the MOSI line toggling even while the CS line is high is enough to cause problems, presumably because the card is not yet in SPI mode and the toggling is being treated as part of some SDIO transaction. |
Add a counterpart to the
spi_release
function call that locks the context without needing to initiate a transaction. This is intended to be used when SPI bus access needs to be blocked before the device is accessed.One example of this requirement is power cycling an SD card, where the bus should be kept idle after power up until starting the switch from SD mode to SPI mode. This requires locking the bus before power is applied.
Currently no tests in this PR, there doesn't appear to be any tests of
spi_release
in the tree, happy to take suggestions on what to do.