1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 #ifndef HPM_OTP_DRV_H
8 #define HPM_OTP_DRV_H
9 
10 /**
11  * @brief OTP APIs
12  * @defgroup otp_interface OTP driver APIs
13  * @{
14  */
15 
16 #include "hpm_common.h"
17 
18 /***********************************************************************************************************************
19  * Definitions
20  **********************************************************************************************************************/
21 /**
22  * @brief OTP region definitions
23  */
24 typedef enum {
25     otp_region0_mask = 1U,  /*!< Address range: [0, 7]  */
26     otp_region1_mask = 2U,  /*!< Address range: [8, 15] */
27     otp_region2_mask = 4U,  /*!< Address range: [16, 127] */
28     otp_region3_mask = 8U,  /*!< Address range: user defined */
29 } otp_region_t;
30 
31 /**
32  * @brief OTP lock options
33  */
34 typedef enum {
35     otp_no_lock = 0,
36     otp_read_only = 1,
37     otp_permanent_no_lock = 2,
38     otp_disable_access = 3,
39     otp_lock_option_max = otp_disable_access,
40 } otp_lock_option_t;
41 
42 enum {
43     otp_write_disallowed = MAKE_STATUS(status_group_otp, 0),
44 };
45 
46 /***********************************************************************************************************************
47  * Prototypes
48  **********************************************************************************************************************/
49 #ifdef __cpluscplus
50 extern "C" {
51 #endif
52 
53 /**
54  * @brief Initialize OTP controller
55  */
56 void otp_init(void);
57 
58 /**
59  * @brief De-initialize OTP controller
60  */
61 void otp_deinit(void);
62 
63 /**
64  * @brief Read the OTP word from shadow register
65  * @param [in] addr OTP word index
66  * @retval OTP word value
67  */
68 uint32_t otp_read_from_shadow(uint32_t addr);
69 
70 /**
71  * @brief Read the specified OTP word from OTP IP bus
72  * @param [in] addr OTP word index
73  * @retval OTP word value
74  */
75 uint32_t otp_read_from_ip(uint32_t addr);
76 
77 /**
78  * @brief Program a word to specified OTP field
79  * @param [in] addr OTP word index
80  * @param [in] src Pointer to the data to be programmed
81  * @param [in] num_of_words Number of words to be programmed, only 1 is allowed
82  * @return API execution status
83  */
84 hpm_stat_t otp_program(uint32_t addr, const uint32_t *src, uint32_t num_of_words);
85 
86 /**
87  * @brief Reload a OTP region
88  * @param [in] region OTP region option
89  * @return API execution status
90  */
91 hpm_stat_t otp_reload(otp_region_t region);
92 
93 /**
94  * @brief Change the Software lock permission
95  * @param [in] addr OTP word index
96  * @param [in] lock_option OTP lcok option
97  * @return API execution status
98  */
99 hpm_stat_t otp_lock_otp(uint32_t addr, otp_lock_option_t lock_option);
100 
101 /**
102  * @brief OTP lock shadow
103  * @param [in] addr OTP word index
104  * @param [in] lock_option OTP lock option
105  * @return API execution status
106  */
107 hpm_stat_t otp_lock_shadow(uint32_t addr, otp_lock_option_t lock_option);
108 
109 /**
110  * @brief Set the configurable region range
111  * @param [in] start OTP word start index
112  * @param [in] num_of_words Number of words in configuration region
113  * @retval status_out_of_range Invalid range
114  * @retval status_success Operation is successful
115  */
116 hpm_stat_t otp_set_configurable_region(uint32_t start, uint32_t num_of_words);
117 
118 /**
119  * @return Write data to OTP shadow register
120  * @param [in] addr OTP word index
121  * @param [in] val Data to be written
122  * @return API execution status
123  */
124 hpm_stat_t otp_write_shadow_register(uint32_t addr, uint32_t val);
125 
126 
127 #ifdef __cpluscplus
128 }
129 #endif
130 /**
131  * @}
132  */
133 
134 
135 
136 
137 #endif
138