iproc_qspi.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2017 - 2020, Broadcom
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef IPROC_QSPI_H
  7. #define IPROC_QSPI_H
  8. #include <platform_def.h>
  9. /*SPI configuration enable*/
  10. #define IPROC_QSPI_CLK_SPEED 62500000
  11. #define SPI_CPHA (1 << 0)
  12. #define SPI_CPOL (1 << 1)
  13. #define IPROC_QSPI_MODE0 0
  14. #define IPROC_QSPI_MODE3 (SPI_CPOL|SPI_CPHA)
  15. #define IPROC_QSPI_BUS 0
  16. #define IPROC_QSPI_CS 0
  17. #define IPROC_QSPI_BASE_REG QSPI_CTRL_BASE_ADDR
  18. #define IPROC_QSPI_CRU_CONTROL_REG QSPI_CLK_CTRL
  19. #define QSPI_AXI_CLK 200000000
  20. #define QSPI_RETRY_COUNT_US_MAX 200000
  21. /* Chip attributes */
  22. #define QSPI_REG_BASE IPROC_QSPI_BASE_REG
  23. #define CRU_CONTROL_REG IPROC_QSPI_CRU_CONTROL_REG
  24. #define SPBR_DIV_MIN 8U
  25. #define SPBR_DIV_MAX 255U
  26. #define NUM_CDRAM_BYTES 16U
  27. /* Register fields */
  28. #define MSPI_SPCR0_MSB_BITS_8 0x00000020
  29. /* Flash opcode and parameters */
  30. #define CDRAM_PCS0 2
  31. #define CDRAM_CONT (1 << 7)
  32. #define CDRAM_BITS_EN (1 << 6)
  33. #define CDRAM_QUAD_MODE (1 << 8)
  34. #define CDRAM_RBIT_INPUT (1 << 10)
  35. /* MSPI registers */
  36. #define QSPI_MSPI_MODE_REG_BASE (QSPI_REG_BASE + 0x200)
  37. #define MSPI_SPCR0_LSB_REG 0x000
  38. #define MSPI_SPCR0_MSB_REG 0x004
  39. #define MSPI_SPCR1_LSB_REG 0x008
  40. #define MSPI_SPCR1_MSB_REG 0x00c
  41. #define MSPI_NEWQP_REG 0x010
  42. #define MSPI_ENDQP_REG 0x014
  43. #define MSPI_SPCR2_REG 0x018
  44. #define MSPI_STATUS_REG 0x020
  45. #define MSPI_CPTQP_REG 0x024
  46. #define MSPI_TXRAM_REG 0x040
  47. #define MSPI_RXRAM_REG 0x0c0
  48. #define MSPI_CDRAM_REG 0x140
  49. #define MSPI_WRITE_LOCK_REG 0x180
  50. #define MSPI_DISABLE_FLUSH_GEN_REG 0x184
  51. #define MSPI_SPCR0_MSB_REG_MSTR_SHIFT 7
  52. #define MSPI_SPCR0_MSB_REG_16_BITS_PER_WD_SHIFT (0 << 2)
  53. #define MSPI_SPCR0_MSB_REG_MODE_MASK 0x3
  54. /* BSPI registers */
  55. #define QSPI_BSPI_MODE_REG_BASE QSPI_REG_BASE
  56. #define BSPI_MAST_N_BOOT_CTRL_REG 0x008
  57. #define BSPI_BUSY_STATUS_REG 0x00c
  58. #define MSPI_CMD_COMPLETE_MASK 1
  59. #define BSPI_BUSY_MASK 1
  60. #define MSPI_CTRL_MASK 1
  61. #define MSPI_SPE (1 << 6)
  62. #define MSPI_CONT_AFTER_CMD (1 << 7)
  63. /* State */
  64. enum bcm_qspi_state {
  65. QSPI_STATE_DISABLED,
  66. QSPI_STATE_MSPI,
  67. QSPI_STATE_BSPI
  68. };
  69. /* QSPI private data */
  70. struct bcmspi_priv {
  71. /* Specified SPI parameters */
  72. uint32_t max_hz;
  73. uint32_t spi_mode;
  74. /* State */
  75. enum bcm_qspi_state state;
  76. int mspi_16bit;
  77. /* Registers */
  78. uintptr_t mspi_hw;
  79. uintptr_t bspi_hw;
  80. };
  81. int iproc_qspi_setup(uint32_t bus, uint32_t cs,
  82. uint32_t max_hz, uint32_t mode);
  83. int iproc_qspi_claim_bus(void);
  84. void iproc_qspi_release_bus(void);
  85. int iproc_qspi_xfer(uint32_t bitlen, const void *dout,
  86. void *din, unsigned long flags);
  87. #endif /* _IPROC_QSPI_H_ */