xref: /linux/drivers/i2c/busses/i2c-stm32.h (revision d6a5c562214f26e442c8ec3ff1e28e16675d1bcf)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * i2c-stm32.h
4  *
5  * Copyright (C) M'boumba Cedric Madianga 2017
6  * Copyright (C) STMicroelectronics 2017
7  * Author: M'boumba Cedric Madianga <cedric.madianga@gmail.com>
8  *
9  */
10 
11 #ifndef _I2C_STM32_H
12 #define _I2C_STM32_H
13 
14 #include <linux/dma-direction.h>
15 #include <linux/dmaengine.h>
16 #include <linux/dma-mapping.h>
17 
18 enum stm32_i2c_speed {
19 	STM32_I2C_SPEED_STANDARD, /* 100 kHz */
20 	STM32_I2C_SPEED_FAST, /* 400 kHz */
21 	STM32_I2C_SPEED_FAST_PLUS, /* 1 MHz */
22 	STM32_I2C_SPEED_END,
23 };
24 
25 /**
26  * struct stm32_i2c_dma - DMA specific data
27  * @chan_tx: dma channel for TX transfer
28  * @chan_rx: dma channel for RX transfer
29  * @chan_using: dma channel used for the current transfer (TX or RX)
30  * @dma_buf: dma buffer
31  * @dma_len: dma buffer len
32  * @dma_transfer_dir: dma transfer direction indicator
33  * @dma_data_dir: dma transfer mode indicator
34  * @dma_complete: dma transfer completion
35  */
36 struct stm32_i2c_dma {
37 	struct dma_chan *chan_tx;
38 	struct dma_chan *chan_rx;
39 	struct dma_chan *chan_using;
40 	dma_addr_t dma_buf;
41 	unsigned int dma_len;
42 	enum dma_transfer_direction dma_transfer_dir;
43 	enum dma_data_direction dma_data_dir;
44 	struct completion dma_complete;
45 };
46 
47 struct stm32_i2c_dma *stm32_i2c_dma_request(struct device *dev,
48 					    dma_addr_t phy_addr,
49 					    u32 txdr_offset, u32 rxdr_offset);
50 
51 void stm32_i2c_dma_free(struct stm32_i2c_dma *dma);
52 
53 int stm32_i2c_prep_dma_xfer(struct device *dev, struct stm32_i2c_dma *dma,
54 			    bool rd_wr, u32 len, u8 *buf,
55 			    dma_async_tx_callback callback,
56 			    void *dma_async_param);
57 
58 #endif /* _I2C_STM32_H */
59