spi-bcm-qspi.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2016 Broadcom
  4. */
  5. #ifndef __SPI_BCM_QSPI_H__
  6. #define __SPI_BCM_QSPI_H__
  7. #include <linux/types.h>
  8. #include <linux/io.h>
  9. /* BSPI interrupt masks */
  10. #define INTR_BSPI_LR_OVERREAD_MASK BIT(4)
  11. #define INTR_BSPI_LR_SESSION_DONE_MASK BIT(3)
  12. #define INTR_BSPI_LR_IMPATIENT_MASK BIT(2)
  13. #define INTR_BSPI_LR_SESSION_ABORTED_MASK BIT(1)
  14. #define INTR_BSPI_LR_FULLNESS_REACHED_MASK BIT(0)
  15. #define BSPI_LR_INTERRUPTS_DATA \
  16. (INTR_BSPI_LR_SESSION_DONE_MASK | \
  17. INTR_BSPI_LR_FULLNESS_REACHED_MASK)
  18. #define BSPI_LR_INTERRUPTS_ERROR \
  19. (INTR_BSPI_LR_OVERREAD_MASK | \
  20. INTR_BSPI_LR_IMPATIENT_MASK | \
  21. INTR_BSPI_LR_SESSION_ABORTED_MASK)
  22. #define BSPI_LR_INTERRUPTS_ALL \
  23. (BSPI_LR_INTERRUPTS_ERROR | \
  24. BSPI_LR_INTERRUPTS_DATA)
  25. /* MSPI Interrupt masks */
  26. #define INTR_MSPI_HALTED_MASK BIT(6)
  27. #define INTR_MSPI_DONE_MASK BIT(5)
  28. #define MSPI_INTERRUPTS_ALL \
  29. (INTR_MSPI_DONE_MASK | \
  30. INTR_MSPI_HALTED_MASK)
  31. #define QSPI_INTERRUPTS_ALL \
  32. (MSPI_INTERRUPTS_ALL | \
  33. BSPI_LR_INTERRUPTS_ALL)
  34. struct platform_device;
  35. struct dev_pm_ops;
  36. enum {
  37. MSPI_DONE = 0x1,
  38. BSPI_DONE = 0x2,
  39. BSPI_ERR = 0x4,
  40. MSPI_BSPI_DONE = 0x7
  41. };
  42. struct bcm_qspi_soc_intc {
  43. void (*bcm_qspi_int_ack)(struct bcm_qspi_soc_intc *soc_intc, int type);
  44. void (*bcm_qspi_int_set)(struct bcm_qspi_soc_intc *soc_intc, int type,
  45. bool en);
  46. u32 (*bcm_qspi_get_int_status)(struct bcm_qspi_soc_intc *soc_intc);
  47. };
  48. /* Read controller register*/
  49. static inline u32 bcm_qspi_readl(bool be, void __iomem *addr)
  50. {
  51. if (be)
  52. return ioread32be(addr);
  53. else
  54. return readl_relaxed(addr);
  55. }
  56. /* Write controller register*/
  57. static inline void bcm_qspi_writel(bool be,
  58. unsigned int data, void __iomem *addr)
  59. {
  60. if (be)
  61. iowrite32be(data, addr);
  62. else
  63. writel_relaxed(data, addr);
  64. }
  65. static inline u32 get_qspi_mask(int type)
  66. {
  67. switch (type) {
  68. case MSPI_DONE:
  69. return INTR_MSPI_DONE_MASK;
  70. case BSPI_DONE:
  71. return BSPI_LR_INTERRUPTS_ALL;
  72. case MSPI_BSPI_DONE:
  73. return QSPI_INTERRUPTS_ALL;
  74. case BSPI_ERR:
  75. return BSPI_LR_INTERRUPTS_ERROR;
  76. }
  77. return 0;
  78. }
  79. /* The common driver functions to be called by the SoC platform driver */
  80. int bcm_qspi_probe(struct platform_device *pdev,
  81. struct bcm_qspi_soc_intc *soc_intc);
  82. int bcm_qspi_remove(struct platform_device *pdev);
  83. /* pm_ops used by the SoC platform driver called on PM suspend/resume */
  84. extern const struct dev_pm_ops bcm_qspi_pm_ops;
  85. #endif /* __SPI_BCM_QSPI_H__ */