atmel_spi.h 2.7 KB

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