i2c: buffer mode support when mode changes through bus restart#417
Open
Shreehari-AlifSemi wants to merge 5 commits intoalifsemi:mainfrom
Conversation
RupeshKumar-AlifSemi
approved these changes
Mar 16, 2026
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rename variables used in buffer mode communication to follow the driver naming style and improve clarity. Signed-off-by: Shreehari HK <shreehari.hk@alifsemi.com>
- Remove the buf_pos reset in the dw_transfer() API, as this function is not intended to be used for I2C target mode. Signed-off-by: Shreehari HK <shreehari.hk@alifsemi.com>
- Replace the shared buf_pos variable with separate rx_pos and tx_pos variables to independently track RX and TX buffer progress. - Previously, a single variable was used for both RX and TX buffer tracking, which could lead to incorrect behavior when switching communication modes if the expected number of bytes was not transferred. Signed-off-by: Shreehari HK <shreehari.hk@alifsemi.com>
- Reset buffer mode variables when configuring the controller for slave mode. Signed-off-by: Shreehari HK <shreehari.hk@alifsemi.com>
- In slave mode, there is no interrupt generated for a RESTART condition. The buffer mode communication logic currently assumes that the transfer terminates only when a STOP condition is detected. - When the bus issues a RESTART instead of STOP, the buffer mode state is not handled correctly, which can lead to data mismatch or communication errors when the transfer direction changes. - Handle this case by detecting a START condition and resetting the buffer mode state accordingly. Signed-off-by: Shreehari HK <shreehari.hk@alifsemi.com>
fb85899 to
309faa9
Compare
| ret = i2c_dw_set_slave_mode(dev, cfg->address, cfg->flags); | ||
| write_intr_mask(DW_INTR_MASK_RX_FULL | DW_INTR_MASK_RD_REQ | DW_INTR_MASK_TX_ABRT | | ||
| DW_INTR_MASK_STOP_DET, | ||
| DW_INTR_MASK_START_DET | DW_INTR_MASK_STOP_DET, |
Contributor
There was a problem hiding this comment.
Should we have this flag enabled only for the buffer mode?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The PR performs the following:
Rename variables used in buffer mode communication to follow the driver naming style and improve clarity.
Remove the buf_pos reset in the dw_transfer() API, as this function is not intended to be used for I2C target mode.
Replace the shared buf_pos variable with separate rx_pos and tx_pos variables to independently track RX and TX buffer progress.
Reset buffer mode variables when configuring the controller for slave mode.
Add buffer mode support during communication direction change through RESTART:
In slave mode, there is no interrupt generated for a RESTART condition.
The buffer mode communication logic currently assumes that the transfer
terminates only when a STOP condition is detected.
When the bus issues a RESTART instead of STOP, the buffer mode state
is not handled correctly, which can lead to data mismatch or
communication errors when the transfer direction changes.
Handle this case by detecting a START condition and resetting
the buffer mode state accordingly.