blob: 85578d4be0343ce9ac0bd3f1a9bbb2d349533b44 [file] [log] [blame]
David Brownell9904f222006-01-08 13:34:26 -08001#ifndef __SPI_BITBANG_H
2#define __SPI_BITBANG_H
3
Fernando Luis Vazquez Caoeffdb942008-10-29 14:01:21 -07004#include <linux/workqueue.h>
5
David Brownell9904f222006-01-08 13:34:26 -08006struct spi_bitbang {
David Brownell9904f222006-01-08 13:34:26 -08007 spinlock_t lock;
David Brownell9904f222006-01-08 13:34:26 -08008 u8 busy;
David Brownell9904f222006-01-08 13:34:26 -08009 u8 use_dma;
David Brownelldccd5732007-07-17 04:04:02 -070010 u8 flags; /* extra spi->mode support */
David Brownell9904f222006-01-08 13:34:26 -080011
12 struct spi_master *master;
13
Imre Deak4cff33f2006-02-17 10:02:18 -080014 /* setup_transfer() changes clock and/or wordsize to match settings
15 * for this transfer; zeroes restore defaults from spi_device.
16 */
17 int (*setup_transfer)(struct spi_device *spi,
18 struct spi_transfer *t);
19
David Brownell9904f222006-01-08 13:34:26 -080020 void (*chipselect)(struct spi_device *spi, int is_on);
Vitaly Wool8275c642006-01-08 13:34:28 -080021#define BITBANG_CS_ACTIVE 1 /* normally nCS, active low */
22#define BITBANG_CS_INACTIVE 0
David Brownell9904f222006-01-08 13:34:26 -080023
Vitaly Wool8275c642006-01-08 13:34:28 -080024 /* txrx_bufs() may handle dma mapping for transfers that don't
25 * already have one (transfer.{tx,rx}_dma is zero), or use PIO
26 */
David Brownell9904f222006-01-08 13:34:26 -080027 int (*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t);
Vitaly Wool8275c642006-01-08 13:34:28 -080028
29 /* txrx_word[SPI_MODE_*]() just looks like a shift register */
David Brownell9904f222006-01-08 13:34:26 -080030 u32 (*txrx_word[4])(struct spi_device *spi,
31 unsigned nsecs,
32 u32 word, u8 bits);
33};
34
35/* you can call these default bitbang->master methods from your custom
36 * methods, if you like.
37 */
38extern int spi_bitbang_setup(struct spi_device *spi);
Hans-Peter Nilsson0ffa0282007-02-12 00:52:45 -080039extern void spi_bitbang_cleanup(struct spi_device *spi);
Kumar Galaff9f4772006-04-02 16:06:35 -050040extern int spi_bitbang_setup_transfer(struct spi_device *spi,
41 struct spi_transfer *t);
David Brownell9904f222006-01-08 13:34:26 -080042
43/* start or stop queue processing */
44extern int spi_bitbang_start(struct spi_bitbang *spi);
Axel Lind9721ae2014-03-29 18:50:12 +080045extern void spi_bitbang_stop(struct spi_bitbang *spi);
David Brownell9904f222006-01-08 13:34:26 -080046
47#endif /* __SPI_BITBANG_H */