1 /* 2 * Copyright (c) 2021-2023, The TrustedFirmware-M Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #include "cc3xx_lcs.h" 9 10 #include "cc3xx_dev.h" 11 #include "cc3xx_lcs_defs.h" 12 #include "cc3xx_error.h" 13 cc3xx_lowlevel_lcs_get(cc3xx_lcs_t * lcs)14cc3xx_err_t cc3xx_lowlevel_lcs_get(cc3xx_lcs_t* lcs) 15 { 16 uint32_t code = 0; 17 18 /* Wait until the NVM controller is idle */ 19 while (! (P_CC3XX->nvm.nvm_is_idle & 0b1U)) {} 20 21 if (! (P_CC3XX->nvm.lcs_is_valid & 0b1U)) { 22 return CC3XX_ERR_INVALID_LCS; 23 } 24 25 code = P_CC3XX->nvm.lcs_reg & 0b111U; 26 27 switch (code) { 28 case CC3XX_LCS_CM_CODE: 29 *lcs = cc3xx_lcs_cm; 30 break; 31 case CC3XX_LCS_DM_CODE: 32 *lcs = cc3xx_lcs_dm; 33 break; 34 case CC3XX_LCS_SE_CODE: 35 *lcs = cc3xx_lcs_se; 36 break; 37 case CC3XX_LCS_RMA_CODE: 38 *lcs = cc3xx_lcs_rma; 39 break; 40 default: 41 return CC3XX_ERR_INVALID_LCS; 42 } 43 44 return CC3XX_ERR_SUCCESS; 45 } 46 cc3xx_lowlevel_lcs_get_name(cc3xx_lcs_t lcs)47const char* cc3xx_lowlevel_lcs_get_name(cc3xx_lcs_t lcs) 48 { 49 switch (lcs) { 50 case cc3xx_lcs_cm: 51 return "LCS_CM"; 52 case cc3xx_lcs_dm: 53 return "LCS_DM"; 54 case cc3xx_lcs_se: 55 return "LCS_SE"; 56 case cc3xx_lcs_rma: 57 return "LCS_RMA"; 58 default: 59 return "LCS_UNKNOWN"; 60 } 61 } 62