2019-04-12 07:54:54 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright 2019 NXP
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <console.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fuse.h>
|
2023-04-28 04:08:09 +00:00
|
|
|
#include <firmware/imx/sci/sci.h>
|
2019-04-12 07:54:54 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-05-11 07:16:07 +00:00
|
|
|
#include <linux/arm-smccc.h>
|
2019-04-12 07:54:54 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#define FSL_ECC_WORD_START_1 0x10
|
|
|
|
#define FSL_ECC_WORD_END_1 0x10F
|
|
|
|
|
2020-05-03 14:31:46 +00:00
|
|
|
#ifdef CONFIG_IMX8QM
|
|
|
|
#define FSL_ECC_WORD_START_2 0x1A0
|
|
|
|
#define FSL_ECC_WORD_END_2 0x1FF
|
|
|
|
#elif defined(CONFIG_IMX8QXP)
|
2019-04-12 07:54:54 +00:00
|
|
|
#define FSL_ECC_WORD_START_2 0x220
|
|
|
|
#define FSL_ECC_WORD_END_2 0x31F
|
2020-05-03 14:31:46 +00:00
|
|
|
#endif
|
2019-04-12 07:54:54 +00:00
|
|
|
|
|
|
|
#define FSL_QXP_FUSE_GAP_START 0x110
|
|
|
|
#define FSL_QXP_FUSE_GAP_END 0x21F
|
|
|
|
|
|
|
|
#define FSL_SIP_OTP_READ 0xc200000A
|
|
|
|
#define FSL_SIP_OTP_WRITE 0xc200000B
|
|
|
|
|
|
|
|
int fuse_read(u32 bank, u32 word, u32 *val)
|
|
|
|
{
|
|
|
|
return fuse_sense(bank, word, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
int fuse_sense(u32 bank, u32 word, u32 *val)
|
|
|
|
{
|
2020-05-11 07:16:07 +00:00
|
|
|
struct arm_smccc_res res;
|
2019-04-12 07:54:54 +00:00
|
|
|
|
|
|
|
if (bank != 0) {
|
|
|
|
printf("Invalid bank argument, ONLY bank 0 is supported\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-05-11 07:16:07 +00:00
|
|
|
arm_smccc_smc(FSL_SIP_OTP_READ, (unsigned long)word, 0, 0,
|
|
|
|
0, 0, 0, 0, &res);
|
|
|
|
*val = (u32)res.a1;
|
2019-04-12 07:54:54 +00:00
|
|
|
|
2020-05-11 07:16:07 +00:00
|
|
|
return res.a0;
|
2019-04-12 07:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fuse_prog(u32 bank, u32 word, u32 val)
|
|
|
|
{
|
2020-05-11 07:16:07 +00:00
|
|
|
struct arm_smccc_res res;
|
|
|
|
|
2019-04-12 07:54:54 +00:00
|
|
|
if (bank != 0) {
|
|
|
|
printf("Invalid bank argument, ONLY bank 0 is supported\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_IMX8QXP)) {
|
|
|
|
if (word >= FSL_QXP_FUSE_GAP_START &&
|
|
|
|
word <= FSL_QXP_FUSE_GAP_END) {
|
|
|
|
printf("Invalid word argument for this SoC\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((word >= FSL_ECC_WORD_START_1 && word <= FSL_ECC_WORD_END_1) ||
|
|
|
|
(word >= FSL_ECC_WORD_START_2 && word <= FSL_ECC_WORD_END_2)) {
|
|
|
|
puts("Warning: Words in this index range have ECC protection\n"
|
|
|
|
"and can only be programmed once per word. Individual bit\n"
|
|
|
|
"operations will be rejected after the first one.\n"
|
|
|
|
"\n\n Really program this word? <y/N>\n");
|
|
|
|
|
|
|
|
if (!confirm_yesno()) {
|
|
|
|
puts("Word programming aborted\n");
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 07:16:07 +00:00
|
|
|
arm_smccc_smc(FSL_SIP_OTP_WRITE, (unsigned long)word,
|
|
|
|
(unsigned long)val, 0, 0, 0, 0, 0, &res);
|
|
|
|
|
|
|
|
return res.a0;
|
2019-04-12 07:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fuse_override(u32 bank, u32 word, u32 val)
|
|
|
|
{
|
|
|
|
printf("Override fuse to i.MX8 in u-boot is forbidden\n");
|
|
|
|
return -EPERM;
|
|
|
|
}
|