spi_bitbang.h 1.6 KB

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