hal_efuse.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright (C) 2020 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _HAL_EFUSE_H_
  13. #define _HAL_EFUSE_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "hal_config.h"
  18. #if defined(CONFIG_SOC_8910)
  19. #include "8910/hal_efuse_def.h"
  20. #elif defined(CONFIG_SOC_8811)
  21. #include "8811/hal_efuse_def.h"
  22. #elif defined(CONFIG_SOC_8850)
  23. #include "8850/hal_efuse_def.h"
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #define HAL_EFUSE_OP_SINGLE_READ (0)
  29. #define HAL_EFUSE_OP_DOUBLE_READ (1)
  30. #define HAL_EFUSE_OP_SINGLE_WRITE (2)
  31. #define HAL_EFUSE_OP_DOUBLE_WRITE (3)
  32. /**
  33. * \brief efuse block lock state
  34. */
  35. typedef enum
  36. {
  37. HAL_EFUSE_BLOCK_NOT_LOCKED, ///< not locked
  38. HAL_EFUSE_BLOCK_LOCKED, ///< locked
  39. HAL_EFUSE_BLOCK_PARTIAL_LOCKED, ///< one of the two double block is blocked
  40. } halEfuseBlockLockState_t;
  41. /**
  42. * \brief efuse read or write parameter
  43. */
  44. typedef struct
  45. {
  46. uint8_t op; ///< read or write
  47. uint16_t block_index; ///< block index
  48. union {
  49. uint32_t *rval; ///< read value pointer
  50. uint32_t wval; ///< write value
  51. };
  52. } halEfuseReadWriteOp_t;
  53. /**
  54. * \brief efuse single block count
  55. *
  56. * \return single bit efuse word count
  57. */
  58. unsigned halEfuseCount(void);
  59. /**
  60. * \brief multiple efuse block read or write
  61. *
  62. * It will return false on the first failure.
  63. *
  64. * \param params read or write parameters
  65. * \param count parameter count
  66. * \return
  67. * - true on success
  68. * - false on fail, invalid parameter, not readable or writable
  69. */
  70. bool halEfuseReadWrite(halEfuseReadWriteOp_t *params, uint32_t count);
  71. /**
  72. * \brief efuse block lock state
  73. *
  74. * On invalid parameter, this return not locked.
  75. *
  76. * \param is_double whether to access with double bit
  77. * \param block_index block index
  78. * \return lock state
  79. */
  80. halEfuseBlockLockState_t halEfuseGetLockState(bool is_double, uint32_t block_index);
  81. /**
  82. * \brief invalidate efuse block read cache
  83. *
  84. * Both single block and double block cache will be invalidated. Invalid
  85. * parameter will be ignored silently.
  86. *
  87. * \param is_double whether to access with double bit
  88. * \param block_index block index
  89. */
  90. void halEfuseCacheInvalidate(bool is_double, uint32_t block_index);
  91. /**
  92. * \brief invalidate all efuse blocks read cache
  93. */
  94. void halEfuseCacheInvalidateAll(void);
  95. /**
  96. * \brief set fake data of efuse (DEBUG ONLY)
  97. *
  98. * This is only for debug. Due to efuse can be written only once, it will
  99. * be inconvenient to debug efuse related software. This will set fake
  100. * data into cache.
  101. *
  102. * This will only set cache data of single block or double block. So, most
  103. * likely, the single data and double are inconsistent. Caller shall handle
  104. * it. Also, it won't check whether the block is accessible.
  105. *
  106. * It will never be called in real products.
  107. *
  108. * \param is_double whether to access with double bit
  109. * \param block_index block index
  110. * \param val value to be set
  111. * \return
  112. * - true on success
  113. * - false on fail, invalid parameter
  114. */
  115. bool halEfuseFakeWrite(bool is_double, uint32_t block_index, uint32_t val);
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif /* _DRV_EFUSE_H_ */