Skip to content

Conversation

@fabin-mchp
Copy link
Contributor

This pull request introduces DMA support for I2C transfers in the Microchip I2C g1 driver and updates the device tree nodes for the sam_e54_xpro board to enable DMA functionality for I2C peripherals.

add properties for dma support in binding yaml for i2c

Signed-off-by: Fabin V Martin <Fabinv.Martin@microchip.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 3, 2025

@nandojve nandojve added this to the v4.4.0 milestone Dec 3, 2025
Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

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

DMA require samples and tests working in mainline.

Comment on lines +1860 to +1900
#define I2C_MCHP_DMA_CHANNELS(n) \
.i2c_dma.dma_dev = DEVICE_DT_GET(MCHP_DT_INST_DMA_CTLR(n, tx)), \
.i2c_dma.tx_dma_request = MCHP_DT_INST_DMA_TRIGSRC(n, tx), \
.i2c_dma.tx_dma_channel = MCHP_DT_INST_DMA_CHANNEL(n, tx), \
.i2c_dma.rx_dma_request = MCHP_DT_INST_DMA_TRIGSRC(n, rx), \
.i2c_dma.rx_dma_channel = MCHP_DT_INST_DMA_CHANNEL(n, rx),
Copy link
Member

Choose a reason for hiding this comment

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

This assumes that DMA definition are always available.
What happen if that information is not ?
How the driver should behave ? It should fall back to interrupt mode ?
I assume that it is a valid scenario using one I2C with DMA and another with Interrupt. Is the driver ready for that situation ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. If the DMA definitions are not available, the driver will fall back to interrupt mode.
Using one I2C instance with DMA and another with interrupts is a valid scenario. However, the current driver does not support this configuration. We can consider adding support for mixed DMA/interrupt configurations as a future feature enhancement.

Copy link
Member

Choose a reason for hiding this comment

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

However, the current driver does not support this configuration.

Ok, but then user can configure the system wrongly because he need to add DMA lines for all instances with status=OKAY, right ? If the driver do not support mixed configuration maybe we need to add some assert to pass the message:

you are selection DMA to be used in I2C but you do not configure the DMA lines for the instance X. You need configure all I2C DMA lines to enable I2C DMA support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve added a compile-time build assert as suggested. This way, if DMA is enabled for I2C, all instances need to have their DMA lines correctly configured, helping to catch any misconfigurations during the build.

@fabin-mchp fabin-mchp force-pushed the g1_i2c_driver_dma_support branch from fd461c8 to d046416 Compare December 5, 2025 12:02
@fabin-mchp fabin-mchp requested a review from nandojve December 5, 2025 13:41
Comment on lines +1860 to +1900
#define I2C_MCHP_DMA_CHANNELS(n) \
.i2c_dma.dma_dev = DEVICE_DT_GET(MCHP_DT_INST_DMA_CTLR(n, tx)), \
.i2c_dma.tx_dma_request = MCHP_DT_INST_DMA_TRIGSRC(n, tx), \
.i2c_dma.tx_dma_channel = MCHP_DT_INST_DMA_CHANNEL(n, tx), \
.i2c_dma.rx_dma_request = MCHP_DT_INST_DMA_TRIGSRC(n, rx), \
.i2c_dma.rx_dma_channel = MCHP_DT_INST_DMA_CHANNEL(n, rx),
Copy link
Member

Choose a reason for hiding this comment

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

However, the current driver does not support this configuration.

Ok, but then user can configure the system wrongly because he need to add DMA lines for all instances with status=OKAY, right ? If the driver do not support mixed configuration maybe we need to add some assert to pass the message:

you are selection DMA to be used in I2C but you do not configure the DMA lines for the instance X. You need configure all I2C DMA lines to enable I2C DMA support.

@fabin-mchp fabin-mchp force-pushed the g1_i2c_driver_dma_support branch from d046416 to b9d6219 Compare December 8, 2025 05:27
@fabin-mchp fabin-mchp requested a review from nandojve December 8, 2025 05:54
@fabin-mchp
Copy link
Contributor Author

