fuse.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright 2019 NXP
  4. */
  5. #include <common.h>
  6. #include <console.h>
  7. #include <errno.h>
  8. #include <fuse.h>
  9. #include <firmware/imx/sci/sci.h>
  10. #include <asm/arch/sys_proto.h>
  11. #include <asm/global_data.h>
  12. #include <linux/arm-smccc.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. #define FSL_ECC_WORD_START_1 0x10
  15. #define FSL_ECC_WORD_END_1 0x10F
  16. #ifdef CONFIG_IMX8QM
  17. #define FSL_ECC_WORD_START_2 0x1A0
  18. #define FSL_ECC_WORD_END_2 0x1FF
  19. #elif defined(CONFIG_IMX8QXP)
  20. #define FSL_ECC_WORD_START_2 0x220
  21. #define FSL_ECC_WORD_END_2 0x31F
  22. #endif
  23. #define FSL_QXP_FUSE_GAP_START 0x110
  24. #define FSL_QXP_FUSE_GAP_END 0x21F
  25. #define FSL_SIP_OTP_READ 0xc200000A
  26. #define FSL_SIP_OTP_WRITE 0xc200000B
  27. int fuse_read(u32 bank, u32 word, u32 *val)
  28. {
  29. return fuse_sense(bank, word, val);
  30. }
  31. int fuse_sense(u32 bank, u32 word, u32 *val)
  32. {
  33. struct arm_smccc_res res;
  34. if (bank != 0) {
  35. printf("Invalid bank argument, ONLY bank 0 is supported\n");
  36. return -EINVAL;
  37. }
  38. arm_smccc_smc(FSL_SIP_OTP_READ, (unsigned long)word, 0, 0,
  39. 0, 0, 0, 0, &res);
  40. *val = (u32)res.a1;
  41. return res.a0;
  42. }
  43. int fuse_prog(u32 bank, u32 word, u32 val)
  44. {
  45. struct arm_smccc_res res;
  46. if (bank != 0) {
  47. printf("Invalid bank argument, ONLY bank 0 is supported\n");
  48. return -EINVAL;
  49. }
  50. if (IS_ENABLED(CONFIG_IMX8QXP)) {
  51. if (word >= FSL_QXP_FUSE_GAP_START &&
  52. word <= FSL_QXP_FUSE_GAP_END) {
  53. printf("Invalid word argument for this SoC\n");
  54. return -EINVAL;
  55. }
  56. }
  57. if ((word >= FSL_ECC_WORD_START_1 && word <= FSL_ECC_WORD_END_1) ||
  58. (word >= FSL_ECC_WORD_START_2 && word <= FSL_ECC_WORD_END_2)) {
  59. puts("Warning: Words in this index range have ECC protection\n"
  60. "and can only be programmed once per word. Individual bit\n"
  61. "operations will be rejected after the first one.\n"
  62. "\n\n Really program this word? <y/N>\n");
  63. if (!confirm_yesno()) {
  64. puts("Word programming aborted\n");
  65. return -EPERM;
  66. }
  67. }
  68. arm_smccc_smc(FSL_SIP_OTP_WRITE, (unsigned long)word,
  69. (unsigned long)val, 0, 0, 0, 0, 0, &res);
  70. return res.a0;
  71. }
  72. int fuse_override(u32 bank, u32 word, u32 val)
  73. {
  74. printf("Override fuse to i.MX8 in u-boot is forbidden\n");
  75. return -EPERM;
  76. }