blob: 4d7f2f524d0a2d9e8b62d74dce22f5f8feb53313 [file] [log] [blame]
Peng Fan0fe6f162019-04-12 07:54:54 +00001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2019 NXP
4 */
5
6#include <common.h>
7#include <console.h>
8#include <errno.h>
9#include <fuse.h>
10#include <asm/arch/sci/sci.h>
11#include <asm/arch/sys_proto.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15#define FSL_ECC_WORD_START_1 0x10
16#define FSL_ECC_WORD_END_1 0x10F
17
Ye Li390f4602020-05-03 22:31:46 +080018#ifdef CONFIG_IMX8QM
19#define FSL_ECC_WORD_START_2 0x1A0
20#define FSL_ECC_WORD_END_2 0x1FF
21#elif defined(CONFIG_IMX8QXP)
Peng Fan0fe6f162019-04-12 07:54:54 +000022#define FSL_ECC_WORD_START_2 0x220
23#define FSL_ECC_WORD_END_2 0x31F
Ye Li390f4602020-05-03 22:31:46 +080024#endif
Peng Fan0fe6f162019-04-12 07:54:54 +000025
26#define FSL_QXP_FUSE_GAP_START 0x110
27#define FSL_QXP_FUSE_GAP_END 0x21F
Peng Fan0fe6f162019-04-12 07:54:54 +000028
29#define FSL_SIP_OTP_READ 0xc200000A
30#define FSL_SIP_OTP_WRITE 0xc200000B
31
32int fuse_read(u32 bank, u32 word, u32 *val)
33{
34 return fuse_sense(bank, word, val);
35}
36
37int fuse_sense(u32 bank, u32 word, u32 *val)
38{
39 unsigned long ret = 0, value = 0;
40
41 if (bank != 0) {
42 printf("Invalid bank argument, ONLY bank 0 is supported\n");
43 return -EINVAL;
44 }
45
46 ret = call_imx_sip_ret2(FSL_SIP_OTP_READ, (unsigned long)word, &value,
47 0, 0);
48 *val = (u32)value;
49
50 return ret;
51}
52
53int fuse_prog(u32 bank, u32 word, u32 val)
54{
55 if (bank != 0) {
56 printf("Invalid bank argument, ONLY bank 0 is supported\n");
57 return -EINVAL;
58 }
59
60 if (IS_ENABLED(CONFIG_IMX8QXP)) {
61 if (word >= FSL_QXP_FUSE_GAP_START &&
62 word <= FSL_QXP_FUSE_GAP_END) {
63 printf("Invalid word argument for this SoC\n");
64 return -EINVAL;
65 }
66 }
67
68 if ((word >= FSL_ECC_WORD_START_1 && word <= FSL_ECC_WORD_END_1) ||
69 (word >= FSL_ECC_WORD_START_2 && word <= FSL_ECC_WORD_END_2)) {
70 puts("Warning: Words in this index range have ECC protection\n"
71 "and can only be programmed once per word. Individual bit\n"
72 "operations will be rejected after the first one.\n"
73 "\n\n Really program this word? <y/N>\n");
74
75 if (!confirm_yesno()) {
76 puts("Word programming aborted\n");
77 return -EPERM;
78 }
79 }
80
81 return call_imx_sip(FSL_SIP_OTP_WRITE, (unsigned long)word,
Ye Lie5e91092019-10-26 16:24:03 +020082 (unsigned long)val, 0, 0);
Peng Fan0fe6f162019-04-12 07:54:54 +000083}
84
85int fuse_override(u32 bank, u32 word, u32 val)
86{
87 printf("Override fuse to i.MX8 in u-boot is forbidden\n");
88 return -EPERM;
89}