Skip to content

i2c: buffer mode support when mode changes through bus restart#417

Open
Shreehari-AlifSemi wants to merge 5 commits intoalifsemi:mainfrom
Shreehari-AlifSemi:PSBT-1553-i2c_buffer_mode_support_when_mode_changes_through_bus_RESTART
Open

i2c: buffer mode support when mode changes through bus restart#417
Shreehari-AlifSemi wants to merge 5 commits intoalifsemi:mainfrom
Shreehari-AlifSemi:PSBT-1553-i2c_buffer_mode_support_when_mode_changes_through_bus_RESTART

Conversation

@Shreehari-AlifSemi
Copy link
Copy Markdown
Contributor

The PR performs the following:

  1. Rename variables used in buffer mode communication to follow the driver naming style and improve clarity.

  2. Remove the buf_pos reset in the dw_transfer() API, as this function is not intended to be used for I2C target mode.

  3. Replace the shared buf_pos variable with separate rx_pos and tx_pos variables to independently track RX and TX buffer progress.

  4. Reset buffer mode variables when configuring the controller for slave mode.

  5. 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.

@VeijoPesonen VeijoPesonen changed the title Psbt-1553: i2c: buffer mode support when mode changes through bus restart i2c: buffer mode support when mode changes through bus restart Mar 12, 2026
@RupeshKumar-AlifSemi RupeshKumar-AlifSemi requested review from a team and Copilot March 16, 2026 09:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@Shreehari-AlifSemi Shreehari-AlifSemi force-pushed the PSBT-1553-i2c_buffer_mode_support_when_mode_changes_through_bus_RESTART branch from fb85899 to 309faa9 Compare March 16, 2026 10:12
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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this flag enabled only for the buffer mode?

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