hi_spi.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef __HI_SPI_H__
  2. #define __HI_SPI_H__
  3. typedef unsigned long long __u64;
  4. typedef unsigned int __u32;
  5. typedef unsigned short __u16;
  6. typedef unsigned char __u8;
  7. #ifdef __HuaweiLite__
  8. #include <spi.h>
  9. #else
  10. /* User space versions of kernel symbols for SPI clocking modes,
  11. * matching <linux/spi/spi.h>
  12. */
  13. #define SPI_CPHA 0x01
  14. #define SPI_CPOL 0x02
  15. #define SPI_MODE_0 (0|0)
  16. #define SPI_MODE_1 (0|SPI_CPHA)
  17. #define SPI_MODE_2 (SPI_CPOL|0)
  18. #define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
  19. #define SPI_CS_HIGH 0x04
  20. #define SPI_LSB_FIRST 0x08
  21. #define SPI_3WIRE 0x10
  22. #define SPI_LOOP 0x20
  23. #define SPI_NO_CS 0x40
  24. #define SPI_READY 0x80
  25. /*---------------------------------------------------------------------------*/
  26. /* IOCTL commands */
  27. #define SPI_IOC_MAGIC 'k'
  28. /**
  29. * struct spi_ioc_transfer - describes a single SPI transfer
  30. * @tx_buf: Holds pointer to userspace buffer with transmit data, or null.
  31. * If no data is provided, zeroes are shifted out.
  32. * @rx_buf: Holds pointer to userspace buffer for receive data, or null.
  33. * @len: Length of tx and rx buffers, in bytes.
  34. * @speed_hz: Temporary override of the device's bitrate.
  35. * @bits_per_word: Temporary override of the device's wordsize.
  36. * @delay_usecs: If nonzero, how long to delay after the last bit transfer
  37. * before optionally deselecting the device before the next transfer.
  38. * @cs_change: True to deselect device before starting the next transfer.
  39. *
  40. * This structure is mapped directly to the kernel spi_transfer structure;
  41. * the fields have the same meanings, except of course that the pointers
  42. * are in a different address space (and may be of different sizes in some
  43. * cases, such as 32-bit i386 userspace over a 64-bit x86_64 kernel).
  44. * Zero-initialize the structure, including currently unused fields, to
  45. * accommodate potential future updates.
  46. *
  47. * SPI_IOC_MESSAGE gives userspace the equivalent of kernel spi_sync().
  48. * Pass it an array of related transfers, they'll execute together.
  49. * Each transfer may be half duplex (either direction) or full duplex.
  50. *
  51. * struct spi_ioc_transfer mesg[4];
  52. * ...
  53. * status = ioctl(fd, SPI_IOC_MESSAGE(4), mesg);
  54. *
  55. * So for example one transfer might send a nine bit command (right aligned
  56. * in a 16-bit word), the next could read a block of 8-bit data before
  57. * terminating that command by temporarily deselecting the chip; the next
  58. * could send a different nine bit command (re-selecting the chip), and the
  59. * last transfer might write some register values.
  60. */
  61. struct spi_ioc_transfer {
  62. __u64 tx_buf;
  63. __u64 rx_buf;
  64. __u32 len;
  65. __u32 speed_hz;
  66. __u16 delay_usecs;
  67. __u8 bits_per_word;
  68. __u8 cs_change;
  69. __u32 pad;
  70. /* If the contents of 'struct spi_ioc_transfer' ever change
  71. * incompatibly, then the ioctl number (currently 0) must change;
  72. * ioctls with constant size fields get a bit more in the way of
  73. * error checking than ones (like this) where that field varies.
  74. *
  75. * NOTE: struct layout is the same in 64bit and 32bit userspace.
  76. */
  77. };
  78. /* not all platforms use <asm-generic/ioctl.h> or _IOC_TYPECHECK() ... */
  79. #define SPI_MSGSIZE(N) \
  80. ((((N)*(sizeof (struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \
  81. ? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)
  82. #define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)])
  83. /* Read / Write of SPI mode (SPI_MODE_0..SPI_MODE_3) */
  84. #define SPI_IOC_RD_MODE _IOR(SPI_IOC_MAGIC, 1, __u8)
  85. #define SPI_IOC_WR_MODE _IOW(SPI_IOC_MAGIC, 1, __u8)
  86. /* Read / Write SPI bit justification */
  87. #define SPI_IOC_RD_LSB_FIRST _IOR(SPI_IOC_MAGIC, 2, __u8)
  88. #define SPI_IOC_WR_LSB_FIRST _IOW(SPI_IOC_MAGIC, 2, __u8)
  89. /* Read / Write SPI device word length (1..N) */
  90. #define SPI_IOC_RD_BITS_PER_WORD _IOR(SPI_IOC_MAGIC, 3, __u8)
  91. #define SPI_IOC_WR_BITS_PER_WORD _IOW(SPI_IOC_MAGIC, 3, __u8)
  92. /* Read / Write SPI device default max speed hz */
  93. #define SPI_IOC_RD_MAX_SPEED_HZ _IOR(SPI_IOC_MAGIC, 4, __u32)
  94. #define SPI_IOC_WR_MAX_SPEED_HZ _IOW(SPI_IOC_MAGIC, 4, __u32)
  95. #endif
  96. #endif /* __HI_SPI_H__ */