xref: /rk3399_ARM-atf/plat/st/stm32mp1/services/bsec_svc.c (revision 06f3c7058c42a9f1a9f7df75ea2de71a000855e8)
1 /*
2  * Copyright (c) 2016-2024, STMicroelectronics - All Rights Reserved
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 
8 #include <common/debug.h>
9 #include <drivers/st/bsec.h>
10 #include <drivers/st/bsec2_reg.h>
11 
12 #include <platform_def.h>
13 #include <stm32mp1_smc.h>
14 #include <stm32mp_svc_setup.h>
15 
16 #include "bsec_svc.h"
17 
18 uint32_t bsec_main(uint32_t x1, uint32_t x2, uint32_t x3,
19 		   uint32_t *ret_otp_value)
20 {
21 	uint32_t result;
22 	uint32_t tmp_data = 0U;
23 
24 	switch (x1) {
25 	case STM32_SMC_READ_SHADOW:
26 		result = bsec_read_otp(ret_otp_value, x2);
27 		break;
28 	case STM32_SMC_PROG_OTP:
29 		*ret_otp_value = 0U;
30 		result = bsec_program_otp(x3, x2);
31 		break;
32 	case STM32_SMC_WRITE_SHADOW:
33 		*ret_otp_value = 0U;
34 		result = bsec_write_otp(x3, x2);
35 		break;
36 	case STM32_SMC_READ_OTP:
37 		*ret_otp_value = 0U;
38 		result = bsec_read_otp(&tmp_data, x2);
39 		if (result != BSEC_OK) {
40 			break;
41 		}
42 
43 		result = bsec_shadow_read_otp(ret_otp_value, x2);
44 		if (result != BSEC_OK) {
45 			break;
46 		}
47 
48 		result = bsec_write_otp(tmp_data, x2);
49 		break;
50 
51 	default:
52 		return STM32_SMC_INVALID_PARAMS;
53 	}
54 
55 	return (result == BSEC_OK) ? STM32_SMC_OK : STM32_SMC_FAILED;
56 }
57