1 /* 2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef __HAL_OTP_H__ 20 #define __HAL_OTP_H__ 21 22 #include "hal_efuse.h" 23 24 #define OTP_USER_IF_BASE g_efuse_otp_reg_base 25 #define OTP_USER_WORK_MODE (OTP_USER_IF_BASE + 0x0000) 26 #define OTP_USER_OP_START (OTP_USER_IF_BASE + 0x0004) 27 #define OTP_USER_KEY_INDEX (OTP_USER_IF_BASE + 0x0008) 28 #define OTP_USER_KEY_DATA0 (OTP_USER_IF_BASE + 0x000c) 29 #define OTP_USER_KEY_DATA1 (OTP_USER_IF_BASE + 0x0010) 30 #define OTP_USER_KEY_DATA2 (OTP_USER_IF_BASE + 0x0014) 31 #define OTP_USER_KEY_DATA3 (OTP_USER_IF_BASE + 0x0018) 32 #define OTP_USER_KEY_DATA4 (OTP_USER_IF_BASE + 0x001c) 33 #define OTP_USER_KEY_DATA5 (OTP_USER_IF_BASE + 0x0020) 34 #define OTP_USER_KEY_DATA6 (OTP_USER_IF_BASE + 0x0024) 35 #define OTP_USER_KEY_DATA7 (OTP_USER_IF_BASE + 0x0028) 36 #define OTP_USER_KEY_DATA8 (OTP_USER_IF_BASE + 0x002c) 37 #define OTP_USER_FLAG_VALUE (OTP_USER_IF_BASE + 0x0030) 38 #define OTP_USER_FLAG_INDEX (OTP_USER_IF_BASE + 0x0034) 39 #define OTP_USER_REV_ADDR (OTP_USER_IF_BASE + 0x0038) 40 #define OTP_USER_REV_WDATA (OTP_USER_IF_BASE + 0x003c) 41 #define OTP_USER_REV_RDATA (OTP_USER_IF_BASE + 0x0040) 42 #define OTP_USER_LOCK_STA0 (OTP_USER_IF_BASE + 0x0044) 43 #define OTP_USER_LOCK_STA1 (OTP_USER_IF_BASE + 0x0048) 44 #define OTP_USER_CTRL_STA (OTP_USER_IF_BASE + 0x004c) 45 46 #define OTP_WAIT_TIME_OUT 10000 47 #define OTP_OP_START_VAL 0x1acce551 48 49 typedef enum { 50 OTP_USER_LOCK_STA0_TYPE, 51 OTP_USER_LOCK_STA1_TYPE, 52 OTP_USER_LOCK_UNKNOWN_STA, 53 } otp_lock_sta_type; 54 55 typedef enum { 56 OTP_READ_LOCK_STA_MODE, 57 OTP_LOCK_CIPHER_KEY_MODE, 58 OTP_WRITE_KEY_ID_OR_PASSWD_MODE, 59 OTP_KEY_ID_OR_PASSWD_CRC_MODE, 60 OTP_SET_FLAG_ENABLE_MODE, 61 OTP_WRITE_USER_ROOM_MODE, 62 OTP_READ_USER_ROOM_MODE, 63 OTP_UNKNOWN_MODE, 64 } otp_user_work_mode; 65 66 typedef enum { 67 OTP_USER_KEY0, 68 OTP_USER_KEY1, 69 OTP_USER_KEY2, 70 OTP_USER_KEY3, 71 OTP_USER_KEY_JTAG_PW_ID, 72 OTP_USER_KEY_JTAG_PW, 73 OTP_USER_KEY_ROOTKEY, 74 OTP_USER_KEY_UNKNOWN, 75 } otp_user_key_index; 76 77 typedef enum { 78 OTP_KEY_LENGTH_64BIT, 79 OTP_KEY_LENGTH_128BIT, 80 OTP_KEY_LENGTH_256BIT, 81 OTP_KEY_LENGTH_UNSUPPORT, 82 } otp_user_key_length; 83 84 hi_s32 hal_efuse_otp_init(hi_void); 85 hi_s32 hal_efuse_otp_load_cipher_key(hi_u32 chn_id, hi_u32 opt_id); 86 hi_void hal_efuse_otp_set_reg_base(hi_u8 *reg_base); 87 hi_u8 *hal_efuse_otp_get_reg_base(hi_void); 88 unsigned short calculate_crc16 (const unsigned char *data_array_ptr, unsigned long data_array_length); 89 90 #endif 91