fspi_api.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright 2021 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. /*!
  8. * @file fspi_api.h
  9. * @brief This file contains the FlexSPI/FSPI API to communicate
  10. * to attached Slave device.
  11. * @addtogroup FSPI_API
  12. * @{
  13. */
  14. #ifndef FSPI_API_H
  15. #define FSPI_API_H
  16. #if DEBUG_FLEXSPI
  17. #define SZ_57M 0x3900000u
  18. #endif
  19. /*!
  20. * Basic set of APIs.
  21. */
  22. /*!
  23. * @details AHB read/IP Read, decision to be internal to API
  24. * Minimum Read size = 1Byte
  25. * @param[in] src_off source offset from where data to read from flash
  26. * @param[out] des Destination location where data needs to be copied
  27. * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits
  28. *
  29. * @return XSPI_SUCCESS or error code
  30. */
  31. int xspi_read(uint32_t src_off, uint32_t *des, uint32_t len);
  32. /*!
  33. * @details Sector erase, Minimum size
  34. * 256KB(0x40000)/128KB(0x20000)/64K(0x10000)/4K(0x1000)
  35. * depending upon flash, Calls xspi_wren() internally
  36. * @param[out] erase_offset Destination erase location on flash which
  37. * has to be erased, needs to be multiple of 0x40000/0x20000/0x10000
  38. * @param[in] erase_len length in bytes in Hex like 0x100000 for 1MB, minimum
  39. * erase size is 1 sector(0x40000/0x20000/0x10000)
  40. *
  41. * @return XSPI_SUCCESS or error code
  42. */
  43. int xspi_sector_erase(uint32_t erase_offset, uint32_t erase_len);
  44. /*!
  45. * @details IP write, For writing data to flash, calls xspi_wren() internally.
  46. * Single/multiple page write can start @any offset, but performance will be low
  47. * due to ERRATA
  48. * @param[out] dst_off Destination location on flash where data needs to
  49. * be written
  50. * @param[in] src source offset from where data to be read
  51. * @param[in] len length in bytes,where 1-word=4-bytes/32-bits
  52. *
  53. * @return XSPI_SUCCESS or error code
  54. */
  55. int xspi_write(uint32_t dst_off, void *src, uint32_t len);
  56. /*!
  57. * @details fspi_init, Init function.
  58. * @param[in] uint32_t base_reg_addr
  59. * @param[in] uint32_t flash_start_addr
  60. *
  61. * @return XSPI_SUCCESS or error code
  62. */
  63. int fspi_init(uint32_t base_reg_addr, uint32_t flash_start_addr);
  64. /*!
  65. * @details is_flash_busy, Check if any erase or write or lock is
  66. * pending on flash/slave
  67. * @param[in] void
  68. *
  69. * @return TRUE/FLASE
  70. */
  71. bool is_flash_busy(void);
  72. /*!
  73. * Advanced set of APIs.
  74. */
  75. /*!
  76. * @details Write enable, to be used by advance users only.
  77. * Step 1 for sending write commands to flash.
  78. * @param[in] dst_off destination offset where data will be written
  79. *
  80. * @return XSPI_SUCCESS or error code
  81. */
  82. int xspi_wren(uint32_t dst_off);
  83. /*!
  84. * @details AHB read, meaning direct memory mapped access to flash,
  85. * Minimum Read size = 1Byte
  86. * @param[in] src_off source offset from where data to read from flash,
  87. * needs to be word aligned
  88. * @param[out] des Destination location where data needs to be copied
  89. * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits
  90. *
  91. * @return XSPI_SUCCESS or error code
  92. */
  93. int xspi_ahb_read(uint32_t src_off, uint32_t *des, uint32_t len);
  94. /*!
  95. * @details IP read, READ via RX buffer from flash, minimum READ size = 1Byte
  96. * @param[in] src_off source offset from where data to be read from flash
  97. * @param[out] des Destination location where data needs to be copied
  98. * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits
  99. *
  100. * @return XSPI_SUCCESS or error code
  101. */
  102. int xspi_ip_read(uint32_t src_off, uint32_t *des, uint32_t len);
  103. /*!
  104. * @details CHIP erase, Erase complete chip in one go
  105. *
  106. * @return XSPI_SUCCESS or error code
  107. */
  108. int xspi_bulk_erase(void);
  109. /*!
  110. * Add test cases to confirm flash read/erase/write functionality.
  111. */
  112. void fspi_test(uint32_t fspi_test_addr, uint32_t size, int extra);
  113. #endif /* FSPI_API_H */