-
Notifications
You must be signed in to change notification settings - Fork 8.1k
drivers: smbus: stm32: add support for pcall api #97188
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?
Conversation
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.
Commit "drivers: smbus: stm32: add support for pcall api" LGTM.
021b6e2
to
59dbf70
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.
In the SMBus specification the process call seems to be specified differently:
There is no count for send and receive with a variable length, just a hard coded word exchange (write and read)?
There seems to be no difference between version 3.1 and 3.2 of the SMBus specification regarding the process call, btw.
* This works because the STM I2C driver processes each message serially. | ||
* The addressing math assumes little-endian. | ||
*/ | ||
msgs[3].buf = (uint8_t *)&msgs[4].len; |
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.
neat trick
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.
I think that came from @jgrowdenTT 😀
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.
Thanks, but I can't claim credit :) it's a repeat of the idea in smbus_stm32_block_read
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.
Probably @alewycky-tenstorrent in that case 😀
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.
It seems a little unsafe to blindly trust a size from the wire 🙂
But since the driver already does it...
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.
Indeed. If caller is expected to set the input value to the size available in the output buffer, it would be worth checking that the received data won't overflow memory. As you said @mathieuchopstm, it's seems something to address driver wide (possibly outside of this P-R).
I see this change implements the block write/read process call (Section "6.5.8 Block Write-Block Read Process Call" of the spec). Indeed the "Process Call" (single word) this is already implemented by @cfriedt, @jgrowdenTT, did you plan to also implement single word "Process Call"? |
@etienne-lms - I can take a look at it |
Sorry - my bad, this was the pcall block API. I'll add the pcall API shortly. |
Add SMBus Block Write-Block Read Process Call API for STM32. This implementation also supports PEC mode (packet error checking) and is dependent on PEC support already being supported in-tree. Signed-off-by: James Growden <jgrowden@tenstorrent.com> Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
59dbf70
to
e649a3d
Compare
@etienne-lms @benediktibk @mathieuchopstm @erwango - please take another look |
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.
Otherwise LGTM
drivers/smbus/smbus_stm32.c
Outdated
|
||
return result; | ||
num_msgs = smbus_pec_num_msgs(data->config, ARRAY_SIZE(msgs)); | ||
smbus_write_prepare_pec(data->config, periph_addr, msgs, ARRAY_SIZE(msgs)); |
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.
My understanding is that the PEC byte is read here. Is this correct?
(Also, am I misunderstanding or is the PEC byte completely ignored?? Shouldn't smbus_read_check_pec
be called?)
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.
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.
Fixed!
* This works because the STM I2C driver processes each message serially. | ||
* The addressing math assumes little-endian. | ||
*/ | ||
msgs[3].buf = (uint8_t *)&msgs[4].len; |
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.
It seems a little unsafe to blindly trust a size from the wire 🙂
But since the driver already does it...
Implement smbus_stm32_pcall() with packet error correction. For more information, please see chapter 6.5.6 of the SMBus specification. https://smbus.org/specs/SMBus_3_1_20180319.pdf Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
e649a3d
to
85ed3ab
Compare
|
* This works because the STM I2C driver processes each message serially. | ||
* The addressing math assumes little-endian. | ||
*/ | ||
msgs[3].buf = (uint8_t *)&msgs[4].len; |
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.
Indeed. If caller is expected to set the input value to the size available in the output buffer, it would be worth checking that the received data won't overflow memory. As you said @mathieuchopstm, it's seems something to address driver wide (possibly outside of this P-R).
Add SMBus Process Call / Process Call Block APIs for STM32.
This implementation also supports PEC mode (packet error checking) and is dependent on PEC support already being supported in-tree.
For more details, please see Sections 6.5.6 and 6.5.8 of the SMBus 3.1 Specification.
https://smbus.org/specs/SMBus_3_1_20180319.pdf