atmel_spi.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Register definitions for the Atmel AT32/AT91 SPI Controller
  3. */
  4. /* Register offsets */
  5. #include <linux/bitops.h>
  6. #define ATMEL_SPI_CR 0x0000
  7. #define ATMEL_SPI_MR 0x0004
  8. #define ATMEL_SPI_RDR 0x0008
  9. #define ATMEL_SPI_TDR 0x000c
  10. #define ATMEL_SPI_SR 0x0010
  11. #define ATMEL_SPI_IER 0x0014
  12. #define ATMEL_SPI_IDR 0x0018
  13. #define ATMEL_SPI_IMR 0x001c
  14. #define ATMEL_SPI_CSR(x) (0x0030 + 4 * (x))
  15. #define ATMEL_SPI_VERSION 0x00fc
  16. /* Bits in CR */
  17. #define ATMEL_SPI_CR_SPIEN BIT(0)
  18. #define ATMEL_SPI_CR_SPIDIS BIT(1)
  19. #define ATMEL_SPI_CR_SWRST BIT(7)
  20. #define ATMEL_SPI_CR_LASTXFER BIT(24)
  21. /* Bits in MR */
  22. #define ATMEL_SPI_MR_MSTR BIT(0)
  23. #define ATMEL_SPI_MR_PS BIT(1)
  24. #define ATMEL_SPI_MR_PCSDEC BIT(2)
  25. #define ATMEL_SPI_MR_FDIV BIT(3)
  26. #define ATMEL_SPI_MR_MODFDIS BIT(4)
  27. #define ATMEL_SPI_MR_WDRBT BIT(5)
  28. #define ATMEL_SPI_MR_LLB BIT(7)
  29. #define ATMEL_SPI_MR_PCS(x) (((x) & 15) << 16)
  30. #define ATMEL_SPI_MR_DLYBCS(x) ((x) << 24)
  31. /* Bits in RDR */
  32. #define ATMEL_SPI_RDR_RD(x) (x)
  33. #define ATMEL_SPI_RDR_PCS(x) ((x) << 16)
  34. /* Bits in TDR */
  35. #define ATMEL_SPI_TDR_TD(x) (x)
  36. #define ATMEL_SPI_TDR_PCS(x) ((x) << 16)
  37. #define ATMEL_SPI_TDR_LASTXFER BIT(24)
  38. /* Bits in SR/IER/IDR/IMR */
  39. #define ATMEL_SPI_SR_RDRF BIT(0)
  40. #define ATMEL_SPI_SR_TDRE BIT(1)
  41. #define ATMEL_SPI_SR_MODF BIT(2)
  42. #define ATMEL_SPI_SR_OVRES BIT(3)
  43. #define ATMEL_SPI_SR_ENDRX BIT(4)
  44. #define ATMEL_SPI_SR_ENDTX BIT(5)
  45. #define ATMEL_SPI_SR_RXBUFF BIT(6)
  46. #define ATMEL_SPI_SR_TXBUFE BIT(7)
  47. #define ATMEL_SPI_SR_NSSR BIT(8)
  48. #define ATMEL_SPI_SR_TXEMPTY BIT(9)
  49. #define ATMEL_SPI_SR_SPIENS BIT(16)
  50. /* Bits in CSRx */
  51. #define ATMEL_SPI_CSRx_CPOL BIT(0)
  52. #define ATMEL_SPI_CSRx_NCPHA BIT(1)
  53. #define ATMEL_SPI_CSRx_CSAAT BIT(3)
  54. #define ATMEL_SPI_CSRx_BITS(x) ((x) << 4)
  55. #define ATMEL_SPI_CSRx_SCBR(x) ((x) << 8)
  56. #define ATMEL_SPI_CSRx_SCBR_MAX GENMASK(7, 0)
  57. #define ATMEL_SPI_CSRx_DLYBS(x) ((x) << 16)
  58. #define ATMEL_SPI_CSRx_DLYBCT(x) ((x) << 24)
  59. /* Bits in VERSION */
  60. #define ATMEL_SPI_VERSION_REV(x) ((x) & 0xfff)
  61. #define ATMEL_SPI_VERSION_MFN(x) ((x) << 16)
  62. /* Constants for CSRx:BITS */
  63. #define ATMEL_SPI_BITS_8 0
  64. #define ATMEL_SPI_BITS_9 1
  65. #define ATMEL_SPI_BITS_10 2
  66. #define ATMEL_SPI_BITS_11 3
  67. #define ATMEL_SPI_BITS_12 4
  68. #define ATMEL_SPI_BITS_13 5
  69. #define ATMEL_SPI_BITS_14 6
  70. #define ATMEL_SPI_BITS_15 7
  71. #define ATMEL_SPI_BITS_16 8
  72. struct atmel_spi_slave {
  73. struct spi_slave slave;
  74. void *regs;
  75. u32 mr;
  76. };
  77. static inline struct atmel_spi_slave *to_atmel_spi(struct spi_slave *slave)
  78. {
  79. return container_of(slave, struct atmel_spi_slave, slave);
  80. }
  81. /* Register access macros */
  82. #define spi_readl(as, reg) \
  83. readl(as->regs + ATMEL_SPI_##reg)
  84. #define spi_writel(as, reg, value) \
  85. writel(value, as->regs + ATMEL_SPI_##reg)