bsec.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2017-2022, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef BSEC_H
  7. #define BSEC_H
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10. #include <lib/utils_def.h>
  11. /*
  12. * IP configuration
  13. */
  14. #define BSEC_OTP_MASK GENMASK(4, 0)
  15. #define BSEC_OTP_BANK_SHIFT 5
  16. #define BSEC_TIMEOUT_VALUE 0xFFFF
  17. /*
  18. * Return status
  19. */
  20. #define BSEC_OK 0U
  21. #define BSEC_ERROR 0xFFFFFFFFU
  22. #define BSEC_DISTURBED 0xFFFFFFFEU
  23. #define BSEC_INVALID_PARAM 0xFFFFFFFCU
  24. #define BSEC_PROG_FAIL 0xFFFFFFFBU
  25. #define BSEC_LOCK_FAIL 0xFFFFFFFAU
  26. #define BSEC_TIMEOUT 0xFFFFFFF9U
  27. #define BSEC_RETRY 0xFFFFFFF8U
  28. #define BSEC_NOT_SUPPORTED 0xFFFFFFF7U
  29. #define BSEC_WRITE_LOCKED 0xFFFFFFF6U
  30. #define BSEC_ERROR_INVALID_FVR 0xFFFFFFF5U
  31. /*
  32. * OTP MODE
  33. */
  34. #define BSEC_MODE_OPEN1 0x00U
  35. #define BSEC_MODE_SECURED 0x01U
  36. #define BSEC_MODE_OPEN2 0x02U
  37. #define BSEC_MODE_INVALID 0x04U
  38. /*
  39. * OTP Lock services definition.
  40. * Value must corresponding to the bit number in the register.
  41. * Special case: (bit number << 1) for BSEC3.
  42. */
  43. #define BSEC_LOCK_UPPER_OTP 0x00
  44. #define BSEC_LOCK_GWLOCK 0x01
  45. #define BSEC_LOCK_DEBUG 0x02
  46. #define BSEC_LOCK_PROGRAM 0x03
  47. #define BSEC_LOCK_KVLOCK 0x04
  48. /*
  49. * Values for struct bsec_config::freq
  50. */
  51. #define FREQ_10_20_MHZ 0x0
  52. #define FREQ_20_30_MHZ 0x1
  53. #define FREQ_30_45_MHZ 0x2
  54. #define FREQ_45_67_MHZ 0x3
  55. /*
  56. * Device info structure, providing device-specific functions and a means of
  57. * adding driver-specific state.
  58. */
  59. struct bsec_config {
  60. uint8_t den_lock; /*
  61. * Debug enable sticky lock
  62. * 1 debug enable is locked until next reset
  63. */
  64. /* BSEC2 only */
  65. uint8_t tread; /* SAFMEM Reading current level default 0 */
  66. uint8_t pulse_width; /* SAFMEM Programming pulse width default 1 */
  67. uint8_t freq; /*
  68. * SAFMEM CLOCK see freq value define
  69. * default FREQ_45_67_MHZ
  70. */
  71. uint8_t power; /* Power up SAFMEM. 1 power up, 0 power off */
  72. uint8_t prog_lock; /*
  73. * Programming Sticky lock
  74. * 1 programming is locked until next reset
  75. */
  76. uint8_t upper_otp_lock; /*
  77. * Shadowing of upper OTP sticky lock
  78. * 1 shadowing of upper OTP is locked
  79. * until next reset
  80. */
  81. };
  82. uint32_t bsec_probe(void);
  83. uint32_t bsec_get_base(void);
  84. uint32_t bsec_set_config(struct bsec_config *cfg);
  85. uint32_t bsec_get_config(struct bsec_config *cfg);
  86. uint32_t bsec_shadow_register(uint32_t otp);
  87. uint32_t bsec_read_otp(uint32_t *val, uint32_t otp);
  88. uint32_t bsec_write_otp(uint32_t val, uint32_t otp);
  89. uint32_t bsec_program_otp(uint32_t val, uint32_t otp);
  90. uint32_t bsec_permanent_lock_otp(uint32_t otp);
  91. void bsec_write_debug_conf(uint32_t val);
  92. uint32_t bsec_read_debug_conf(void);
  93. void bsec_write_scratch(uint32_t val);
  94. uint32_t bsec_read_scratch(void);
  95. uint32_t bsec_get_status(void);
  96. uint32_t bsec_get_hw_conf(void);
  97. uint32_t bsec_get_version(void);
  98. uint32_t bsec_get_id(void);
  99. uint32_t bsec_get_magic_id(void);
  100. uint32_t bsec_set_sr_lock(uint32_t otp);
  101. uint32_t bsec_read_sr_lock(uint32_t otp, bool *value);
  102. uint32_t bsec_set_sw_lock(uint32_t otp);
  103. uint32_t bsec_read_sw_lock(uint32_t otp, bool *value);
  104. uint32_t bsec_set_sp_lock(uint32_t otp);
  105. uint32_t bsec_read_sp_lock(uint32_t otp, bool *value);
  106. uint32_t bsec_read_permanent_lock(uint32_t otp, bool *value);
  107. uint32_t bsec_otp_lock(uint32_t service);
  108. uint32_t bsec_shadow_read_otp(uint32_t *otp_value, uint32_t word);
  109. uint32_t bsec_check_nsec_access_rights(uint32_t otp);
  110. #endif /* BSEC_H */