fabin-mchp commented Dec 8, 2025

DMA require samples and tests working in mainline.

@nandojve Thanks for your comment.

I have a doubt regarding this. Do you mean that we need add the board name sam_e54_xpro in sample.yaml and testcase.yaml

#include <zephyr/irq.h>
#include <zephyr/logging/log.h>
#include <zephyr/drivers/i2c.h>
#ifdef CONFIG_I2C_MCHP_DMA_DRIVEN
Copy link
Contributor

Choose a reason for hiding this comment

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

ifdef really needed? Any build issues if removed?

Copy link
Contributor Author

@fabin-mchp fabin-mchp Dec 9, 2025

Choose a reason for hiding this comment

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

The build works fine without the #ifdef. I added it just to include these headers only when DMA support is enabled.
Should I remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed #ifdef as per suggestion.

{
struct i2c_mchp_dev_data *data = dev->data;

/* left-shift address by 1 for R/W bit. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Dropping the comment here seems unrelated

@nandojve
Copy link
Member

nandojve commented Dec 8, 2025

DMA require samples and tests working in mainline.

@nandojve Thanks for your comment.

I have a doubt regarding this. Do you mean that we need add the board name sam_e54_xpro in sample.yaml and testcase.yaml

yes, otherwise it will not build in CI. When a sample/testcase.yaml is filtering by platform-allow, usually only those run in CI.

@fabin-mchp
Copy link
Contributor Author

fabin-mchp commented Dec 9, 2025

DMA require samples and tests working in mainline.

@nandojve Thanks for your comment.
I have a doubt regarding this. Do you mean that we need add the board name sam_e54_xpro in sample.yaml and testcase.yaml

yes, otherwise it will not build in CI. When a sample/testcase.yaml is filtering by platform-allow, usually only those run in CI.

@nandojve
The existing tests under tests/drivers/i2c are not supported on the sam_e54_xpro because they depend on specific sensors and multiple EEPROM devices that this board does not have. Therefore, we created dedicated test applications for this board, which will be submitted as a separate PR.
I can only find the rtio_loopback sample under samples/drivers/i2c for testing I2C transfers using RTIO. However, this sample does not currently support the sam_e54_xpro board.

@fabin-mchp fabin-mchp requested a review from teburd December 9, 2025 07:45
dma support added for i2c transfer

Signed-off-by: Fabin V Martin <Fabinv.Martin@microchip.com>
add dma properties in i2c node.

Signed-off-by: Fabin V Martin <Fabinv.Martin@microchip.com>
@fabin-mchp fabin-mchp force-pushed the g1_i2c_driver_dma_support branch from b9d6219 to 6b436c4 Compare December 11, 2025 09:50
@sonarqubecloud
Copy link

@nandojve
Copy link
Member

DMA require samples and tests working in mainline.

@nandojve Thanks for your comment.
I have a doubt regarding this. Do you mean that we need add the board name sam_e54_xpro in sample.yaml and testcase.yaml

yes, otherwise it will not build in CI. When a sample/testcase.yaml is filtering by platform-allow, usually only those run in CI.

@nandojve The existing tests under tests/drivers/i2c are not supported on the sam_e54_xpro because they depend on specific sensors and multiple EEPROM devices that this board does not have. Therefore, we created dedicated test applications for this board, which will be submitted as a separate PR. I can only find the rtio_loopback sample under samples/drivers/i2c for testing I2C transfers using RTIO. However, this sample does not currently support the sam_e54_xpro board.

Hi @fabin-mchp ,

I'm really against bring content without a way to keep it sane. I think we really should work in the direction to bring content with tests because it is the only way to serve well community and customers. Otherwise instead focus in the improvements and new features we will start at some point to only fix problems in the tree because we did not tested well. I understand that you are testing locally but Zephyr changes so much that it is very easy to someone create a problem if we don't have a way to catch it.

I would say you should bring the test here and make it generic enough to capture not only Microchip but other devices. You can be surprise with the problems. If that happens, we make the test available only to MCHP and then people can fix at their time.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants