Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 2 | #ifndef __SPI_BITBANG_H |
| 3 | #define __SPI_BITBANG_H |
| 4 | |
Fernando Luis Vazquez Cao | effdb94 | 2008-10-29 14:01:21 -0700 | [diff] [blame] | 5 | #include <linux/workqueue.h> |
| 6 | |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 7 | struct spi_bitbang { |
Nicolas Boichat | c15f6ed | 2015-08-17 11:52:54 +0800 | [diff] [blame] | 8 | struct mutex lock; |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 9 | u8 busy; |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 10 | u8 use_dma; |
David Lechner | 7c201ea | 2018-07-16 22:20:49 -0500 | [diff] [blame] | 11 | u16 flags; /* extra spi->mode support */ |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 12 | |
| 13 | struct spi_master *master; |
| 14 | |
Imre Deak | 4cff33f | 2006-02-17 10:02:18 -0800 | [diff] [blame] | 15 | /* setup_transfer() changes clock and/or wordsize to match settings |
| 16 | * for this transfer; zeroes restore defaults from spi_device. |
| 17 | */ |
| 18 | int (*setup_transfer)(struct spi_device *spi, |
| 19 | struct spi_transfer *t); |
| 20 | |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 21 | void (*chipselect)(struct spi_device *spi, int is_on); |
Vitaly Wool | 8275c64 | 2006-01-08 13:34:28 -0800 | [diff] [blame] | 22 | #define BITBANG_CS_ACTIVE 1 /* normally nCS, active low */ |
| 23 | #define BITBANG_CS_INACTIVE 0 |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 24 | |
Vitaly Wool | 8275c64 | 2006-01-08 13:34:28 -0800 | [diff] [blame] | 25 | /* txrx_bufs() may handle dma mapping for transfers that don't |
| 26 | * already have one (transfer.{tx,rx}_dma is zero), or use PIO |
| 27 | */ |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 28 | int (*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t); |
Vitaly Wool | 8275c64 | 2006-01-08 13:34:28 -0800 | [diff] [blame] | 29 | |
| 30 | /* txrx_word[SPI_MODE_*]() just looks like a shift register */ |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 31 | u32 (*txrx_word[4])(struct spi_device *spi, |
| 32 | unsigned nsecs, |
Lorenzo Bianconi | 304d343 | 2018-07-28 10:19:13 +0200 | [diff] [blame] | 33 | u32 word, u8 bits, unsigned flags); |
Lorenzo Bianconi | 4b859db | 2018-07-28 10:19:14 +0200 | [diff] [blame] | 34 | int (*set_line_direction)(struct spi_device *spi, bool output); |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | /* you can call these default bitbang->master methods from your custom |
| 38 | * methods, if you like. |
| 39 | */ |
| 40 | extern int spi_bitbang_setup(struct spi_device *spi); |
Hans-Peter Nilsson | 0ffa028 | 2007-02-12 00:52:45 -0800 | [diff] [blame] | 41 | extern void spi_bitbang_cleanup(struct spi_device *spi); |
Kumar Gala | ff9f477 | 2006-04-02 16:06:35 -0500 | [diff] [blame] | 42 | extern int spi_bitbang_setup_transfer(struct spi_device *spi, |
| 43 | struct spi_transfer *t); |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 44 | |
| 45 | /* start or stop queue processing */ |
| 46 | extern int spi_bitbang_start(struct spi_bitbang *spi); |
Andrey Smirnov | 45beec3 | 2019-04-02 21:01:32 -0700 | [diff] [blame] | 47 | extern int spi_bitbang_init(struct spi_bitbang *spi); |
Axel Lin | d9721ae | 2014-03-29 18:50:12 +0800 | [diff] [blame] | 48 | extern void spi_bitbang_stop(struct spi_bitbang *spi); |
David Brownell | 9904f22 | 2006-01-08 13:34:26 -0800 | [diff] [blame] | 49 | |
| 50 | #endif /* __SPI_BITBANG_H */ |