spi-bcm-qspi.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright 2016 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License, version 2, as
  6. * published by the Free Software Foundation (the "GPL").
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License version 2 (GPLv2) for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * version 2 (GPLv2) along with this source code.
  15. */
  16. #ifndef __SPI_BCM_QSPI_H__
  17. #define __SPI_BCM_QSPI_H__
  18. #include <linux/types.h>
  19. #include <linux/io.h>
  20. /* BSPI interrupt masks */
  21. #define INTR_BSPI_LR_OVERREAD_MASK BIT(4)
  22. #define INTR_BSPI_LR_SESSION_DONE_MASK BIT(3)
  23. #define INTR_BSPI_LR_IMPATIENT_MASK BIT(2)
  24. #define INTR_BSPI_LR_SESSION_ABORTED_MASK BIT(1)
  25. #define INTR_BSPI_LR_FULLNESS_REACHED_MASK BIT(0)
  26. #define BSPI_LR_INTERRUPTS_DATA \
  27. (INTR_BSPI_LR_SESSION_DONE_MASK | \
  28. INTR_BSPI_LR_FULLNESS_REACHED_MASK)
  29. #define BSPI_LR_INTERRUPTS_ERROR \
  30. (INTR_BSPI_LR_OVERREAD_MASK | \
  31. INTR_BSPI_LR_IMPATIENT_MASK | \
  32. INTR_BSPI_LR_SESSION_ABORTED_MASK)
  33. #define BSPI_LR_INTERRUPTS_ALL \
  34. (BSPI_LR_INTERRUPTS_ERROR | \
  35. BSPI_LR_INTERRUPTS_DATA)
  36. /* MSPI Interrupt masks */
  37. #define INTR_MSPI_HALTED_MASK BIT(6)
  38. #define INTR_MSPI_DONE_MASK BIT(5)
  39. #define MSPI_INTERRUPTS_ALL \
  40. (INTR_MSPI_DONE_MASK | \
  41. INTR_MSPI_HALTED_MASK)
  42. #define QSPI_INTERRUPTS_ALL \
  43. (MSPI_INTERRUPTS_ALL | \
  44. BSPI_LR_INTERRUPTS_ALL)
  45. struct platform_device;
  46. struct dev_pm_ops;
  47. enum {
  48. MSPI_DONE = 0x1,
  49. BSPI_DONE = 0x2,
  50. BSPI_ERR = 0x4,
  51. MSPI_BSPI_DONE = 0x7
  52. };
  53. struct bcm_qspi_soc_intc {
  54. void (*bcm_qspi_int_ack)(struct bcm_qspi_soc_intc *soc_intc, int type);
  55. void (*bcm_qspi_int_set)(struct bcm_qspi_soc_intc *soc_intc, int type,
  56. bool en);
  57. u32 (*bcm_qspi_get_int_status)(struct bcm_qspi_soc_intc *soc_intc);
  58. };
  59. /* Read controller register*/
  60. static inline u32 bcm_qspi_readl(bool be, void __iomem *addr)
  61. {
  62. if (be)
  63. return ioread32be(addr);
  64. else
  65. return readl_relaxed(addr);
  66. }
  67. /* Write controller register*/
  68. static inline void bcm_qspi_writel(bool be,
  69. unsigned int data, void __iomem *addr)
  70. {
  71. if (be)
  72. iowrite32be(data, addr);
  73. else
  74. writel_relaxed(data, addr);
  75. }
  76. static inline u32 get_qspi_mask(int type)
  77. {
  78. switch (type) {
  79. case MSPI_DONE:
  80. return INTR_MSPI_DONE_MASK;
  81. case BSPI_DONE:
  82. return BSPI_LR_INTERRUPTS_ALL;
  83. case MSPI_BSPI_DONE:
  84. return QSPI_INTERRUPTS_ALL;
  85. case BSPI_ERR:
  86. return BSPI_LR_INTERRUPTS_ERROR;
  87. }
  88. return 0;
  89. }
  90. /* The common driver functions to be called by the SoC platform driver */
  91. int bcm_qspi_probe(struct platform_device *pdev,
  92. struct bcm_qspi_soc_intc *soc_intc);
  93. int bcm_qspi_remove(struct platform_device *pdev);
  94. /* pm_ops used by the SoC platform driver called on PM suspend/resume */
  95. extern const struct dev_pm_ops bcm_qspi_pm_ops;
  96. #endif /* __SPI_BCM_QSPI_H__ */