Skip to content

Commit 693abfe

Browse files
decsnykartben
authored andcommitted
drivers: i2s_mcux_sai: Clean up top of file
Put DT_DRV_COMPAT at top of file by custom Consolidate logging macros Clean up checks and use build assert Remove header file which was not necessary Remove unnecessary forward declarations Fix the type of the stream state to be more precise, it is used as the enum i2s_state type. This requires handling all the enum cases in switch statements Signed-off-by: Declan Snyder <[email protected]>
1 parent 5aeda6f commit 693abfe

File tree

2 files changed

+23
-50
lines changed

2 files changed

+23
-50
lines changed

drivers/i2s/i2s_mcux_sai.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* @brief I2S bus (SAI) driver for NXP i.MX RT series.
1010
*/
1111

12+
#define DT_DRV_COMPAT nxp_mcux_i2s
13+
1214
#include <errno.h>
1315
#include <string.h>
1416
#include <zephyr/sys/__assert.h>
@@ -21,26 +23,30 @@
2123
#include <zephyr/drivers/clock_control.h>
2224
#include <zephyr/dt-bindings/clock/imx_ccm.h>
2325
#include <zephyr/sys/barrier.h>
26+
#include <zephyr/device.h>
2427
#include <soc.h>
2528

26-
#include "i2s_mcux_sai.h"
29+
#include <fsl_sai.h>
30+
#include <fsl_edma.h>
2731

28-
#define LOG_DOMAIN dev_i2s_mcux
29-
#define LOG_LEVEL CONFIG_I2S_LOG_LEVEL
3032
#include <zephyr/logging/log.h>
31-
#include <zephyr/irq.h>
32-
33-
LOG_MODULE_REGISTER(LOG_DOMAIN);
33+
LOG_MODULE_REGISTER(dev_i2s_mcux, CONFIG_I2S_LOG_LEVEL);
3434

35-
#define DT_DRV_COMPAT nxp_mcux_i2s
3635
#define NUM_DMA_BLOCKS_RX_PREP 3
37-
#define MAX_TX_DMA_BLOCKS CONFIG_DMA_TCD_QUEUE_SIZE
38-
#if (NUM_DMA_BLOCKS_RX_PREP >= CONFIG_DMA_TCD_QUEUE_SIZE)
39-
#error NUM_DMA_BLOCKS_RX_PREP must be < CONFIG_DMA_TCD_QUEUE_SIZE
40-
#endif
41-
#if defined(CONFIG_DMA_MCUX_EDMA) && (NUM_DMA_BLOCKS_RX_PREP < 3)
42-
#error eDMA avoids TCD coherency issue if NUM_DMA_BLOCKS_RX_PREP >= 3
43-
#endif
36+
#if defined(CONFIG_DMA_MCUX_EDMA)
37+
BUILD_ASSERT(NUM_DMA_BLOCKS_RX_PREP >= 3,
38+
"eDMA avoids TCD coherency issue if NUM_DMA_BLOCKS_RX_PREP >= 3");
39+
#endif /* CONFIG_DMA_MCUX_EDMA */
40+
41+
#define MAX_TX_DMA_BLOCKS CONFIG_DMA_TCD_QUEUE_SIZE
42+
BUILD_ASSERT(MAX_TX_DMA_BLOCKS > NUM_DMA_BLOCKS_RX_PREP,
43+
"NUM_DMA_BLOCKS_RX_PREP must be < CONFIG_DMA_TCD_QUEUE_SIZE");
44+
45+
#define SAI_WORD_SIZE_BITS_MIN 8
46+
#define SAI_WORD_SIZE_BITS_MAX 32
47+
48+
#define SAI_WORD_PER_FRAME_MIN 0
49+
#define SAI_WORD_PER_FRAME_MAX 32
4450

4551
/*
4652
* SAI driver uses source_gather_en/dest_scatter_en feature of DMA, and relies
@@ -65,7 +71,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
6571
* (may optionally block) from out_queue and presented to application.
6672
*/
6773
struct stream {
68-
int32_t state;
74+
enum i2s_state state;
6975
uint32_t dma_channel;
7076
uint32_t start_channel;
7177
void (*irq_call_back)(void);
@@ -111,10 +117,6 @@ struct i2s_dev_data {
111117
void *rx_out_msgs[CONFIG_I2S_RX_BLOCK_COUNT];
112118
};
113119

114-
static void i2s_dma_tx_callback(const struct device *, void *, uint32_t, int);
115-
static void i2s_tx_stream_disable(const struct device *, bool drop);
116-
static void i2s_rx_stream_disable(const struct device *, bool in_drop, bool out_drop);
117-
118120
static inline void i2s_purge_stream_buffers(struct stream *strm, struct k_mem_slab *mem_slab,
119121
bool in_drop, bool out_drop)
120122
{
@@ -388,7 +390,6 @@ static void i2s_dma_rx_callback(const struct device *dma_dev, void *arg, uint32_
388390
LOG_ERR("%p -> in_queue %p err %d", buffer, &strm->in_queue,
389391
ret);
390392
}
391-
392393
}
393394
} else {
394395
i2s_rx_stream_disable(dev, true, false);
@@ -399,6 +400,8 @@ static void i2s_dma_rx_callback(const struct device *dma_dev, void *arg, uint32_
399400
case I2S_STATE_ERROR:
400401
i2s_rx_stream_disable(dev, true, true);
401402
break;
403+
default:
404+
break;
402405
}
403406
}
404407

drivers/i2s/i2s_mcux_sai.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)