1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
11 #include <dm/device.h>
12 #include <dm/uclass.h>
13 #include <power/stpmic1.h>
15 #define STM32MP_OTP_BANK 0
16 #define STM32MP_NVM_BANK 1
19 * The 'fuse' command API
21 int fuse_read(u32 bank, u32 word, u32 *val)
27 case STM32MP_OTP_BANK:
28 ret = uclass_get_device_by_driver(UCLASS_MISC,
29 DM_DRIVER_GET(stm32mp_bsec),
33 ret = misc_read(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
41 #ifdef CONFIG_PMIC_STPMIC1
42 case STM32MP_NVM_BANK:
43 ret = uclass_get_device_by_driver(UCLASS_MISC,
44 DM_DRIVER_GET(stpmic1_nvm),
49 ret = misc_read(dev, -word, val, 1);
55 #endif /* CONFIG_PMIC_STPMIC1 */
58 printf("stm32mp %s: wrong value for bank %i\n", __func__, bank);
66 int fuse_prog(u32 bank, u32 word, u32 val)
72 case STM32MP_OTP_BANK:
73 ret = uclass_get_device_by_driver(UCLASS_MISC,
74 DM_DRIVER_GET(stm32mp_bsec),
78 ret = misc_write(dev, word * 4 + STM32_BSEC_OTP_OFFSET,
86 #ifdef CONFIG_PMIC_STPMIC1
87 case STM32MP_NVM_BANK:
88 ret = uclass_get_device_by_driver(UCLASS_MISC,
89 DM_DRIVER_GET(stpmic1_nvm),
93 ret = misc_write(dev, word, &val, 1);
99 #endif /* CONFIG_PMIC_STPMIC1 */
102 printf("stm32mp %s: wrong value for bank %i\n", __func__, bank);
110 int fuse_sense(u32 bank, u32 word, u32 *val)
116 case STM32MP_OTP_BANK:
117 ret = uclass_get_device_by_driver(UCLASS_MISC,
118 DM_DRIVER_GET(stm32mp_bsec),
122 ret = misc_read(dev, word * 4 + STM32_BSEC_OTP_OFFSET, val, 4);
129 #ifdef CONFIG_PMIC_STPMIC1
130 case STM32MP_NVM_BANK:
131 ret = uclass_get_device_by_driver(UCLASS_MISC,
132 DM_DRIVER_GET(stpmic1_nvm),
137 ret = misc_read(dev, word, val, 1);
143 #endif /* CONFIG_PMIC_STPMIC1 */
146 printf("stm32mp %s: wrong value for bank %i\n", __func__, bank);
154 int fuse_override(u32 bank, u32 word, u32 val)
160 case STM32MP_OTP_BANK:
161 ret = uclass_get_device_by_driver(UCLASS_MISC,
162 DM_DRIVER_GET(stm32mp_bsec),
166 ret = misc_write(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
174 #ifdef CONFIG_PMIC_STPMIC1
175 case STM32MP_NVM_BANK:
176 ret = uclass_get_device_by_driver(UCLASS_MISC,
177 DM_DRIVER_GET(stpmic1_nvm),
181 ret = misc_write(dev, -word, &val, 1);
187 #endif /* CONFIG_PMIC_STPMIC1 */
190 printf("stm32mp %s: wrong value for bank %i\n",