Skip to content

Conversation

ArunMCHP
Copy link
Contributor

This pull request adds DMA driver support for the Microchip DMAC peripheral. It introduces the DMA driver implementation and updates the devicetree for the SAM D5x/E5x series to include the required node and bindings.

Add the device tree node and the binding file for
microchip dma G1 Peripheral.

Signed-off-by: Arunprasath P <[email protected]>
@zephyrbot zephyrbot added platform: Microchip MEC Microchip MEC Platform platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) area: DMA Direct Memory Access labels Sep 19, 2025
Copy link
Contributor

@teburd teburd left a comment

Choose a reason for hiding this comment

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

A good number of things I see that need sorting out, might see some more things once the noise is cut down a bit. If you are using an LLM to generate some stuff, I recommend not doing so (it appears like you might, as there's a lot of redundent commentary in my opinion).

*
* Represents the different states a DMA channel can be in during its lifecycle.
*/
typedef enum dma_mchp_ch_state {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to typedef this enum

* This enumeration defines the possible interrupt status codes
* that indicate the outcome of a DMA transaction.
*/
typedef enum {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to typedef this enum

* This enumeration defines attribute types that describe hardware-specific
* constraints and capabilities for DMA transfers.
*/
typedef enum dma_mchp_attribute_type {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm seeing a pattern, but yeah like the others, don't typedef enums/structs please. We somewhat follow linux coding style and typedefs like this aren't warranted.

https://kernel.org/doc/html/latest/process/coding-style.html#typedefs

{
dmac_reg->DMAC_CTRL |= DMAC_CTRL_DMAENABLE(0);
dmac_reg->DMAC_CTRL |= DMAC_CTRL_SWRST_Msk;
while ((dmac_reg->DMAC_CTRL & DMAC_CTRL_SWRST_Msk) >> DMAC_CTRL_SWRST_Pos) {
Copy link
Contributor

Choose a reason for hiding this comment

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

use the WAIT_FOR macro here with a time limit if the hardware has some guarantees on time to reset you can follow and fail on

* @param dmac_reg Pointer to the base address of the DMAC peripheral registers.
* @param enable Boolean value to enable (true) or disable (false) the DMA controller.
*/
static inline void dmac_enable(dmac_registers_t *dmac_reg, bool enable)
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend a dmac_enable/dmac_disable pair instead of a bool param here

ret = 0;
} while (0);

if (irq_locked == true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed if you use goto and labels or early returns, please fix and drop do { } while(0);

dma_mchp_channel_config_t *dma_channel_config;

/* Pool of descriptor */
struct k_fifo dma_desc_pool;
Copy link
Contributor

Choose a reason for hiding this comment

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

k_fifo really isn't the right tool for this, either use a k_mem_slab, sys_block, or array with atomic bitmap signaling used/unused. If you want the cheapest computational route make an array of arrays, one array for each channel with some number of descriptors. No locks, no lists, no checks needed at all since channels are single owner.


/*******************************************
* @brief Devicetree definitions
*******************************************/
Copy link
Contributor

Choose a reason for hiding this comment

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

Really not needing to be doc commented here, this is a private file, no doc comments will result in doxygen generation, but its nice to see a consistent style.

Regardless large comment blocks like this aren't needed, everyone in zephyr knows what the DT_DRV_COMPAT is for

*******************************************/
#define DT_DRV_COMPAT microchip_dmac_g1_dma

/*******************************************
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to add large comments splitting up sections of the C file like this

* This macro defines the required alignment (in bytes) for the starting address
* of a DMA buffer. For 32-bit transfers, a 4-byte alignment is required.
*/
#define DMAC_BUF_ADDR_ALIGNMENT 4
Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly the define is pretty self documented, simple

/* Address alignment for DMA buffers */

Is plenty here, no need to go to length details like this, its just adding line noise.

Same for other defines in the file.

Add DMA driver for Microchip DMA G1 IP Peripherals.

Signed-off-by: Arunprasath P <[email protected]>
Update sam_e54_xpro.yml to include DMA in the supported
features list.

Signed-off-by: Arunprasath P <[email protected]>
Copy link

sonarqubecloud bot commented Oct 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Boards/SoCs area: Devicetree Bindings area: DMA Direct Memory Access platform: Microchip MEC Microchip MEC Platform platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants