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 | |
| 18 | #ifdef CONFIG_IMX8QXP |
| 19 | #define FSL_ECC_WORD_START_2 0x220 |
| 20 | #define FSL_ECC_WORD_END_2 0x31F |
| 21 | |
| 22 | #define FSL_QXP_FUSE_GAP_START 0x110 |
| 23 | #define FSL_QXP_FUSE_GAP_END 0x21F |
| 24 | #endif |
| 25 | |
| 26 | #define FSL_SIP_OTP_READ 0xc200000A |
| 27 | #define FSL_SIP_OTP_WRITE 0xc200000B |
| 28 | |
| 29 | int fuse_read(u32 bank, u32 word, u32 *val) |
| 30 | { |
| 31 | return fuse_sense(bank, word, val); |
| 32 | } |
| 33 | |
| 34 | int fuse_sense(u32 bank, u32 word, u32 *val) |
| 35 | { |
| 36 | unsigned long ret = 0, value = 0; |
| 37 | |
| 38 | if (bank != 0) { |
| 39 | printf("Invalid bank argument, ONLY bank 0 is supported\n"); |
| 40 | return -EINVAL; |
| 41 | } |
| 42 | |
| 43 | ret = call_imx_sip_ret2(FSL_SIP_OTP_READ, (unsigned long)word, &value, |
| 44 | 0, 0); |
| 45 | *val = (u32)value; |
| 46 | |
| 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | int fuse_prog(u32 bank, u32 word, u32 val) |
| 51 | { |
| 52 | if (bank != 0) { |
| 53 | printf("Invalid bank argument, ONLY bank 0 is supported\n"); |
| 54 | return -EINVAL; |
| 55 | } |
| 56 | |
| 57 | if (IS_ENABLED(CONFIG_IMX8QXP)) { |
| 58 | if (word >= FSL_QXP_FUSE_GAP_START && |
| 59 | word <= FSL_QXP_FUSE_GAP_END) { |
| 60 | printf("Invalid word argument for this SoC\n"); |
| 61 | return -EINVAL; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if ((word >= FSL_ECC_WORD_START_1 && word <= FSL_ECC_WORD_END_1) || |
| 66 | (word >= FSL_ECC_WORD_START_2 && word <= FSL_ECC_WORD_END_2)) { |
| 67 | puts("Warning: Words in this index range have ECC protection\n" |
| 68 | "and can only be programmed once per word. Individual bit\n" |
| 69 | "operations will be rejected after the first one.\n" |
| 70 | "\n\n Really program this word? <y/N>\n"); |
| 71 | |
| 72 | if (!confirm_yesno()) { |
| 73 | puts("Word programming aborted\n"); |
| 74 | return -EPERM; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return call_imx_sip(FSL_SIP_OTP_WRITE, (unsigned long)word, |
| 79 | (unsigned long)val, 0); |
| 80 | } |
| 81 | |
| 82 | int fuse_override(u32 bank, u32 word, u32 val) |
| 83 | { |
| 84 | printf("Override fuse to i.MX8 in u-boot is forbidden\n"); |
| 85 | return -EPERM; |
| 86 | } |