Peng Fan | 0fe6f16 | 2019-04-12 07:54:54 +0000 | [diff] [blame] | 1 | // 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 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
| 15 | #define FSL_ECC_WORD_START_1 0x10 |
| 16 | #define FSL_ECC_WORD_END_1 0x10F |
| 17 | |
Ye Li | 390f460 | 2020-05-03 22:31:46 +0800 | [diff] [blame] | 18 | #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 Fan | 0fe6f16 | 2019-04-12 07:54:54 +0000 | [diff] [blame] | 22 | #define FSL_ECC_WORD_START_2 0x220 |
| 23 | #define FSL_ECC_WORD_END_2 0x31F |
Ye Li | 390f460 | 2020-05-03 22:31:46 +0800 | [diff] [blame] | 24 | #endif |
Peng Fan | 0fe6f16 | 2019-04-12 07:54:54 +0000 | [diff] [blame] | 25 | |
| 26 | #define FSL_QXP_FUSE_GAP_START 0x110 |
| 27 | #define FSL_QXP_FUSE_GAP_END 0x21F |
Peng Fan | 0fe6f16 | 2019-04-12 07:54:54 +0000 | [diff] [blame] | 28 | |
| 29 | #define FSL_SIP_OTP_READ 0xc200000A |
| 30 | #define FSL_SIP_OTP_WRITE 0xc200000B |
| 31 | |
| 32 | int fuse_read(u32 bank, u32 word, u32 *val) |
| 33 | { |
| 34 | return fuse_sense(bank, word, val); |
| 35 | } |
| 36 | |
| 37 | int 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 | |
| 53 | int 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 Li | e5e9109 | 2019-10-26 16:24:03 +0200 | [diff] [blame] | 82 | (unsigned long)val, 0, 0); |
Peng Fan | 0fe6f16 | 2019-04-12 07:54:54 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | int 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 | } |