davinci_spi.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
  3. *
  4. * Register definitions for the DaVinci SPI Controller
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef _DAVINCI_SPI_H_
  9. #define _DAVINCI_SPI_H_
  10. struct davinci_spi_regs {
  11. dv_reg gcr0; /* 0x00 */
  12. dv_reg gcr1; /* 0x04 */
  13. dv_reg int0; /* 0x08 */
  14. dv_reg lvl; /* 0x0c */
  15. dv_reg flg; /* 0x10 */
  16. dv_reg pc0; /* 0x14 */
  17. dv_reg pc1; /* 0x18 */
  18. dv_reg pc2; /* 0x1c */
  19. dv_reg pc3; /* 0x20 */
  20. dv_reg pc4; /* 0x24 */
  21. dv_reg pc5; /* 0x28 */
  22. dv_reg rsvd[3];
  23. dv_reg dat0; /* 0x38 */
  24. dv_reg dat1; /* 0x3c */
  25. dv_reg buf; /* 0x40 */
  26. dv_reg emu; /* 0x44 */
  27. dv_reg delay; /* 0x48 */
  28. dv_reg def; /* 0x4c */
  29. dv_reg fmt0; /* 0x50 */
  30. dv_reg fmt1; /* 0x54 */
  31. dv_reg fmt2; /* 0x58 */
  32. dv_reg fmt3; /* 0x5c */
  33. dv_reg intvec0; /* 0x60 */
  34. dv_reg intvec1; /* 0x64 */
  35. };
  36. #define BIT(x) (1 << (x))
  37. /* SPIGCR0 */
  38. #define SPIGCR0_SPIENA_MASK 0x1
  39. #define SPIGCR0_SPIRST_MASK 0x0
  40. /* SPIGCR0 */
  41. #define SPIGCR1_CLKMOD_MASK BIT(1)
  42. #define SPIGCR1_MASTER_MASK BIT(0)
  43. #define SPIGCR1_SPIENA_MASK BIT(24)
  44. /* SPIPC0 */
  45. #define SPIPC0_DIFUN_MASK BIT(11) /* SIMO */
  46. #define SPIPC0_DOFUN_MASK BIT(10) /* SOMI */
  47. #define SPIPC0_CLKFUN_MASK BIT(9) /* CLK */
  48. #define SPIPC0_EN0FUN_MASK BIT(0)
  49. /* SPIFMT0 */
  50. #define SPIFMT_SHIFTDIR_SHIFT 20
  51. #define SPIFMT_POLARITY_SHIFT 17
  52. #define SPIFMT_PHASE_SHIFT 16
  53. #define SPIFMT_PRESCALE_SHIFT 8
  54. /* SPIDAT1 */
  55. #define SPIDAT1_CSHOLD_SHIFT 28
  56. #define SPIDAT1_CSNR_SHIFT 16
  57. /* SPIDELAY */
  58. #define SPI_C2TDELAY_SHIFT 24
  59. #define SPI_T2CDELAY_SHIFT 16
  60. /* SPIBUF */
  61. #define SPIBUF_RXEMPTY_MASK BIT(31)
  62. #define SPIBUF_TXFULL_MASK BIT(29)
  63. /* SPIDEF */
  64. #define SPIDEF_CSDEF0_MASK BIT(0)
  65. #define SPI0_BUS 0
  66. #define SPI0_BASE CONFIG_SYS_SPI_BASE
  67. /*
  68. * Define default SPI0_NUM_CS as 1 for existing platforms that uses this
  69. * driver. Platform can configure number of CS using CONFIG_SYS_SPI0_NUM_CS
  70. * if more than one CS is supported and by defining CONFIG_SYS_SPI0.
  71. */
  72. #ifndef CONFIG_SYS_SPI0
  73. #define SPI0_NUM_CS 1
  74. #else
  75. #define SPI0_NUM_CS CONFIG_SYS_SPI0_NUM_CS
  76. #endif
  77. /*
  78. * define CONFIG_SYS_SPI1 when platform has spi-1 device (bus #1) and
  79. * CONFIG_SYS_SPI1_NUM_CS defines number of CS on this bus
  80. */
  81. #ifdef CONFIG_SYS_SPI1
  82. #define SPI1_BUS 1
  83. #define SPI1_NUM_CS CONFIG_SYS_SPI1_NUM_CS
  84. #define SPI1_BASE CONFIG_SYS_SPI1_BASE
  85. #endif
  86. /*
  87. * define CONFIG_SYS_SPI2 when platform has spi-2 device (bus #2) and
  88. * CONFIG_SYS_SPI2_NUM_CS defines number of CS on this bus
  89. */
  90. #ifdef CONFIG_SYS_SPI2
  91. #define SPI2_BUS 2
  92. #define SPI2_NUM_CS CONFIG_SYS_SPI2_NUM_CS
  93. #define SPI2_BASE CONFIG_SYS_SPI2_BASE
  94. #endif
  95. struct davinci_spi_slave {
  96. struct spi_slave slave;
  97. struct davinci_spi_regs *regs;
  98. unsigned int freq;
  99. };
  100. static inline struct davinci_spi_slave *to_davinci_spi(struct spi_slave *slave)
  101. {
  102. return container_of(slave, struct davinci_spi_slave, slave);
  103. }
  104. #endif /* _DAVINCI_SPI_H_ */