1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * 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, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 #include "drv_osal_lib.h"
20 #include "drv_ioctl_otp.h"
21 #include "drv_otp.h"
22
drv_ioctl_otp(hi_u32 cmd,hi_void * argp)23 hi_s32 drv_ioctl_otp(hi_u32 cmd, hi_void *argp)
24 {
25 hi_s32 ret;
26 hi_u32 nr;
27
28 nr = otp_ioc_nr(cmd);
29
30 hi_otp_check_formula_fail(argp == HI_NULL, HI_ERR_OTP_NULL_PTR);
31 hi_otp_check_formula_fail(nr >= CMD_OTP_COUNT, HI_ERR_OTP_INVALID_PARAM);
32
33 switch (cmd) {
34 case CMD_OTP_SET_USER_DATA: {
35 otp_user_data *data = (otp_user_data *)argp;
36 ret = drv_otp_set_user_data(data->field_name, data->offset,
37 addr_via_const(data->value), data->value_len);
38 hi_otp_func_fail_return(drv_otp_set_user_data, ret != HI_SUCCESS, ret);
39 break;
40 }
41 case CMD_OTP_GET_USER_DATA: {
42 otp_user_data *data = (otp_user_data *)argp;
43 ret = drv_otp_get_user_data(data->field_name, data->offset,
44 addr_via(data->value), data->value_len);
45 hi_otp_func_fail_return(drv_otp_get_user_data, ret != HI_SUCCESS, ret);
46 break;
47 }
48 case CMD_OTP_BURN_PRODUCT_PV: {
49 otp_product_pv *product_pv = (otp_product_pv *)argp;
50 ret = drv_otp_burn_product_pv(addr_via_const(product_pv->pv), product_pv->num);
51 hi_otp_func_fail_return(drv_otp_burn_product_pv, ret != HI_SUCCESS, ret);
52 break;
53 }
54 case CMD_OTP_READ_PRODUCT_PV: {
55 otp_product_pv *product_pv = (otp_product_pv *)argp;
56 ret = drv_otp_read_product_pv(addr_via(product_pv->pv), product_pv->num);
57 hi_otp_func_fail_return(drv_otp_read_product_pv, ret != HI_SUCCESS, ret);
58 break;
59 }
60 case CMD_OTP_KEY_VERIFY_STATUS: {
61 otp_key_verify_status *status = (otp_key_verify_status *)argp;
62 ret = drv_otp_get_key_verify_status(status->field_name, &status->status);
63 hi_otp_func_fail_return(drv_otp_get_key_verify_status, ret != HI_SUCCESS, ret);
64 break;
65 }
66 default: {
67 hi_otp_err("invalid command\n");
68 return HI_ERR_OTP_INVALID_PARAM;
69 }
70 }
71
72 return ret;
73 }
74
75