1 /*
2  * Copyright (c) 2018 STMicroelectronics
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _STM32_I2S_H_
8 #define _STM32_I2S_H_
9 
10 struct queue_item {
11 	void *mem_block;
12 	size_t size;
13 };
14 
15 /* Device constant configuration parameters */
16 struct i2s_stm32_cfg {
17 	SPI_TypeDef *i2s;
18 	const struct stm32_pclken *pclken;
19 	size_t pclk_len;
20 	const struct pinctrl_dev_config *pcfg;
21 	void (*irq_config)(const struct device *dev);
22 	bool master_clk_sel;
23 };
24 
25 struct stream {
26 	int32_t state;
27 	struct k_msgq *msgq;
28 
29 	const struct device *dev_dma;
30 	uint32_t dma_channel;
31 	struct dma_config dma_cfg;
32 	uint8_t priority;
33 	bool src_addr_increment;
34 	bool dst_addr_increment;
35 	uint8_t fifo_threshold;
36 	bool tx_stop_for_drain;
37 
38 	struct i2s_config cfg;
39 	void *mem_block;
40 	bool last_block;
41 	bool master;
42 	int (*stream_start)(struct stream *, const struct device *dev);
43 	void (*stream_disable)(struct stream *, const struct device *dev);
44 };
45 
46 /* Device run time data */
47 struct i2s_stm32_data {
48 	struct stream rx;
49 	struct stream tx;
50 };
51 
52 /* checks that DMA Tx packet is fully transmitted over the I2S */
ll_func_i2s_dma_busy(SPI_TypeDef * i2s)53 static inline uint32_t ll_func_i2s_dma_busy(SPI_TypeDef *i2s)
54 {
55 #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_i2s)
56 	return LL_SPI_IsActiveFlag_TXC(i2s) == 0;
57 #else
58 	/* the I2S Tx empty and busy flags are needed */
59 	return (LL_SPI_IsActiveFlag_TXE(i2s) &&
60 		!LL_SPI_IsActiveFlag_BSY(i2s));
61 #endif
62 }
63 
64 #endif	/* _STM32_I2S_H_ */
65