blob: 51d8c060e513ef767125a6268b459df91091b8df [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David Brownell9904f222006-01-08 13:34:26 -08002#ifndef __SPI_BITBANG_H
3#define __SPI_BITBANG_H
4
Fernando Luis Vazquez Caoeffdb942008-10-29 14:01:21 -07005#include <linux/workqueue.h>
6
David Brownell9904f222006-01-08 13:34:26 -08007struct spi_bitbang {
Nicolas Boichatc15f6ed2015-08-17 11:52:54 +08008 struct mutex lock;
David Brownell9904f222006-01-08 13:34:26 -08009 u8 busy;
David Brownell9904f222006-01-08 13:34:26 -080010 u8 use_dma;
David Brownelldccd5732007-07-17 04:04:02 -070011 u8 flags; /* extra spi->mode support */
David Brownell9904f222006-01-08 13:34:26 -080012
13 struct spi_master *master;
14
Imre Deak4cff33f2006-02-17 10:02:18 -080015 /* 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 Brownell9904f222006-01-08 13:34:26 -080021 void (*chipselect)(struct spi_device *spi, int is_on);
Vitaly Wool8275c642006-01-08 13:34:28 -080022#define BITBANG_CS_ACTIVE 1 /* normally nCS, active low */
23#define BITBANG_CS_INACTIVE 0
David Brownell9904f222006-01-08 13:34:26 -080024
Vitaly Wool8275c642006-01-08 13:34:28 -080025 /* 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 Brownell9904f222006-01-08 13:34:26 -080028 int (*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t);
Vitaly Wool8275c642006-01-08 13:34:28 -080029
30 /* txrx_word[SPI_MODE_*]() just looks like a shift register */
David Brownell9904f222006-01-08 13:34:26 -080031 u32 (*txrx_word[4])(struct spi_device *spi,
32 unsigned nsecs,
33 u32 word, u8 bits);
34};
35
36/* you can call these default bitbang->master methods from your custom
37 * methods, if you like.
38 */
39extern int spi_bitbang_setup(struct spi_device *spi);
Hans-Peter Nilsson0ffa0282007-02-12 00:52:45 -080040extern void spi_bitbang_cleanup(struct spi_device *spi);
Kumar Galaff9f4772006-04-02 16:06:35 -050041extern int spi_bitbang_setup_transfer(struct spi_device *spi,
42 struct spi_transfer *t);
David Brownell9904f222006-01-08 13:34:26 -080043
44/* start or stop queue processing */
45extern int spi_bitbang_start(struct spi_bitbang *spi);
Axel Lind9721ae2014-03-29 18:50:12 +080046extern void spi_bitbang_stop(struct spi_bitbang *spi);
David Brownell9904f222006-01-08 13:34:26 -080047
48#endif /* __SPI_BITBANG_H */