1 /*
2 * Copyright 2022 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include "fsl_romapi_otp.h"
9 #include "fsl_romapi.h"
10
11 #define OCOTP_API_TREE ((ocotp_driver_t *)(((uint32_t *)ROM_API_TREE_ADDR)[6]))
12
13 /*!
14 * @brief Initialize OCOTP controller
15 */
otp_version(void)16 uint32_t otp_version(void)
17 {
18 return (OCOTP->OTP_VERSION);
19 }
20
21 /*!
22 * @brief Initialize OCOTP controller
23 */
otp_init(uint32_t src_clk_freq)24 status_t otp_init(uint32_t src_clk_freq)
25 {
26 assert(OCOTP_API_TREE);
27 return OCOTP_API_TREE->init(src_clk_freq);
28 }
29
30 /*!
31 * @brief Deinitialize OCOTP controller
32 */
otp_deinit(void)33 status_t otp_deinit(void)
34 {
35 assert(OCOTP_API_TREE);
36 return OCOTP_API_TREE->deinit();
37 }
38
39 /*!
40 * @brief Reload OTP shadow registers
41 */
otp_shadow_register_reload(void)42 status_t otp_shadow_register_reload(void)
43 {
44 assert(OCOTP_API_TREE);
45 return OCOTP_API_TREE->reload();
46 }
47
48 /*!
49 * @brief Reads a fuse word
50 */
otp_fuse_read(uint32_t addr,uint32_t * data)51 status_t otp_fuse_read(uint32_t addr, uint32_t *data)
52 {
53 uint32_t argChk;
54 assert(OCOTP_API_TREE);
55 argChk = addr ^ ((uint32_t) data);
56 return OCOTP_API_TREE->fuse_read(addr, data, argChk);
57 }
58
59 /*!
60 * @brief Programs a fuse word
61 */
otp_fuse_program(uint32_t addr,uint32_t data)62 status_t otp_fuse_program(uint32_t addr, uint32_t data)
63 {
64 assert(OCOTP_API_TREE);
65 return OCOTP_API_TREE->fuse_program(addr, data, false);
66 }
67
68 /*!
69 * @brief Perform CRC check using HW OTP controller
70 */
otp_crc_check(uint32_t start_addr,uint32_t end_addr,uint32_t crc_addr)71 status_t otp_crc_check(uint32_t start_addr, uint32_t end_addr, uint32_t crc_addr)
72 {
73 assert(OCOTP_API_TREE);
74 return OCOTP_API_TREE->crc_check(start_addr, end_addr, crc_addr);
75 }
76
77 /*!
78 * @brief Perform CRC calculation
79 */
otp_crc_calc(uint32_t * src,uint32_t numberOfWords,uint32_t * crcChecksum)80 status_t otp_crc_calc(uint32_t *src, uint32_t numberOfWords, uint32_t *crcChecksum)
81 {
82 assert(OCOTP_API_TREE);
83 return OCOTP_API_TREE->crc_calc(src, numberOfWords, crcChecksum);
84 }
85
86 /*!
87 * @brief Perform CRC check using CRC module.
88 */
otp_crc_check_sw(uint32_t * src,uint32_t numberOfWords,uint32_t crc_fuse_idx)89 status_t otp_crc_check_sw(uint32_t *src, uint32_t numberOfWords, uint32_t crc_fuse_idx)
90 {
91 assert(OCOTP_API_TREE);
92 return OCOTP_API_TREE->crc_check_sw(src, numberOfWords, crc_fuse_idx);
93 }
94