Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __SPI_BITBANG_H
0003 #define __SPI_BITBANG_H
0004 
0005 #include <linux/workqueue.h>
0006 
0007 struct spi_bitbang {
0008     struct mutex        lock;
0009     u8          busy;
0010     u8          use_dma;
0011     u16         flags;      /* extra spi->mode support */
0012 
0013     struct spi_master   *master;
0014 
0015     /* setup_transfer() changes clock and/or wordsize to match settings
0016      * for this transfer; zeroes restore defaults from spi_device.
0017      */
0018     int (*setup_transfer)(struct spi_device *spi,
0019             struct spi_transfer *t);
0020 
0021     void    (*chipselect)(struct spi_device *spi, int is_on);
0022 #define BITBANG_CS_ACTIVE   1   /* normally nCS, active low */
0023 #define BITBANG_CS_INACTIVE 0
0024 
0025     /* txrx_bufs() may handle dma mapping for transfers that don't
0026      * already have one (transfer.{tx,rx}_dma is zero), or use PIO
0027      */
0028     int (*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t);
0029 
0030     /* txrx_word[SPI_MODE_*]() just looks like a shift register */
0031     u32 (*txrx_word[4])(struct spi_device *spi,
0032             unsigned nsecs,
0033             u32 word, u8 bits, unsigned flags);
0034     int (*set_line_direction)(struct spi_device *spi, bool output);
0035 };
0036 
0037 /* you can call these default bitbang->master methods from your custom
0038  * methods, if you like.
0039  */
0040 extern int spi_bitbang_setup(struct spi_device *spi);
0041 extern void spi_bitbang_cleanup(struct spi_device *spi);
0042 extern int spi_bitbang_setup_transfer(struct spi_device *spi,
0043                       struct spi_transfer *t);
0044 
0045 /* start or stop queue processing */
0046 extern int spi_bitbang_start(struct spi_bitbang *spi);
0047 extern int spi_bitbang_init(struct spi_bitbang *spi);
0048 extern void spi_bitbang_stop(struct spi_bitbang *spi);
0049 
0050 #endif  /* __SPI_BITBANG_H */