mt_kernel_power_off_charging.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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) 2010. 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 <printf.h>
  36. #include <platform/mt_typedefs.h>
  37. #include <platform/mt_rtc.h>
  38. #include <platform/boot_mode.h>
  39. #include <platform/mtk_wdt.h>
  40. #include <platform/mt_pmic.h>
  41. #include <env.h>
  42. #define OFF_MODE_CHARGE "off-mode-charge"
  43. extern BOOL meta_mode_check(void);
  44. extern int mtk_wdt_boot_check(void);
  45. extern bool rtc_2sec_boot_check(void);
  46. void set_off_mode_charge_status(int enable_charge)
  47. {
  48. static char *env_buf = NULL;
  49. env_buf = (char *)malloc(sizeof(int));
  50. if (!env_buf) {
  51. dprintf(CRITICAL, "off-mode-charge malloc failed\n");
  52. return;
  53. }
  54. memset(env_buf,0x00,sizeof(int));
  55. sprintf(env_buf,"%d", enable_charge);
  56. set_env(OFF_MODE_CHARGE, env_buf);
  57. free(env_buf);
  58. return ;
  59. }
  60. int get_off_mode_charge_status(void)
  61. {
  62. char *charge_buf = NULL;
  63. int enable_charge = 1;
  64. charge_buf = get_env(OFF_MODE_CHARGE);
  65. if (charge_buf == NULL) {
  66. set_off_mode_charge_status(1);
  67. return 1;
  68. }
  69. enable_charge = atoi(charge_buf);
  70. return enable_charge;
  71. }
  72. BOOL is_force_boot(void)
  73. {
  74. if (rtc_boot_check(true))
  75. {
  76. dprintf(INFO, "[%s] Bypass Kernel Power off charging mode and enter Alarm Boot\n", __func__);
  77. return TRUE;
  78. }
  79. else if (meta_mode_check())
  80. {
  81. dprintf(INFO, "[%s] Bypass Kernel Power off charging mode and enter Meta Boot\n", __func__);
  82. return TRUE;
  83. }
  84. else if (pmic_detect_powerkey() || mtk_wdt_boot_check()==WDT_BY_PASS_PWK_REBOOT || rtc_2sec_boot_check())
  85. {
  86. dprintf(INFO, "[%s] Bypass Kernel Power off charging mode and enter Normal Boot\n", __func__);
  87. g_boot_mode = NORMAL_BOOT;
  88. return TRUE;
  89. }
  90. return FALSE;
  91. }
  92. BOOL kernel_power_off_charging_detection(void)
  93. {
  94. int off_mode_status = 1;
  95. /* */
  96. if(is_force_boot()) {
  97. //upmu_set_rg_chrind_on(0);
  98. dprintf(INFO, "[%s] Turn off HW Led\n", __func__);
  99. return FALSE;
  100. }
  101. off_mode_status = get_off_mode_charge_status();
  102. dprintf(INFO, "[%s] off_mode_status %d\n", __func__, off_mode_status);
  103. if(upmu_is_chr_det() == KAL_TRUE) {
  104. if (off_mode_status) {
  105. g_boot_mode = KERNEL_POWER_OFF_CHARGING_BOOT;
  106. } else {
  107. g_boot_mode = NORMAL_BOOT;
  108. //upmu_set_rg_chrind_on(0);
  109. return FALSE;
  110. }
  111. return TRUE;
  112. }
  113. else {
  114. /* power off */
  115. #ifndef NO_POWER_OFF
  116. dprintf(INFO, "[kernel_power_off_charging_detection] power off\n");
  117. mt6575_power_off();
  118. #endif
  119. return FALSE;
  120. }
  121. /* */
  122. }