xref: /linux/include/linux/spi/spi_bitbang.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef	__SPI_BITBANG_H
3 #define	__SPI_BITBANG_H
4 
5 #include <linux/workqueue.h>
6 
7 typedef u32 (*spi_bb_txrx_word_fn)(struct spi_device *, unsigned int, u32, u8, unsigned int);
8 
9 struct spi_bitbang {
10 	struct mutex		lock;
11 	u8			busy;
12 	u8			use_dma;
13 	u16			flags;		/* extra spi->mode support */
14 
15 	struct spi_controller	*ctlr;
16 
17 	/* setup_transfer() changes clock and/or wordsize to match settings
18 	 * for this transfer; zeroes restore defaults from spi_device.
19 	 */
20 	int	(*setup_transfer)(struct spi_device *spi,
21 			struct spi_transfer *t);
22 
23 	void	(*chipselect)(struct spi_device *spi, int is_on);
24 #define	BITBANG_CS_ACTIVE	1	/* normally nCS, active low */
25 #define	BITBANG_CS_INACTIVE	0
26 
27 	void	(*set_mosi_idle)(struct spi_device *spi);
28 	/* txrx_bufs() may handle dma mapping for transfers that don't
29 	 * already have one (transfer.{tx,rx}_dma is zero), or use PIO
30 	 */
31 	int	(*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t);
32 
33 	/* txrx_word[SPI_MODE_*]() just looks like a shift register */
34 	spi_bb_txrx_word_fn txrx_word[SPI_MODE_X_MASK + 1];
35 
36 	int	(*set_line_direction)(struct spi_device *spi, bool output);
37 };
38 
39 /* you can call these default bitbang->master methods from your custom
40  * methods, if you like.
41  */
42 extern int spi_bitbang_setup(struct spi_device *spi);
43 extern void spi_bitbang_cleanup(struct spi_device *spi);
44 extern int spi_bitbang_setup_transfer(struct spi_device *spi,
45 				      struct spi_transfer *t);
46 
47 /* start or stop queue processing */
48 extern int spi_bitbang_start(struct spi_bitbang *spi);
49 extern int spi_bitbang_init(struct spi_bitbang *spi);
50 extern void spi_bitbang_stop(struct spi_bitbang *spi);
51 
52 #endif	/* __SPI_BITBANG_H */
53