From 426f66ac8877e7dfd3fc9fe6dedd20705e4660e6 Mon Sep 17 00:00:00 2001 From: Adam Kondraciuk Date: Wed, 3 Dec 2025 10:41:44 +0100 Subject: [PATCH 1/2] Revert "[nrf fromlist] drivers: i2s: nrf_tdm: Add guards for buffers size" This reverts commit 84698d898b1c89c782e38b69bb85916da27f0e2e. Signed-off-by: Adam Kondraciuk (cherry picked from commit 2921353daef0b41c4074393a4a96c9bc9433082f) --- drivers/i2s/i2s_nrf_tdm.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/drivers/i2s/i2s_nrf_tdm.c b/drivers/i2s/i2s_nrf_tdm.c index 2e9e94c07023..07c561b77503 100644 --- a/drivers/i2s/i2s_nrf_tdm.c +++ b/drivers/i2s/i2s_nrf_tdm.c @@ -32,11 +32,6 @@ LOG_MODULE_REGISTER(tdm_nrf, CONFIG_I2S_LOG_LEVEL); */ #define NRFX_TDM_STATUS_TRANSFER_STOPPED BIT(1) -/* Due to hardware limitations, the TDM peripheral requires the rx/tx size - * to be greater than 8 bytes. - */ -#define NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED 8 - /* Maximum clock divider value. Corresponds to CKDIV2. */ #define NRFX_TDM_MAX_SCK_DIV_VALUE TDM_CONFIG_SCK_DIV_SCKDIV_Max #define NRFX_TDM_MAX_MCK_DIV_VALUE TDM_CONFIG_MCK_DIV_DIV_Max @@ -480,11 +475,9 @@ static int tdm_nrf_configure(const struct device *dev, enum i2s_dir dir, __ASSERT_NO_MSG(tdm_cfg->mem_slab != NULL && tdm_cfg->block_size != 0); - if ((tdm_cfg->block_size % sizeof(uint32_t)) != 0 || - tdm_cfg->block_size <= NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED) { - LOG_ERR("This device can only transmit full 32-bit words greater than %u bytes.", - NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED); - return -EIO; + if ((tdm_cfg->block_size % sizeof(uint32_t)) != 0) { + LOG_ERR("This device can transfer only full 32-bit words"); + return -EINVAL; } switch (tdm_cfg->word_size) { @@ -680,18 +673,11 @@ static int tdm_nrf_write(const struct device *dev, void *mem_block, size_t size) return -EIO; } - if (size > drv_data->tx.cfg.block_size) { + if (size > drv_data->tx.cfg.block_size || size < sizeof(uint32_t)) { LOG_ERR("This device can only write blocks up to %u bytes", drv_data->tx.cfg.block_size); return -EIO; } - - if ((size % sizeof(uint32_t)) != 0 || size <= NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED) { - LOG_ERR("This device can only write full 32-bit words greater than %u bytes.", - NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED); - return -EIO; - } - ret = dmm_buffer_out_prepare(drv_cfg->mem_reg, buf.mem_block, buf.size, (void **)&buf.dmm_buf); ret = k_msgq_put(&drv_data->tx_queue, &buf, SYS_TIMEOUT_MS(drv_data->tx.cfg.timeout)); From b5d0a0fc18956938300a1f673f51956d30d21185 Mon Sep 17 00:00:00 2001 From: Adam Kondraciuk Date: Mon, 1 Dec 2025 10:15:21 +0100 Subject: [PATCH 2/2] [nrf fromlist] drivers: i2s: nrf_tdm: Add guards for buffers size TDM peripheral requires TXD.MAXCNT and RXD.MAXCNT registers to be: - multiple of 4 bytes - larger than 8 bytes Upstream PR #: 100288 Signed-off-by: Adam Kondraciuk (cherry picked from commit c717584f1a66d914fd87128b3e3c8dd952c8725c) --- drivers/i2s/i2s_nrf_tdm.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/i2s/i2s_nrf_tdm.c b/drivers/i2s/i2s_nrf_tdm.c index 07c561b77503..f1a691e0cefb 100644 --- a/drivers/i2s/i2s_nrf_tdm.c +++ b/drivers/i2s/i2s_nrf_tdm.c @@ -32,6 +32,11 @@ LOG_MODULE_REGISTER(tdm_nrf, CONFIG_I2S_LOG_LEVEL); */ #define NRFX_TDM_STATUS_TRANSFER_STOPPED BIT(1) +/* Due to hardware limitations, the TDM peripheral requires the rx/tx size + * to be greater than 8 bytes. + */ +#define NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED 8 + /* Maximum clock divider value. Corresponds to CKDIV2. */ #define NRFX_TDM_MAX_SCK_DIV_VALUE TDM_CONFIG_SCK_DIV_SCKDIV_Max #define NRFX_TDM_MAX_MCK_DIV_VALUE TDM_CONFIG_MCK_DIV_DIV_Max @@ -475,8 +480,10 @@ static int tdm_nrf_configure(const struct device *dev, enum i2s_dir dir, __ASSERT_NO_MSG(tdm_cfg->mem_slab != NULL && tdm_cfg->block_size != 0); - if ((tdm_cfg->block_size % sizeof(uint32_t)) != 0) { - LOG_ERR("This device can transfer only full 32-bit words"); + if ((tdm_cfg->block_size % sizeof(uint32_t)) != 0 || + tdm_cfg->block_size <= NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED) { + LOG_ERR("This device can only transmit full 32-bit words greater than %u bytes.", + NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED); return -EINVAL; } @@ -673,11 +680,18 @@ static int tdm_nrf_write(const struct device *dev, void *mem_block, size_t size) return -EIO; } - if (size > drv_data->tx.cfg.block_size || size < sizeof(uint32_t)) { + if (size > drv_data->tx.cfg.block_size) { LOG_ERR("This device can only write blocks up to %u bytes", drv_data->tx.cfg.block_size); return -EIO; } + + if ((size % sizeof(uint32_t)) != 0 || size <= NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED) { + LOG_ERR("This device can only write full 32-bit words greater than %u bytes.", + NRFX_TDM_MIN_TRANSFER_SIZE_ALLOWED); + return -EIO; + } + ret = dmm_buffer_out_prepare(drv_cfg->mem_reg, buf.mem_block, buf.size, (void **)&buf.dmm_buf); ret = k_msgq_put(&drv_data->tx_queue, &buf, SYS_TIMEOUT_MS(drv_data->tx.cfg.timeout));