Squashed backup commit (no shallow-clone history issues) of xiaomi-mt6833-dev/kernel_xiaomi_mt6833 (lineage-23.2 branch, upstream commit 9eece662e) plus all fixes applied to get everpal_defconfig building clean against a modern (GCC 15.2.0) toolchain -- see the previous commit message on the lineage-23.2 branch (also in this repo history is not available here since this is a squashed snapshot; full incremental history lives in the local DL380 checkout and the upstream GitHub remote). Upstream: https://github.com/xiaomi-mt6833-dev/kernel_xiaomi_mt6833 (lineage-23.2)
164 lines
2.8 KiB
C
164 lines
2.8 KiB
C
/*
|
|
* Copyright (C) 2017 MediaTek Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See http://www.gnu.org/licenses/gpl-2.0.html for more details.
|
|
*/
|
|
#include <linux/types.h>
|
|
#include <mt-plat/mtk_battery.h>
|
|
#include <mt-plat/mtk_boot.h>
|
|
#include <mtk_gauge_class.h>
|
|
#include <mtk_battery_internal.h>
|
|
#include <mt-plat/upmu_common.h>
|
|
#include <mach/upmu_sw.h>
|
|
|
|
#if (CONFIG_MTK_GAUGE_VERSION != 30)
|
|
signed int battery_get_bat_voltage(void)
|
|
{
|
|
return 4000;
|
|
}
|
|
|
|
signed int battery_get_bat_current(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
signed int battery_get_bat_current_mA(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
signed int battery_get_soc(void)
|
|
{
|
|
return 50;
|
|
}
|
|
|
|
signed int battery_get_uisoc(void)
|
|
{
|
|
int boot_mode = get_boot_mode();
|
|
|
|
if ((boot_mode == META_BOOT) ||
|
|
(boot_mode == ADVMETA_BOOT) ||
|
|
(boot_mode == FACTORY_BOOT) ||
|
|
(boot_mode == ATE_FACTORY_BOOT))
|
|
return 75;
|
|
|
|
return 50;
|
|
}
|
|
|
|
signed int battery_get_bat_temperature(void)
|
|
{
|
|
return 25;
|
|
}
|
|
|
|
signed int battery_get_ibus(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
signed int battery_get_vbus(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
signed int battery_get_bat_avg_current(void)
|
|
{
|
|
return 0;
|
|
}
|
|
#else
|
|
signed int battery_get_bat_voltage(void)
|
|
{
|
|
return pmic_get_battery_voltage();
|
|
}
|
|
|
|
signed int battery_get_bat_current(void)
|
|
{
|
|
int curr_val;
|
|
bool is_charging;
|
|
|
|
is_charging = gauge_get_current(&curr_val);
|
|
if (is_charging == false)
|
|
curr_val = 0 - curr_val;
|
|
return curr_val;
|
|
}
|
|
|
|
signed int battery_get_bat_current_mA(void)
|
|
{
|
|
return battery_get_bat_current() / 10;
|
|
}
|
|
|
|
signed int battery_get_soc(void)
|
|
{
|
|
struct mtk_battery *gm = get_mtk_battery();
|
|
|
|
if (gm != NULL)
|
|
return gm->soc;
|
|
else
|
|
return 50;
|
|
}
|
|
|
|
signed int battery_get_uisoc(void)
|
|
{
|
|
int boot_mode = get_boot_mode();
|
|
struct mtk_battery *gm = get_mtk_battery();
|
|
|
|
if ((boot_mode == META_BOOT) ||
|
|
(boot_mode == ADVMETA_BOOT) ||
|
|
(boot_mode == FACTORY_BOOT) ||
|
|
(boot_mode == ATE_FACTORY_BOOT))
|
|
return 75;
|
|
|
|
|
|
if (gm != NULL)
|
|
return gm->ui_soc;
|
|
else
|
|
return 50;
|
|
}
|
|
|
|
signed int battery_get_bat_temperature(void)
|
|
{
|
|
/* TODO */
|
|
if (is_battery_init_done())
|
|
return force_get_tbat(true);
|
|
else
|
|
return -127;
|
|
}
|
|
|
|
signed int battery_get_ibus(void)
|
|
{
|
|
return pmic_get_ibus();
|
|
}
|
|
|
|
signed int battery_get_vbus(void)
|
|
{
|
|
return pmic_get_vbus();
|
|
}
|
|
|
|
signed int battery_get_bat_avg_current(void)
|
|
{
|
|
bool valid;
|
|
|
|
return gauge_get_average_current(&valid);
|
|
}
|
|
|
|
/* GM25 only */
|
|
int en_intr_VBATON_UNDET(int en)
|
|
{
|
|
pmic_enable_interrupt(INT_VBATON_UNDET, en, "VBATON_UNDET");
|
|
return 0;
|
|
}
|
|
|
|
int reg_VBATON_UNDET(void (*callback)(void))
|
|
{
|
|
pmic_register_interrupt_callback(INT_VBATON_UNDET, callback);
|
|
return 0;
|
|
}
|
|
|
|
#endif
|