mt_efuse.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2017. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. *
  31. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. #include <stdlib.h>
  36. #include <debug.h>
  37. #ifndef MACH_FPGA_NO_DISPLAY
  38. #include <video.h>
  39. #endif
  40. #define EFUSE_PART_NAME "efuse"
  41. #define CHK_SIZE 20
  42. #define CHK_THRESHOLD 19
  43. #define EFUSE_NONE 0x00
  44. #define EFUSE_FINE 0xAA
  45. #define EFUSE_BROKEN 0x5A
  46. #define EFUSE_REBLOW 0x55
  47. extern int mboot_recovery_load_raw_part(char *part_name, unsigned long *addr, unsigned int size);
  48. static int mboot_efuse_load_misc(unsigned char *misc_addr, unsigned int size)
  49. {
  50. int ret;
  51. dprintf(SPEW, "[%s]: size is %u\n", __func__, size);
  52. dprintf(SPEW, "[%s]: misc_addr is 0x%p\n", __func__, misc_addr);
  53. ret = mboot_recovery_load_raw_part(EFUSE_PART_NAME, (unsigned long *) misc_addr, size);
  54. return ret;
  55. }
  56. #ifdef MTK_EFUSE_WRITER_SUPPORT
  57. unsigned int mt_efuse_get(void)
  58. {
  59. unsigned char data[CHK_SIZE] = {0};
  60. unsigned char efuse = EFUSE_NONE;
  61. char *str = "";
  62. int ret, i, cnt;
  63. ret = mboot_efuse_load_misc(data, CHK_SIZE);
  64. if (ret < 0) {
  65. dprintf(CRITICAL, "%s: read partition failed\n", __func__);
  66. goto fail;
  67. }
  68. switch (data[0]) {
  69. case EFUSE_FINE:
  70. case EFUSE_BROKEN:
  71. case EFUSE_REBLOW:
  72. efuse = data[0];
  73. break;
  74. }
  75. if (efuse != EFUSE_NONE) {
  76. for (i = cnt = 1; i < CHK_SIZE; i++) {
  77. if (data[i] == efuse)
  78. cnt++;
  79. }
  80. if (cnt >= CHK_THRESHOLD) {
  81. if (efuse == EFUSE_FINE)
  82. str = "success";
  83. else if (efuse == EFUSE_BROKEN)
  84. str = "broken";
  85. else if (efuse == EFUSE_REBLOW)
  86. str = "reblow";
  87. #ifndef MACH_FPGA_NO_DISPLAY
  88. video_printf("efuse blow: %s\n", str);
  89. #endif
  90. }
  91. }
  92. fail:
  93. return (unsigned int)efuse;
  94. }
  95. #else
  96. unsigned int mt_efuse_get(void)
  97. {
  98. return 0;
  99. }
  100. #endif