Lines Matching +full:otp +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
25 #define BSEC_SWLOCK_OFF 0x07C /* write in OTP sticky lock */
47 * OTP Lock services definition
53 * bsec_check_error() - Check status of one otp
55 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
56 * Return: 0 if no error, -EAGAIN or -ENOTSUPP
58 static u32 bsec_check_error(u32 base, u32 otp) in bsec_check_error() argument
63 bit = 1 << (otp & OTP_LOCK_MASK); in bsec_check_error()
64 bank = ((otp >> OTP_LOCK_BANK_SHIFT) & OTP_LOCK_MASK) * sizeof(u32); in bsec_check_error()
67 return -EAGAIN; in bsec_check_error()
69 return -ENOTSUPP; in bsec_check_error()
75 * bsec_lock() - manage lock for each type SR/SP/SW
77 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
80 static bool bsec_read_lock(u32 address, u32 otp) in bsec_read_lock() argument
85 bit = 1 << (otp & OTP_LOCK_MASK); in bsec_read_lock()
86 bank = ((otp >> OTP_LOCK_BANK_SHIFT) & OTP_LOCK_MASK) * sizeof(u32); in bsec_read_lock()
92 * bsec_read_SR_lock() - read SR lock (Shadowing)
94 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
97 static bool bsec_read_SR_lock(u32 base, u32 otp) in bsec_read_SR_lock() argument
99 return bsec_read_lock(base + BSEC_SRLOCK_OFF, otp); in bsec_read_SR_lock()
103 * bsec_read_SP_lock() - read SP lock (program Lock)
105 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
108 static bool bsec_read_SP_lock(u32 base, u32 otp) in bsec_read_SP_lock() argument
110 return bsec_read_lock(base + BSEC_SPLOCK_OFF, otp); in bsec_read_SP_lock()
114 * bsec_SW_lock() - manage SW lock (Write in Shadow)
116 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
119 static bool bsec_read_SW_lock(u32 base, u32 otp) in bsec_read_SW_lock() argument
121 return bsec_read_lock(base + BSEC_SWLOCK_OFF, otp); in bsec_read_SW_lock()
125 * bsec_power_safmem() - Activate or deactivate safmem power
150 * bsec_shadow_register() - copy safmen otp to bsec data
152 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
155 static int bsec_shadow_register(u32 base, u32 otp) in bsec_shadow_register() argument
161 /* check if shadowing of otp is locked */ in bsec_shadow_register()
162 if (bsec_read_SR_lock(base, otp)) in bsec_shadow_register()
163 pr_debug("bsec : OTP %d is locked and refreshed with 0\n", otp); in bsec_shadow_register()
171 power_up = 1; in bsec_shadow_register()
173 /* set BSEC_OTP_CTRL_OFF with the otp value*/ in bsec_shadow_register()
174 writel(otp | BSEC_READ, base + BSEC_OTP_CTRL_OFF); in bsec_shadow_register()
176 /* check otp status*/ in bsec_shadow_register()
183 ret = bsec_check_error(base, otp); in bsec_shadow_register()
192 * bsec_read_shadow() - read an otp data value from shadow
195 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
198 static int bsec_read_shadow(u32 base, u32 *val, u32 otp) in bsec_read_shadow() argument
200 *val = readl(base + BSEC_OTP_DATA_OFF + otp * sizeof(u32)); in bsec_read_shadow()
202 return bsec_check_error(base, otp); in bsec_read_shadow()
206 * bsec_write_shadow() - write value in BSEC data register in shadow
209 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
212 static int bsec_write_shadow(u32 base, u32 val, u32 otp) in bsec_write_shadow() argument
214 /* check if programming of otp is locked */ in bsec_write_shadow()
215 if (bsec_read_SW_lock(base, otp)) in bsec_write_shadow()
216 pr_debug("bsec : OTP %d is lock, write will be ignore\n", otp); in bsec_write_shadow()
218 writel(val, base + BSEC_OTP_DATA_OFF + otp * sizeof(u32)); in bsec_write_shadow()
220 return bsec_check_error(base, otp); in bsec_write_shadow()
224 * bsec_program_otp() - program a bit in SAFMEM
227 * @otp: otp number (0 - BSEC_OTP_MAX_VALUE)
228 * after the function the otp data is not refreshed in shadow
231 static int bsec_program_otp(long base, u32 val, u32 otp) in bsec_program_otp() argument
236 if (bsec_read_SP_lock(base, otp)) in bsec_program_otp()
237 pr_debug("bsec : OTP %d locked, prog will be ignore\n", otp); in bsec_program_otp()
239 if (readl(base + BSEC_OTP_LOCK_OFF) & (1 << BSEC_LOCK_PROGRAM)) in bsec_program_otp()
253 /* set BSEC_OTP_CTRL_OFF with the otp value */ in bsec_program_otp()
254 writel(otp | BSEC_WRITE, base + BSEC_OTP_CTRL_OFF); in bsec_program_otp()
256 /* check otp status*/ in bsec_program_otp()
264 ret = -EACCES; in bsec_program_otp()
266 ret = bsec_check_error(base, otp); in bsec_program_otp()
279 static int stm32mp_bsec_read_otp(struct udevice *dev, u32 *val, u32 otp) in stm32mp_bsec_read_otp() argument
286 ret = bsec_read_shadow(plat->base, &tmp_data, otp); in stm32mp_bsec_read_otp()
290 /* copy otp in shadow */ in stm32mp_bsec_read_otp()
291 ret = bsec_shadow_register(plat->base, otp); in stm32mp_bsec_read_otp()
295 ret = bsec_read_shadow(plat->base, val, otp); in stm32mp_bsec_read_otp()
300 ret = bsec_write_shadow(plat->base, tmp_data, otp); in stm32mp_bsec_read_otp()
304 static int stm32mp_bsec_read_shadow(struct udevice *dev, u32 *val, u32 otp) in stm32mp_bsec_read_shadow() argument
308 return bsec_read_shadow(plat->base, val, otp); in stm32mp_bsec_read_shadow()
311 static int stm32mp_bsec_write_otp(struct udevice *dev, u32 val, u32 otp) in stm32mp_bsec_write_otp() argument
315 return bsec_program_otp(plat->base, val, otp); in stm32mp_bsec_write_otp()
318 static int stm32mp_bsec_write_shadow(struct udevice *dev, u32 val, u32 otp) in stm32mp_bsec_write_shadow() argument
322 return bsec_write_shadow(plat->base, val, otp); in stm32mp_bsec_write_shadow()
332 int otp; in stm32mp_bsec_read() local
335 offset -= STM32_BSEC_OTP_OFFSET; in stm32mp_bsec_read()
338 otp = offset / sizeof(u32); in stm32mp_bsec_read()
340 if (otp < 0 || (otp + nb_otp - 1) > BSEC_OTP_MAX_VALUE) { in stm32mp_bsec_read()
341 dev_err(dev, "wrong value for otp, max value : %i\n", in stm32mp_bsec_read()
343 return -EINVAL; in stm32mp_bsec_read()
346 for (i = otp; i < (otp + nb_otp); i++) { in stm32mp_bsec_read()
347 u32 *addr = &((u32 *)buf)[i - otp]; in stm32mp_bsec_read()
367 int otp; in stm32mp_bsec_write() local
370 offset -= STM32_BSEC_OTP_OFFSET; in stm32mp_bsec_write()
373 otp = offset / sizeof(u32); in stm32mp_bsec_write()
375 if (otp < 0 || (otp + nb_otp - 1) > BSEC_OTP_MAX_VALUE) { in stm32mp_bsec_write()
376 dev_err(dev, "wrong value for otp, max value : %d\n", in stm32mp_bsec_write()
378 return -EINVAL; in stm32mp_bsec_write()
381 for (i = otp; i < otp + nb_otp; i++) { in stm32mp_bsec_write()
382 u32 *val = &((u32 *)buf)[i - otp]; in stm32mp_bsec_write()
403 plat->base = (u32)dev_read_addr_ptr(dev); in stm32mp_bsec_ofdata_to_platdata()
409 { .compatible = "st,stm32mp-bsec" },