/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright 2018-2022 Google LLC
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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 the
 * GNU General Public License for more details.
 */

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#ifdef CONFIG_PM_SLEEP
#define SUPPORT_PM_SLEEP 1
#endif

#include <linux/kernel.h>
#include <linux/printk.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/pm_runtime.h>
#include <linux/platform_device.h>
#include <linux/thermal.h>
#include <linux/slab.h>
#include "gbms_power_supply.h"
#include "google_bms.h"
#include "google_psy.h"
#include "qmath.h"
#include <misc/gvotable.h>
#include <crypto/hash.h>

#include <linux/debugfs.h>

#define BATT_DELAY_INIT_MS		250
#define BATT_WORK_FAST_RETRY_CNT	30
#define BATT_WORK_FAST_RETRY_MS		1000
#define BATT_WORK_DEBOUNCE_RETRY_MS	3000
#define BATT_WORK_ERROR_RETRY_MS	1000

#define DEFAULT_BATT_FAKE_CAPACITY		50
#define DEFAULT_BATT_UPDATE_INTERVAL		30000
#define DEFAULT_BATT_DRV_RL_SOC_THRESHOLD	97
#define DEFAULT_BD_TRICKLE_RL_SOC_THRESHOLD	90
#define DEFAULT_BD_TRICKLE_RESET_SEC		(5 * 60)
#define DEFAULT_HIGH_TEMP_UPDATE_THRESHOLD	550

#define DEFAULT_HEALTH_SAFETY_MARGIN	(30 * 60)

#define MSC_ERROR_UPDATE_INTERVAL		5000
#define MSC_DEFAULT_UPDATE_INTERVAL		30000


/* AACR default slope is disabled by default */
#define AACR_START_CYCLE_DEFAULT	400
#define AACR_MAX_CYCLE_DEFAULT		0 /* disabled */

/* qual time is 0 minutes of charge or 0% increase in SOC */
#define DEFAULT_CHG_STATS_MIN_QUAL_TIME		0
#define DEFAULT_CHG_STATS_MIN_DELTA_SOC		0

/* Voters */
#define MSC_LOGIC_VOTER	"msc_logic"
#define SW_JEITA_VOTER	"sw_jeita"
#define RL_STATE_VOTER	"rl_state"
#define MSC_HEALTH_VOTER "chg_health"
#define BPST_DETECT_VOTER "bpst_detect"

#define UICURVE_MAX	3

/* sync from google/logbuffer.c */
#define LOG_BUFFER_ENTRY_SIZE	256

/* Initial data of history cycle count */
#define HCC_DEFAULT_DELTA_CYCLE_CNT	10

#define BHI_HEALTH_INDEX_DEFAULT	100
#define BHI_MARGINAL_THRESHOLD_DEFAULT	80
#define BHI_NEED_REP_THRESHOLD_DEFAULT	70
#define BHI_CCBIN_INDEX_LIMIT		90
#define BHI_ALGO_FULL_HEALTH		10000
#define BHI_ALGO_ROUND_INDEX		50
#define BHI_CC_MARGINAL_THRESHOLD_DEFAULT	800
#define BHI_CC_NEED_REP_THRESHOLD_DEFAULT	1000

#define BHI_ROUND_INDEX(index) 		\
	(((index) + BHI_ALGO_ROUND_INDEX) / 100)


/* TODO: this is for Adaptive charging, rename */
enum batt_health_ui {
	/* Internal value used when health is cleared via dialog */
	CHG_DEADLINE_DIALOG = -3,
	/* Internal value used when health is settings disabled while running */
	CHG_DEADLINE_SETTING_STOP = -2,
	/* Internal value used when health is settings disabled */
	CHG_DEADLINE_SETTING = -1,
	/* Internal value used when health is cleared via alarms/re-plug */
	CHG_DEADLINE_CLEARED = 0,
};

#if (GBMS_CCBIN_BUCKET_COUNT < 1) || (GBMS_CCBIN_BUCKET_COUNT > 100)
#error "GBMS_CCBIN_BUCKET_COUNT needs to be a value from 1-100"
#endif

#define get_boot_sec() div_u64(ktime_to_ns(ktime_get_boottime()), NSEC_PER_SEC)

struct ssoc_uicurve {
	qnum_t real;
	qnum_t ui;
};

enum batt_rl_status {
	BATT_RL_STATUS_NONE = 0,
	BATT_RL_STATUS_DISCHARGE = -1,
	BATT_RL_STATUS_RECHARGE = 1,
};

#define RL_DELTA_SOC_MAX	8

struct batt_ssoc_rl_state {
	/* rate limiter state */
	qnum_t rl_ssoc_target;
	ktime_t rl_ssoc_last_update;

	/* rate limiter flags */
	bool rl_no_zero;
	int rl_fast_track;
	int rl_track_target;
	/* rate limiter config */
	int rl_delta_max_time;
	qnum_t rl_delta_max_soc;

	int rl_delta_soc_ratio[RL_DELTA_SOC_MAX];
	qnum_t rl_delta_soc_limit[RL_DELTA_SOC_MAX];
	int rl_delta_soc_cnt;

	qnum_t rl_ft_low_limit;
	qnum_t rl_ft_delta_limit;
};

#define SSOC_STATE_BUF_SZ 128
#define SSOC_DELTA 3

struct batt_ssoc_state {
	/* output of gauge data filter */
	qnum_t ssoc_gdf;
	/*  UI Curves */
	int ssoc_curve_type;    /*<0 dsg, >0 chg, 0? */
	struct ssoc_uicurve ssoc_curve[UICURVE_MAX];
	qnum_t ssoc_uic;
	/* output of rate limiter */
	qnum_t ssoc_rl;
	struct batt_ssoc_rl_state ssoc_rl_state;
	int ssoc_delta;

	/* output of rate limiter */
	int rl_rate;
	int rl_last_ssoc;
	ktime_t rl_last_update;

	/* connected or disconnected */
	ktime_t disconnect_time;
	int buck_enabled;

	/* recharge logic */
	int rl_soc_threshold;
	enum batt_rl_status rl_status;

	/* trickle defender */
	bool bd_trickle_enable;
	int bd_trickle_recharge_soc;
	int bd_trickle_cnt;
	bool bd_trickle_dry_run;
	bool bd_trickle_full;
	bool bd_trickle_eoc;
	u32 bd_trickle_reset_sec;

	/* buff */
	char ssoc_state_cstr[SSOC_STATE_BUF_SZ];

	/* Save/Restore fake capacity */
	bool save_soc_available;
	u16 save_soc;
};

struct gbatt_ccbin_data {
	u16 count[GBMS_CCBIN_BUCKET_COUNT];
	char cyc_ctr_cstr[GBMS_CCBIN_CSTR_SIZE];
	struct mutex lock;
	int prev_soc;
};

#define DEFAULT_RES_TEMP_LOW	350
#define DEFAULT_RES_TEMP_HIGH	390
#define DEFAULT_RAVG_SOC_LOW	5
#define DEFAULT_RAVG_SOC_HIGH	75
#define DEFAULT_RES_FILT_LEN	10

struct batt_res {
	bool estimate_requested;

	/* samples */
	int sample_accumulator;
	int sample_count;

	/* registers */
	int filter_count;
	int resistance_avg;

	/* configuration */
	int estimate_filter;
	int ravg_soc_low;
	int ravg_soc_high;
	int res_temp_low;
	int res_temp_high;
};

/* TODO: move single cell disconnect to bhi_data */
enum bpst_batt_status {
	BPST_BATT_UNKNOWN = 0,
	BPST_BATT_CONNECT = 1,
	BPST_BATT_DISCONNECT = 2,
	BPST_BATT_CELL_FAULT = 3,
};

struct batt_bpst {
	struct mutex lock;
	bool bpst_enable;
	bool bpst_detect_disable;
	bool bpst_cell_fault;
	/* single battery disconnect status */
	int bpst_sbd_status;
	int bpst_count_threshold;
	int bpst_chg_rate;
	u8 bpst_count;
};

#define DEV_SN_LENGTH 20
enum batt_paired_state {
	BATT_PAIRING_WRITE_ERROR = -4,
	BATT_PAIRING_READ_ERROR = -3,
	BATT_PAIRING_MISMATCH = -2,
	BATT_PAIRING_DISABLED = -1,
	BATT_PAIRING_ENABLED = 0,
	BATT_PAIRING_PAIRED = 1,
	BATT_PAIRING_RESET = 2,
};

enum batt_lfcollect_status {
	BATT_LFCOLLECT_NOT_AVAILABLE = 0,
	BATT_LFCOLLECT_ENABLED = 1,
	BATT_LFCOLLECT_COLLECT = 2,
};

enum batt_aacr_state {
	BATT_AACR_UNKNOWN = -3,
	BATT_AACR_INVALID_CAP = -2,
	BATT_AACR_UNDER_CYCLES = -1,
	BATT_AACR_DISABLED = 0,
	BATT_AACR_ENABLED = 1,
	BATT_AACR_ALGO_DEFAULT = BATT_AACR_ENABLED,
	BATT_AACR_ALGO_LOW_B, /* lower bound */
	BATT_AACR_MAX,
};

#define BATT_TEMP_RECORD_THR 3
/* discharge saved after charge */
#define SD_CHG_START 0
#define SD_DISCHG_START BATT_TEMP_RECORD_THR
#define BATT_SD_SAVE_SIZE (BATT_TEMP_RECORD_THR * 2)
#define BATT_SD_MAX_HOURS 15120 /* 90 weeks */

/* TODO: move swelling_data to bhi_data  */
struct swelling_data {
	/* Time in different temperature */
	bool is_enable;
	u32 temp_thr[BATT_TEMP_RECORD_THR];
	u32 soc_thr[BATT_TEMP_RECORD_THR];
	/*
	 * cumulative time array format:
	 * | saved  | 0                | 1                | 2                |
	 * |--------| Charge           | Charge           | Charge           |
	 * | Content| > 30degC & > 90% | > 35degC & > 90% | > 40degC & > 95% |
	 *
	 * | saved  | 3                | 4                | 5                |
	 * |--------| Discharge        | Discharge        | Discharge        |
	 * | Content| > 30degC & > 90% | > 35degC & > 90% | > 40degC & > 95% |
	 */
	u16 saved[BATT_SD_SAVE_SIZE];
	ktime_t chg[BATT_TEMP_RECORD_THR];
	ktime_t dischg[BATT_TEMP_RECORD_THR];
	ktime_t last_update;
};


struct bhi_weight bhi_w[] = {
	[BHI_ALGO_ACHI] = {100, 0, 0},
	[BHI_ALGO_ACHI_B] = {100, 0, 0},
	[BHI_ALGO_ACHI_RAVG] = {95, 5, 0},
	[BHI_ALGO_ACHI_RAVG_B] = {95, 5, 0},
	[BHI_ALGO_MIX_N_MATCH] = {90, 10, 5},
};

struct bhi_data
{
	/* context */
	int cycle_count;		/* from the FG */
	int battery_age;		/* from the FG, time in field */

	/* capacity metrics */
	int capacity_design;		/* from the FG or from charge table */
	int capacity_fade;		/* from the FG */

	/* impedance */
	u32 act_impedance;		/* resistance, qualified */
	u32 cur_impedance;		/* resistance, qualified */
	struct batt_res res_state;	/* google_resistance */

	/* swell probability */
	int swell_cumulative;		/* from swell data */
	int ccbin_index;		/* from SOC residency */

};

struct health_data
{
	/* current algorithm */
	int bhi_algo;
	int bhi_w_ci;
	int bhi_w_pi;
	int bhi_w_sd;
	/* current health index and status */
	int bhi_index;
	enum bhi_status bhi_status;
	int marginal_threshold;
	int need_rep_threshold;
	/* cycle count threshold */
	int cycle_count_marginal_threshold;
	int cycle_count_need_rep_threshold;
	/* current health metrics */
	int bhi_cap_index;
	int bhi_imp_index;
	int bhi_sd_index;
	/* debug health metrics */
	int bhi_debug_cycle_count;
	int bhi_debug_cap_index;
	int bhi_debug_imp_index;
	int bhi_debug_sd_index;
	int bhi_debug_health_index;
	/* algo BHI_ALGO_INDI capacity threshold */
	int bhi_indi_cap;

	/* current battery state */
	struct bhi_data bhi_data;

};

#define POWER_METRICS_MAX_DATA	50

struct power_metrics_data {
	unsigned long charge_count;
	unsigned long voltage;
	ktime_t time;
};

struct power_metrics {
	unsigned int polling_rate;
	unsigned int interval;
	unsigned int idx;
	struct power_metrics_data data[POWER_METRICS_MAX_DATA];
	struct delayed_work work;
};

struct csi_stats {
	int ssoc;

	int csi_speed_min;
	int csi_speed_max;

	int csi_current_status;
	int csi_current_type;

	ktime_t csi_time_sum;
	int speed_sum;

	ktime_t last_update;
};

/* battery driver state */
struct batt_drv {
	struct device *device;
	struct power_supply *psy;

	const char *fg_psy_name;
	struct power_supply *fg_psy;
	struct notifier_block fg_nb;

	struct delayed_work init_work;
	struct delayed_work batt_work;

	struct wakeup_source *msc_ws;
	struct wakeup_source *batt_ws;
	struct wakeup_source *taper_ws;
	struct wakeup_source *poll_ws;
	bool hold_taper_ws;

	/* TODO: b/111407333, will likely need to adjust SOC% on wakeup */
	bool init_complete;
	bool resume_complete;
	bool batt_present;
	u32 fake_battery_present;

	struct mutex batt_lock;
	struct mutex chg_lock;

	/* battery work */
	int fg_status;
	int batt_fast_update_cnt;
	u32 batt_update_interval;
	/* update high temperature in time */
	int batt_temp;
	u32 batt_update_high_temp_threshold;
	/* fake battery temp for thermal testing */
	int fake_temp;
	/* triger for recharge logic next update from charger */
	bool batt_full;
	struct batt_ssoc_state ssoc_state;
	/* bin count */
	struct gbatt_ccbin_data cc_data;
	/* fg cycle count */
	int cycle_count;
	/* for testing */
	int fake_aacr_cc;

	/* props */
	int soh;
	int fake_capacity;
	int batt_health;	/* health of battery, triggers defender UI */
	int report_health;	/* log health changes for debug */
	bool dead_battery;
	int capacity_level;
	bool chg_done;

	/* temp outside the charge table */
	int jeita_stop_charging;
	/* health based charging */
	struct batt_chg_health chg_health;

	/* MSC charging */
	u32 battery_capacity;	/* in mAh */
	struct gbms_chg_profile chg_profile;
	union gbms_charger_state chg_state;

	int temp_idx;
	int vbatt_idx;
	int checked_cv_cnt;
	int checked_ov_cnt;
	int checked_tier_switch_cnt;
	int last_log_cnt;

	int fv_uv;
	int cc_max;
	int topoff;
	int msc_update_interval;

	bool disable_votes;
	struct gvotable_election *msc_interval_votable;
	struct gvotable_election *fcc_votable;
	struct gvotable_election *fv_votable;
	struct gvotable_election *temp_dryrun_votable;

	/* FAN level */
	struct gvotable_election *fan_level_votable;
	int fan_last_level;

	/* stats */
	int msc_state;
	int msc_irdrop_state;
	struct mutex stats_lock;
	struct gbms_charging_event ce_data;
	struct gbms_charging_event ce_qual;
	uint32_t chg_sts_qual_time;
	uint32_t chg_sts_delta_soc;

	/* health charge margin time */
	int health_safety_margin;

	/* time to full */
	struct batt_ttf_stats ttf_stats;
	bool ttf_debounce;
	ktime_t ttf_est;

	/* logging */
	struct logbuffer *ssoc_log;

	/* thermal */
	struct thermal_zone_device *tz_dev;

	/* battery virtual sensor */
	struct thermal_zone_device *batt_vs_tz;
	int batt_vs_w;

	/* used to detect battery replacements and reset statistics */
	enum batt_paired_state pairing_state;
	char dev_sn[DEV_SN_LENGTH];

	/* collect battery history/lifetime data (history) */
	enum batt_lfcollect_status blf_state;
	u32 blf_collect_now;
	int hist_delta_cycle_cnt;
	int hist_data_max_cnt;
	int hist_data_saved_cnt;
	void *hist_data;

	/* Battery device info */
	u8 dev_info_check[GBMS_DINF_LEN];

	/* History Device */
	struct gbms_storage_device *history;

	/* Fan control */
	int fan_level;

	/* AACR: Aged Adjusted Charging Rate */
	enum batt_aacr_state aacr_state;
	int aacr_cycle_grace;
	int aacr_cycle_max;
	int aacr_algo;

	/* BHI: updated on disconnect, EOC */
	struct health_data health_data;
	struct swelling_data sd;

	/* CSI: charging speed */
	struct csi_stats csi_stats;
	struct gvotable_election *csi_status_votable;
	int csi_current_status;
	struct gvotable_election *csi_type_votable;
	int csi_current_type;
	int csi_current_speed;
	int fake_charging_speed;

	/* battery power metrics */
	struct power_metrics power_metrics;

	/* battery pack status */
	struct batt_bpst bpst_state;

	/* shutdown flag */
	int boot_to_os_attempts;

	/* battery critical level */
	int batt_critical_voltage;
};

static int gbatt_get_temp(const struct batt_drv *batt_drv, int *temp);

static int gbatt_get_capacity(struct batt_drv *batt_drv);

static inline void batt_update_cycle_count(struct batt_drv *batt_drv)
{
	batt_drv->cycle_count = GPSY_GET_PROP(batt_drv->fg_psy,
					      POWER_SUPPLY_PROP_CYCLE_COUNT);
}

static int google_battery_tz_get_cycle_count(void *data, int *cycle_count)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	if (!cycle_count) {
		pr_err("Cycle Count NULL");
		return -EINVAL;
	}

	if (batt_drv->cycle_count < 0)
		return batt_drv->cycle_count;

	*cycle_count = batt_drv->cycle_count;

	return 0;
}

static int batt_vs_tz_get(struct thermal_zone_device *tzd, int *batt_vs)
{
	struct batt_drv *batt_drv = tzd->devdata;
	int temp, rc;
	unsigned int ibat;
	unsigned long vs_tmp;

	if (!batt_vs)
		return -EINVAL;

	temp = GPSY_GET_INT_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_TEMP, &rc) * 100;
	if (rc)
		return -EINVAL;

	ibat = abs(GPSY_GET_INT_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_CURRENT_AVG, &rc));
	if (rc)
		return -EINVAL;

	vs_tmp = mul_u32_u32(ibat, ibat) * batt_drv->batt_vs_w / 1000000000000;

	*batt_vs = temp - vs_tmp;

	return 0;
}

static struct thermal_zone_device_ops batt_vs_tz_ops = {
	.get_temp = batt_vs_tz_get,
};

static int psy_changed(struct notifier_block *nb,
		       unsigned long action, void *data)
{
	struct power_supply *psy = data;
	struct batt_drv *batt_drv = container_of(nb, struct batt_drv, fg_nb);

	pr_debug("name=%s evt=%lu\n", psy->desc->name, action);

	if ((action != PSY_EVENT_PROP_CHANGED) ||
	    (psy == NULL) || (psy->desc == NULL) || (psy->desc->name == NULL))
		return NOTIFY_OK;

	if (action == PSY_EVENT_PROP_CHANGED &&
	    (!strcmp(psy->desc->name, batt_drv->fg_psy_name))) {
		mod_delayed_work(system_wq, &batt_drv->batt_work, 0);
	}

	return NOTIFY_OK;
}

/* ------------------------------------------------------------------------- */


#define BATT_PRLOG_DEBUG  0
#define BATT_PRLOG_ALWAYS 1
#define BATT_PRLOG_LAST_LOG_COUNT 10

static int debug_printk_prlog = LOGLEVEL_INFO;

static inline int batt_prlog_level(bool level)
{
	return level ? BATT_PRLOG_ALWAYS : BATT_PRLOG_DEBUG;
}

__printf(2,3)
static void batt_prlog__(int info_level, const char *format, ...)
{
	const int level = info_level == BATT_PRLOG_ALWAYS ? LOGLEVEL_INFO : LOGLEVEL_DEBUG;

	if (level <= debug_printk_prlog) {
		va_list args;

		va_start(args, format);
			vprintk(format, args);
		va_end(args);
	}

}

#define batt_prlog(l, fmt, ...) batt_prlog__(l, pr_fmt(fmt), ##__VA_ARGS__)

/* ------------------------------------------------------------------------- */

#define SSOC_TRUE 15
#define SSOC_SPOOF 95
#define SSOC_FULL 100
#define UICURVE_BUF_SZ	(UICURVE_MAX * 15 + 1)
#define SSOC_HIGH_SOC 90

enum ssoc_uic_type {
	SSOC_UIC_TYPE_DSG  = -1,
	SSOC_UIC_TYPE_NONE = 0,
	SSOC_UIC_TYPE_CHG  = 1,
};

const qnum_t ssoc_point_true = qnum_rconst(SSOC_TRUE);
const qnum_t ssoc_point_spoof = qnum_rconst(SSOC_SPOOF);
const qnum_t ssoc_point_full = qnum_rconst(SSOC_FULL);

static struct ssoc_uicurve chg_curve[UICURVE_MAX] = {
	{ ssoc_point_true, ssoc_point_true },
	{ ssoc_point_spoof, ssoc_point_spoof },
	{ ssoc_point_full, ssoc_point_full },
};

static struct ssoc_uicurve dsg_curve[UICURVE_MAX] = {
	{ ssoc_point_true, ssoc_point_true },
	{ ssoc_point_spoof, ssoc_point_full },
	{ ssoc_point_full, ssoc_point_full },
};

static char *ssoc_uicurve_cstr(char *buff, size_t size,
			       struct ssoc_uicurve *curve)
{
	int i, len = 0;

	for (i = 0; i < UICURVE_MAX ; i++) {
		len += scnprintf(&buff[len], size - len,
				"[" QNUM_CSTR_FMT " " QNUM_CSTR_FMT "]",
				qnum_toint(curve[i].real),
				qnum_fracdgt(curve[i].real),
				qnum_toint(curve[i].ui),
				qnum_fracdgt(curve[i].ui));
		if (len >= size)
			break;
	}

	buff[len] = 0;
	return buff;
}

/* NOTE: no bounds checks on this one */
static int ssoc_uicurve_find(qnum_t real, struct ssoc_uicurve *curve)
{
	int i;

	for (i = 1; i < UICURVE_MAX ; i++) {
		if (real == curve[i].real)
			return i;
		if (real > curve[i].real)
			continue;
		break;
	}

	return i-1;
}

static qnum_t ssoc_uicurve_map(qnum_t real, struct ssoc_uicurve *curve)
{
	qnum_t slope = 0, delta_ui, delta_re;
	int i;

	if (real < curve[0].real)
		return real;
	if (real >= curve[UICURVE_MAX - 1].ui)
		return curve[UICURVE_MAX - 1].ui;

	i = ssoc_uicurve_find(real, curve);
	if (curve[i].real == real)
		return curve[i].ui;

	delta_ui = curve[i + 1].ui - curve[i].ui;
	delta_re =  curve[i + 1].real - curve[i].real;
	if (delta_re)
		slope = qnum_div(delta_ui, delta_re);

	return curve[i].ui + qnum_mul(slope, (real - curve[i].real));
}

/* "optimized" to work on 3 element curves */
static void ssoc_uicurve_splice(struct ssoc_uicurve *curve, qnum_t real,
				qnum_t ui)
{
	if (real < curve[0].real || real > curve[2].real)
		return;

#if UICURVE_MAX != 3
#error ssoc_uicurve_splice() only support UICURVE_MAX == 3
#endif

	/* splice only when real is within the curve range */
	curve[1].real = real;
	curve[1].ui = ui;
}

static void ssoc_uicurve_dup(struct ssoc_uicurve *dst,
			     struct ssoc_uicurve *curve)
{
	if (dst != curve)
		memcpy(dst, curve, sizeof(*dst)*UICURVE_MAX);
}


/* ------------------------------------------------------------------------- */

/* could also use the rate of change for this */
static qnum_t ssoc_rl_max_delta(const struct batt_ssoc_rl_state *rls,
				int bucken, ktime_t delta_time)
{
	int i;
	const qnum_t max_delta = ((qnumd_t)rls->rl_delta_max_soc * delta_time) /
				  (rls->rl_delta_max_time ? rls->rl_delta_max_time : 1);

	if (rls->rl_fast_track)
		return max_delta;

	/* might have one table for charging and one for discharging */
	for (i = 0; i < rls->rl_delta_soc_cnt; i++) {
		if (rls->rl_delta_soc_limit[i] == 0)
			break;

		if (rls->rl_ssoc_target < rls->rl_delta_soc_limit[i])
			return ((qnumd_t)max_delta * 10) /
				rls->rl_delta_soc_ratio[i];
	}

	return max_delta;
}

static qnum_t ssoc_apply_rl(struct batt_ssoc_state *ssoc)
{
	const ktime_t now = get_boot_sec();
	struct batt_ssoc_rl_state *rls = &ssoc->ssoc_rl_state;
	qnum_t rl_val;

	/* track ssoc_uic when buck is enabled or the minimum value of uic */
	if (ssoc->buck_enabled ||
	    (!ssoc->buck_enabled && ssoc->ssoc_uic < rls->rl_ssoc_target))
		rls->rl_ssoc_target = ssoc->ssoc_uic;

	/* sanity on the target */
	if (rls->rl_ssoc_target > qnum_fromint(100))
		rls->rl_ssoc_target = qnum_fromint(100);
	if (rls->rl_ssoc_target < qnum_fromint(0))
		rls->rl_ssoc_target = qnum_fromint(0);

	/* closely track target */
	if (rls->rl_track_target) {
		rl_val = rls->rl_ssoc_target;
	} else {
		qnum_t step;
		const ktime_t delta_time = now - rls->rl_ssoc_last_update;
		const ktime_t max_delta = ssoc_rl_max_delta(rls,
							   ssoc->buck_enabled,
							   delta_time);

		/* apply the rate limiter, delta_soc to target */
		step = rls->rl_ssoc_target - ssoc->ssoc_rl;
		if (step < -max_delta)
			step = -max_delta;
		else if (step > max_delta)
			step = max_delta;

		rl_val = ssoc->ssoc_rl + step;
	}

	/* do not increase when not connected */
	if (!ssoc->buck_enabled && rl_val > ssoc->ssoc_rl)
		rl_val = ssoc->ssoc_rl;

	/* will report 0% when rl_no_zero clears */
	if (rls->rl_no_zero && rl_val <= qnum_fromint(1))
		rl_val = qnum_fromint(1);

	rls->rl_ssoc_last_update = now;
	return rl_val;
}

/* ------------------------------------------------------------------------- */

static int ssoc_get_real_raw(const struct batt_ssoc_state *ssoc)
{
	return ssoc->ssoc_gdf;
}

/* a statement :-) */
static qnum_t ssoc_get_capacity_raw(const struct batt_ssoc_state *ssoc)
{
	return ssoc->ssoc_rl;
}

static int ssoc_get_real(const struct batt_ssoc_state *ssoc)
{
	const qnum_t real_raw = ssoc_get_real_raw(ssoc);

	return qnum_toint(real_raw);
}

#define SOC_ROUND_BASE	0.5

/* reported to userspace: call while holding batt_lock */
static int ssoc_get_capacity(const struct batt_ssoc_state *ssoc)
{
	const qnum_t raw = ssoc_get_capacity_raw(ssoc);

	return qnum_roundint(raw, SOC_ROUND_BASE);
}

/* ------------------------------------------------------------------------- */

static void dump_ssoc_state(struct batt_ssoc_state *ssoc_state,
			    struct logbuffer *log)
{
	char buff[UICURVE_BUF_SZ] = { 0 };

	scnprintf(ssoc_state->ssoc_state_cstr,
		  sizeof(ssoc_state->ssoc_state_cstr),
		  "SSOC: l=%d%% gdf=%d.%02d uic=%d.%02d rl=%d.%02d ct=%d curve:%s rls=%d bd_cnt=%d",
		  ssoc_get_capacity(ssoc_state),
		  qnum_toint(ssoc_state->ssoc_gdf),
		  qnum_fracdgt(ssoc_state->ssoc_gdf),
		  qnum_toint(ssoc_state->ssoc_uic),
		  qnum_fracdgt(ssoc_state->ssoc_uic),
		  qnum_toint(ssoc_state->ssoc_rl),
		  qnum_fracdgt(ssoc_state->ssoc_rl),
		  ssoc_state->ssoc_curve_type,
		  ssoc_uicurve_cstr(buff, sizeof(buff), ssoc_state->ssoc_curve),
		  ssoc_state->rl_status,
		  ssoc_state->bd_trickle_cnt);

	logbuffer_log(log, "%s", ssoc_state->ssoc_state_cstr);
	pr_debug("%s\n", ssoc_state->ssoc_state_cstr);
}

/* ------------------------------------------------------------------------- */

/* call while holding batt_lock */
static void ssoc_update(struct batt_ssoc_state *ssoc, qnum_t soc)
{
	struct batt_ssoc_rl_state *rls =  &ssoc->ssoc_rl_state;
	qnum_t delta;

	/* low pass filter */
	ssoc->ssoc_gdf = soc;
	/* spoof UI @ EOC */
	ssoc->ssoc_uic = ssoc_uicurve_map(ssoc->ssoc_gdf, ssoc->ssoc_curve);

	/* first target is current UIC */
	if (rls->rl_ssoc_target == -1) {
		rls->rl_ssoc_target = ssoc->ssoc_uic;
		ssoc->ssoc_rl = ssoc->ssoc_uic;
	}

	/* enable fast track when target under configured limit */
	rls->rl_fast_track |= rls->rl_ssoc_target < rls->rl_ft_low_limit;

	/*
	 * delta fast tracking during charge
	 * NOTE: might use the stats from TTF to determine the maximum rate
	 */
	delta = rls->rl_ssoc_target - ssoc->ssoc_rl;
	if (rls->rl_ft_delta_limit && ssoc->buck_enabled && delta > 0) {
		/* only when SOC increase */
		rls->rl_fast_track |= delta > rls->rl_ft_delta_limit;
	} else if (rls->rl_ft_delta_limit && !ssoc->buck_enabled && delta < 0) {
		/* enable fast track when target under configured limit */
		rls->rl_fast_track |= -delta > rls->rl_ft_delta_limit;
	}

	/*
	 * Right now a simple test on target metric falling under 0.5%
	 * TODO: add a filter that decrements no_zero when a specific
	 * condition is met (ex rl_ssoc_target < 1%).
	 */
	if (rls->rl_no_zero)
		rls->rl_no_zero = rls->rl_ssoc_target > qnum_from_q8_8(128);

	/*  monotonicity and rate of change */
	ssoc->ssoc_rl = ssoc_apply_rl(ssoc);
}

/*
 * Maxim could need:
 *	1fh AvCap, 10h FullCap. 23h FullCapNom
 * QC could need:
 *	QG_CC_SOC, QG_Raw_SOC, QG_Bat_SOC, QG_Sys_SOC, QG_Mon_SOC
 */
static int ssoc_work(struct batt_ssoc_state *ssoc_state,
		     struct power_supply *fg_psy)
{
	int soc_q8_8;
	qnum_t soc_raw;

	/*
	 * TODO: GBMS_PROP_CAPACITY_RAW should return a qnum_t
	 * TODO: add an array here configured in DT with the properties
	 * to query and their weights, make soc_raw come from fusion.
	 */
	soc_q8_8 = GPSY_GET_PROP(fg_psy, GBMS_PROP_CAPACITY_RAW);
	if (soc_q8_8 < 0)
		return -EINVAL;

	/*
	 * soc_raw can come from fusion:
	 *    soc_raw = m1 * w1 + m2 * w2 + ...
	 *
	 * where m1, m2 are gauge metrics, w1,w1 are weights that change
	 * with temperature, state of charge, battery health etc.
	 */
	soc_raw = qnum_from_q8_8(soc_q8_8);

	ssoc_update(ssoc_state, soc_raw);
	return 0;
}

static void ssoc_change_curve_at_gdf(struct batt_ssoc_state *ssoc_state,
				     qnum_t gdf, qnum_t capacity,
				     enum ssoc_uic_type type)
{
	struct ssoc_uicurve *new_curve;

	new_curve = (type == SSOC_UIC_TYPE_DSG) ? dsg_curve : chg_curve;
	ssoc_uicurve_dup(ssoc_state->ssoc_curve, new_curve);
	ssoc_state->ssoc_curve_type = type;

	/* splice at (->ssoc_gdf,->ssoc_rl) because past spoof */
	ssoc_uicurve_splice(ssoc_state->ssoc_curve, gdf, capacity);
}

/*
 * Called on connect and disconnect to adjust the UI curve. On disconnect
 * splice at GDF less a fixed delta while UI is at 100% (i.e. in RL) to
 * avoid showing 100% for "too long" after disconnect.
 */
static void ssoc_change_curve(struct batt_ssoc_state *ssoc_state, qnum_t delta,
			      enum ssoc_uic_type type)
{
	qnum_t ssoc_level = ssoc_get_capacity(ssoc_state);
	qnum_t gdf = ssoc_state->ssoc_gdf; /* actual battery level */

	/* force dsg curve when connect/disconnect with battery at 100% */
	if (ssoc_level >= SSOC_FULL) {
		const qnum_t rlt = qnum_fromint(ssoc_state->rl_soc_threshold);

		/* bounds GDF - DELTA to prevent SSOC/GDF from diverging significantly */
		gdf = gdf > rlt ? gdf : rlt;

		type = SSOC_UIC_TYPE_DSG;
		gdf -=  delta;
	}

	/* adjust gdf to update curve[1].real in ssoc_uicurve_splice() */
	if (gdf > ssoc_point_full)
		gdf = ssoc_point_full;

	ssoc_change_curve_at_gdf(ssoc_state, gdf,
				 ssoc_get_capacity_raw(ssoc_state), type);
}

/* Fan levels limits from battery temperature */
#define FAN_BT_LIMIT_NOT_CARE	320
#define FAN_BT_LIMIT_LOW	420
#define FAN_BT_LIMIT_MED	460
#define FAN_BT_LIMIT_HIGH	480
/* Fan levels limits from charge rate */
#define FAN_CHG_LIMIT_NOT_CARE	10
#define FAN_CHG_LIMIT_LOW	50
#define FAN_CHG_LIMIT_MED	70

static int fan_bt_calculate_level(const struct batt_drv *batt_drv)
{
	int level, temp, ret;

	ret = gbatt_get_temp(batt_drv, &temp);
	if (ret < 0) {

		if (batt_drv->temp_idx < 2)
			level = FAN_LVL_NOT_CARE;
		else if (batt_drv->temp_idx == 3)
			level = FAN_LVL_MED;
		else
			level = FAN_LVL_HIGH;

		pr_warn("FAN_LEVEL: level=%d from temp_idx=%d (%d)\n",
			level, batt_drv->temp_idx, ret);
		return level;
	}

	if (temp <= FAN_BT_LIMIT_NOT_CARE)
		level = FAN_LVL_NOT_CARE;
	else if (temp <= FAN_BT_LIMIT_LOW)
		level = FAN_LVL_LOW;
	else if (temp <= FAN_BT_LIMIT_MED)
		level = FAN_LVL_LOW;
	else if (temp <= FAN_BT_LIMIT_HIGH)
		level = FAN_LVL_HIGH;
	else
		level = FAN_LVL_ALARM;

	return level;
}

static int fan_calculate_level(const struct batt_drv *batt_drv)
{
	int charging_rate, fan_level, chg_fan_level, cc_max;

	if (batt_drv->jeita_stop_charging == 1)
		return FAN_LVL_ALARM;

	/* defender limits from google_charger */
	fan_level = fan_bt_calculate_level(batt_drv);

	cc_max = gvotable_get_current_int_vote(batt_drv->fcc_votable);
	if (cc_max <= 0 || batt_drv->battery_capacity == 0)
		return fan_level;

	/* cc_max is -1 when disconnected */
	charging_rate = cc_max / batt_drv->battery_capacity / 10;
	if (charging_rate < FAN_CHG_LIMIT_NOT_CARE)
		chg_fan_level = FAN_LVL_NOT_CARE;
	else if (charging_rate <= FAN_CHG_LIMIT_LOW)
		chg_fan_level = FAN_LVL_LOW;
	else if (charging_rate <= FAN_CHG_LIMIT_MED)
		chg_fan_level = FAN_LVL_MED;
	else
		chg_fan_level = FAN_LVL_HIGH;

	/* Charge rate can increase the level */
	if (chg_fan_level > fan_level)
		fan_level = chg_fan_level;

	return fan_level;
}

static void fan_level_reset(const struct batt_drv *batt_drv)
{

	if (batt_drv->fan_level_votable)
		gvotable_cast_int_vote(batt_drv->fan_level_votable,
				       "MSC_BATT", 0, false);
}

static int fan_level_cb(struct gvotable_election *el,
			const char *reason, void *vote)
{
	struct batt_drv *batt_drv = gvotable_get_data(el);
	const int last_lvl = batt_drv->fan_last_level;
	int lvl = GVOTABLE_PTR_TO_INT(vote);

	if (!batt_drv)
		return 0;

	if (batt_drv->fan_last_level == lvl)
		return 0;

	pr_debug("FAN_LEVEL %d->%d reason=%s\n",
		batt_drv->fan_last_level, lvl, reason ? reason : "<>");

	batt_drv->fan_last_level = lvl;

	if (!chg_state_is_disconnected(&batt_drv->chg_state)) {

		logbuffer_log(batt_drv->ttf_stats.ttf_log,
			"FAN_LEVEL %d->%d reason=%s",
			last_lvl, lvl,
			reason ? reason : "<>");

		/*
		 * Send the uevent by kobject API to distinguish the uevent sent by
                 * power_supply_changed() since fan_level is not a standard power_supply_property
		 */
		kobject_uevent(&batt_drv->device->kobj, KOBJ_CHANGE);
	}

	return 0;
}
/* ------------------------------------------------------------------------- */

/*
 * enter recharge logic in BATT_RL_STATUS_DISCHARGE on charger_DONE,
 * enter BATT_RL_STATUS_RECHARGE on Fuel Gauge FULL
 * NOTE: batt_rl_update_status() doesn't call this, it flip from DISCHARGE
 * to recharge on its own.
 * NOTE: call holding chg_lock
 * FIX: BatteryDefenderUI different rules when battery defender is enabled
 * @pre rl_status != BATT_RL_STATUS_NONE
 */
static bool batt_rl_enter(struct batt_ssoc_state *ssoc_state,
			  enum batt_rl_status rl_status)
{
	const int rl_current = ssoc_state->rl_status;
	const bool enable = ssoc_state->bd_trickle_enable;
	const bool dry_run = ssoc_state->bd_trickle_dry_run;

	/*
	 * NOTE: NO_OP when RL=DISCHARGE since batt_rl_update_status() flip
	 * between BATT_RL_STATUS_DISCHARGE and BATT_RL_STATUS_RECHARGE
	 * directly.
	 */
	if (rl_current == rl_status || rl_current == BATT_RL_STATUS_DISCHARGE)
		return false;

	/*
	 * NOTE: rl_status transition from *->DISCHARGE on charger FULL (during
	 * charge or at the end of recharge) and transition from
	 * NONE->RECHARGE when battery is full (SOC==100%) before charger is.
	 */
	if (rl_status == BATT_RL_STATUS_DISCHARGE) {
		if (enable && !dry_run && ssoc_state->bd_trickle_cnt > 0) {
			ssoc_change_curve(ssoc_state, 0, SSOC_UIC_TYPE_DSG);
		} else {
			ssoc_uicurve_dup(ssoc_state->ssoc_curve, dsg_curve);
			ssoc_state->ssoc_curve_type = SSOC_UIC_TYPE_DSG;
		}
	}

	ssoc_update(ssoc_state, ssoc_state->ssoc_gdf);
	ssoc_state->rl_status = rl_status;

	return true;
}

static int ssoc_rl_read_dt(struct batt_ssoc_rl_state *rls,
			   struct device_node *node)
{
	u32 tmp, delta_soc[RL_DELTA_SOC_MAX];
	int ret, i;

	ret = of_property_read_u32(node, "google,rl_delta-max-soc", &tmp);
	if (ret == 0)
		rls->rl_delta_max_soc = qnum_fromint(tmp);

	ret = of_property_read_u32(node, "google,rl_delta-max-time", &tmp);
	if (ret == 0)
		rls->rl_delta_max_time = tmp;

	if (!rls->rl_delta_max_soc || !rls->rl_delta_max_time)
		return -EINVAL;

	rls->rl_no_zero = of_property_read_bool(node, "google,rl_no-zero");
	rls->rl_track_target = of_property_read_bool(node,
						     "google,rl_track-target");

	ret = of_property_read_u32(node, "google,rl_ft-low-limit", &tmp);
	if (ret == 0)
		rls->rl_ft_low_limit = qnum_fromint(tmp);

	ret = of_property_read_u32(node, "google,rl_ft-delta-limit", &tmp);
	if (ret == 0)
		rls->rl_ft_delta_limit = qnum_fromint(tmp);

	rls->rl_delta_soc_cnt = of_property_count_elems_of_size(node,
					      "google,rl_soc-limits",
					      sizeof(u32));
	tmp = of_property_count_elems_of_size(node, "google,rl_soc-rates",
					      sizeof(u32));
	if (rls->rl_delta_soc_cnt != tmp || tmp == 0) {
		rls->rl_delta_soc_cnt = 0;
		goto done;
	}

	if (rls->rl_delta_soc_cnt > RL_DELTA_SOC_MAX)
		return -EINVAL;

	ret = of_property_read_u32_array(node, "google,rl_soc-limits",
					 delta_soc,
					 rls->rl_delta_soc_cnt);
	if (ret < 0)
		return ret;

	for (i = 0; i < rls->rl_delta_soc_cnt; i++)
		rls->rl_delta_soc_limit[i] = qnum_fromint(delta_soc[i]);

	ret = of_property_read_u32_array(node, "google,rl_soc-rates",
					 delta_soc,
					 rls->rl_delta_soc_cnt);
	if (ret < 0)
		return ret;

	for (i = 0; i < rls->rl_delta_soc_cnt; i++)
		rls->rl_delta_soc_ratio[i] = delta_soc[i];

done:
	return 0;
}


/*
 * NOTE: might need to use SOC from bootloader as starting point to avoid UI
 * SSOC jumping around or taking long time to coverge. Could technically read
 * charger voltage and estimate SOC% based on empty and full voltage.
 */
static int ssoc_init(struct batt_ssoc_state *ssoc_state,
		     struct device_node *node,
		     struct power_supply *fg_psy)
{
	int ret, capacity;

	ret = ssoc_rl_read_dt(&ssoc_state->ssoc_rl_state, node);
	if (ret < 0)
		ssoc_state->ssoc_rl_state.rl_track_target = 1;
	ssoc_state->ssoc_rl_state.rl_ssoc_target = -1;

	/*
	 * ssoc_work() needs a curve: start with the charge curve to prevent
	 * SSOC% from increasing after a reboot. Curve type must be NONE until
	 * battery knows the charger BUCK_EN state.
	 */
	ssoc_uicurve_dup(ssoc_state->ssoc_curve, chg_curve);
	ssoc_state->ssoc_curve_type = SSOC_UIC_TYPE_NONE;

	ret = ssoc_work(ssoc_state, fg_psy);
	if (ret < 0)
		return -EIO;

	capacity = ssoc_get_capacity(ssoc_state);
	if (capacity >= SSOC_FULL) {
		/* consistent behavior when booting without adapter */
		ssoc_uicurve_dup(ssoc_state->ssoc_curve, dsg_curve);
	} else if (capacity < SSOC_TRUE) {
		/* no split */
	} else if (capacity < SSOC_SPOOF) {
		/* mark the initial point if under spoof */
		ssoc_uicurve_splice(ssoc_state->ssoc_curve,
						ssoc_state->ssoc_gdf,
						ssoc_state->ssoc_rl);

	}

	return 0;
}

/* ------------------------------------------------------------------------- */

/*
 * just reset state, no PS notifications no changes in the UI curve. This is
 * called on startup and on disconnect when the charge driver state is reset
 * NOTE: call holding chg_lock
 */
static void batt_rl_reset(struct batt_drv *batt_drv)
{
	batt_drv->ssoc_state.rl_status = BATT_RL_STATUS_NONE;
}

/*
 * RL recharge: call after SSOC work, restart charging when gdf hit the
 * recharge threshold.
 * NOTE: call holding chg_lock
 */
static void batt_rl_update_status(struct batt_drv *batt_drv)
{
	struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	const bool bd_dry_run = ssoc_state->bd_trickle_dry_run;
	const int bd_cnt = ssoc_state->bd_trickle_cnt;
	int soc, rl_soc_threshold;

	/* already in _RECHARGE or _NONE, done */
	if (ssoc_state->rl_status != BATT_RL_STATUS_DISCHARGE)
		return;
	/* no threashold (why I am here???) */
	if (!ssoc_state->rl_soc_threshold)
		return;
	/* recharge logic work on real soc */
	soc = ssoc_get_real(ssoc_state);

	if (ssoc_state->bd_trickle_enable)
		rl_soc_threshold = ((bd_cnt > 0) && !bd_dry_run) ?
			ssoc_state->bd_trickle_recharge_soc :
			ssoc_state->rl_soc_threshold;
	else
		rl_soc_threshold = ssoc_state->rl_soc_threshold;

	if (soc > rl_soc_threshold)
		return;

	/* change state (will restart charge) on trigger */
	ssoc_state->rl_status = BATT_RL_STATUS_RECHARGE;
	if (batt_drv->psy)
		power_supply_changed(batt_drv->psy);

	if (ssoc_state->bd_trickle_full && ssoc_state->bd_trickle_eoc) {
		ssoc_state->bd_trickle_cnt++;
		ssoc_state->bd_trickle_full = false;
		ssoc_state->bd_trickle_eoc = false;
	}

	dump_ssoc_state(&batt_drv->ssoc_state, batt_drv->ssoc_log);
}

/* ------------------------------------------------------------------------- */

static void bat_log_ttf_change(ktime_t estimate, int max_ratio, struct batt_drv *batt_drv)
{
	const struct gbms_charging_event *ce_data = &batt_drv->ce_data;
	char buff[LOG_BUFFER_ENTRY_SIZE];
	long elap, ibatt_avg, icl_avg;
	int i, len = 0;

	len += scnprintf(&buff[len], sizeof(buff) - len,
			 "MSC_TTF: est:%lld(%lldmin), max_ratio:%d ",
			 estimate, estimate / 60, max_ratio);

	for (i = 0; i < GBMS_STATS_TIER_COUNT; i++) {
		elap = ce_data->tier_stats[i].time_fast +
				  ce_data->tier_stats[i].time_taper +
				  ce_data->tier_stats[i].time_other;
		if (elap) {
			ibatt_avg = ce_data->tier_stats[i].ibatt_sum / elap;
			icl_avg = ce_data->tier_stats[i].icl_sum / elap;
		} else {
			ibatt_avg = 0;
			icl_avg = 0;
		}

		len += scnprintf(&buff[len], sizeof(buff) - len,
				 "[%d:%ld,%ld,%ld]", i, elap / 60, ibatt_avg, icl_avg);
	}

	pr_info("%s", buff);

	batt_drv->ttf_est = estimate;
}

/*
 * msc_logic_health() sync ce_data->ce_health to batt_drv->chg_health
 * . return -EINVAL when the device is not connected to power -ERANGE when
 *   ttf_soc_estimate() returns a negative value (invalid parameters, or
 *   corrupted internal data)
 * . the estimate is 0 when the device is at 100%.
 * . the estimate is negative during debounce, when in overheat, when
 *   custom charge levels are active.
 */
#define MIN_DELTA_FOR_LOG_S 60
static int batt_ttf_estimate(ktime_t *res, struct batt_drv *batt_drv)
{
	qnum_t raw_full = ssoc_point_full - qnum_rconst(SOC_ROUND_BASE);
	qnum_t soc_raw = ssoc_get_real_raw(&batt_drv->ssoc_state);
	ktime_t estimate = 0;
	int rc = 0, max_ratio = 0;

	if (batt_drv->ssoc_state.buck_enabled != 1)
		return -EINVAL;

	if (batt_drv->ttf_stats.ttf_fake != -1) {
		estimate = batt_drv->ttf_stats.ttf_fake;
		goto done;
	}

	/* TTF is 0 when UI shows 100% */
	if (ssoc_get_capacity(&batt_drv->ssoc_state) == SSOC_FULL) {
		estimate = 0;
		goto done;
	}

	/* no estimates during debounce or with special profiles */
	if (batt_drv->ttf_debounce ||
	    batt_drv->batt_health == POWER_SUPPLY_HEALTH_OVERHEAT ||
	    batt_drv->chg_state.f.flags & GBMS_CS_FLAG_CCLVL) {
		estimate = -1;
		goto done;
	}

	/*
	 * Handle rounding (removing it from the end)
	 * example: 96.64% with SOC_ROUND_BASE = 0.5 -> UI = 97
	 *    ttf = elap[96] * 0.36 + elap[97] + elap[98] +
	 * 	    elap[99] * (1 - 0.5)
	 *
	 * negative return value (usually) means data corruption
	 */
	rc = ttf_soc_estimate(&estimate, &batt_drv->ttf_stats,
			      &batt_drv->ce_data, soc_raw, raw_full);
	if (rc < 0)
		estimate = -1;
	else
		max_ratio = rc;

	/* Log data when changed over 1 min */
	if (abs(batt_drv->ttf_est - estimate) > MIN_DELTA_FOR_LOG_S)
		bat_log_ttf_change(estimate, max_ratio, batt_drv);

done:
	*res = estimate;
	return max_ratio;
}

/* ------------------------------------------------------------------------- */
/* CEV = Charging EVent */
static void cev_stats_init(struct gbms_charging_event *ce_data,
			   const struct gbms_chg_profile *profile)
{
	int i;

	memset(ce_data, 0, sizeof(*ce_data));

	ce_data->chg_profile = profile;
	ce_data->charging_stats.voltage_in = -1;
	ce_data->charging_stats.ssoc_in = -1;
	ce_data->charging_stats.voltage_out = -1;
	ce_data->charging_stats.ssoc_out = -1;

	ttf_soc_init(&ce_data->soc_stats);
	ce_data->last_soc = -1;

	for (i = 0; i < GBMS_STATS_TIER_COUNT ; i++)
		gbms_tier_stats_init(&ce_data->tier_stats[i], i);

	/* batt_chg_health_stats_close() will fix this */
	gbms_tier_stats_init(&ce_data->health_stats, GBMS_STATS_AC_TI_INVALID);
	gbms_tier_stats_init(&ce_data->health_pause_stats, GBMS_STATS_AC_TI_PAUSE);
	gbms_tier_stats_init(&ce_data->health_dryrun_stats, GBMS_STATS_AC_TI_V2_PREDICT);

	gbms_tier_stats_init(&ce_data->full_charge_stats, GBMS_STATS_AC_TI_FULL_CHARGE);
	gbms_tier_stats_init(&ce_data->high_soc_stats, GBMS_STATS_AC_TI_HIGH_SOC);
	gbms_tier_stats_init(&ce_data->overheat_stats, GBMS_STATS_BD_TI_OVERHEAT_TEMP);
	gbms_tier_stats_init(&ce_data->cc_lvl_stats, GBMS_STATS_BD_TI_CUSTOM_LEVELS);
	gbms_tier_stats_init(&ce_data->trickle_stats, GBMS_STATS_BD_TI_TRICKLE_CLEARED);
}

static void batt_chg_stats_start(struct batt_drv *batt_drv)
{
	union gbms_ce_adapter_details ad;
	struct gbms_charging_event *ce_data = &batt_drv->ce_data;
	const ktime_t now = get_boot_sec();
	int vin, cc_in;

	mutex_lock(&batt_drv->stats_lock);
	ad.v = batt_drv->ce_data.adapter_details.v;
	cev_stats_init(ce_data, &batt_drv->chg_profile);
	batt_drv->ce_data.adapter_details.v = ad.v;

	vin = GPSY_GET_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_VOLTAGE_NOW);
	ce_data->charging_stats.voltage_in = (vin < 0) ? -1 : vin / 1000;
	ce_data->charging_stats.ssoc_in =
				ssoc_get_capacity(&batt_drv->ssoc_state);
	cc_in = GPSY_GET_PROP(batt_drv->fg_psy,
				POWER_SUPPLY_PROP_CHARGE_COUNTER);
	ce_data->charging_stats.cc_in = (cc_in < 0) ? -1 : cc_in / 1000;

	ce_data->charging_stats.ssoc_out = -1;
	ce_data->charging_stats.voltage_out = -1;

	ce_data->first_update = now;
	ce_data->last_update = now;

	mutex_unlock(&batt_drv->stats_lock);
}

/* call holding stats_lock */
static bool batt_chg_stats_qual(const struct batt_drv *batt_drv)
{
	const struct gbms_charging_event *ce_data = &batt_drv->ce_data;
	const long elap = ce_data->last_update - ce_data->first_update;
	const long ssoc_delta = ce_data->charging_stats.ssoc_out -
				ce_data->charging_stats.ssoc_in;

	return elap >= batt_drv->chg_sts_qual_time ||
	    ssoc_delta >= batt_drv->chg_sts_delta_soc;
}

/* call holding stats_lock */
static void batt_chg_stats_soc_update(struct gbms_charging_event *ce_data,
				      qnum_t soc, ktime_t elap, int tier_index,
				      int cc)
{
	int index;
	const int last_soc = ce_data->last_soc;

	index = qnum_toint(soc);
	if (index < 0)
		index = 0;
	if (index > 100)
		index = 100;
	if (index < last_soc)
		return;

	if (ce_data->soc_stats.elap[index] == 0) {
		ce_data->soc_stats.ti[index] = tier_index;
		ce_data->soc_stats.cc[index] = cc;
	}

	if (last_soc != -1)
		ce_data->soc_stats.elap[last_soc] += elap;

	ce_data->last_soc = index;
}

/* call holding stats_lock */
static void batt_chg_stats_update(struct batt_drv *batt_drv, int temp_idx,
				  int tier_idx, int ibatt_ma, int temp,
				  ktime_t elap)
{
	const int soc_real = ssoc_get_real(&batt_drv->ssoc_state);
	const int msc_state = batt_drv->msc_state; /* last msc_state */
	struct gbms_charging_event *ce_data = &batt_drv->ce_data;
	struct gbms_ce_tier_stats *tier = NULL;
	int cc, soc_in;

	if (elap == 0)
		return;

	/* TODO: read at start of tier and update cc_total of previous */
	cc = GPSY_GET_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_CHARGE_COUNTER);
	if (cc < 0) {
		pr_debug("MSC_STAT cannot read cc=%d\n", cc);
		return;
	}
	cc = cc / 1000;

	soc_in = GPSY_GET_PROP(batt_drv->fg_psy, GBMS_PROP_CAPACITY_RAW);
	if (soc_in < 0) {
		pr_info("MSC_STAT cannot read soc_in=%d\n", soc_in);
		/* We still want to update initialized tiers. */
		soc_in = -1;
	}

	/* Note: To log new voltage tiers, add to list in go/pixel-vtier-defs */
	/* ---  Log tiers in PARALLEL below ---  */

	if (soc_real >= SSOC_HIGH_SOC)
		gbms_stats_update_tier(temp_idx, ibatt_ma, temp, elap, cc,
				       &batt_drv->chg_state, msc_state, soc_in,
				       &ce_data->high_soc_stats);

	if (batt_drv->chg_health.dry_run_deadline > 0)
		gbms_stats_update_tier(temp_idx, ibatt_ma, temp, elap, cc,
				       &batt_drv->chg_state, msc_state, soc_in,
				       &ce_data->health_dryrun_stats);

	/* --- Log tiers in SERIES below --- */
	if (batt_drv->batt_full) {

		/* Override regular charge tiers when fully charged */
		gbms_stats_update_tier(temp_idx, ibatt_ma, temp, elap, cc,
				       &batt_drv->chg_state, msc_state, soc_in,
				       &ce_data->full_charge_stats);

	} else if (msc_state == MSC_HEALTH_PAUSE) {

		/*
		 * We log the pause tier in different AC tier groups so that we
		 * can capture pause time separately.
		 */
		gbms_stats_update_tier(temp_idx, ibatt_ma, temp, elap, cc,
				       &batt_drv->chg_state, msc_state, soc_in,
				       &ce_data->health_pause_stats);

	} else if (msc_state == MSC_HEALTH || msc_state == MSC_HEALTH_ALWAYS_ON) {
		/*
		 * It works because msc_logic call BEFORE updating msc_state.
		 * NOTE: that OVERHEAT and CCLVL disable AC, I should not be
		 * here if either of them are set.
		 * NOTE: We currently only log time when AC is ACTIVE.
		 * Thus, when disconnecting in ENABLED state, we will log a
		 * GBMS_STATS_AC_TI_ENABLED tier with no time, and the regular
		 * charge time is accumulated in normal charge tiers.
		 * Similarly, once we reach 100%, we stop counting time in the
		 * health tier and we rely on the full_charge_stats.
		 */

		/* tier used for TTF during HC, check msc_logic_health() */
		gbms_stats_update_tier(temp_idx, ibatt_ma, temp, elap, cc,
				       &batt_drv->chg_state, msc_state, soc_in,
				       &ce_data->health_stats);
	} else {
		const qnum_t soc = ssoc_get_capacity_raw(&batt_drv->ssoc_state);

		/* book to previous soc unless discharging */
		if (msc_state != MSC_DSG) {
			/* TODO: should I use ssoc instead? */
			batt_chg_stats_soc_update(ce_data, soc, elap,
						  tier_idx, cc);
		}

		/*
		 * ce_data.tier_stats[tier_idx] are used for time to full.
		 * Do not book to them if we are in overheat or LVL
		 */
		tier = &ce_data->tier_stats[tier_idx];
	}

	/* --- Log tiers in PARALLEL that MUST NULL normal tiers below --- */

	/* batt_drv->batt_health is protected with chg_lock, */
	if (batt_drv->batt_health == POWER_SUPPLY_HEALTH_OVERHEAT) {
		gbms_stats_update_tier(temp_idx, ibatt_ma, temp, elap, cc,
				       &batt_drv->chg_state, msc_state, soc_in,
				       &ce_data->overheat_stats);
		tier = NULL;
	}

	/* custom charge levels (DWELL-DEFEND or RETAIL) */
	if (batt_drv->chg_state.f.flags & GBMS_CS_FLAG_CCLVL) {
		gbms_stats_update_tier(temp_idx, ibatt_ma, temp, elap, cc,
				       &batt_drv->chg_state, msc_state, soc_in,
				       &ce_data->cc_lvl_stats);
		tier = NULL;
	}

	/*
	 * Time/current spent in OVERHEAT or at CustomLevel should not
	 * be booked to ce_data.tier_stats[tier_idx]
	 */
	if (!tier)
		return;

	gbms_stats_update_tier(temp_idx, ibatt_ma, temp, elap, cc,
			       &batt_drv->chg_state, msc_state, soc_in, tier);
}

static int batt_chg_health_vti(const struct batt_chg_health *chg_health)
{
	enum chg_health_state rest_state = chg_health->rest_state;
	ktime_t rest_deadline = chg_health->rest_deadline;
	int tier_idx = GBMS_STATS_AC_TI_INVALID;
	bool aon_enabled = chg_health->always_on_soc != -1;

	switch (rest_state) {
	/* battery defender did it */
	case CHG_HEALTH_BD_DISABLED:
	case CHG_HEALTH_CCLVL_DISABLED:
		tier_idx = GBMS_STATS_AC_TI_DEFENDER;
		break;
	/* user disabled with deadline */
	case CHG_HEALTH_USER_DISABLED:
		if (rest_deadline == CHG_DEADLINE_SETTING)
			tier_idx = GBMS_STATS_AC_TI_DISABLE_SETTING;
		else if (rest_deadline == CHG_DEADLINE_SETTING_STOP)
			tier_idx = GBMS_STATS_AC_TI_DISABLE_SETTING_STOP;
		else if (rest_deadline == CHG_DEADLINE_DIALOG)
			tier_idx = GBMS_STATS_AC_TI_DISABLE_DIALOG;
		else
			tier_idx = GBMS_STATS_AC_TI_DISABLE_MISC;
		break;
	/* missed the deadline, TODO: log the deadline */
	case CHG_HEALTH_DISABLED:
		tier_idx = GBMS_STATS_AC_TI_DISABLED;
		break;
	/* disconnected in active mode, TODO: log the deadline */
	case CHG_HEALTH_ACTIVE:
	case CHG_HEALTH_PAUSE:
		if (aon_enabled)
			tier_idx = GBMS_STATS_AC_TI_ACTIVE_AON;
		else
			tier_idx = GBMS_STATS_AC_TI_ACTIVE;
		break;
	/* never became active */
	case CHG_HEALTH_ENABLED:
		if (aon_enabled)
			tier_idx = GBMS_STATS_AC_TI_ENABLED_AON;
		else
			tier_idx = GBMS_STATS_AC_TI_ENABLED;
		break;
	/* active, worked */
	case CHG_HEALTH_DONE:
		if (aon_enabled)
			tier_idx = GBMS_STATS_AC_TI_DONE_AON;
		else
			tier_idx = GBMS_STATS_AC_TI_VALID;
		break;
	default:
		break;
	}

	return tier_idx;
}

static int batt_chg_vbat2tier(const int vbatt_idx)
{
	return vbatt_idx < GBMS_STATS_TIER_COUNT ?
		vbatt_idx : GBMS_STATS_TIER_COUNT - 1;
}

static int batt_bpst_stats_update(struct batt_drv *batt_drv)
{
	struct batt_bpst *bpst_state = &batt_drv->bpst_state;

	if (!bpst_state->bpst_enable)
		return BPST_BATT_UNKNOWN;

	if (bpst_state->bpst_cell_fault)
		return BPST_BATT_CELL_FAULT;

	if (bpst_state->bpst_sbd_status)
		return BPST_BATT_DISCONNECT;

	return BPST_BATT_CONNECT;
}

/* Only the qualified copy gets the timestamp and the exit voltage. */
static bool batt_chg_stats_close(struct batt_drv *batt_drv,
				 char *reason,
				 bool force)
{
	bool publish;
	const int vout = GPSY_GET_PROP(batt_drv->fg_psy,
				POWER_SUPPLY_PROP_VOLTAGE_NOW);
	const int cc_out = GPSY_GET_PROP(batt_drv->fg_psy,
				POWER_SUPPLY_PROP_CHARGE_COUNTER);
	const ktime_t now = get_boot_sec();
	const ktime_t dry_run_deadline = batt_drv->chg_health.dry_run_deadline;

	/* book last period to the current tier
	 * NOTE: vbatt_idx != -1 -> temp_idx != -1
	 */
	if (batt_drv->vbatt_idx != -1 && batt_drv->temp_idx != -1) {
		const ktime_t elap = now - batt_drv->ce_data.last_update;
		const int tier_idx = batt_chg_vbat2tier(batt_drv->vbatt_idx);
		const int ibatt = GPSY_GET_PROP(batt_drv->fg_psy,
						POWER_SUPPLY_PROP_CURRENT_NOW);
		const int temp = GPSY_GET_PROP(batt_drv->fg_psy,
					       POWER_SUPPLY_PROP_TEMP);

		batt_chg_stats_update(batt_drv,
				      batt_drv->temp_idx, tier_idx,
				      ibatt / 1000, temp, elap);
		batt_drv->ce_data.last_update = now;
	}

	/* record the closing in data (and qual) */
	batt_drv->ce_data.charging_stats.voltage_out =
				(vout < 0) ? -1 : vout / 1000;
	batt_drv->ce_data.charging_stats.ssoc_out =
				ssoc_get_capacity(&batt_drv->ssoc_state);
	batt_drv->ce_data.charging_stats.cc_out =
				(cc_out < 0) ? -1 : cc_out / 1000;

	/* close/fix heath charge data (if enabled) */
	memcpy(&batt_drv->ce_data.ce_health, &batt_drv->chg_health,
	       sizeof(batt_drv->ce_data.ce_health));
	batt_drv->ce_data.health_stats.vtier_idx =
				batt_chg_health_vti(&batt_drv->chg_health);
	batt_drv->ce_data.health_dryrun_stats.vtier_idx =
		(now > dry_run_deadline) ? GBMS_STATS_AC_TI_V2_PREDICT_SUCCESS :
						 GBMS_STATS_AC_TI_V2_PREDICT;

	/* TODO: add a field to ce_data to qual weird charge sessions */
	publish = force || batt_chg_stats_qual(batt_drv);
	if (publish) {
		struct gbms_charging_event *ce_qual = &batt_drv->ce_qual;

		/* all charge tiers including health */
		memcpy(ce_qual, &batt_drv->ce_data, sizeof(*ce_qual));

		pr_info("MSC_STAT %s: elap=%lld ssoc=%d->%d v=%d->%d c=%d->%d hdl=%lld hrs=%d hti=%d/%d\n",
			reason,
			ce_qual->last_update - ce_qual->first_update,
			ce_qual->charging_stats.ssoc_in,
			ce_qual->charging_stats.ssoc_out,
			ce_qual->charging_stats.voltage_in,
			ce_qual->charging_stats.voltage_out,
			ce_qual->charging_stats.cc_in,
			ce_qual->charging_stats.cc_out,
			ce_qual->ce_health.rest_deadline,
			ce_qual->ce_health.rest_state,
			ce_qual->health_stats.vtier_idx,
			ce_qual->health_pause_stats.vtier_idx);
	}

	return publish;
}

static int batt_chg_stats_soc_next(const struct gbms_charging_event *ce_data,
				   int i)
{
	int soc_next;

	if (i == GBMS_STATS_TIER_COUNT -1)
		return ce_data->last_soc;

	soc_next = ce_data->tier_stats[i + 1].soc_in >> 8;
	if (soc_next <= 0)
		return ce_data->last_soc;

	return soc_next;
}

static void bat_log_chg_stats(struct logbuffer *log,
			      const struct gbms_charging_event *ce_data)
{
	const char *adapter_name =
		gbms_chg_ev_adapter_s(ce_data->adapter_details.ad_type);
	int i;

	logbuffer_log(log, "A: %s,%d,%d,%d",
			adapter_name,
			ce_data->adapter_details.ad_type,
			ce_data->adapter_details.ad_voltage * 100,
			ce_data->adapter_details.ad_amperage * 100);

	logbuffer_log(log, "S: %hu,%hu, %hu,%hu %hu,%hu %ld,%ld, %u",
			ce_data->charging_stats.ssoc_in,
			ce_data->charging_stats.voltage_in,
			ce_data->charging_stats.ssoc_out,
			ce_data->charging_stats.voltage_out,
			ce_data->charging_stats.cc_in,
			ce_data->charging_stats.cc_out,
			ce_data->first_update,
			ce_data->last_update,
			ce_data->chg_profile->capacity_ma);

	for (i = 0; i < GBMS_STATS_TIER_COUNT; i++) {
		const int soc_next = batt_chg_stats_soc_next(ce_data, i);
		const int soc_in = ce_data->tier_stats[i].soc_in >> 8;
		const long elap = ce_data->tier_stats[i].time_fast +
				  ce_data->tier_stats[i].time_taper +
				  ce_data->tier_stats[i].time_other;
		/* retrun len in below functions sometimes more than 256 */
		char buff[LOG_BUFFER_ENTRY_SIZE * 2] = {0};
		int len = 0;

		/* Do not output tiers without time */
		if (!elap)
			continue;

		len = gbms_tier_stats_cstr(buff, sizeof(buff),
						&ce_data->tier_stats[i], true);
		gbms_log_cstr_handler(log, buff, len);

		if (soc_next) {
			len = ttf_soc_cstr(buff, sizeof(buff),
					   &ce_data->soc_stats,
					   soc_in, soc_next);
			gbms_log_cstr_handler(log, buff, len);
		}
	}
}

/* End of charging: close stats, qualify event publish data */
static void batt_chg_stats_pub(struct batt_drv *batt_drv, char *reason,
			       bool force, bool skip_uevent)
{
	bool publish;

	mutex_lock(&batt_drv->stats_lock);
	publish = batt_chg_stats_close(batt_drv, reason, force);
	if (publish) {
		ttf_stats_update(&batt_drv->ttf_stats,
				 &batt_drv->ce_qual, false);

		if (skip_uevent == false)
			kobject_uevent(&batt_drv->device->kobj, KOBJ_CHANGE);
	}

	bat_log_chg_stats(batt_drv->ttf_stats.ttf_log, &batt_drv->ce_data);
	mutex_unlock(&batt_drv->stats_lock);
}

/* health_stats->tier_index is set on stats_close() */
static int batt_health_stats_cstr(char *buff, int size,
				  const struct gbms_charging_event *ce_data,
				  bool verbose)
{
	const struct gbms_ce_tier_stats *health_stats = &ce_data->health_stats;
	const int vti = batt_chg_health_vti(&ce_data->ce_health);
	int len = 0;

	len += scnprintf(&buff[len], size - len, "\nH: %d %d %lld %d\n",
			 ce_data->ce_health.rest_state, vti,
			 ce_data->ce_health.rest_deadline,
			 ce_data->ce_health.always_on_soc);

	/* no additional tier stats when vti is invalid */
	if (vti == GBMS_STATS_AC_TI_INVALID)
		return len;

	len += gbms_tier_stats_cstr(&buff[len], size - len,
				    health_stats, verbose);

	/* Only add pause tier logging if there is pause time */
	if (ce_data->health_pause_stats.soc_in != -1)
		len += gbms_tier_stats_cstr(&buff[len], size - len,
					    &ce_data->health_pause_stats,
					    verbose);

	return len;
}

/* doesn't output hc stats */
static int batt_chg_stats_cstr(char *buff, int size,
			       const struct gbms_charging_event *ce_data,
			       bool verbose)
{
	int i, len = 0;

	if (verbose) {
		const char *adapter_name =
			gbms_chg_ev_adapter_s(ce_data->adapter_details.ad_type);

		len += scnprintf(&buff[len], size - len, "A: %s,",
				adapter_name);
	}

	len += scnprintf(&buff[len], size - len, "%d,%d,%d",
				ce_data->adapter_details.ad_type,
				ce_data->adapter_details.ad_voltage * 100,
				ce_data->adapter_details.ad_amperage * 100);

	len += scnprintf(&buff[len], size - len, "%s%hu,%hu, %hu,%hu %u",
				(verbose) ?  "\nS: " : ", ",
				ce_data->charging_stats.ssoc_in,
				ce_data->charging_stats.voltage_in,
				ce_data->charging_stats.ssoc_out,
				ce_data->charging_stats.voltage_out,
				ce_data->chg_profile->capacity_ma);


	if (verbose) {
		len += scnprintf(&buff[len], size - len, " %hu,%hu",
				ce_data->charging_stats.cc_in,
				ce_data->charging_stats.cc_out);

		len += scnprintf(&buff[len], size - len, " %lld,%lld",
				ce_data->first_update,
				ce_data->last_update);
	}

	for (i = 0; i < GBMS_STATS_TIER_COUNT; i++) {
		const int soc_next = batt_chg_stats_soc_next(ce_data, i);
		const int soc_in = ce_data->tier_stats[i].soc_in >> 8;
		const long elap = ce_data->tier_stats[i].time_fast +
				  ce_data->tier_stats[i].time_taper +
				  ce_data->tier_stats[i].time_other;

		/* Do not output tiers without time */
		if (!elap)
			continue;

		len += gbms_tier_stats_cstr(&buff[len], size - len,
					    &ce_data->tier_stats[i],
					    verbose);

		if (soc_next)
			len += ttf_soc_cstr(&buff[len], size - len,
					    &ce_data->soc_stats,
					    soc_in, soc_next);
	}

	/* Does not currently check MSC_HEALTH */
	if (ce_data->health_dryrun_stats.soc_in != -1)
		len += gbms_tier_stats_cstr(&buff[len], size - len,
					    &ce_data->health_dryrun_stats,
					    verbose);

	if (ce_data->full_charge_stats.soc_in != -1)
		len += gbms_tier_stats_cstr(&buff[len], size - len,
					    &ce_data->full_charge_stats,
					    verbose);

	if (ce_data->high_soc_stats.soc_in != -1)
		len += gbms_tier_stats_cstr(&buff[len], size - len,
					    &ce_data->high_soc_stats,
					    verbose);

	if (ce_data->overheat_stats.soc_in != -1)
		len += gbms_tier_stats_cstr(&buff[len], size - len,
					    &ce_data->overheat_stats,
					    verbose);

	if (ce_data->cc_lvl_stats.soc_in != -1)
		len += gbms_tier_stats_cstr(&buff[len], size - len,
					    &ce_data->cc_lvl_stats,
					    verbose);

	/* If bd_clear triggers, we need to know about it even if trickle hasn't
	 * triggered
	 */
	if (ce_data->trickle_stats.soc_in != -1 || ce_data->bd_clear_trickle)
		len += gbms_tier_stats_cstr(&buff[len], size - len,
					    &ce_data->trickle_stats,
					    verbose);

	return len;
}

/* ------------------------------------------------------------------------- */

static int batt_ravg_value(const struct batt_res *rstate)
{
	return rstate->resistance_avg * 100;
}

static void batt_res_dump_logs(const struct batt_res *rstate)
{
	pr_info("RAVG: req:%d, sample:%d[%d], filt_cnt:%d, res_avg:%d\n",
		rstate->estimate_requested, rstate->sample_accumulator,
		rstate->sample_count, rstate->filter_count,
		rstate->resistance_avg);
}

static void batt_res_state_set(struct batt_res *rstate, bool breq)
{
	rstate->estimate_requested = breq;
	rstate->sample_accumulator = 0;
	rstate->sample_count = 0;
}

static int batt_ravg_write(int resistance_avg, int filter_count)
{
	const u16 ravg = (resistance_avg > 0xffff ) ?  0xffff : resistance_avg;
	const u16 rfcn = filter_count & 0xffff;
	int ret;

	ret = gbms_storage_write(GBMS_TAG_RAVG, &ravg, sizeof(ravg));
	if (ret < 0) {
		pr_debug("RAVG: failed to write RAVG (%d)\n", ret);
		return -EIO;
	}

	/*
	 * filter_count <= estimate_filter
	 * TODO: we might not need this...
	 * TODO: check the error path (ravg saved but filter count not saved)
	 */
	ret = gbms_storage_write(GBMS_TAG_RFCN, &rfcn, sizeof(rfcn));
	if (ret < 0) {
		pr_debug("RAVG: failed to write RFCN (%d)\n", ret);
		return -EIO;
	}

	return 0;
}

static void batt_res_update(struct batt_res *rstate)
{
	int filter_estimate = 0;
	int total_estimate = 0;
	long new_estimate = 0;

	/* accumulator is scaled */
	new_estimate = rstate->sample_accumulator / rstate->sample_count;
	filter_estimate = rstate->resistance_avg * rstate->filter_count;

	rstate->filter_count++;
	if (rstate->filter_count > rstate->estimate_filter) {
		rstate->filter_count = rstate->estimate_filter;
		filter_estimate -= rstate->resistance_avg;
	}

	total_estimate = filter_estimate + new_estimate;
	rstate->resistance_avg = total_estimate / rstate->filter_count;
}

static int batt_res_load_data(struct batt_res *rstate,
			      struct power_supply *fg_psy)
{
	u16 resistance_avg = 0, filter_count = 0;
	int ret;

	ret = gbms_storage_read(GBMS_TAG_RAVG, &resistance_avg,
				sizeof(resistance_avg));
	if (ret < 0) {
		pr_err("failed to get resistance_avg(%d)\n", ret);
		goto error_done;
	}

	ret = gbms_storage_read(GBMS_TAG_RFCN, &filter_count,
				sizeof(filter_count));
	if (ret < 0) {
		pr_err("failed to get resistance filt_count(%d)\n", ret);
		goto error_done;
	}

	/* no value in storage: start now (or start over) */
	if (resistance_avg == 0xffff || filter_count == 0xffff) {
		resistance_avg = 0;
		filter_count = 0;
	}

error_done:
	rstate->resistance_avg = resistance_avg;
	rstate->filter_count = filter_count;
	return 0;
}

/*
 * accumulate and resistance when SOC is between ravg_soc_low and ravg_soc_high
 * and temperature is in the right range. Discard the new sample if the device
 * is disconencted.
 * hold mutex_unlock(&batt_drv->chg_lock);
 */
static void batt_res_work(struct batt_drv *batt_drv)
{
	struct batt_res *rstate = &batt_drv->health_data.bhi_data.res_state;
	const int soc = ssoc_get_real(&batt_drv->ssoc_state);
	struct power_supply *fg_psy = batt_drv->fg_psy;
	int ret, temp, resistance;

	if (soc >= rstate->ravg_soc_high) {

		/* done: recalculate resistance_avg and save it */
		if (rstate->sample_count > 0) {
			batt_res_update(rstate);

			ret = batt_ravg_write(rstate->resistance_avg,
					      rstate->filter_count);
			if (ret == 0)
				batt_res_dump_logs(rstate);
		}

		/* loose the new data when it cannot save */
		batt_res_state_set(rstate, false);
		return;
	}

	/* wait for it */
	if (soc < rstate->ravg_soc_low)
		return;

	/* do not collect samples when temperature is outside the range */
	temp = GPSY_GET_INT_PROP(fg_psy, POWER_SUPPLY_PROP_TEMP, &ret);
	if (ret < 0 || temp < rstate->res_temp_low || temp > rstate->res_temp_high)
		return;

	/* resistance in mOhm, skip read errors */
	resistance = GPSY_GET_INT_PROP(fg_psy, GBMS_PROP_RESISTANCE, &ret);
	if (ret < 0)
		return;

	/* accumulate samples if temperature and SOC are within range */
	rstate->sample_accumulator += resistance / 100;
	rstate->sample_count++;
	pr_debug("RAVG: sample:%d[%d], filt_cnt:%d\n",
		 rstate->sample_accumulator, rstate->sample_count,
		 rstate->filter_count);
}

/* ------------------------------------------------------------------------- */

static void batt_log_csi_ttf_info(struct batt_drv *batt_drv)
{
	struct csi_stats *csi_stats = &batt_drv->csi_stats;
	const bool same_type_and_status =
		csi_stats->csi_current_type == batt_drv->csi_current_type &&
		csi_stats->csi_current_status == batt_drv->csi_current_status;
	int current_speed = batt_drv->csi_current_speed < 0 ? 0 :
			    batt_drv->csi_current_speed;
	const ktime_t right_now = get_boot_sec();
	int ssoc = -1;

	if (!batt_drv->init_complete)
		return;

	if (chg_state_is_disconnected(&batt_drv->chg_state))
		goto log_and_done;

	ssoc = ssoc_get_capacity(&batt_drv->ssoc_state);
	if (ssoc == csi_stats->ssoc && same_type_and_status) {
		const ktime_t elap = right_now - csi_stats->last_update;

		csi_stats->last_update = right_now;

		/* accumulate only positive*/
		if (batt_drv->csi_current_speed < 0)
			return;

		if (current_speed < csi_stats->csi_speed_min)
			csi_stats->csi_speed_min = current_speed;
		else if (current_speed > csi_stats->csi_speed_max)
			csi_stats->csi_speed_max = current_speed;

		csi_stats->speed_sum += current_speed * elap;
		csi_stats->csi_time_sum += elap;
		return;
	}

log_and_done:
	csi_stats->csi_current_status = batt_drv->csi_current_status;
	csi_stats->csi_current_type = batt_drv->csi_current_type;

	if (csi_stats->ssoc != -1) {
		const int csi_speed_avg = csi_stats->csi_time_sum == 0 ?
					  csi_stats->speed_sum :
					  (csi_stats->speed_sum / csi_stats->csi_time_sum);
		const int cc = GPSY_GET_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_CHARGE_COUNTER);
		ktime_t res = 0;
		const int max_ratio = batt_ttf_estimate(&res, batt_drv);

		if (max_ratio < 0)
			res = 0;

		gbms_logbuffer_prlog(batt_drv->ttf_stats.ttf_log, LOGLEVEL_INFO, 0, LOGLEVEL_DEBUG,
				     "ssoc=%d temp=%d CSI[min=%d max=%d avg=%d type=%d status=%d TTF[cc=%d time=%lld %lld:%lld:%lld (est=%lld max_ratio=%d)]",
				     csi_stats->ssoc, batt_drv->batt_temp, csi_stats->csi_speed_min,
				     csi_stats->csi_speed_max, csi_speed_avg,
				     csi_stats->csi_current_type, csi_stats->csi_current_status,
				     cc / 1000, right_now, res / 3600, (res % 3600) / 60,
				     (res % 3600) % 60, res, max_ratio);

	}

	/* ssoc == -1 on disconnect */
	if (ssoc == -1)
		current_speed = 0;

	csi_stats->ssoc = ssoc;
	csi_stats->csi_speed_min = current_speed;
	csi_stats->csi_speed_max = current_speed;

	csi_stats->csi_time_sum = 0;
	csi_stats->speed_sum = 0;
	csi_stats->last_update = right_now;
}

static int csi_status_cb(struct gvotable_election *el, const char *reason,
			 void *value)
{
	struct batt_drv *batt_drv = gvotable_get_data(el);
	int status = GVOTABLE_PTR_TO_INT(value);

	if (!batt_drv || batt_drv->csi_current_status == status)
		return 0;

	batt_drv->csi_current_status = status;
	batt_log_csi_ttf_info(batt_drv);

	if (batt_drv->psy)
		power_supply_changed(batt_drv->psy);

	return 0;
}

static int csi_type_cb(struct gvotable_election *el, const char *reason,
		       void *value)
{
	struct batt_drv *batt_drv = gvotable_get_data(el);
	int type = GVOTABLE_PTR_TO_INT(value);

	if (!batt_drv || batt_drv->csi_current_type == type)
		return 0;

	batt_drv->csi_current_type = type;
	batt_log_csi_ttf_info(batt_drv);

	if (batt_drv->psy)
		power_supply_changed(batt_drv->psy);

	return 0;
}

/* all reset on disconnect */
static void batt_update_csi_type(struct batt_drv *batt_drv)
{
	const bool is_disconnected = chg_state_is_disconnected(&batt_drv->chg_state);
	const bool is_trickle = batt_drv->ssoc_state.bd_trickle_cnt > 0;
	const bool is_ac = batt_drv->msc_state == MSC_HEALTH ||
			batt_drv->msc_state == MSC_HEALTH_PAUSE ||
			batt_drv->msc_state == MSC_HEALTH_ALWAYS_ON;

	if (!batt_drv->csi_type_votable) {
		batt_drv->csi_type_votable =
			gvotable_election_get_handle(VOTABLE_CSI_TYPE);
		if (!batt_drv->csi_type_votable)
			return;
	}

	/* normal or full if connected, nothing otherwise */
	gvotable_cast_long_vote(batt_drv->csi_type_votable, "CSI_TYPE_CONNECTED",
				is_disconnected ? CSI_TYPE_None : CSI_TYPE_Normal,
				true);

	/* SW JEITA */
	gvotable_cast_long_vote(batt_drv->csi_type_votable, "CSI_TYPE_JEITA",
				CSI_TYPE_JEITA,
				!is_disconnected && batt_drv->jeita_stop_charging == 1);

	/* Longlife is set on TEMP, DWELL and TRICKLE */
	gvotable_cast_long_vote(batt_drv->csi_type_votable, "CSI_TYPE_TRICKLE",
				CSI_TYPE_LongLife,
				!is_disconnected && is_trickle);

	/* Adaptive charging, individually */
	gvotable_cast_long_vote(batt_drv->csi_type_votable, "CSI_TYPE_AC",
				CSI_TYPE_Adaptive,
				!is_disconnected && is_ac);

	/* CSI_TYPE_Fault is permanent TODO: check single cell disconnect */
	gvotable_cast_long_vote(batt_drv->csi_type_votable, "CSI_TYPE_SINGLE_CELL",
				CSI_TYPE_Fault, false);
}

static bool batt_csi_check_ad_qual(const struct batt_drv *chg_drv)
{
	return false; /* TODO */
}

/*
 * these are absolute values: an underpowered adapter is a problem when
 * charging speed falls under 80%.
 */
static bool batt_csi_check_ad_power(const union gbms_ce_adapter_details *ad)
{
	const unsigned int ad_mw = (ad->ad_voltage * ad->ad_amperage) * 10000;
	unsigned int limit_mw = 9000 * 2000;	/* 18 Watts: it changes with the device */

	switch (ad->ad_type) {
		case CHG_EV_ADAPTER_TYPE_USB:
		case CHG_EV_ADAPTER_TYPE_USB_SDP:
		case CHG_EV_ADAPTER_TYPE_USB_CDP:
		case CHG_EV_ADAPTER_TYPE_USB_ACA:
		case CHG_EV_ADAPTER_TYPE_USB_C:
		case CHG_EV_ADAPTER_TYPE_USB_PD:
		case CHG_EV_ADAPTER_TYPE_USB_PD_DRP:
		case CHG_EV_ADAPTER_TYPE_USB_PD_PPS:
		case CHG_EV_ADAPTER_TYPE_USB_BRICKID:
		case CHG_EV_ADAPTER_TYPE_USB_HVDCP:
		case CHG_EV_ADAPTER_TYPE_USB_HVDCP3:
			break;
		case CHG_EV_ADAPTER_TYPE_WLC:
		case CHG_EV_ADAPTER_TYPE_WLC_EPP:
		case CHG_EV_ADAPTER_TYPE_WLC_SPP:
			limit_mw = 7500000;
			break;
		case CHG_EV_ADAPTER_TYPE_EXT:
		case CHG_EV_ADAPTER_TYPE_EXT1:
		case CHG_EV_ADAPTER_TYPE_EXT2:
		case CHG_EV_ADAPTER_TYPE_EXT_UNKNOWN:
			limit_mw = 10500 * 1250;
			break;
		default:
			break;
	}

	return ad_mw < limit_mw;
}

/*
 * COLD and HOT are only at the limits, we might want to flag anything that is
 * not the reference tier instead.
 */
static void batt_update_csi_status(struct batt_drv *batt_drv)
{
	const struct gbms_chg_profile *profile = &batt_drv->chg_profile;
	const int temp_hot_idx = profile->temp_nb_limits - 1;
	const bool is_cold = batt_drv->batt_temp < profile->temp_limits[0];
	const bool is_hot = batt_drv->batt_temp >= profile->temp_limits[temp_hot_idx];
	const bool is_trickle = batt_drv->ssoc_state.bd_trickle_cnt > 0;
	const bool is_disconnected = chg_state_is_disconnected(&batt_drv->chg_state);
	const union gbms_ce_adapter_details *ad = &batt_drv->ce_data.adapter_details;

	if (!batt_drv->csi_status_votable) {
		batt_drv->csi_status_votable =
			gvotable_election_get_handle(VOTABLE_CSI_STATUS);
		if (!batt_drv->csi_status_votable)
			return;
	}

	/*
	 * discharging when the battery current is negative. There will likely
	 * be a more specific reason (e.g System_* or Adapter_* or one of
	 * Defender_*).
	 */

	/* Charging Status Health_Cold */
	gvotable_cast_long_vote(batt_drv->csi_status_votable, "CSI_STATUS_COLD",
				CSI_STATUS_Health_Cold,
				!is_disconnected && is_cold);

	/* Charging Status Health_Hot */
	gvotable_cast_long_vote(batt_drv->csi_status_votable, "CSI_STATUS_HOT",
				CSI_STATUS_Health_Hot,
				!is_disconnected && is_hot);

	/* looks at absolute power, it could look also look at golden adapter */
	gvotable_cast_long_vote(batt_drv->csi_status_votable, "CSI_STATUS_ADA_POWR",
				CSI_STATUS_Adapter_Power,
				!is_disconnected && !batt_drv->chg_done &&
				batt_csi_check_ad_power(ad));

	/* Adapter quality looks at input voltage and current */
	gvotable_cast_long_vote(batt_drv->csi_status_votable, "CSI_STATUS_ADA_QUAL",
				CSI_STATUS_Adapter_Quality,
				!is_disconnected && batt_csi_check_ad_qual(batt_drv));

	/* Charging Status Defender_Trickle */
	gvotable_cast_long_vote(batt_drv->csi_status_votable, "CSI_STATUS_DEFEND_TRICKLE",
				CSI_STATUS_Defender_Trickle,
				!is_disconnected && is_trickle);

	gvotable_cast_long_vote(batt_drv->csi_status_votable, "CSI_STATUS_DSG",
				CSI_STATUS_NotCharging,
				!is_disconnected && batt_drv->msc_state == MSC_DSG);

	gvotable_cast_long_vote(batt_drv->csi_status_votable, "CSI_STATUS_100",
				CSI_STATUS_Charging,
				!is_disconnected && batt_drv->chg_done);

	gvotable_cast_long_vote(batt_drv->csi_status_votable, "CSI_STATUS_CHG",
					CSI_STATUS_Charging, !is_disconnected);
}

#define CSI_CHG_SPEED_MAX 100
#define CSI_CHG_SPEED_MIN 0

/*
 * slowing down due to batt_drv->temp_idx != from reference is reported
 * in status as CSI_STATUS_COLD or CSI_STATUS_HOT.
 *
 *	cc_max = GBMS_CCCM_LIMITS(profile, batt_drv->temp_idx, batt_drv->vbatt_idx);
 *	if (cc_max && cc_max < nominal_demand)
 *		nominal_demand = cc_max;
 */
static int batt_calc_charging_speed(struct batt_drv *batt_drv)
{
	const struct gbms_chg_profile *profile = &batt_drv->chg_profile;
	const int soc = ssoc_get_capacity(&batt_drv->ssoc_state);
	const int chg_type = batt_drv->chg_state.f.chg_type;
	int cc_max, vbatt_idx, ibatt, nominal_demand;
	int chg_speed = -1;

	if (chg_state_is_disconnected(&batt_drv->chg_state))
		return -1;

	if (batt_drv->fake_charging_speed)
		return batt_drv->fake_charging_speed;

	/* if the battery is the limit, speed is 100% */
	if (chg_type == POWER_SUPPLY_CHARGE_TYPE_TAPER)
		return 100;

	/* Get average current via tiers. */
	vbatt_idx = ttf_pwr_vtier_idx(&batt_drv->ttf_stats, soc);

	/* Wait 1 min to get avg_ibat */
	ibatt = ttf_pwr_ibatt(&batt_drv->ce_data.tier_stats[vbatt_idx]);
	if (ibatt == 0)
		return -1;

	/* Get nominal demand current via ttf table */
	nominal_demand = ttf_ref_cc(&batt_drv->ttf_stats, soc);
	if (nominal_demand < 0)
		return -1;

	/*
	 * Adjust demand to battery temperature when batt_drv->temp_idx is
	 * different from the reference. Here status will either be *_COLD
	 * or *_HOT.
	 */
	cc_max = GBMS_CCCM_LIMITS(profile, batt_drv->temp_idx, batt_drv->vbatt_idx);
	if (cc_max && cc_max < nominal_demand)
		nominal_demand = cc_max;

	chg_speed = ibatt * 100 / nominal_demand;

	/* bound in [0,100] */
	if (chg_speed > CSI_CHG_SPEED_MAX)
		chg_speed = CSI_CHG_SPEED_MAX;
	else if (chg_speed < CSI_CHG_SPEED_MIN)
		chg_speed = CSI_CHG_SPEED_MIN;

	return chg_speed;
}

static void batt_update_csi_info(struct batt_drv *batt_drv)
{
	int charging_speed;

	batt_update_csi_type(batt_drv);
	batt_update_csi_status(batt_drv);

	charging_speed = batt_calc_charging_speed(batt_drv);
	if (batt_drv->csi_current_speed != charging_speed) {
		batt_drv->csi_current_speed = charging_speed;
		batt_log_csi_ttf_info(batt_drv);
	}
}

/* ------------------------------------------------------------------------- */

/* NOTE: should not reset always_on_soc */
static inline void batt_reset_rest_state(struct batt_chg_health *chg_health)
{
	chg_health->rest_cc_max = -1;
	chg_health->rest_fv_uv = -1;

	/* Keep negative deadlines (they mean user has disabled via settings)
	 * NOTE: CHG_DEADLINE_DIALOG needs to be applied only for the current
	 * session. Therefore, it should be cleared on disconnect.
	 */
	if (chg_health->rest_deadline < 0 &&
	    chg_health->rest_deadline != CHG_DEADLINE_DIALOG) {
		chg_health->rest_state = CHG_HEALTH_USER_DISABLED;
	} else {
		chg_health->rest_state = CHG_HEALTH_INACTIVE;
		chg_health->rest_deadline = 0;
	}

	chg_health->dry_run_deadline = 0;
	chg_health->active_time = 0;
}

/* should not reset rl state */
static inline void batt_reset_chg_drv_state(struct batt_drv *batt_drv)
{
	/* the wake assertion will be released on disconnect and on SW JEITA */
	if (batt_drv->hold_taper_ws) {
		batt_drv->hold_taper_ws = false;
		__pm_relax(batt_drv->taper_ws);
	}

	/* polling */
	batt_drv->batt_fast_update_cnt = 0;
	batt_drv->ttf_debounce = 1;
	batt_drv->fg_status = POWER_SUPPLY_STATUS_UNKNOWN;
	batt_drv->chg_done = false;
	batt_drv->ssoc_state.bd_trickle_full = false;
	batt_drv->ssoc_state.bd_trickle_eoc = false;
	/* algo */
	batt_drv->temp_idx = -1;
	batt_drv->vbatt_idx = -1;
	batt_drv->fv_uv = -1;
	batt_drv->cc_max = -1;
	batt_drv->msc_update_interval = -1;
	batt_drv->jeita_stop_charging = -1;
	/* timers */
	batt_drv->checked_cv_cnt = 0;
	batt_drv->checked_ov_cnt = 0;
	batt_drv->checked_tier_switch_cnt = 0;
	/* stats and logs */
	batt_drv->msc_state = -1;
	batt_drv->last_log_cnt = 0;
	/* health */
	batt_reset_rest_state(&batt_drv->chg_health);
	/* fan level */
	fan_level_reset(batt_drv);
}

/*
 * software JEITA, disable charging when outside the charge table.
 * NOTE: ->jeita_stop_charging is either -1 (init or reset), 1 (disable) or 0
 * TODO: need to be able to disable (leave to HW)
 */
static bool msc_logic_soft_jeita(struct batt_drv *batt_drv, int temp)
{
	const struct gbms_chg_profile *profile = &batt_drv->chg_profile;

	if (temp < profile->temp_limits[0] ||
	    temp >= profile->temp_limits[profile->temp_nb_limits - 1]) {
		if (batt_drv->jeita_stop_charging < 0) {
			batt_drv->jeita_stop_charging = 1;
			batt_prlog(BATT_PRLOG_ALWAYS,
				   "MSC_JEITA temp=%d off limits, do not enable charging\n",
				   temp);
		} else if (batt_drv->jeita_stop_charging == 0) {
			batt_prlog(BATT_PRLOG_ALWAYS,
				   "MSC_JEITA temp=%d off limits, disabling charging\n",
				    temp);
		}

		return true;
	}

	return false;
}

/* TODO: only change batt_drv->checked_ov_cnt, an */
static int msc_logic_irdrop(struct batt_drv *batt_drv,
			    int vbatt, int ibatt, int temp_idx,
			    int *vbatt_idx, int *fv_uv,
			    int *update_interval)
{
	const struct gbms_chg_profile *profile = &batt_drv->chg_profile;
	const int vtier = profile->volt_limits[*vbatt_idx];
	const int chg_type = batt_drv->chg_state.f.chg_type;
	const int utv_margin = profile->cv_range_accuracy;
	const int otv_margin = profile->cv_otv_margin;
	const int switch_cnt = profile->cv_tier_switch_cnt;
	int vchg = batt_drv->chg_state.f.vchrg;
	int msc_state = MSC_NONE;
	bool match_enable;

	if (batt_drv->chg_state.f.flags & GBMS_CS_FLAG_NOCOMP)
		vchg = 0;
	match_enable = vchg != 0;

	if ((vbatt - vtier) > otv_margin) {
		/* OVER: vbatt over vtier for more than margin */
		const int cc_max = GBMS_CCCM_LIMITS(profile, temp_idx,
						    *vbatt_idx);

		/*
		 * pullback when over tier voltage, fast poll, penalty
		 * on TAPER_RAISE and no cv debounce (so will consider
		 * switching voltage tiers if the current is right).
		 * NOTE: lowering voltage might cause a small drop in
		 * current (we should remain  under next tier)
		 */
		*fv_uv = gbms_msc_round_fv_uv(profile, vtier,
			*fv_uv - profile->fv_uv_resolution);
		if (*fv_uv < vtier)
			*fv_uv = vtier;

		*update_interval = profile->cv_update_interval;
		batt_drv->checked_ov_cnt = profile->cv_tier_ov_cnt;
		batt_drv->checked_cv_cnt = 0;

		if (batt_drv->checked_tier_switch_cnt > 0 || !match_enable) {
			/* no pullback, next tier if already counting */
			msc_state = MSC_VSWITCH;
			*vbatt_idx = batt_drv->vbatt_idx + 1;

			batt_prlog(BATT_PRLOG_ALWAYS,
				   "MSC_VSWITCH vt=%d vb=%d ibatt=%d me=%d\n",
				   vtier, vbatt, ibatt, match_enable);
		} else if (-ibatt == cc_max) {
			/* pullback, double penalty if at full current */
			msc_state = MSC_VOVER;
			batt_drv->checked_ov_cnt *= 2;

			batt_prlog(BATT_PRLOG_ALWAYS,
				   "MSC_VOVER vt=%d  vb=%d ibatt=%d fv_uv=%d->%d\n",
				   vtier, vbatt, ibatt,
				   batt_drv->fv_uv, *fv_uv);
		} else {
			/* simple pullback */
			msc_state = MSC_PULLBACK;
			batt_prlog(BATT_PRLOG_ALWAYS,
				  "MSC_PULLBACK vt=%d vb=%d ibatt=%d fv_uv=%d->%d\n",
				  vtier, vbatt, ibatt,
				  batt_drv->fv_uv, *fv_uv);
		}

		/*
		 * might get here after windup because algo will track the
		 * voltage drop caused from load as IRDROP.
		 * TODO: make sure that being current limited clear
		 * the taper condition.
		 */

	} else if (chg_type == POWER_SUPPLY_CHARGE_TYPE_FAST) {
		/*
		 * FAST: usual compensation (vchrg is vqcom)
		 * NOTE: there is a race in reading from charger and
		 * data might not be consistent (b/110318684)
		 * NOTE: could add PID loop for management of thermals
		 */
		const int vchrg_ua = vchg * 1000;

		msc_state = MSC_FAST;

		/* invalid or 0 vchg disable IDROP compensation */
		if (vchrg_ua <= 0) {
			/* could keep it steady instead */
			*fv_uv = vtier;
		} else if (vchrg_ua > vbatt) {
			*fv_uv = gbms_msc_round_fv_uv(profile, vtier,
				vtier + (vchrg_ua - vbatt));
		}

		/* no tier switch in fast charge (TODO unless close to tier) */
		if (batt_drv->checked_cv_cnt == 0)
			batt_drv->checked_cv_cnt = 1;

		batt_prlog(BATT_PRLOG_ALWAYS,
			   "MSC_FAST vt=%d vb=%d ib=%d fv_uv=%d->%d vchrg=%d cv_cnt=%d\n",
			   vtier, vbatt, ibatt, batt_drv->fv_uv, *fv_uv,
			   batt_drv->chg_state.f.vchrg,
			   batt_drv->checked_cv_cnt);

	} else if (chg_type == POWER_SUPPLY_CHARGE_TYPE_TRICKLE) {
		/*
		 * Precharge: charging current/voltage are limited in
		 * hardware, no point in applying irdrop compensation.
		 * Just wait for battery voltage to raise over the
		 * precharge to fast charge threshold.
		 */
		msc_state = MSC_TYPE;

		/* no tier switching in trickle */
		if (batt_drv->checked_cv_cnt == 0)
			batt_drv->checked_cv_cnt = 1;

		batt_prlog(BATT_PRLOG_ALWAYS, "MSC_PRE vt=%d vb=%d fv_uv=%d chg_type=%d\n",
			   vtier, vbatt, *fv_uv, chg_type);
	} else if (chg_type != POWER_SUPPLY_CHARGE_TYPE_TAPER) {
		const int type_margin = utv_margin;

		/*
		 * Not fast, taper or precharge: in *_UNKNOWN and *_NONE.
		 * Set checked_cv_cnt=0 when voltage is withing utv_margin of
		 * vtier (tune marging) to force checking current and avoid
		 * early termination for lack of headroom. Carry on at the
		 * same update_interval otherwise.
		 */
		msc_state = MSC_TYPE;
		if (vbatt > (vtier - type_margin)) {
			*update_interval = profile->cv_update_interval;
			batt_drv->checked_cv_cnt = 0;
		} else {
			batt_drv->checked_cv_cnt = 1;
		}

		batt_prlog(BATT_PRLOG_ALWAYS,
			   "MSC_TYPE vt=%d margin=%d cv_cnt=%d vb=%d fv_uv=%d chg_type=%d\n",
			   vtier, type_margin, batt_drv->checked_cv_cnt, vbatt,
			   *fv_uv, chg_type);

	} else if (batt_drv->checked_ov_cnt) {
		/*
		 * TAPER_DLY: countdown to raise fv_uv and/or check
		 * for tier switch, will keep steady...
		 */
		batt_prlog(BATT_PRLOG_ALWAYS,
			   "MSC_DLY vt=%d vb=%d fv_uv=%d margin=%d cv_cnt=%d, ov_cnt=%d\n",
			   vtier, vbatt, *fv_uv, profile->cv_range_accuracy,
			   batt_drv->checked_cv_cnt,
			   batt_drv->checked_ov_cnt);

		msc_state = MSC_DLY;
		batt_drv->checked_ov_cnt -= 1;
		*update_interval = profile->cv_update_interval;

	} else if ((vtier - vbatt) < utv_margin) {
		const bool log_level = batt_drv->msc_state != MSC_STEADY &&
				      batt_drv->msc_state != MSC_RSTC;

		/* TAPER_STEADY: close enough to tier */

		msc_state = MSC_STEADY;
		*update_interval = profile->cv_update_interval;

		batt_prlog(batt_prlog_level(log_level),
			   "MSC_STEADY vt=%d vb=%d fv_uv=%d margin=%d\n",
			   vtier, vbatt, *fv_uv,
			   profile->cv_range_accuracy);
	} else if (batt_drv->checked_tier_switch_cnt >= (switch_cnt - 1)) {
		/*
		 * TAPER_TIERCNTING: prepare to switch to next tier
		 * so not allow to raise vfloat to prevent battery
		 * voltage over than tier
		 */
		msc_state = MSC_TIERCNTING;
		*update_interval = profile->cv_update_interval;

		batt_prlog(BATT_PRLOG_ALWAYS,
			   "MSC_TIERCNTING vt=%d vb=%d fv_uv=%d margin=%d\n",
			   vtier, vbatt, *fv_uv,
			   profile->cv_range_accuracy);
	} else if (match_enable) {
		/*
		 * TAPER_RAISE: under tier vlim, raise one click &
		 * debounce taper (see above handling of STEADY)
		 */
		msc_state = MSC_RAISE;
		*fv_uv = gbms_msc_round_fv_uv(profile, vtier,
			*fv_uv + profile->fv_uv_resolution);
		*update_interval = profile->cv_update_interval;

		/* debounce next taper voltage adjustment */
		batt_drv->checked_cv_cnt = profile->cv_debounce_cnt;

		batt_prlog(BATT_PRLOG_ALWAYS, "MSC_RAISE vt=%d vb=%d fv_uv=%d->%d\n",
			   vtier, vbatt, batt_drv->fv_uv, *fv_uv);
	} else {
		msc_state = MSC_STEADY;
		batt_prlog(BATT_PRLOG_DEBUG, "MSC_DISB vt=%d vb=%d fv_uv=%d->%d\n",
			vtier, vbatt, batt_drv->fv_uv, *fv_uv);
	}

	return msc_state;
}

/* battery health based charging on SOC */
static enum chg_health_state msc_health_active(const struct batt_drv *batt_drv)
{
	int ssoc, ssoc_threshold = -1;

	ssoc_threshold = CHG_HEALTH_REST_SOC(&batt_drv->chg_health);
	if (ssoc_threshold < 0)
		return CHG_HEALTH_INACTIVE;

	ssoc = ssoc_get_capacity(&batt_drv->ssoc_state);
	if (ssoc >= ssoc_threshold)
		return CHG_HEALTH_ACTIVE;

	return CHG_HEALTH_ENABLED;
}

#define HEALTH_PAUSE_DEBOUNCE 180
#define HEALTH_PAUSE_MAX_SSOC 95
#define HEALTH_PAUSE_TIME 3
static bool msc_health_pause(struct batt_drv *batt_drv, const ktime_t ttf,
			      const ktime_t now,
			      const enum chg_health_state rest_state) {
	const struct gbms_charging_event *ce_data = &batt_drv->ce_data;
	const struct gbms_ce_tier_stats	*h = &ce_data->health_stats;
	struct batt_chg_health *rest = &batt_drv->chg_health;
	const ktime_t deadline = rest->rest_deadline;
	const ktime_t safety_margin = (ktime_t)batt_drv->health_safety_margin;
	/* Note: We only capture ACTIVE time in health stats */
	const ktime_t elap_h = h->time_fast + h->time_taper + h->time_other;
	const int ssoc = ssoc_get_capacity(&batt_drv->ssoc_state);

	/*
	 * the safety marging cannot be less than 0 (it would subtract time from TTF and would
         * cause AC to never meet 100% in time). Use 0<= to disable PAUSE.
	 */
	if (safety_margin <= 0)
		return false;

	/*
	 * Expected behavior:
	 * 1. ACTIVE: small current run a while for ttf
	 * 2. PAUSE: when time is enough to pause
	 * 3. ACTIVE: when time out and back to ACTIVE charge
	 */
	if (rest_state != CHG_HEALTH_ACTIVE && rest_state != CHG_HEALTH_PAUSE)
		return false;

	/*
	 * ssoc: transfer in high soc impact charge full condition, disable pause
	 * behavior in high soc
	 */
	if (ssoc > HEALTH_PAUSE_MAX_SSOC)
		return false;

	/*
	 * elap_h: running active for a while wait status and current stable
	 * need to re-check before re-enter pause, so we need to minus previous
	 * health active time (rest->active_time) for next HEALTH_PAUSE_DEBOUNCE
	 */
	if (elap_h - rest->active_time < HEALTH_PAUSE_DEBOUNCE)
		return false;

	/* prevent enter <---> leave PAUSE too many times */
	if (rest->active_time > (HEALTH_PAUSE_TIME * HEALTH_PAUSE_DEBOUNCE))
		return false;

	/* check if time meets the PAUSE condition or not */
	if (ttf > 0 && deadline > now + ttf + safety_margin)
		return true;

	/* record time for next pause check */
	rest->active_time = elap_h;

	return false;
}


/*
 * for logging, userspace should use
 *   deadline == 0 on fast replug (leave initial deadline ok)
 *   deadline == -1 when the feature is disabled
 *       if charge health was active/enabled, set to -2
 *   deadline == absolute requested deadline (if always_on is set)
 * return true if there was a change
 */
static bool batt_health_set_chg_deadline(struct batt_chg_health *chg_health,
					 long long deadline_s)
{
	enum chg_health_state rest_state = chg_health->rest_state;
	bool new_deadline;

	/* disabled in settings */
	if (deadline_s < 0) {
		new_deadline = chg_health->rest_deadline != deadline_s;
		chg_health->rest_state = CHG_HEALTH_USER_DISABLED;

		/* disabled with notification; assumes that the dialog exists
		 * only if there is a >0 deadline.
		 */
		if (deadline_s == CHG_DEADLINE_DIALOG)
			chg_health->rest_deadline = CHG_DEADLINE_DIALOG;
		else if (chg_health->rest_deadline > 0) /* was active */
			chg_health->rest_deadline = CHG_DEADLINE_SETTING_STOP;
		else
			chg_health->rest_deadline = CHG_DEADLINE_SETTING;

	/* disabled with replug */
	} else if (deadline_s == 0) {
		new_deadline = chg_health->rest_deadline != deadline_s;
		/* ->rest_deadline will be reset to 0 on disconnect */

		/* Don't disable A/C if already done */
		if (chg_health->rest_state != CHG_HEALTH_DONE)
			chg_health->rest_state = CHG_HEALTH_USER_DISABLED;

	} else { /* enabled from any previous state */
		const ktime_t rest_deadline = get_boot_sec() + deadline_s;

		/* ->always_on SOC overrides the deadline */
		new_deadline = chg_health->rest_deadline != rest_deadline;
		chg_health->rest_state = CHG_HEALTH_ENABLED;
		chg_health->rest_deadline = rest_deadline;
	}

	return new_deadline || rest_state != chg_health->rest_state;
}

#define HEALTH_CHG_RATE_BEFORE_TRIGGER 80
/* health based charging trade charging speed for battery cycle life. */
static bool msc_logic_health(struct batt_drv *batt_drv)
{
	const struct gbms_chg_profile *profile = &batt_drv->chg_profile;
	struct batt_chg_health *rest = &batt_drv->chg_health;
	const ktime_t deadline = rest->rest_deadline;
	enum chg_health_state rest_state = rest->rest_state;
	const bool aon_enabled = rest->always_on_soc != -1;
	const int capacity_ma = batt_drv->battery_capacity;
	const ktime_t now = get_boot_sec();
	int fv_uv = -1, cc_max = -1;
	bool changed = false;
	ktime_t ttf = 0;
	int ret;

	/* move to ENABLED if INACTIVE when aon_enabled is set */
	if (aon_enabled && rest_state == CHG_HEALTH_INACTIVE)
		rest_state = CHG_HEALTH_ENABLED;

	/*
	 * on disconnect batt_reset_rest_state() will set rest_state to
	 * CHG_HEALTH_USER_DISABLED if the deadline is negative.
	 */
	if (rest_state == CHG_HEALTH_CCLVL_DISABLED ||
	    rest_state == CHG_HEALTH_BD_DISABLED ||
	    rest_state == CHG_HEALTH_USER_DISABLED ||
	    rest_state == CHG_HEALTH_DISABLED ||
	    rest_state == CHG_HEALTH_INACTIVE)
		goto done_no_op;

	/* Keeps AC enabled after DONE */
	if (rest_state == CHG_HEALTH_DONE)
		goto done_exit;

	/* disable AC because we are running custom charging levels */
	if (batt_drv->chg_state.f.flags & GBMS_CS_FLAG_CCLVL) {
		rest_state = CHG_HEALTH_CCLVL_DISABLED;
		goto done_exit;
	}

	/* disable AC because BD-TEMP triggered */
	if (batt_drv->batt_health == POWER_SUPPLY_HEALTH_OVERHEAT) {
		rest_state = CHG_HEALTH_BD_DISABLED;
		goto done_exit;
	}

	/*
	 * ret < 0 right after plug-in or when the device is discharging due
	 * to a large sysload or an underpowered adapter (or both). Current
	 * strategy leaves everything as is (hoping) that the load is temporary.
	 * The estimate will be negative when BD is triggered and during the
	 * debounce period.
	 */
	ret = batt_ttf_estimate(&ttf, batt_drv);
	if (ret < 0)
		return false;

	/* estimate is 0 at 100%: set to done and keep AC enabled in RL */
	if (ttf == 0) {
		rest_state = CHG_HEALTH_DONE;
		goto done_exit;
	}

	/*
	 * rest_state here is either ENABLED or ACTIVE, transition to DISABLED
	 * when the deadline cannot be met with the current rate. set a new
	 * deadline or reset always_on_soc to re-enable AC for this session.
	 * NOTE: A device with AON enabled might (will) receive a deadline if
	 * plugged in within the AC window: ignore it.
	 * NOTE: cannot have a negative deadline with rest_state different
	 * from CHG_HEALTH_USER_DISABLED.
	 * TODO: consider adding a margin or debounce it.
	 */
	if (aon_enabled == false && rest_state == CHG_HEALTH_ACTIVE &&
	    deadline > 0 && ttf != -1 && now + ttf > deadline) {
		rest_state = CHG_HEALTH_DISABLED;
		goto done_exit;
	}

	/* Decide enter PAUSE state or not by time if not set ACA */
	if (aon_enabled == false &&
	    msc_health_pause(batt_drv, ttf, now, rest_state)) {
		rest_state = CHG_HEALTH_PAUSE;
		goto done_exit;
	}

	/*
	 * rest_state here is either ENABLED or ACTIVE,
	 * NOTE: State might transition from _ACTIVE to _ENABLED after a
	 * discharge cycle that makes the battery fall under the threshold.
	 * State will transition back to _ENABLED after some time unless
	 * the deadline is met.
	 */
	rest_state = msc_health_active(batt_drv);

done_exit:
	if (rest_state == CHG_HEALTH_ACTIVE || rest_state == CHG_HEALTH_DONE) {
		/* cc_max in ua: capacity in mAh, rest_rate in deciPct */
		cc_max = capacity_ma * rest->rest_rate * 10;

		/*
		 * default FV_UV to the last charge tier since fv_uv will be
		 * set to that on _DONE.
		 * NOTE this might need to be adjusted for the actual charge
		 * tiers that have nonzero charging current
		 */
		fv_uv = profile->volt_limits[profile->volt_nb_limits - 1];

		/* TODO: make sure that we wakeup when we are close to ttf */
	} else if (rest_state == CHG_HEALTH_ENABLED) {
		cc_max = capacity_ma * rest->rest_rate_before_trigger * 10;
	} else if (rest_state == CHG_HEALTH_PAUSE) {
		/*
		 * pause charging behavior when the the deadline is longer than
		 * expected charge time. return back to CHG_HEALTH_ACTIVE and
		 * start health charge when now + ttf + margine close to deadline
		*/
		cc_max = 0;
	}

done_no_op:
	/* send a power supply event when rest_state changes */
	changed = rest->rest_state != rest_state;

	/* msc_logic_* will vote on cc_max and fv_uv. */
	rest->rest_cc_max = cc_max;
	rest->rest_fv_uv = fv_uv;

	if (!changed)
		return false;

	gbms_logbuffer_prlog(batt_drv->ttf_stats.ttf_log, LOGLEVEL_INFO, 0, LOGLEVEL_DEBUG,
			     "MSC_HEALTH: now=%lld deadline=%lld aon_soc=%d ttf=%lld state=%d->%d fv_uv=%d, cc_max=%d safety_margin=%d active_time:%lld",
			     now, rest->rest_deadline, rest->always_on_soc, ttf, rest->rest_state,
			     rest_state, fv_uv, cc_max, batt_drv->health_safety_margin,
			     rest->active_time);

	rest->rest_state = rest_state;
	memcpy(&batt_drv->ce_data.ce_health, &batt_drv->chg_health,
			sizeof(batt_drv->ce_data.ce_health));
	return true;
}

static int msc_pm_hold(int msc_state)
{
	int pm_state = -1;

	switch (msc_state) {
	case MSC_RAISE:
	case MSC_VOVER:
	case MSC_PULLBACK:
		pm_state = 1; /* __pm_stay_awake */
		break;
	case MSC_SEED:
	case MSC_DSG:
	case MSC_VSWITCH:
	case MSC_NEXT:
	case MSC_LAST:
	case MSC_RSTC:
	case MSC_HEALTH:
	case MSC_HEALTH_PAUSE:
	case MSC_HEALTH_ALWAYS_ON:
	case MSC_WAIT:
	case MSC_FAST:
	case MSC_NYET:
	case MSC_STEADY:
		pm_state = 0;  /* pm_relax */
		break;
	default:
		pr_debug("hold not defined for msc_state=%d\n", msc_state);
		pm_state = 0;  /* pm_relax */
		break;
	}

	return pm_state;
}

/* same as design when under the grace period */
static u32 aacr_get_reference_capacity(const struct batt_drv *batt_drv, int cycle_count)
{
	const int design_capacity = batt_drv->battery_capacity;
	const int aacr_cycle_grace = batt_drv->aacr_cycle_grace;
	const int aacr_cycle_max = batt_drv->aacr_cycle_max;
	int fade10;

	fade10 = gbms_aacr_fade10(&batt_drv->chg_profile, cycle_count);
	if (fade10 >= 0) {
		/* use interpolation between known points */
	} else if (aacr_cycle_max && (cycle_count > aacr_cycle_grace)) {
		/* or use slope from ->aacr_cycle_grace for 20% @ ->aacr_cycle_max */
		fade10 = (200 * (cycle_count -  aacr_cycle_grace)) /
			 (aacr_cycle_max - aacr_cycle_grace);

		pr_debug("%s: aacr_cycle_max=%d, cycle_count=%d fade10=%d\n",
			 __func__, aacr_cycle_max, cycle_count, fade10);
	} else {
		fade10 = 0;
	}

	return design_capacity - (design_capacity * fade10 / 1000);
}

/* 80% of design_capacity min, design_capacity in grace, aacr or negative */
static int aacr_get_capacity_at_cycle(const struct batt_drv *batt_drv, int cycle_count)
{
	const int design_capacity = batt_drv->battery_capacity; /* mAh */
	const int min_capacity = (batt_drv->battery_capacity * 80) / 100;
	int reference_capacity, full_cap_nom, full_capacity;
	struct power_supply *fg_psy = batt_drv->fg_psy;
	int aacr_capacity;

	/* batt_drv->cycle_count might be negative */
	if (cycle_count <= batt_drv->aacr_cycle_grace)
		return design_capacity;

	/* peg at 80% of design when over limit (if set) */
	if (batt_drv->aacr_cycle_max && (cycle_count >= batt_drv->aacr_cycle_max))
		return min_capacity;

	reference_capacity = aacr_get_reference_capacity(batt_drv, cycle_count);
	if (reference_capacity <= 0)
		return design_capacity;

	/* full_cap_nom in uAh, need to scale to mAh */
	full_cap_nom = GPSY_GET_PROP(fg_psy, POWER_SUPPLY_PROP_CHARGE_FULL);
	if (full_cap_nom < 0)
		return full_cap_nom;

	full_cap_nom /= 1000;

	if (batt_drv->aacr_algo == BATT_AACR_ALGO_LOW_B)
		full_capacity = min(min(full_cap_nom, design_capacity), reference_capacity);
	else
		full_capacity = max(min(full_cap_nom, design_capacity), reference_capacity);

	aacr_capacity = max(full_capacity, min_capacity);
	aacr_capacity = (aacr_capacity / 50) * 50; /* 50mAh, ~1% capacity */

	pr_debug("%s: design=%d reference=%d full_cap_nom=%d full=%d aacr=%d algo=%d\n",
		 __func__, design_capacity, reference_capacity, full_cap_nom,
		 full_capacity, aacr_capacity, batt_drv->aacr_algo);

	return aacr_capacity;
}

/* design_capacity when not enabled, never a negative value */
static u32 aacr_get_capacity(struct batt_drv *batt_drv)
{
	int capacity = batt_drv->battery_capacity;
	int cycle_count;

	if (batt_drv->fake_aacr_cc)
		cycle_count = batt_drv->fake_aacr_cc;
	else
		cycle_count = batt_drv->cycle_count;

	if (batt_drv->aacr_state == BATT_AACR_DISABLED)
		goto exit_done;

	if (cycle_count <= batt_drv->aacr_cycle_grace) {
		batt_drv->aacr_state = BATT_AACR_UNDER_CYCLES;
	} else {
		int aacr_capacity;

		aacr_capacity = aacr_get_capacity_at_cycle(batt_drv, cycle_count);
		if (aacr_capacity < 0) {
			batt_drv->aacr_state = BATT_AACR_INVALID_CAP;
		} else {
			batt_drv->aacr_state = BATT_AACR_ENABLED;
			capacity = aacr_capacity;
		}
	}

exit_done:
	return (u32)capacity;
}

/* BHI -------------------------------------------------------------------- */

#define ONE_YEAR_HRS		(24 * 365)
#define BHI_INDI_CAP_DEFAULT	85
static int bhi_individual_conditions_index(const struct health_data *health_data)
{
	const struct bhi_data *bhi_data = &health_data->bhi_data;
	const int cur_impedance = batt_ravg_value(&bhi_data->res_state);
	const int age_impedance_max = bhi_data->act_impedance * 2;
	const int cur_capacity_pct = 100 - bhi_data->capacity_fade;
	const int bhi_indi_cap = health_data->bhi_indi_cap;

	if (health_data->bhi_data.battery_age >= ONE_YEAR_HRS ||
	    cur_impedance >= age_impedance_max || cur_capacity_pct <= bhi_indi_cap)
		return health_data->need_rep_threshold * 100;

	return BHI_ALGO_FULL_HEALTH;
}

/* GBMS_PROP_CAPACITY_FADE_RATE access this via GBMS_TAG_HCNT */
static int hist_get_index(int cycle_count, const struct batt_drv *batt_drv)
{
	/* wait for history to be initialized */
	if (batt_drv->hist_data_max_cnt <= 0 || cycle_count <= 0)
		return -ENODATA;

	return cycle_count / batt_drv->hist_delta_cycle_cnt;
}

static int bhi_cap_data_update(struct bhi_data *bhi_data, struct batt_drv *batt_drv)
{
	struct power_supply *fg_psy = batt_drv->fg_psy;
	int cap_fade;

	/* GBMS_PROP_CAPACITY_FADE_RATE is in percent */
	cap_fade = GPSY_GET_PROP(fg_psy, GBMS_PROP_CAPACITY_FADE_RATE);
	if (cap_fade < 0)
		return -ENODATA;
	if (cap_fade > 100)
		cap_fade = 100;

	bhi_data->capacity_fade = cap_fade;

	pr_debug("%s: cap_fade=%d, cycle_count=%d\n", __func__,
		bhi_data->capacity_fade, bhi_data->cycle_count);

	return 0;
}


/*
 * NOTE: make sure that the FG and this code use the same reference value for
 * capacity. Also GBMS_PROP_CAPACITY_FADE_RATE is in percent.
 */
static int bhi_health_get_capacity(int algo, const struct bhi_data *bhi_data)
{
	return bhi_data->capacity_design * (100 - bhi_data->capacity_fade) / 100;
}

/* The limit for capacity is 80% of design */
static int bhi_calc_cap_index(int algo, struct batt_drv *batt_drv)
{
	const struct health_data *health_data = &batt_drv->health_data;
	const struct bhi_data *bhi_data = &health_data->bhi_data;
	int capacity_health, index, capacity_aacr = 0;

	if (algo == BHI_ALGO_DISABLED)
		return BHI_ALGO_FULL_HEALTH;

	if (health_data->bhi_debug_cap_index)
		return health_data->bhi_debug_cap_index;

	if (!bhi_data->capacity_design)
		return -ENODATA;

	capacity_health = bhi_health_get_capacity(algo, bhi_data);

	/* for BHI_ALGO_ACHI_B compare to aacr capacity */
	if (algo == BHI_ALGO_ACHI_B || algo == BHI_ALGO_ACHI_RAVG_B) {
		capacity_aacr = aacr_get_capacity(batt_drv);

		if (capacity_health < capacity_aacr)
			capacity_health = capacity_aacr;
	}

	/*
	 * TODO: compare to google_capacity?
	 * ret = gbms_storage_read(GBMS_TAG_GCFE, &gcap sizeof(gcap));
	 */

	index = (capacity_health * BHI_ALGO_FULL_HEALTH) / bhi_data->capacity_design;
	if (index > BHI_ALGO_FULL_HEALTH)
		index = BHI_ALGO_FULL_HEALTH;

	pr_debug("%s: algo=%d index=%d ch=%d, ca=%d, cd=%d, fr=%d\n", __func__,
		algo, index, capacity_health, capacity_aacr, bhi_data->capacity_design,
		bhi_data->capacity_fade);

	return index;
}

/* read and qualify the battery initial impedance */
static int bhi_imp_read_ai(struct bhi_data *bhi_data, struct power_supply *fg_psy)
{
	int act_impedance;


	/* use ravg if the filter is full? */
	act_impedance = batt_ravg_value(&bhi_data->res_state);

	/* TODO: qualify with filter length */

	return act_impedance;
}

/* hold mutex_unlock(&batt_drv->chg_lock); */
static int bhi_imp_data_update(struct bhi_data *bhi_data, struct power_supply *fg_psy)
{
	const int use_ravg = true;
	int act_impedance = bhi_data->act_impedance;
	int cur_impedance;

	if (!act_impedance) {
		act_impedance = GPSY_GET_PROP(fg_psy, GBMS_PROP_HEALTH_ACT_IMPEDANCE);
		if (act_impedance == -EINVAL) {
			int ret;

			act_impedance = use_ravg ? bhi_imp_read_ai(bhi_data, fg_psy) :
					GPSY_GET_PROP(fg_psy, GBMS_PROP_HEALTH_IMPEDANCE);
			if (act_impedance <= 0)
				goto exit_done;

			ret = GPSY_SET_PROP(fg_psy, GBMS_PROP_HEALTH_ACT_IMPEDANCE,
					    act_impedance);
			if (ret < 0)
				goto exit_done;
		}

		if (act_impedance < 0)
			goto exit_done;

		/* primed, saved */
		bhi_data->act_impedance = act_impedance;
		return 0;
	}


	cur_impedance = batt_ravg_value(&bhi_data->res_state);

	/*
	 *  Can delegate to the FG with:
	 * 	cur_impedance = GPSY_GET_PROP(fg_psy, GBMS_PROP_HEALTH_IMPEDANCE);
	 * if (cur_impedance < 0)
	 * 	goto exit_done;
	 */

	 /* max in this session. Use average maybe? */
	 if (cur_impedance > bhi_data->cur_impedance)
		bhi_data->cur_impedance = cur_impedance;

exit_done:
	pr_debug("%s: cur_impedance=%d, act_impedance=%d\n", __func__,
		 cur_impedance, act_impedance);
	return 0;
}
/* pick the impedance from the algo */
static int bhi_health_get_impedance(int algo, const struct bhi_data *bhi_data)
{
	u32 cur_impedance;

	switch (algo) {
	case BHI_ALGO_DISABLED:
	case BHI_ALGO_CYCLE_COUNT:
	case BHI_ALGO_ACHI_RAVG:
	case BHI_ALGO_ACHI_RAVG_B:
	case BHI_ALGO_MIX_N_MATCH:
		cur_impedance = batt_ravg_value(&bhi_data->res_state);
		break;
	default:
		return 0;
	}

	if (cur_impedance <= 0)
		cur_impedance = bhi_data->act_impedance;

	return cur_impedance;
}

static int bhi_calc_imp_index(int algo, const struct health_data *health_data)
{
	const struct bhi_data *bhi_data = &health_data->bhi_data;
	u32 cur_impedance;
	int imp_index;

	if (!bhi_data->act_impedance)
		return BHI_ALGO_FULL_HEALTH;

	if (health_data->bhi_debug_imp_index)
		return health_data->bhi_debug_imp_index;

	cur_impedance = bhi_health_get_impedance(algo, bhi_data);
	if (cur_impedance == 0)
		return BHI_ALGO_FULL_HEALTH;

	/*
	 * TODO: on algo==*_B bounds check cur_impedance against res10
	 * before calculating the impedance index.
	 */

	/* The limit is 2x of activation. */
	imp_index = (2 * bhi_data->act_impedance - cur_impedance) * BHI_ALGO_FULL_HEALTH /
		    bhi_data->act_impedance;
	if (imp_index < 0)
		imp_index = 0;

	pr_debug("%s: algo=%d index=%d current=%d, activation=%d\n", __func__,
		 algo, imp_index, cur_impedance, bhi_data->act_impedance);

	return imp_index;
}

static int bhi_calc_sd_total(const struct swelling_data *sd)
{
	int i, swell_total = 0;
	ktime_t time_at;

	for (i = 0; i < BATT_TEMP_RECORD_THR ; i++) {
		time_at = sd->chg[i] / 3600;
		time_at += sd->dischg[i] / 3600;
		// TODO: use weights for temperature and soc
		// eg. sd->temp_thr[i]/10, sd->soc_thr[i],
		swell_total += time_at;
	}

	return swell_total;
}

static int bhi_calc_sd_index(int algo, const struct health_data *health_data)
{
	const struct bhi_data *bhi_data = &health_data->bhi_data;

	if (health_data->bhi_debug_sd_index)
		return health_data->bhi_debug_sd_index;

	pr_debug("%s: algo=%d index=%d\n", __func__, algo, bhi_data->ccbin_index);
	return bhi_data->ccbin_index;
}

static int bhi_cycle_count_index(const struct health_data *health_data)
{
	const int cc = health_data->bhi_data.cycle_count;
	const int cc_mt = health_data->cycle_count_marginal_threshold;
	const int cc_nrt = health_data->cycle_count_need_rep_threshold;
	const int h_mt = health_data->marginal_threshold;
	const int h_nrt = health_data->need_rep_threshold;
	int cc_index;

	/* threshold should be reasonable */
	if (h_mt < h_nrt || cc_nrt <= cc_mt)
		return BHI_ALGO_FULL_HEALTH;

	/* use interpolation to get index via cycle count/health threshold */
	cc_index = (h_mt - h_nrt) * (cc - cc_nrt) / (cc_mt - cc_nrt) + h_nrt;
	cc_index = cc_index * 100; /* for BHI_ROUND_INDEX*/

	if (cc_index > BHI_ALGO_FULL_HEALTH)
		cc_index = BHI_ALGO_FULL_HEALTH;

	if (cc_index < 0)
		cc_index = 0;

	return cc_index;
}

static int bhi_calc_health_index(int algo, const struct health_data *health_data,
				 int cap_index, int imp_index, int sd_index)
{
	int ratio, index;
	int w_ci = 0;
	int w_ii = 0;
	int w_sd = 0;

	if (health_data->bhi_debug_health_index)
		return health_data->bhi_debug_health_index;

	switch (algo) {
	case BHI_ALGO_DISABLED:
		return BHI_ALGO_FULL_HEALTH;
	case BHI_ALGO_CYCLE_COUNT:
		return bhi_cycle_count_index(health_data);
	case BHI_ALGO_ACHI:
	case BHI_ALGO_ACHI_B:
	case BHI_ALGO_ACHI_RAVG:
	case BHI_ALGO_ACHI_RAVG_B:
	case BHI_ALGO_MIX_N_MATCH:
		w_ci = bhi_w[algo].w_ci;
		w_ii = bhi_w[algo].w_ii;
		w_sd = bhi_w[algo].w_sd;
		break;
	case BHI_ALGO_DEBUG:
		w_ci = health_data->bhi_w_ci;
		w_ii = health_data->bhi_w_pi;
		w_sd = health_data->bhi_w_sd;
		break;
	case BHI_ALGO_INDI:
		return bhi_individual_conditions_index(health_data);
	default:
		return -EINVAL;
	}

	if (cap_index < 0)
		w_ci = 0;
	if (imp_index < 0)
		w_ii = 0;
	if (sd_index < 0)
		w_sd = 0;

	/* TODO: check single cell disconnect */

	ratio = w_ci + w_ii + w_sd;
	if (ratio > 100)
		return -ERANGE;
	if (!ratio)
		return 100;

	index = (cap_index * w_ci + imp_index * w_ii + sd_index * w_sd) / ratio;
	pr_debug("%s: algo=%d index=%d cap_index=%d/%d  imp_index=%d/%d sd_index=%d/%d\n",
		 __func__, algo, index, cap_index, w_ci, imp_index, w_ii, sd_index, w_sd);

	return index;
}

static enum bhi_status bhi_calc_health_status(int algo, int health_index,
					      const struct health_data *data)
{
	enum bhi_status health_status;

	if (algo == BHI_ALGO_DISABLED)
		return BH_UNKNOWN;

	if (health_index < 0)
		health_status = BH_UNKNOWN;
	else if (health_index <= data->need_rep_threshold)
		health_status = BH_NEEDS_REPLACEMENT;
	else if (health_index <= data->marginal_threshold)
		health_status = BH_MARGINAL;
	else
		health_status = BH_NOMINAL;

	return health_status;
}

static int batt_bhi_data_save(struct batt_drv *batt_drv)
{
	/* TODO: load save health status, index, cap index, imp index */

	/* TODO: save current impedance if not using RAVG */

	return 0;
}

static int batt_bhi_data_load(struct batt_drv *batt_drv)
{
	/* TODO: load last health status, index, cap index, imp index */
	/* TODO: prime current impedance if not using RAVG */

	return 0;
}

/* call holding mutex_lock(&batt_drv->chg_lock)  */
static int batt_bhi_stats_update(struct batt_drv *batt_drv)
{
	struct health_data *health_data = &batt_drv->health_data;
	struct power_supply *fg_psy = batt_drv->fg_psy;
	const int bhi_algo = health_data->bhi_algo;
	enum bhi_status status;
	bool changed = false;
	int age, index;


	/* age (and cycle count* might be used in the calc */
	age = GPSY_GET_PROP(fg_psy, GBMS_PROP_BATTERY_AGE);
	if (age < 0)
		return -EIO;
	health_data->bhi_data.battery_age = age;

	/* cycle count is cached */
	if (health_data->bhi_debug_cycle_count != 0)
		health_data->bhi_data.cycle_count = health_data->bhi_debug_cycle_count;
	else
		health_data->bhi_data.cycle_count = batt_drv->cycle_count;

	index = bhi_calc_cap_index(bhi_algo, batt_drv);
	if (index < 0)
		index = BHI_ALGO_FULL_HEALTH;
	changed |= health_data->bhi_cap_index != index;
	health_data->bhi_cap_index = index;

	index = bhi_calc_imp_index(bhi_algo, health_data);
	if (index < 0)
		index = BHI_ALGO_FULL_HEALTH;
	changed |= health_data->bhi_imp_index != index;
	health_data->bhi_imp_index = index;

	index = bhi_calc_sd_index(bhi_algo, health_data);
	if (index < 0)
		index = BHI_ALGO_FULL_HEALTH;
	changed |= health_data->bhi_sd_index != index;
	health_data->bhi_sd_index = index;

	index = bhi_calc_health_index(bhi_algo, health_data,
				      health_data->bhi_cap_index,
				      health_data->bhi_imp_index,
				      health_data->bhi_sd_index);
	if (index < 0)
		index = BHI_ALGO_FULL_HEALTH;

	changed |= health_data->bhi_index != index;
	health_data->bhi_index = index;

	status = bhi_calc_health_status(bhi_algo, BHI_ROUND_INDEX(index), health_data);
	changed |= health_data->bhi_status != status;
	health_data->bhi_status = status;

	pr_debug("%s: algo=%d status=%d bhi=%d cap_index=%d, imp_index=%d sd_index=%d (%d)\n", __func__,
		 bhi_algo, health_data->bhi_status, health_data->bhi_index,
		 health_data->bhi_cap_index, health_data->bhi_imp_index,
		 health_data->bhi_sd_index,  changed);


	if (changed) {
		int ret;

		/* TODO: send a power supply event? */

		ret = batt_bhi_data_save(batt_drv);
		if (ret < 0)
			pr_err("BHI: cannot save data (%d)\n", ret);
	}

	return changed;
}

/*
 * calculate the ratio of the time spent at under the soc_limit vs the time
 * spent over the soc_limit in percent.
 * call holding mutex_lock(&batt_drv->chg_lock);
 */
static int bhi_cycle_count_residency(struct gbatt_ccbin_data *ccd , int soc_limit)
{
	int i, under = 0, over = 0;

	for (i = 0; i < GBMS_CCBIN_BUCKET_COUNT; i++) {
		if (ccd->count[i] == 0xFFFF)
			continue;
		if ((i * 10) < soc_limit)
			under += ccd->count[i];
		else
			over += ccd->count[i];
	}

	pr_debug("%s: under=%d, over=%d limit=%d\n", __func__, under, over, soc_limit);
	return (under * BHI_ALGO_FULL_HEALTH) / (under + over);
}

/* call holding mutex_lock(&batt_drv->chg_lock)  */
static int batt_bhi_stats_update_all(struct batt_drv *batt_drv)
{
	struct health_data *health_data = &batt_drv->health_data;
	int ret;

	/* swell probability: cc residecy needs ccd->lock */
	batt_drv->health_data.bhi_data.ccbin_index =
		bhi_cycle_count_residency(&batt_drv->cc_data, BHI_CCBIN_INDEX_LIMIT);
	/* swell cumulative needs a new lock */
	batt_drv->health_data.bhi_data.swell_cumulative =
		bhi_calc_sd_total(&batt_drv->sd);

	pr_debug("BHI: limit=%d%% ccbin_index=%d swell_total=%d\n",
			BHI_CCBIN_INDEX_LIMIT,
			batt_drv->health_data.bhi_data.ccbin_index,
			batt_drv->health_data.bhi_data.swell_cumulative);

	/* impedance should be pretty recent */
	ret = bhi_imp_data_update(&health_data->bhi_data, batt_drv->fg_psy);
	if (ret < 0)
		pr_err("bhi imp data not available (%d)\n", ret);

	/* bhi_capacity_index on disconnect */
	ret = bhi_cap_data_update(&batt_drv->health_data.bhi_data, batt_drv);
	if (ret < 0)
		pr_err("bhi cap data not available (%d)\n", ret);

	batt_bhi_stats_update(batt_drv);

	return 0;
}

/* ------------------------------------------------------------------------ */


/* TODO: factor msc_logic_irdop from the logic about tier switch */
static int msc_logic(struct batt_drv *batt_drv)
{
	bool sw_jeita;
	int msc_state = MSC_NONE;
	struct power_supply *fg_psy = batt_drv->fg_psy;
	struct gbms_chg_profile *profile = &batt_drv->chg_profile;
	int vbatt_idx = batt_drv->vbatt_idx, fv_uv = batt_drv->fv_uv, temp_idx;
	int temp, ibatt, vbatt, ioerr;
	int update_interval = MSC_DEFAULT_UPDATE_INTERVAL;
	const ktime_t now = get_boot_sec();
	ktime_t elap = now - batt_drv->ce_data.last_update;
	bool changed;

	temp = GPSY_GET_INT_PROP(fg_psy, POWER_SUPPLY_PROP_TEMP, &ioerr);
	if (ioerr < 0)
		return -EIO;

	/*
	 * driver state is (was) reset when we hit the SW jeita limit.
	 * NOTE: resetting driver state will release the wake assertion
	 */
	sw_jeita = msc_logic_soft_jeita(batt_drv, temp);
	if (sw_jeita) {
		/* reset batt_drv->jeita_stop_charging to -1 */
		if (batt_drv->jeita_stop_charging == 0)
			batt_reset_chg_drv_state(batt_drv);

		return 0;
	} else if (batt_drv->jeita_stop_charging) {
		batt_prlog(BATT_PRLOG_ALWAYS,
			   "MSC_JEITA temp=%d ok, enabling charging\n",
			   temp);
		batt_drv->jeita_stop_charging = 0;
	}

	ibatt = GPSY_GET_INT_PROP(fg_psy, POWER_SUPPLY_PROP_CURRENT_NOW,
					  &ioerr);
	if (ioerr < 0)
		return -EIO;

	vbatt = GPSY_GET_PROP(fg_psy, POWER_SUPPLY_PROP_VOLTAGE_NOW);
	if (vbatt < 0)
		return -EIO;

	/*
	 * Multi Step Charging with IRDROP compensation when vchrg is != 0
	 * vbatt_idx = batt_drv->vbatt_idx, fv_uv = batt_drv->fv_uv
	 */
	temp_idx = gbms_msc_temp_idx(profile, temp);
	if (temp_idx != batt_drv->temp_idx || batt_drv->fv_uv == -1 ||
		batt_drv->vbatt_idx == -1) {

		msc_state = MSC_SEED;

		/* seed voltage and charging table only on connect, book 0 time */
		if (batt_drv->vbatt_idx == -1)
			vbatt_idx = gbms_msc_voltage_idx(profile, vbatt);

		batt_prlog(BATT_PRLOG_ALWAYS,
			   "MSC_SEED temp=%d vb=%d temp_idx:%d->%d, vbatt_idx:%d->%d\n",
			   temp, vbatt, batt_drv->temp_idx, temp_idx,
			   batt_drv->vbatt_idx, vbatt_idx);

		/* Debounce tier switch only when not already switching */
		if (batt_drv->checked_tier_switch_cnt == 0)
			batt_drv->checked_cv_cnt = profile->cv_debounce_cnt;
	} else if (ibatt > 0) {
		const int vtier = profile->volt_limits[vbatt_idx];
		const bool log_level = batt_drv->msc_state != MSC_DSG ||
				       batt_drv->cc_max != 0;

		/*
		 * Track battery voltage if discharging is due to system load,
		 * low ILIM or lack of headroom; stop charging work and reset
		 * batt_drv state() when discharging is due to disconnect.
		 * NOTE: POWER_SUPPLY_PROP_STATUS return *_DISCHARGING only on
		 * disconnect.
		 * NOTE: same vbat_idx will not change fv_uv
		 */
		msc_state = MSC_DSG;
		vbatt_idx = gbms_msc_voltage_idx(profile, vbatt);

		batt_prlog(batt_prlog_level(log_level),
			   "MSC_DSG vbatt_idx:%d->%d vt=%d fv_uv=%d vb=%d ib=%d cv_cnt=%d ov_cnt=%d\n",
			   batt_drv->vbatt_idx, vbatt_idx, vtier, fv_uv, vbatt, ibatt,
			   batt_drv->checked_cv_cnt, batt_drv->checked_ov_cnt);

	} else if (batt_drv->vbatt_idx == profile->volt_nb_limits - 1) {
		const int chg_type = batt_drv->chg_state.f.chg_type;
		const int vtier = profile->volt_limits[vbatt_idx];
		int log_level;

		/*
		 * will not adjust charger voltage only in the configured
		 * last tier.
		 * NOTE: might not be the "real" last tier since can I have
		 * tiers with max charge current == 0.
		 * NOTE: should I use a voltage limit instead?
		 */

		if (chg_type == POWER_SUPPLY_CHARGE_TYPE_FAST) {
			msc_state = MSC_FAST;
		} else if (chg_type != POWER_SUPPLY_CHARGE_TYPE_TAPER) {
			msc_state = MSC_TYPE;
		} else {
			msc_state = MSC_LAST;
		}

		log_level = batt_prlog_level(batt_drv->msc_state != msc_state);
		if (log_level != BATT_PRLOG_ALWAYS && msc_state == MSC_LAST) {

			if (batt_drv->last_log_cnt > 0)
				batt_drv->last_log_cnt--;
			if (batt_drv->last_log_cnt == 0) {
				batt_drv->last_log_cnt = BATT_PRLOG_LAST_LOG_COUNT;
				log_level = batt_prlog_level(true);
			}
		}

		batt_prlog(log_level, "MSC_LAST vt=%d fv_uv=%d vb=%d ib=%d\n",
			   vtier, fv_uv, vbatt, ibatt);

	} else {
		const int tier_idx = batt_drv->vbatt_idx;
		const int vtier = profile->volt_limits[vbatt_idx];
		const int switch_cnt = profile->cv_tier_switch_cnt;
		const int cc_next_max = GBMS_CCCM_LIMITS(profile, temp_idx,
							vbatt_idx + 1);

		/* book elapsed time to previous tier & msc_irdrop_state */
		msc_state = msc_logic_irdrop(batt_drv,
					     vbatt, ibatt, temp_idx,
					     &vbatt_idx, &fv_uv,
					     &update_interval);

		if (msc_pm_hold(msc_state) == 1 && !batt_drv->hold_taper_ws) {
			__pm_stay_awake(batt_drv->taper_ws);
			batt_drv->hold_taper_ws = true;
		}

		mutex_lock(&batt_drv->stats_lock);
		gbms_chg_stats_tier(&batt_drv->ce_data.tier_stats[tier_idx],
				    batt_drv->msc_irdrop_state, elap);
		batt_drv->msc_irdrop_state = msc_state;
		mutex_unlock(&batt_drv->stats_lock);

		/*
		 * Basic multi step charging: switch to next tier when ibatt
		 * is under next tier cc_max.
		 */
		if (batt_drv->checked_cv_cnt > 0) {
			/* debounce period on tier switch */
			batt_drv->checked_cv_cnt -= 1;

			batt_prlog(batt_prlog_level(msc_state != MSC_FAST),
				   "MSC_WAIT s:%d->%d vt=%d fv_uv=%d vb=%d ib=%d cv_cnt=%d ov_cnt=%d t_cnt=%d\n",
				   msc_state, MSC_WAIT, vtier, fv_uv, vbatt, ibatt,
				   batt_drv->checked_cv_cnt, batt_drv->checked_ov_cnt,
				   batt_drv->checked_tier_switch_cnt);

			if (-ibatt > cc_next_max)
				batt_drv->checked_tier_switch_cnt = 0;

			msc_state = MSC_WAIT;
		} else if (-ibatt > cc_next_max) {

			/* current over next tier, reset tier switch count */
			batt_prlog(BATT_PRLOG_ALWAYS,
				   "MSC_RSTC s:%d->%d vt=%d fv_uv=%d vb=%d ib=%d cc_next_max=%d t_cnt=%d->0\n",
				   msc_state, MSC_RSTC, vtier, fv_uv, vbatt, ibatt, cc_next_max,
				   batt_drv->checked_tier_switch_cnt);

			batt_drv->checked_tier_switch_cnt = 0;
			msc_state = MSC_RSTC;
		} else if (batt_drv->checked_tier_switch_cnt >= switch_cnt) {
			/* next tier, fv_uv detemined at MSC_SET */
			vbatt_idx = batt_drv->vbatt_idx + 1;

			batt_prlog(BATT_PRLOG_ALWAYS,
				   "MSC_NEXT s:%d->%d tier vb=%d ib=%d vbatt_idx=%d->%d\n",
				   msc_state, MSC_NEXT, vbatt, ibatt,
				   batt_drv->vbatt_idx, vbatt_idx);

			msc_state = MSC_NEXT;
		} else {
			/* current under next tier, +1 on tier switch count */
			batt_drv->checked_tier_switch_cnt++;

			batt_prlog(BATT_PRLOG_ALWAYS,
				   "MSC_NYET s:%d->%d vt=%d vb=%d ib=%d cc_next_max=%d t_cnt=%d\n",
				   msc_state, MSC_NYET, vtier, vbatt, ibatt, cc_next_max,
				   batt_drv->checked_tier_switch_cnt);

			msc_state = MSC_NYET;
		}

	}

	if (msc_pm_hold(msc_state) == 0 && batt_drv->hold_taper_ws) {
		batt_drv->hold_taper_ws = false;
		__pm_relax(batt_drv->taper_ws);
	}

	/* need a new fv_uv only on a new voltage tier.  */
	if (vbatt_idx != batt_drv->vbatt_idx) {
		fv_uv = profile->volt_limits[vbatt_idx];
		batt_drv->checked_tier_switch_cnt = 0;
		batt_drv->checked_ov_cnt = 0;
	}

	/*
	 * book elapsed time to previous tier & msc_state
	 * NOTE: temp_idx != -1 but batt_drv->msc_state could be -1
	 */
	mutex_lock(&batt_drv->stats_lock);
	if (vbatt_idx != -1 && vbatt_idx < profile->volt_nb_limits) {
		int tier_idx = batt_chg_vbat2tier(batt_drv->vbatt_idx);

		/* this is the seed after the connect */
		if (tier_idx == -1) {
			tier_idx = batt_chg_vbat2tier(vbatt_idx);
			elap = 0;
		}

		batt_chg_stats_update(batt_drv, temp_idx, tier_idx,
				      ibatt / 1000, temp,
				      elap);

	}

	batt_drv->msc_state = msc_state;
	batt_drv->ce_data.last_update = now;
	mutex_unlock(&batt_drv->stats_lock);

	changed = batt_drv->temp_idx != temp_idx ||
		  batt_drv->vbatt_idx != vbatt_idx ||
		  batt_drv->fv_uv != fv_uv;
	batt_prlog(batt_prlog_level(changed),
		   "MSC_LOGIC temp_idx:%d->%d, vbatt_idx:%d->%d, fv=%d->%d, ui=%d->%d cv_cnt=%d ov_cnt=%d\n",
		   batt_drv->temp_idx, temp_idx, batt_drv->vbatt_idx, vbatt_idx,
		   batt_drv->fv_uv, fv_uv, batt_drv->cc_max, update_interval,
		   batt_drv->checked_cv_cnt, batt_drv->checked_ov_cnt);

	/* next update */
	batt_drv->msc_update_interval = update_interval;
	batt_drv->vbatt_idx = vbatt_idx;
	batt_drv->temp_idx = temp_idx;
	batt_drv->cc_max = GBMS_CCCM_LIMITS(profile, temp_idx, vbatt_idx);
	batt_drv->topoff = profile->topoff_limits[temp_idx];
	batt_drv->fv_uv = fv_uv;

	return 0;
}

/* no ssoc_delta when in overheat */
static int ssoc_get_delta(struct batt_drv *batt_drv)
{
	const bool overheat = batt_drv->batt_health ==
			      POWER_SUPPLY_HEALTH_OVERHEAT;

	return overheat ? 0 : qnum_fromint(batt_drv->ssoc_state.ssoc_delta);
}

/* TODO: handle the whole state buck_enable state */
static void ssoc_change_state(struct batt_ssoc_state *ssoc_state, bool ben)
{
	const ktime_t now = get_boot_sec();

	if (!ben) {
		ssoc_state->disconnect_time = now;
	} else if (ssoc_state->disconnect_time) {
		const u32 trickle_reset = ssoc_state->bd_trickle_reset_sec;
		const long long elap = now - ssoc_state->disconnect_time;

		if (trickle_reset && elap > trickle_reset)
			ssoc_state->bd_trickle_cnt = 0;

		pr_debug("MSC_BD: bd_trickle_cnt=%d dsc_time=%lld elap=%lld\n",
			 ssoc_state->bd_trickle_cnt,
			 ssoc_state->disconnect_time,
			 elap);

		ssoc_state->disconnect_time = 0;
	}

	ssoc_state->buck_enabled = ben;
}

static void bd_trickle_reset(struct batt_ssoc_state *ssoc_state,
			     struct gbms_charging_event *ce_data)
{
	ssoc_state->bd_trickle_cnt = 0;
	ssoc_state->disconnect_time = 0;
	ssoc_state->bd_trickle_full = false;
	ssoc_state->bd_trickle_eoc = false;

	/* Set to false in cev_stats_init */
	ce_data->bd_clear_trickle = true;
}

static void batt_prlog_din(union gbms_charger_state *chg_state, int log_level)
{
	batt_prlog(log_level,
		   "MSC_DIN chg_state=%lx f=0x%x chg_s=%s chg_t=%s vchg=%d icl=%d\n",
		   (unsigned long)chg_state->v,
		   chg_state->f.flags,
		   gbms_chg_status_s(chg_state->f.chg_status),
		   gbms_chg_type_s(chg_state->f.chg_type),
		   chg_state->f.vchrg,
		   chg_state->f.icl);
}

static void google_battery_dump_profile(const struct gbms_chg_profile *profile)
{
	char *buff;

	buff = kzalloc(GBMS_CHG_ALG_BUF_SZ, GFP_KERNEL);
	if (buff) {
		gbms_dump_chg_profile(buff, GBMS_CHG_ALG_BUF_SZ, profile);
		pr_info("%s", buff);
		kfree(buff);
	}
}

/* cell fault: disconnect of one of the battery cells */
static bool batt_cell_fault_detect(struct batt_bpst *bpst_state)
{
	int bpst_sbd_status;

	/*
	 * fake bpst_sbd_status by "echo 1 > /d/bpst/bpst_sbd_status"
	 * TODO: will implement the code from the algo in b/203019566
	 */
	bpst_sbd_status = bpst_state->bpst_sbd_status;

	return !!bpst_sbd_status && !bpst_state->bpst_detect_disable;
}

static int batt_bpst_detect_begin(struct batt_bpst *bpst_state)
{
	const int bpst_count_threshold = bpst_state->bpst_count_threshold;
	u8 data;
	int ret;

	if (bpst_state->bpst_detect_disable)
		return 0;

	ret = gbms_storage_read(GBMS_TAG_BPST, &data, sizeof(data));
	if (ret < 0)
		return -EINVAL;

	if (data == 0xff) {
		data = 0;
		ret = gbms_storage_write(GBMS_TAG_BPST, &data, sizeof(data));
		if (ret < 0)
			return -EINVAL;
	}
	bpst_state->bpst_count = data;
	if (bpst_count_threshold > 0) {
		bpst_state->bpst_cell_fault = (data >= (u8)bpst_count_threshold);
		pr_debug("%s: MSC_BPST: single battery disconnect %d\n",
			 __func__, bpst_state->bpst_cell_fault);
	}

	/* reset detection status */
	bpst_state->bpst_sbd_status = 0;

	pr_debug("%s: MSC_BPST: %d in connected\n", __func__, data);
	return 0;
}

static int batt_bpst_detect_update(struct batt_drv *batt_drv)
{
	struct batt_bpst *bpst_state = &batt_drv->bpst_state;
	const u8 data = bpst_state->bpst_count + 1;
	int ret;

	if (data < 0xff) {
		ret = gbms_storage_write(GBMS_TAG_BPST, &data, sizeof(data));
		if (ret < 0)
			return -EINVAL;
	}

	pr_debug("%s: MSC_BPST: %d in disconnected\n", __func__, data);
	return 0;
}

static int batt_bpst_reset(struct batt_bpst *bpst_state)
{
	if (bpst_state->bpst_enable) {
		u8 data = 0;

		return gbms_storage_write(GBMS_TAG_BPST, &data, sizeof(data));
	}

	return 0;
}

#define BATT_BPST_DEFAULT_CHG_RATE 100
static int batt_init_bpst_profile(struct batt_drv *batt_drv)
{
	struct batt_bpst *bpst_state = &batt_drv->bpst_state;
	struct device_node *node = batt_drv->device->of_node;
	int ret;

	/* set cell_fault initial status */
	bpst_state->bpst_cell_fault = false;

	bpst_state->bpst_enable = of_property_read_bool(node, "google,bpst-enable");
	if (!bpst_state->bpst_enable)
		return -EINVAL;

	ret = of_property_read_u32(node, "google,bpst-chg-rate", &bpst_state->bpst_chg_rate);
	if (ret < 0)
		bpst_state->bpst_chg_rate = BATT_BPST_DEFAULT_CHG_RATE;

	return 0;
}

/* call holding mutex_lock(&batt_drv->chg_lock); */
static int batt_chg_logic(struct batt_drv *batt_drv)
{
	int rc, err = 0;
	bool jeita_stop;
	bool changed = false;
	const bool disable_votes = batt_drv->disable_votes;
	const int ssoc = ssoc_get_capacity(&batt_drv->ssoc_state);
	union gbms_charger_state *chg_state = &batt_drv->chg_state;
	int log_vote_level = BATT_PRLOG_DEBUG;

	if (!batt_drv->chg_profile.cccm_limits)
		return -EINVAL;

	__pm_stay_awake(batt_drv->msc_ws);

	batt_prlog_din(chg_state, BATT_PRLOG_ALWAYS);

	/* disconnect! */
	if (chg_state_is_disconnected(chg_state)) {
		const qnum_t ssoc_delta = ssoc_get_delta(batt_drv);

		if (batt_drv->ssoc_state.buck_enabled == 0)
			goto msc_logic_exit;

		/* update bpst */
		mutex_lock(&batt_drv->bpst_state.lock);
		if (batt_drv->bpst_state.bpst_enable) {
			bool cell_fault_detect = batt_cell_fault_detect(&batt_drv->bpst_state);

			if (cell_fault_detect) {
				rc = batt_bpst_detect_update(batt_drv);
				pr_info("MSC_BPST: cell_fault_detect in disconnected(%d)\n", rc);
			}
		}
		mutex_unlock(&batt_drv->bpst_state.lock);

		/* here on: disconnect */
		batt_log_csi_ttf_info(batt_drv);
		batt_chg_stats_pub(batt_drv, "disconnect", false, false);

		/* change curve before changing the state. */
		ssoc_change_curve(&batt_drv->ssoc_state, ssoc_delta,
				  SSOC_UIC_TYPE_DSG);

		batt_drv->chg_health.rest_deadline = 0;
		batt_reset_chg_drv_state(batt_drv);
		batt_update_cycle_count(batt_drv);
		batt_rl_reset(batt_drv);

		/* trigger google_capacity learning. */
		err = GPSY_SET_PROP(batt_drv->fg_psy,
				    GBMS_PROP_BATT_CE_CTRL,
				    false);
		if (err < 0)
			pr_err("Cannot set the BATT_CE_CTRL.\n");

		/* TODO: move earlier and include the change to the curve */
		ssoc_change_state(&batt_drv->ssoc_state, 0);
		changed = true;

		/* google_resistance: update and stop accumulation. */
		batt_res_work(batt_drv);
		batt_res_state_set(&batt_drv->health_data.bhi_data.res_state, false);

		batt_bhi_stats_update_all(batt_drv);
		goto msc_logic_done;
	}

	/*
	 * here when connected to power supply
	 * The following block one only on start.
	 */
	if (batt_drv->ssoc_state.buck_enabled <= 0) {
		struct bhi_data *bhi_data = &batt_drv->health_data.bhi_data;
		struct device_node *node = batt_drv->device->of_node;
		const qnum_t ssoc_delta = ssoc_get_delta(batt_drv);
		u32 capacity;

		/*
		 * FIX: BatteryDefenderUI needs use a different curve because
		 * bd->bd_voltage_trigger needs now to be 100%. In alternative
		 * we use the regular charge curve and show that charging stop
		 * BEFORE reaching 100%. This is similar to what we do if BD
		 * trigger over bd->bd_voltage_trigger BUT under SSOC=100%
		 */
		ssoc_change_curve(&batt_drv->ssoc_state, ssoc_delta,
				  SSOC_UIC_TYPE_CHG);

		/* google_resistance is calculated while charging */
		if (bhi_data->res_state.estimate_filter)
			batt_res_state_set(&bhi_data->res_state, true);

		capacity = aacr_get_capacity(batt_drv);
		if (capacity != batt_drv->chg_profile.capacity_ma) {
			gbms_init_chg_table(&batt_drv->chg_profile, node, capacity);
			google_battery_dump_profile(&batt_drv->chg_profile);
		}

		batt_chg_stats_start(batt_drv);

		err = GPSY_SET_PROP(batt_drv->fg_psy, GBMS_PROP_BATT_CE_CTRL, true);
		if (err < 0)
			pr_err("Cannot set the BATT_CE_CTRL (%d)\n", err);

		/* released in battery_work() */
		__pm_stay_awake(batt_drv->poll_ws);
		batt_drv->batt_fast_update_cnt = BATT_WORK_FAST_RETRY_CNT;
		mod_delayed_work(system_wq, &batt_drv->batt_work,
				 msecs_to_jiffies(BATT_WORK_FAST_RETRY_MS));

		/* TODO: move earlier and include the change to the curve */
		ssoc_change_state(&batt_drv->ssoc_state, 1);
		changed = true;

		/* start bpst detect */
		mutex_lock(&batt_drv->bpst_state.lock);
		if (batt_drv->bpst_state.bpst_enable) {
			rc = batt_bpst_detect_begin(&batt_drv->bpst_state);
			if (rc < 0)
				pr_err("MSC_BPST: Cannot start bpst detect\n");
		}
		mutex_unlock(&batt_drv->bpst_state.lock);

		/* reset ttf tier */
		ttf_tier_reset(&batt_drv->ttf_stats);
	}

	/*
	 * enter RL in DISCHARGE on charger DONE and enter RL in RECHARGE on
	 * battery FULL (i.e. SSOC==100%). charger DONE forces the discharge
	 * curve while RECHARGE will not modify the current curve.
	 */
	if ((batt_drv->chg_state.f.flags & GBMS_CS_FLAG_DONE) != 0) {
		changed = batt_rl_enter(&batt_drv->ssoc_state,
					BATT_RL_STATUS_DISCHARGE);

		batt_drv->chg_done = true;
		batt_drv->ssoc_state.bd_trickle_eoc = true;
	} else if (batt_drv->batt_full) {
		changed = batt_rl_enter(&batt_drv->ssoc_state,
					BATT_RL_STATUS_RECHARGE);
		batt_drv->ssoc_state.bd_trickle_full = true;
	}

	err = msc_logic(batt_drv);
	if (err < 0) {
		/* NOTE: google charger will poll again. */
		batt_drv->msc_update_interval = -1;

		batt_prlog(BATT_PRLOG_ALWAYS,
			   "MSC_DOUT ERROR=%d fv_uv=%d cc_max=%d update_interval=%d\n",
			   err, batt_drv->fv_uv, batt_drv->cc_max,
			   batt_drv->msc_update_interval);

		goto msc_logic_exit;
	}

	/*
	 * TODO: might need to behave in a different way when health based
	 * charging is active
	 */
	changed |= msc_logic_health(batt_drv);
	if (CHG_HEALTH_REST_IS_AON(&batt_drv->chg_health, ssoc)) {
		batt_drv->msc_state = MSC_HEALTH_ALWAYS_ON;
		batt_drv->fv_uv = 0;
	} else if (CHG_HEALTH_REST_IS_ACTIVE(&batt_drv->chg_health)) {
		batt_drv->msc_state = MSC_HEALTH;
		/* make sure using rest_fv_uv when HEALTH_ACTIVE */
		batt_drv->fv_uv = 0;
	} else if (CHG_HEALTH_REST_IS_PAUSE(&batt_drv->chg_health)) {
		batt_drv->msc_state = MSC_HEALTH_PAUSE;
	}

msc_logic_done:

	/* set ->cc_max = 0 on RL and SW_JEITA, no vote on interval in RL_DSG */
	if (batt_drv->ssoc_state.rl_status == BATT_RL_STATUS_DISCHARGE) {
		log_vote_level = batt_prlog_level(batt_drv->cc_max != 0);
		batt_drv->msc_update_interval = -1;
		batt_drv->cc_max = 0;
	}

	jeita_stop = batt_drv->jeita_stop_charging == 1;
	if (jeita_stop) {
		log_vote_level = batt_prlog_level(batt_drv->cc_max != 0);
		batt_drv->cc_max = 0;
	}

	if (changed)
		log_vote_level = BATT_PRLOG_ALWAYS;
	batt_prlog(log_vote_level,
		   "%s msc_state=%d cv_cnt=%d ov_cnt=%d rl_sts=%d temp_idx:%d, vbatt_idx:%d  fv_uv=%d cc_max=%d update_interval=%d\n",
		   (disable_votes) ? "MSC_DOUT" : "MSC_VOTE",
		   batt_drv->msc_state,
		   batt_drv->checked_cv_cnt, batt_drv->checked_ov_cnt,
		   batt_drv->ssoc_state.rl_status,
		   batt_drv->temp_idx, batt_drv->vbatt_idx,
		   batt_drv->fv_uv, batt_drv->cc_max,
		   batt_drv->msc_update_interval);

	 /*
	  * google_charger has voted(<=0) on msc_interval_votable and the
	  * votes on fcc and fv_uv will not be applied until google_charger
	  * votes a non-zero value.
	  *
	  * SW_JEITA: ->jeita_stop_charging != 0
	  * . ->msc_update_interval = -1 , fv_uv = -1 and ->cc_max = 0
	  * . vote(0) on ->fcc_votable with SW_JEITA_VOTER
	  * BATT_RL: rl_status == BATT_RL_STATUS_DISCHARGE
	  * . ->msc_update_interval = -1 , fv_uv = -1 and ->cc_max = 0
	  * . vote(0) on ->fcc_votable with SW_JEITA_VOTER
	  *
	  * Votes for MSC_LOGIC_VOTER will be all disabled.
	  */
	if (!batt_drv->fv_votable)
		batt_drv->fv_votable =
			gvotable_election_get_handle(VOTABLE_MSC_FV);
	if (batt_drv->fv_votable) {
		const int rest_fv_uv = batt_drv->chg_health.rest_fv_uv;

		gvotable_cast_int_vote(batt_drv->fv_votable,
				       MSC_LOGIC_VOTER, batt_drv->fv_uv,
				       !disable_votes && (batt_drv->fv_uv > 0));

		gvotable_cast_int_vote(batt_drv->fv_votable,
				       MSC_HEALTH_VOTER, rest_fv_uv,
				       !disable_votes && (rest_fv_uv > 0));
	}

	if (!batt_drv->fcc_votable)
		batt_drv->fcc_votable =
			gvotable_election_get_handle(VOTABLE_MSC_FCC);
	if (batt_drv->fcc_votable) {
		enum batt_rl_status rl_status = batt_drv->ssoc_state.rl_status;
		const int rest_cc_max = batt_drv->chg_health.rest_cc_max;
		struct batt_bpst *bpst_state = &batt_drv->bpst_state;

		/* while in RL => ->cc_max != -1 && ->fv_uv != -1 */
		gvotable_cast_int_vote(batt_drv->fcc_votable, RL_STATE_VOTER, 0,
				       !disable_votes &&
				       (rl_status == BATT_RL_STATUS_DISCHARGE));

		/* jeita_stop_charging != 0 => ->fv_uv = -1 && cc_max == -1 */
		gvotable_cast_int_vote(batt_drv->fcc_votable, SW_JEITA_VOTER, 0,
				       !disable_votes && jeita_stop);

		/* health based charging */
		gvotable_cast_int_vote(batt_drv->fcc_votable,
				       MSC_HEALTH_VOTER, rest_cc_max,
				       !disable_votes && (rest_cc_max != -1));

		gvotable_cast_int_vote(batt_drv->fcc_votable,
				       MSC_LOGIC_VOTER, batt_drv->cc_max,
				       !disable_votes &&
				       (batt_drv->cc_max != -1));

		/* bpst detection */
		if (bpst_state->bpst_detect_disable || bpst_state->bpst_cell_fault) {
			const int chg_rate = batt_drv->bpst_state.bpst_chg_rate;
			const int bpst_cc_max = (batt_drv->cc_max == -1) ? batt_drv->cc_max
							: ((batt_drv->cc_max * chg_rate) / 100);

			gvotable_cast_int_vote(batt_drv->fcc_votable,
					       BPST_DETECT_VOTER, bpst_cc_max,
					       !disable_votes &&
					       (bpst_cc_max != -1));
		}
	}

	/* Fan level can be updated only during power transfer */
	if (batt_drv->fan_level_votable) {
		int level = fan_calculate_level(batt_drv);

		gvotable_cast_int_vote(batt_drv->fan_level_votable,
				       "MSC_BATT", level, true);
		pr_debug("MSC_FAN_LVL: level=%d\n", level);
	}

	if (!batt_drv->msc_interval_votable)
		batt_drv->msc_interval_votable =
			gvotable_election_get_handle(VOTABLE_MSC_INTERVAL);
	if (batt_drv->msc_interval_votable)
		gvotable_cast_int_vote(batt_drv->msc_interval_votable,
				       MSC_LOGIC_VOTER,
				       batt_drv->msc_update_interval,
				       !disable_votes &&
				       (batt_drv->msc_update_interval != -1));

	batt_update_csi_info(batt_drv);

msc_logic_exit:

	if (changed) {
		dump_ssoc_state(&batt_drv->ssoc_state, batt_drv->ssoc_log);
		if (batt_drv->psy)
			power_supply_changed(batt_drv->psy);
	}

	__pm_relax(batt_drv->msc_ws);
	return err;
}

static struct device_node *batt_id_node(struct batt_drv *batt_drv)
{
	struct device_node *config_node = batt_drv->device->of_node;
	struct device_node *child_node;
	int ret = 0;
	u32 batt_id, gbatt_id;

	ret = gbms_storage_read(GBMS_TAG_BRID, &batt_id, sizeof(batt_id));
	if (ret < 0) {
		pr_warn("Failed to get batt_id (%d)\n", ret);
		return config_node;
	}

	for_each_child_of_node(config_node, child_node) {
		ret = of_property_read_u32(child_node, "google,batt-id",
					   &gbatt_id);
		if (ret != 0)
			continue;

		if (batt_id == gbatt_id)
			return child_node;
	}

	return config_node;
}

/* charge profile not in battery */
static int batt_init_chg_profile(struct batt_drv *batt_drv)
{
	struct gbms_chg_profile *profile = &batt_drv->chg_profile;
	struct device_node *node = batt_drv->device->of_node;
	int ret = 0;

	/* handle retry */
	if (!profile->cccm_limits) {
		ret = gbms_init_chg_profile(profile, node);
		if (ret < 0)
			return -EINVAL;
	}

	/* this is in mAh */
	ret = of_property_read_u32(node, "google,chg-battery-capacity",
				   &batt_drv->battery_capacity);
	if (ret < 0)
		pr_warn("read chg-battery-capacity from gauge\n");

	/*
	 * use battery FULL design when is not specified in DT. When battery is
	 * not present use default capacity from DT (if present) or disable
	 * charging altogether.
	 */
	if (batt_drv->battery_capacity == 0) {
		u32 fc = 0;
		struct power_supply *fg_psy = batt_drv->fg_psy;

		if (batt_drv->batt_present) {
			fc = GPSY_GET_PROP(fg_psy, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN);
			if (fc == -EAGAIN)
				return -EPROBE_DEFER;
			if (fc > 0) {
				pr_info("successfully read charging profile:\n");
				/* convert uA to mAh*/
				batt_drv->battery_capacity = fc / 1000;
			}

		}

		if (batt_drv->battery_capacity == 0) {
			struct device_node *node = batt_drv->device->of_node;

			ret = of_property_read_u32(node,
					"google,chg-battery-default-capacity",
						&batt_drv->battery_capacity);
			if (ret < 0)
				pr_warn("battery not present, no default capacity, zero charge table\n");
			else
				pr_warn("battery not present, using default capacity\n");
		}
	}

	/* TODO: dump the AACR table if supported */
	ret = gbms_read_aacr_limits(profile, batt_id_node(batt_drv));
	if (ret == 0)
		pr_info("AACR: supported\n");

	/* aacr tables enable AACR by default UNLESS explicitly disabled */
	ret = of_property_read_bool(node, "google,aacr-disable");
	if (!ret && profile->aacr_nb_limits)
		batt_drv->aacr_state = BATT_AACR_ENABLED;

	ret = of_property_read_u32(node, "google,aacr-algo", &batt_drv->aacr_algo);
	if (ret < 0)
		batt_drv->aacr_algo = BATT_AACR_ALGO_DEFAULT;

	/* NOTE: with NG charger tolerance is applied from "charger" */
	gbms_init_chg_table(profile, node, aacr_get_capacity(batt_drv));

	return 0;
}

/* ------------------------------------------------------------------------- */

/* call holding mutex_unlock(&ccd->lock); */
static int batt_cycle_count_store(struct gbatt_ccbin_data *ccd)
{
	int ret;

	ret = gbms_storage_write(GBMS_TAG_BCNT, ccd->count, sizeof(ccd->count));
	if (ret < 0 && ret != -ENOENT) {
		pr_err("failed to set bin_counts ret=%d\n", ret);
		return ret;
	}

	return 0;
}

/* call holding mutex_unlock(&ccd->lock); */
static int batt_cycle_count_load(struct gbatt_ccbin_data *ccd)
{
	int ret, i;

	ret = gbms_storage_read(GBMS_TAG_BCNT, ccd->count, sizeof(ccd->count));
	if (ret < 0 && ret != -ENOENT) {
		pr_err("failed to get bin_counts ret=%d\n", ret);
		return ret;
	}

	for (i = 0; i < GBMS_CCBIN_BUCKET_COUNT; i++)
		if (ccd->count[i] == 0xFFFF)
			ccd->count[i] = 0;

	ccd->prev_soc = -1;
	return 0;
}

/* update only when SSOC is increasing, not need to check charging */
static void batt_cycle_count_update(struct batt_drv *batt_drv, int soc)
{
	struct gbatt_ccbin_data *ccd = &batt_drv->cc_data;

	if (soc < 0 || soc > 100)
		return;

	mutex_lock(&ccd->lock);

	if (ccd->prev_soc != -1 && soc > ccd->prev_soc) {
		int bucket, cnt;

		for (cnt = soc ; cnt > ccd->prev_soc ; cnt--) {
			/* cnt decremented by 1 for bucket symmetry */
			bucket = (cnt - 1) * GBMS_CCBIN_BUCKET_COUNT / 100;
			ccd->count[bucket]++;
		}

		/* NOTE: could store on FULL or disconnect instead */
		(void)batt_cycle_count_store(ccd);
	}

	ccd->prev_soc = soc;

	mutex_unlock(&ccd->lock);
}

/* ------------------------------------------------------------------------- */

#ifdef CONFIG_DEBUG_FS

static ssize_t cycle_counts_store(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret;

	mutex_lock(&batt_drv->cc_data.lock);

	ret = gbms_cycle_count_sscan(batt_drv->cc_data.count, buf);
	if (ret == 0) {
		ret = batt_cycle_count_store(&batt_drv->cc_data);
		if (ret < 0)
			pr_err("cannot store bin count ret=%d\n", ret);
	}

	if (ret == 0)
		ret = count;

	mutex_unlock(&batt_drv->cc_data.lock);

	return ret;
}

static ssize_t cycle_counts_show(struct device *dev,
				 struct device_attribute *attr,
				 char *buff)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int len;

	mutex_lock(&batt_drv->cc_data.lock);
	len = gbms_cycle_count_cstr(buff, PAGE_SIZE, batt_drv->cc_data.count);
	mutex_unlock(&batt_drv->cc_data.lock);

	return len;
}

static const DEVICE_ATTR_RW(cycle_counts);

static ssize_t resistance_show(struct device *dev,
				   struct device_attribute *attr,
				   char *buff)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int value = -1;

	if (batt_drv->fg_psy)
		value = GPSY_GET_PROP(batt_drv->fg_psy, GBMS_PROP_RESISTANCE);

	return scnprintf(buff, PAGE_SIZE, "%d\n", value);
}

static const DEVICE_ATTR_RO(resistance);

static ssize_t resistance_avg_show(struct device *dev,
				   struct device_attribute *attr,
				   char *buff)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	/* resistance_avg is scaled */
	return scnprintf(buff, PAGE_SIZE, "%d\n",
			 batt_ravg_value(&batt_drv->health_data.bhi_data.res_state));
}

static const DEVICE_ATTR_RO(resistance_avg);

static ssize_t charge_full_estimate_show(struct device *dev,
				   struct device_attribute *attr,
				   char *buff)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int value = -1;

	if (batt_drv->fg_psy)
		value = GPSY_GET_PROP(batt_drv->fg_psy, GBMS_PROP_CHARGE_FULL_ESTIMATE);

	return scnprintf(buff, PAGE_SIZE, "%d\n", value);
}

static const DEVICE_ATTR_RO(charge_full_estimate);


static int cycle_count_bins_store(void *data, u64 val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;
	int ret;

	mutex_lock(&batt_drv->cc_data.lock);
	ret = batt_cycle_count_store(&batt_drv->cc_data);
	if (ret < 0)
		pr_err("cannot store bin count ret=%d\n", ret);
	mutex_unlock(&batt_drv->cc_data.lock);

	return ret;
}

static int cycle_count_bins_reload(void *data, u64 *val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;
	int ret;

	mutex_lock(&batt_drv->cc_data.lock);
	ret = batt_cycle_count_load(&batt_drv->cc_data);
	if (ret < 0)
		pr_err("cannot restore bin count ret=%d\n", ret);
	mutex_unlock(&batt_drv->cc_data.lock);
	*val = ret;

	return ret;
}

DEFINE_SIMPLE_ATTRIBUTE(cycle_count_bins_sync_fops,
				cycle_count_bins_reload,
				cycle_count_bins_store, "%llu\n");


static int debug_get_ssoc_gdf(void *data, u64 *val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;
	*val = batt_drv->ssoc_state.ssoc_gdf;
	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(debug_ssoc_gdf_fops, debug_get_ssoc_gdf, NULL, "%llu\n");


static int debug_get_ssoc_uic(void *data, u64 *val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;
	*val = batt_drv->ssoc_state.ssoc_uic;
	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(debug_ssoc_uic_fops, debug_get_ssoc_uic, NULL, "%llu\n");

static int debug_get_ssoc_rls(void *data, u64 *val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	mutex_lock(&batt_drv->chg_lock);
	*val = batt_drv->ssoc_state.rl_status;
	mutex_unlock(&batt_drv->chg_lock);

	return 0;
}

static int debug_set_ssoc_rls(void *data, u64 val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	if (val < 0 || val > 2)
		return -EINVAL;

	mutex_lock(&batt_drv->chg_lock);
	batt_drv->ssoc_state.rl_status = val;
	if (!batt_drv->fcc_votable)
		batt_drv->fcc_votable =
			gvotable_election_get_handle(VOTABLE_MSC_FCC);
	if (batt_drv->fcc_votable)
		gvotable_cast_int_vote(batt_drv->fcc_votable, RL_STATE_VOTER, 0,
				       batt_drv->ssoc_state.rl_status ==
				       BATT_RL_STATUS_DISCHARGE);
	mutex_unlock(&batt_drv->chg_lock);

	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(debug_ssoc_rls_fops,
				debug_get_ssoc_rls, debug_set_ssoc_rls, "%llu\n");


static ssize_t debug_get_ssoc_uicurve(struct file *filp,
					   char __user *buf,
					   size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	char tmp[UICURVE_BUF_SZ] = { 0 };

	mutex_lock(&batt_drv->chg_lock);
	ssoc_uicurve_cstr(tmp, sizeof(tmp), batt_drv->ssoc_state.ssoc_curve);
	mutex_unlock(&batt_drv->chg_lock);

	return simple_read_from_buffer(buf, count, ppos, tmp, strlen(tmp));
}

static ssize_t debug_set_ssoc_uicurve(struct file *filp,
					 const char __user *user_buf,
					 size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	int ret, curve_type;
	char buf[8];

	ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
	if (!ret)
		return -EFAULT;

	mutex_lock(&batt_drv->chg_lock);

	/* FIX: BatteryDefenderUI doesn't really handle this yet */
	curve_type = (int)simple_strtoull(buf, NULL, 10);
	if (curve_type >= -1 && curve_type <= 1)
		ssoc_change_curve(&batt_drv->ssoc_state, 0, curve_type);
	else
		ret = -EINVAL;

	mutex_unlock(&batt_drv->chg_lock);

	if (ret == 0)
		ret = count;

	return 0;
}

BATTERY_DEBUG_ATTRIBUTE(debug_ssoc_uicurve_cstr_fops,
					debug_get_ssoc_uicurve,
					debug_set_ssoc_uicurve);

static int debug_force_psy_update(void *data, u64 val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	if (!batt_drv->psy)
		return -EINVAL;

	power_supply_changed(batt_drv->psy);
	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(debug_force_psy_update_fops,
				NULL, debug_force_psy_update, "%llu\n");

/* Adaptive Charging */
static int debug_chg_health_rest_rate_read(void *data, u64 *val)
{
	struct batt_drv *batt_drv = data;

	if (!batt_drv->psy)
		return -EINVAL;

	*val = batt_drv->chg_health.rest_rate;
	return 0;
}

/* Adaptive Charging */
static int debug_chg_health_rest_rate_write(void *data, u64 val)
{
	struct batt_drv *batt_drv = data;

	if (!batt_drv->psy)
		return -EINVAL;

	batt_drv->chg_health.rest_rate = val;
	return 0;
}

/* Adaptive Charging */
DEFINE_SIMPLE_ATTRIBUTE(debug_chg_health_rest_rate_fops,
			debug_chg_health_rest_rate_read,
			debug_chg_health_rest_rate_write, "%llu\n");


/* Adaptive Charging */
static int debug_chg_health_rest_rate_before_trigger_read(void *data, u64 *val)
{
	struct batt_drv *batt_drv = data;

	if (!batt_drv->psy)
		return -EINVAL;

	*val = batt_drv->chg_health.rest_rate_before_trigger;
	return 0;
}

/* Adaptive Charging */
static int debug_chg_health_rest_rate_before_trigger_write(void *data, u64 val)
{
	struct batt_drv *batt_drv = data;

	if (!batt_drv->psy)
		return -EINVAL;

	batt_drv->chg_health.rest_rate_before_trigger = val;
	return 0;
}

/* Adaptive Charging */
DEFINE_SIMPLE_ATTRIBUTE(debug_chg_health_rest_rate_before_trigger_fops,
			debug_chg_health_rest_rate_before_trigger_read,
			debug_chg_health_rest_rate_before_trigger_write, "%llu\n");

/* Adaptive Charging */
static int debug_chg_health_thr_soc_read(void *data, u64 *val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	if (!batt_drv->psy)
		return -EINVAL;

	*val = batt_drv->chg_health.rest_soc;
	return 0;
}

/* Adaptive Charging */
static int debug_chg_health_thr_soc_write(void *data, u64 val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	if (!batt_drv->psy)
		return -EINVAL;

	batt_drv->chg_health.rest_soc = val;
	return 0;
}

/* Adaptive Charging */
DEFINE_SIMPLE_ATTRIBUTE(debug_chg_health_thr_soc_fops,
			debug_chg_health_thr_soc_read,
			debug_chg_health_thr_soc_write, "%llu\n");

/* Adaptive Charging */
static int debug_chg_health_set_stage(void *data, u64 val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	if (!batt_drv->psy)
		return -EINVAL;

	switch (val) {
	case CHG_HEALTH_DISABLED:
	case CHG_HEALTH_INACTIVE:
	case CHG_HEALTH_ENABLED:
	case CHG_HEALTH_ACTIVE:
	case CHG_HEALTH_DONE:
		break;
	default:
		return -EINVAL;
	}

	batt_drv->chg_health.rest_state = val;
	return 0;
}

/* Adaptive Charging */
DEFINE_SIMPLE_ATTRIBUTE(debug_chg_health_stage_fops, NULL,
			debug_chg_health_set_stage, "%llu\n");

/* debug variable */
static int raw_profile_cycles;

static ssize_t debug_get_chg_raw_profile(struct file *filp,
					 char __user *buf,
					 size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	char *tmp;
	int len;

	tmp = kzalloc(PAGE_SIZE, GFP_KERNEL);
	if (!tmp)
		return -ENOMEM;

	if (raw_profile_cycles) {
		struct gbms_chg_profile profile;
		int count;

		len = gbms_init_chg_profile(&profile, batt_drv->device->of_node);
		if (len < 0)
			goto exit_done;

		/* len is the capacity */
		len = aacr_get_capacity_at_cycle(batt_drv, raw_profile_cycles);
		if (len <= 0) {
			gbms_free_chg_profile(&profile);
			goto exit_done;
		}

		count = scnprintf(tmp, PAGE_SIZE, "AACR Profile at %d cycles\n",
				  raw_profile_cycles);
		gbms_init_chg_table(&profile, batt_drv->device->of_node, len);
		gbms_dump_chg_profile(&tmp[count], PAGE_SIZE - count, &profile);
		gbms_free_chg_profile(&profile);
	} else {
		gbms_dump_chg_profile(tmp, PAGE_SIZE, &batt_drv->chg_profile);
	}

	len = simple_read_from_buffer(buf, count, ppos, tmp, strlen(tmp));

exit_done:
	kfree(tmp);
	return len;
}

static ssize_t debug_set_chg_raw_profile(struct file *filp,
					 const char __user *user_buf,
					 size_t count, loff_t *ppos)
{
	int ret = 0, val;
	char buf[8];

	ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
	if (!ret)
		return -EFAULT;

	buf[ret] = '\0';
	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	raw_profile_cycles = val;
	return count;
}

BATTERY_DEBUG_ATTRIBUTE(debug_chg_raw_profile_fops,
			debug_get_chg_raw_profile,
			debug_set_chg_raw_profile);

static ssize_t debug_get_power_metrics(struct file *filp, char __user *buf,
				       size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	char *tmp;
	int idx, len = 0;

	tmp = kzalloc(PAGE_SIZE, GFP_KERNEL);
	if (!tmp)
		return -ENOMEM;

	for(idx = 0; idx < POWER_METRICS_MAX_DATA; idx++) {
		len += scnprintf(&tmp[len], PAGE_SIZE - len, "%2d: %8ld/%8ld - %5lld\n", idx,
				 batt_drv->power_metrics.data[idx].voltage,
				 batt_drv->power_metrics.data[idx].charge_count,
				 batt_drv->power_metrics.data[idx].time);
	}

	len = simple_read_from_buffer(buf, count, ppos, tmp, strlen(tmp));
	kfree(tmp);

	return len;
}

BATTERY_DEBUG_ATTRIBUTE(debug_power_metrics_fops, debug_get_power_metrics, NULL);

static int debug_bpst_sbd_status_read(void *data, u64 *val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	*val = batt_drv->bpst_state.bpst_sbd_status;
	return 0;
}

static int debug_bpst_sbd_status_write(void *data, u64 val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;

	if (val < 0 || val > 1)
		return -EINVAL;

	mutex_lock(&batt_drv->bpst_state.lock);
	batt_drv->bpst_state.bpst_sbd_status = val;
	mutex_unlock(&batt_drv->bpst_state.lock);

	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(debug_bpst_sbd_status_fops,
			debug_bpst_sbd_status_read,
			debug_bpst_sbd_status_write, "%llu\n");

static int debug_ravg_fops_write(void *data, u64 val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)data;
	struct batt_res *res_state = &batt_drv->health_data.bhi_data.res_state;
	int resistance_avg = val / 100, filter_count = 1;
	int ret;

	mutex_lock(&batt_drv->chg_lock);

	batt_res_state_set(res_state, false);
	res_state->resistance_avg = resistance_avg;
	res_state->filter_count = filter_count;

	/* reset storage to defaults */
	if (val == 0) {
		resistance_avg = 0xffff;
		filter_count = 0xffff;
	}

	ret = batt_ravg_write(resistance_avg, filter_count);
	pr_info("RAVG: update val=%d, resistance_avg=%x filter_count=%x (%d)\n",
		(int)val, resistance_avg, filter_count, ret);
	mutex_unlock(&batt_drv->chg_lock);

	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(debug_ravg_fops, NULL, debug_ravg_fops_write, "%llu\n");


#endif

/* ------------------------------------------------------------------------- */

static ssize_t debug_get_fake_temp(struct file *filp,
					   char __user *buf,
					   size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	char tmp[8];

	mutex_lock(&batt_drv->chg_lock);
	scnprintf(tmp, sizeof(tmp), "%d\n", batt_drv->fake_temp);
	mutex_unlock(&batt_drv->chg_lock);

	return simple_read_from_buffer(buf, count, ppos, tmp, strlen(tmp));
}

static ssize_t debug_set_fake_temp(struct file *filp,
					 const char __user *user_buf,
					 size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	int ret = 0, val;
	char buf[8];

	ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
	if (!ret)
		return -EFAULT;

	buf[ret] = '\0';
	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	mutex_lock(&batt_drv->chg_lock);
	batt_drv->fake_temp = val;
	mutex_unlock(&batt_drv->chg_lock);

	return count;
}

BATTERY_DEBUG_ATTRIBUTE(debug_fake_temp_fops, debug_get_fake_temp,
			debug_set_fake_temp);


static enum batt_paired_state
batt_reset_pairing_state(const struct batt_drv *batt_drv)
{
	char dev_info[GBMS_DINF_LEN];
	int ret = 0;

	memset(dev_info, 0xff, sizeof(dev_info));
	ret = gbms_storage_write(GBMS_TAG_DINF, dev_info, sizeof(dev_info));
	if (ret < 0)
		return -EIO;

	return 0;
}

static ssize_t debug_set_pairing_state(struct file *filp,
					 const char __user *user_buf,
					 size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	int ret = 0, val;
	char buf[8];

	ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
	if (ret <= 0)
		return ret;

	buf[ret] = '\0';
	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	mutex_lock(&batt_drv->chg_lock);

	if (val == BATT_PAIRING_ENABLED) {
		batt_drv->pairing_state = BATT_PAIRING_ENABLED;
		mod_delayed_work(system_wq, &batt_drv->batt_work, 0);
	} else if (val == BATT_PAIRING_RESET) {

		/* send a paring enable to re-pair OR reboot */
		ret = batt_reset_pairing_state(batt_drv);
		if (ret == 0)
			batt_drv->pairing_state = BATT_PAIRING_DISABLED;
		else
			count = -EIO;
	} else {
		count = -EINVAL;
	}
	mutex_unlock(&batt_drv->chg_lock);

	return count;
}

BATTERY_DEBUG_ATTRIBUTE(debug_pairing_fops, 0, debug_set_pairing_state);

/* TODO: add write to stop/start collection, erase history etc. */
static ssize_t debug_get_blf_state(struct file *filp, char __user *buf,
				   size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	char tmp[8];

	mutex_lock(&batt_drv->chg_lock);
	scnprintf(tmp, sizeof(tmp), "%d\n", batt_drv->blf_state);
	mutex_unlock(&batt_drv->chg_lock);

	return simple_read_from_buffer(buf, count, ppos, tmp, strlen(tmp));
}
BATTERY_DEBUG_ATTRIBUTE(debug_blf_state_fops, debug_get_blf_state, 0);

static ssize_t debug_get_bhi_status(struct file *filp, char __user *buf,
				   size_t count, loff_t *ppos)
{
	struct batt_drv *batt_drv = (struct batt_drv *)filp->private_data;
	struct health_data *health_data = &batt_drv->health_data;
	const int cap_idx = health_data->bhi_debug_cap_index;
	const int imp_idx = health_data->bhi_debug_imp_index;
	const int sd_idx = health_data->bhi_debug_sd_index;
	const int algo = BHI_ALGO_DEBUG;
	int health_idx = health_data->bhi_debug_health_index;
	int health_status, len;
	char *tmp;

	tmp = kzalloc(PAGE_SIZE, GFP_KERNEL);
	if (!tmp)
		return -ENOMEM;

	if (health_idx == 0)
		health_idx = bhi_calc_health_index(algo, health_data, cap_idx, imp_idx, sd_idx);

	health_status = bhi_calc_health_status(algo, BHI_ROUND_INDEX(health_idx), health_data);

	if (health_data->bhi_debug_health_index != 0)
		scnprintf(tmp, PAGE_SIZE, "%d, %d\n", health_status, health_idx);
	else
		scnprintf(tmp, PAGE_SIZE, "%d, %d [%d/%d %d/%d %d/%d]\n", health_status,
			  health_idx, cap_idx, health_data->bhi_w_ci, imp_idx,
			  health_data->bhi_w_pi, sd_idx, health_data->bhi_w_sd);

	len = simple_read_from_buffer(buf, count, ppos, tmp, strlen(tmp));
	kfree(tmp);

	return len;
}
BATTERY_DEBUG_ATTRIBUTE(debug_bhi_status_fops, debug_get_bhi_status, 0);

/* TODO: add writes to restart pairing (i.e. provide key) */
static ssize_t batt_pairing_state_show(struct device *dev,
				       struct device_attribute *attr,
				       char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int len;

	mutex_lock(&batt_drv->chg_lock);
	len = scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->pairing_state);
	mutex_unlock(&batt_drv->chg_lock);
	return len;
}

static const DEVICE_ATTR(pairing_state, 0444, batt_pairing_state_show, NULL);


static ssize_t batt_ctl_chg_stats_actual(struct device *dev,
					 struct device_attribute *attr,
					 const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);

	if (count < 1)
		return -ENODATA;

	switch (buf[0]) {
	case 'p': /* publish data to qual */
	case 'P': /* force publish data to qual */
		batt_chg_stats_pub(batt_drv, "debug cmd", buf[0] == 'P', false);
		break;
	default:
		count = -EINVAL;
		break;
	}

	return count;
}

static ssize_t batt_show_chg_stats_actual(struct device *dev,
				   struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);
	int len;

	mutex_lock(&batt_drv->stats_lock);
	len = batt_chg_stats_cstr(buf, PAGE_SIZE, &batt_drv->ce_data, false);
	mutex_unlock(&batt_drv->stats_lock);

	return len;
}

static const DEVICE_ATTR(charge_stats_actual, 0664,
					     batt_show_chg_stats_actual,
					     batt_ctl_chg_stats_actual);

static ssize_t batt_ctl_chg_stats(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);

	if (count < 1)
		return -ENODATA;

	mutex_lock(&batt_drv->stats_lock);
	switch (buf[0]) {
	case 0:
	case '0': /* invalidate current qual */
		cev_stats_init(&batt_drv->ce_qual, &batt_drv->chg_profile);
		break;
	}
	mutex_unlock(&batt_drv->stats_lock);

	return count;
}

/* regular and health stats */
static ssize_t batt_chg_qual_stats_cstr(char *buff, int size,
					struct gbms_charging_event *ce_qual,
					bool verbose)
{
	ssize_t len = 0;

	len += batt_chg_stats_cstr(&buff[len], size - len, ce_qual, verbose);
	if (ce_qual->ce_health.rest_state != CHG_HEALTH_INACTIVE)
		len += batt_health_stats_cstr(&buff[len], size - len,
					      ce_qual, verbose);
	return len;
}

static ssize_t batt_show_chg_stats(struct device *dev,
				   struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);
	struct gbms_charging_event *ce_qual = &batt_drv->ce_qual;
	int len = -ENODATA;

	mutex_lock(&batt_drv->stats_lock);
	if (ce_qual->last_update - ce_qual->first_update)
		len = batt_chg_qual_stats_cstr(buf, PAGE_SIZE, ce_qual, false);
	mutex_unlock(&batt_drv->stats_lock);

	return len;
}

static const DEVICE_ATTR(charge_stats, 0664, batt_show_chg_stats,
					     batt_ctl_chg_stats);

/* show current/active and qual data */
static ssize_t batt_show_chg_details(struct device *dev,
				     struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);
	struct gbms_charging_event *ce_data = &batt_drv->ce_data;
	const bool qual_valid = (batt_drv->ce_qual.last_update -
				batt_drv->ce_qual.first_update) != 0;
	int len = 0;

	mutex_lock(&batt_drv->stats_lock);

	/* this is the current one */
	len += batt_chg_stats_cstr(&buf[len], PAGE_SIZE - len, ce_data, true);

	/*
	 * stats are accumulated in ce_data->health_stats, rest_* fields
	 * are set on stats_close()
	 */
	if (batt_drv->chg_health.rest_state != CHG_HEALTH_INACTIVE) {
		const struct gbms_ce_tier_stats *h = &batt_drv->ce_data.health_stats;
		const struct gbms_ce_tier_stats *p = &batt_drv->ce_data.health_pause_stats;
		const long elap_h = h->time_fast + h->time_taper + h->time_other;
		const long elap_p = p->time_fast + p->time_taper + p->time_other;
		const ktime_t now = get_boot_sec();
		int vti;

		vti = batt_chg_health_vti(&batt_drv->chg_health);
		len += scnprintf(&buf[len], PAGE_SIZE - len,
				"\nH: %d %d %ld %ld %lld %lld %d",
				batt_drv->chg_health.rest_state,
				vti, elap_h, elap_p, now,
				batt_drv->chg_health.rest_deadline,
				batt_drv->chg_health.always_on_soc);

		/* NOTE: vtier_idx is -1, can also check elap  */
		if (h->soc_in != -1)
			len += gbms_tier_stats_cstr(&buf[len],
						    PAGE_SIZE - len, h, !!elap_h);
		if (p->soc_in != -1)
			len += gbms_tier_stats_cstr(&buf[len],
						    PAGE_SIZE - len, p, !!elap_p);
	}

	len += scnprintf(&buf[len], PAGE_SIZE - len, "\n");

	/* this was the last one (if present) */
	if (qual_valid) {
		len += batt_chg_qual_stats_cstr(&buf[len], PAGE_SIZE - len,
						&batt_drv->ce_qual, true);
		len += scnprintf(&buf[len], PAGE_SIZE - len, "\n");
	}

	mutex_unlock(&batt_drv->stats_lock);

	return len;
}

static const DEVICE_ATTR(charge_details, 0444, batt_show_chg_details,
					       NULL);

/* tier and soc details */
static ssize_t batt_show_ttf_details(struct device *dev,
				     struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = (struct batt_drv *)
					power_supply_get_drvdata(psy);
	struct batt_ttf_stats *ttf_stats;
	int len;

	if (!batt_drv->ssoc_state.buck_enabled)
		return -ENODATA;

	ttf_stats = kzalloc(sizeof(*ttf_stats), GFP_KERNEL);
	if (!ttf_stats)
		return -ENOMEM;

	mutex_lock(&batt_drv->stats_lock);
	/* update a private copy of ttf stats */
	ttf_stats_update(ttf_stats_dup(ttf_stats, &batt_drv->ttf_stats),
			 &batt_drv->ce_data, false);
	mutex_unlock(&batt_drv->stats_lock);

	len = ttf_dump_details(buf, PAGE_SIZE, ttf_stats,
			       batt_drv->ce_data.last_soc);
	kfree(ttf_stats);

	return len;
}

static const DEVICE_ATTR(ttf_details, 0444, batt_show_ttf_details, NULL);

/* house stats */
static ssize_t batt_show_ttf_stats(struct device *dev,
				   struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);
	const int verbose = true;
	int i, len = 0;

	mutex_lock(&batt_drv->stats_lock);

	for (i = 0; i < GBMS_STATS_TIER_COUNT; i++)
		len += ttf_tier_cstr(&buf[len], PAGE_SIZE,
				     &batt_drv->ttf_stats.tier_stats[i]);

	len += scnprintf(&buf[len], PAGE_SIZE - len, "\n");

	if (verbose)
		len += ttf_soc_cstr(&buf[len], PAGE_SIZE - len,
				    &batt_drv->ttf_stats.soc_stats,
				    0, 99);

	mutex_unlock(&batt_drv->stats_lock);

	return len;
}

/* userspace restore the TTF data with this */
static ssize_t batt_ctl_ttf_stats(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	int res;
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);

	if (count < 1)
		return -ENODATA;
	if (!batt_drv->ssoc_state.buck_enabled)
		return -ENODATA;

	mutex_lock(&batt_drv->stats_lock);
	switch (buf[0]) {
	case 'u':
	case 'U': /* force update */
		ttf_stats_update(&batt_drv->ttf_stats, &batt_drv->ce_data,
				 (buf[0] == 'U'));
		break;
	default:
		/* TODO: userspace restore of the data */
		res = ttf_stats_sscan(&batt_drv->ttf_stats, buf, count);
		if (res < 0)
			count = res;
		break;
	}
	mutex_unlock(&batt_drv->stats_lock);

	return count;
}

static const DEVICE_ATTR(ttf_stats, 0664, batt_show_ttf_stats,
					  batt_ctl_ttf_stats);

/* ------------------------------------------------------------------------- */

static ssize_t chg_health_show_stage(struct device *dev,
				     struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = (struct batt_drv *)
					power_supply_get_drvdata(psy);
	const char *s = "Inactive";

	mutex_lock(&batt_drv->chg_lock);
	switch (batt_drv->chg_health.rest_state) {
	case CHG_HEALTH_DISABLED:
		s = "Disabled";
		break;
	case CHG_HEALTH_ENABLED:
		s = "Enabled";
		break;
	case CHG_HEALTH_PAUSE:
	case CHG_HEALTH_ACTIVE:
		s = "Active";
		break;
	case CHG_HEALTH_DONE:
		s = "Done";
		break;
	default:
		break;
	}
	mutex_unlock(&batt_drv->chg_lock);

	return scnprintf(buf, PAGE_SIZE, "%s\n", s);
}

static const DEVICE_ATTR(charge_stage, 0444, chg_health_show_stage, NULL);

static ssize_t chg_health_charge_limit_get(struct device *dev,
					   struct device_attribute *attr,
					   char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 batt_drv->chg_health.always_on_soc);
}
/* setting disable (deadline = -1) or replug (deadline == 0) will disable */
static ssize_t chg_health_charge_limit_set(struct device *dev,
					   struct device_attribute *attr,
					   const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);
	const int always_on_soc = simple_strtol(buf, NULL, 10);
	enum chg_health_state rest_state;

	/* Always enable AC when SOC is over trigger */
	if (always_on_soc < -1 || always_on_soc > 99)
		return -EINVAL;

	mutex_lock(&batt_drv->chg_lock);

	/*
	 * There are interesting overlaps with the AC standard behavior since
	 * the aon limit can be set at any time (and while AC limit is active)
	 * TODO: fully document the state machine
	 */
	rest_state = batt_drv->chg_health.rest_state;

	if (always_on_soc != -1) {
		switch (rest_state) {
		case CHG_HEALTH_DISABLED: /* didn't meet deadline */
		case CHG_HEALTH_INACTIVE: /* deadline was not provided */
			rest_state = CHG_HEALTH_ENABLED;
			break;
		default:
			/* _DONE, _ENABLED, _ACTIVE, _USER_DISABLED */
			break;
		}
	} else if (batt_drv->chg_health.always_on_soc != -1) {

		switch (rest_state) {
		case CHG_HEALTH_ENABLED: /* waiting for always_on_soc */
		case CHG_HEALTH_ACTIVE: /* activated at always_on_soc */
			if (batt_drv->chg_health.rest_deadline > 0)
				rest_state = CHG_HEALTH_ENABLED;
			else
				rest_state = CHG_HEALTH_INACTIVE;
			break;
		default:
			/* _DONE, _DISABLED, _USER_DISABLED */
			break;
		}
	}

	batt_drv->chg_health.always_on_soc = always_on_soc;
	batt_drv->chg_health.rest_state = rest_state;

	mutex_unlock(&batt_drv->chg_lock);
	power_supply_changed(batt_drv->psy);
	return count;
}

static DEVICE_ATTR(charge_limit, 0660, chg_health_charge_limit_get,
		   chg_health_charge_limit_set);

static ssize_t batt_show_chg_deadline(struct device *dev,
				      struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);
	const struct batt_chg_health *rest = &batt_drv->chg_health;
	const bool aon_enabled = rest->always_on_soc != -1;
	const ktime_t now = get_boot_sec();
	long long deadline = 0;
	ktime_t ttf = 0;
	int ret = 0;

	mutex_lock(&batt_drv->chg_lock);

	/*
	 * = (rest_deadline <= 0) means state is either Inactive or Disabled
	 * = (rest_deadline < now) means state is either Done or Disabled
	 *
	 * State becomes Disabled from Enabled or Active when/if msc_logic()
	 * determines that the device cannot reach full before the deadline.
	 *
	 * UI checks for:
	 *   (stage == 'Active' || stage == 'Enabled') && deadline > 0
	 */
	deadline = batt_drv->chg_health.rest_deadline;

	/* ACA: show time to full when ACA triggered */
	if (aon_enabled && rest->rest_state == CHG_HEALTH_ACTIVE) {
		ret = batt_ttf_estimate(&ttf, batt_drv);
		if (ret < 0)
			pr_debug("unable to get ttf (%d)\n", ret);
		else
			deadline = now + ttf;
	}

	if (deadline > 0 && deadline > now)
		deadline -= now;
	else if (deadline > 0)
		deadline = 0;

	mutex_unlock(&batt_drv->chg_lock);

	/*
	 * deadline < 0 feature disabled. deadline = 0 expired or disabled for
	 * this session, deadline > 0 time to deadline otherwise.
	 */
	return scnprintf(buf, PAGE_SIZE, "%lld\n", (long long)deadline);
}

/* userspace restore the TTF data with this */
static ssize_t batt_set_chg_deadline(struct device *dev,
				     struct device_attribute *attr,
				     const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);
	long long deadline_s;
	bool changed;

	/* API works in seconds */
	deadline_s = simple_strtoll(buf, NULL, 10);

	mutex_lock(&batt_drv->chg_lock);
	/* Let deadline < 0 pass to set stats */
	if (!batt_drv->ssoc_state.buck_enabled && deadline_s >= 0) {
		mutex_unlock(&batt_drv->chg_lock);
		return -EINVAL;
	}

	changed = batt_health_set_chg_deadline(&batt_drv->chg_health,
					       deadline_s);
	mutex_unlock(&batt_drv->chg_lock);

	if (changed)
		power_supply_changed(batt_drv->psy);

	gbms_logbuffer_prlog(batt_drv->ttf_stats.ttf_log, LOGLEVEL_INFO, 0, LOGLEVEL_DEBUG,
			     "MSC_HEALTH: deadline_s=%lld deadline at %lld",
			     deadline_s, batt_drv->chg_health.rest_deadline);

	return count;
}

static const DEVICE_ATTR(charge_deadline, 0664, batt_show_chg_deadline,
						batt_set_chg_deadline);

static ssize_t charge_deadline_dryrun_store(struct device *dev,
					    struct device_attribute *attr,
					    const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =
		(struct batt_drv *)power_supply_get_drvdata(psy);
	long long deadline_s;

	/* API works in seconds */
	deadline_s = simple_strtoll(buf, NULL, 10);

	mutex_lock(&batt_drv->chg_lock);
	if (!batt_drv->ssoc_state.buck_enabled || deadline_s < 0) {
		mutex_unlock(&batt_drv->chg_lock);
		return -EINVAL;
	}
	batt_drv->chg_health.dry_run_deadline = get_boot_sec() + deadline_s;
	mutex_unlock(&batt_drv->chg_lock);

	return count;
}

static DEVICE_ATTR_WO(charge_deadline_dryrun);

enum batt_ssoc_status {
	BATT_SSOC_STATUS_UNKNOWN = 0,
	BATT_SSOC_STATUS_CONNECTED = 1,
	BATT_SSOC_STATUS_DISCONNECTED = 2,
	BATT_SSOC_STATUS_FULL = 3,
};

static ssize_t ssoc_details_show(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	int len = 0;
	enum batt_ssoc_status status = BATT_SSOC_STATUS_UNKNOWN;
	char buff[UICURVE_BUF_SZ] = { 0 };

	mutex_lock(&batt_drv->chg_lock);

	if (ssoc_state->buck_enabled == 0) {
		status = BATT_SSOC_STATUS_DISCONNECTED;
	} else if (ssoc_state->buck_enabled == 1) {
		if (batt_drv->batt_full)
			status = BATT_SSOC_STATUS_FULL;
		else
			status = BATT_SSOC_STATUS_CONNECTED;
	}

	len = scnprintf(
		buf, sizeof(ssoc_state->ssoc_state_cstr),
		"soc: l=%d%% gdf=%d.%02d uic=%d.%02d rl=%d.%02d\n"
		"curve:%s\n"
		"status: ct=%d rl=%d s=%d\n",
		ssoc_get_capacity(ssoc_state), qnum_toint(ssoc_state->ssoc_gdf),
		qnum_fracdgt(ssoc_state->ssoc_gdf),
		qnum_toint(ssoc_state->ssoc_uic),
		qnum_fracdgt(ssoc_state->ssoc_uic),
		qnum_toint(ssoc_state->ssoc_rl),
		qnum_fracdgt(ssoc_state->ssoc_rl),
		ssoc_uicurve_cstr(buff, sizeof(buff), ssoc_state->ssoc_curve),
		ssoc_state->ssoc_curve_type, ssoc_state->rl_status, status);

	mutex_unlock(&batt_drv->chg_lock);

	return len;
}

static const DEVICE_ATTR_RO(ssoc_details);

static ssize_t show_bd_trickle_enable(struct device *dev,
				      struct device_attribute *attr,
				      char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 batt_drv->ssoc_state.bd_trickle_enable);
}

static ssize_t set_bd_trickle_enable(struct device *dev,
				     struct device_attribute *attr,
				     const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret = 0, val;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	batt_drv->ssoc_state.bd_trickle_enable = !!val;

	return count;
}

static DEVICE_ATTR(bd_trickle_enable, 0660,
		   show_bd_trickle_enable, set_bd_trickle_enable);

static ssize_t show_bd_trickle_cnt(struct device *dev,
				   struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 batt_drv->ssoc_state.bd_trickle_cnt);
}

static ssize_t set_bd_trickle_cnt(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret = 0, val;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	batt_drv->ssoc_state.bd_trickle_cnt = val;

	return count;
}

static DEVICE_ATTR(bd_trickle_cnt, 0660,
		   show_bd_trickle_cnt, set_bd_trickle_cnt);

static ssize_t show_bd_trickle_recharge_soc(struct device *dev,
					    struct device_attribute *attr,
					    char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 batt_drv->ssoc_state.bd_trickle_recharge_soc);
}

#define BD_RL_SOC_FULL		100
#define BD_RL_SOC_LOW		50
static ssize_t set_bd_trickle_recharge_soc(struct device *dev,
					   struct device_attribute *attr,
					   const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret = 0, val;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	if ((val >= BD_RL_SOC_FULL) || (val < BD_RL_SOC_LOW))
		return count;

	batt_drv->ssoc_state.bd_trickle_recharge_soc = val;

	return count;
}

static DEVICE_ATTR(bd_trickle_recharge_soc, 0660,
		   show_bd_trickle_recharge_soc, set_bd_trickle_recharge_soc);

static ssize_t show_bd_trickle_dry_run(struct device *dev,
				       struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 batt_drv->ssoc_state.bd_trickle_dry_run);
}

static ssize_t set_bd_trickle_dry_run(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret = 0, val;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	batt_drv->ssoc_state.bd_trickle_dry_run = val ? true : false;

	return count;
}

static DEVICE_ATTR(bd_trickle_dry_run, 0660,
		   show_bd_trickle_dry_run, set_bd_trickle_dry_run);

static ssize_t show_bd_trickle_reset_sec(struct device *dev,
					 struct device_attribute *attr,
					 char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 batt_drv->ssoc_state.bd_trickle_reset_sec);
}

static ssize_t set_bd_trickle_reset_sec(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	unsigned int val;
	int ret = 0;

	ret = kstrtouint(buf, 0, &val);
	if (ret < 0)
		return ret;

	batt_drv->ssoc_state.bd_trickle_reset_sec = val;

	return count;
}

static DEVICE_ATTR(bd_trickle_reset_sec, 0660,
		   show_bd_trickle_reset_sec, set_bd_trickle_reset_sec);

static ssize_t bd_clear_store(struct device *dev,
			      struct device_attribute *attr,
			      const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret = 0, val = 0;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	if (val)
		bd_trickle_reset(&batt_drv->ssoc_state, &batt_drv->ce_data);

	return count;
}

static DEVICE_ATTR_WO(bd_clear);

static ssize_t batt_show_time_to_ac(struct device *dev,
				    struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);
	const int soc = CHG_HEALTH_REST_SOC(&batt_drv->chg_health);
	qnum_t soc_raw = ssoc_get_capacity_raw(&batt_drv->ssoc_state);
	qnum_t soc_health = qnum_fromint(soc);
	ktime_t estimate;
	int rc;

	rc = ttf_soc_estimate(&estimate, &batt_drv->ttf_stats,
			      &batt_drv->ce_data, soc_raw,
			      soc_health - qnum_rconst(SOC_ROUND_BASE));
	if (rc < 0)
		estimate = -1;

	if (estimate == -1)
		return -ERANGE;

	return scnprintf(buf, PAGE_SIZE, "%lld\n", (long long)estimate);
}

static const DEVICE_ATTR(time_to_ac, 0444, batt_show_time_to_ac, NULL);

static ssize_t batt_show_ac_soc(struct device *dev,
				    struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv =(struct batt_drv *)
					power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 CHG_HEALTH_REST_SOC(&batt_drv->chg_health));
}

static const DEVICE_ATTR(ac_soc, 0444, batt_show_ac_soc, NULL);


static ssize_t batt_show_charger_state(struct device *dev,
				       struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "0x%llx\n", batt_drv->chg_state.v);
}

static const DEVICE_ATTR(charger_state, 0444, batt_show_charger_state, NULL);


static ssize_t batt_show_charge_type(struct device *dev,
				       struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->chg_state.f.chg_type);
}

static const DEVICE_ATTR(charge_type, 0444, batt_show_charge_type, NULL);


static ssize_t batt_show_constant_charge_current(struct device *dev,
				       struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->cc_max);
}

static const DEVICE_ATTR(constant_charge_current, 0444,
			 batt_show_constant_charge_current, NULL);


static ssize_t batt_show_constant_charge_voltage(struct device *dev,
				       struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->fv_uv);
}

static const DEVICE_ATTR(constant_charge_voltage, 0444,
			 batt_show_constant_charge_voltage, NULL);

static ssize_t fan_level_store(struct device *dev,
			       struct device_attribute *attr,
			       const char *buf, size_t count) {
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret = 0;
	int level;

	ret = kstrtoint(buf, 0, &level);
	if (ret < 0)
		return ret;

	if ((level < FAN_LVL_UNKNOWN) || (level > FAN_LVL_ALARM))
		return -ERANGE;

	batt_drv->fan_level = level;

	/* always send a power supply event when forcing the value */
	if (batt_drv->psy)
		power_supply_changed(batt_drv->psy);

	return count;
}

static ssize_t fan_level_show(struct device *dev,
			      struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int result = 0;

	if (batt_drv->fan_level == -1 && batt_drv->fan_level_votable)
		result = gvotable_get_current_int_vote(
				batt_drv->fan_level_votable);
	else
		result = batt_drv->fan_level;

	return scnprintf(buf, PAGE_SIZE, "%d\n", result);
}

static const DEVICE_ATTR_RW(fan_level);

static ssize_t show_health_safety_margin(struct device *dev,
				   struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 batt_drv->health_safety_margin);
}

static ssize_t set_health_safety_margin(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret = 0, val;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	/*
	 * less than 0 is not accaptable: we will not reach full in time.
	 * set to 0 to disable PAUSE but keep AC charge
	 */
	if (val < 0)
		val = 0;

	batt_drv->health_safety_margin = val;

	return count;
}

static DEVICE_ATTR(health_safety_margin, 0660,
		    show_health_safety_margin, set_health_safety_margin);

/* BPST ------------------------------------------------------------------- */

static ssize_t bpst_reset_store(struct device *dev,
			      struct device_attribute *attr,
			      const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	struct batt_bpst *bpst_state = &batt_drv->bpst_state;
	int ret = 0, val = 0;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	if (val) {
		ret = batt_bpst_reset(bpst_state);
		if (ret < 0)
			pr_err("%s: MSC_BPST: Cannot reset GBMS_TAG_BPST (%d)\n", __func__, ret);
	}

	return count;
}

static DEVICE_ATTR_WO(bpst_reset);

static ssize_t show_bpst_detect_disable(struct device *dev,
				        struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 batt_drv->bpst_state.bpst_detect_disable);
}

static ssize_t set_bpst_detect_disable(struct device *dev,
				       struct device_attribute *attr,
				       const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int ret = 0, val;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	mutex_lock(&batt_drv->bpst_state.lock);
	batt_drv->bpst_state.bpst_detect_disable = !!val;
	mutex_unlock(&batt_drv->bpst_state.lock);
	if (batt_drv->psy)
		power_supply_changed(batt_drv->psy);

	return count;
}

static DEVICE_ATTR(bpst_detect_disable, 0660,
		   show_bpst_detect_disable, set_bpst_detect_disable);

/* AACR ------------------------------------------------------------------- */

static ssize_t aacr_state_store(struct device *dev,
			       struct device_attribute *attr,
			       const char *buf, size_t count) {
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int val, state, algo, ret = 0;

	ret = kstrtoint(buf, 0, &val);
	if (ret < 0)
		return ret;

	if (val < BATT_AACR_DISABLED) /* not allow minus value */
		return -ERANGE;

	switch (val) {
	case BATT_AACR_DISABLED:
		state = BATT_AACR_DISABLED;
		break;
	case BATT_AACR_ENABLED:
		state = BATT_AACR_ENABLED;
		algo = BATT_AACR_ALGO_DEFAULT;
		break;
	case BATT_AACR_ALGO_LOW_B:
		state = BATT_AACR_ENABLED;
		algo = BATT_AACR_ALGO_LOW_B;
		break;
	default:
		return -ERANGE;
	}

	if (batt_drv->aacr_state == state && batt_drv->aacr_algo == algo)
		return count;

	pr_info("aacr_state: %d -> %d, aacr_algo: %d -> %d\n",
		batt_drv->aacr_state, state, batt_drv->aacr_algo, algo);
	batt_drv->aacr_state = state;
	batt_drv->aacr_algo = algo;
	return count;
}

static ssize_t aacr_state_show(struct device *dev,
			      struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->aacr_state);
}

static const DEVICE_ATTR_RW(aacr_state);


static ssize_t aacr_cycle_grace_store(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int value, ret = 0;

	ret = kstrtoint(buf, 0, &value);
	if (ret < 0)
		return ret;

	batt_drv->aacr_cycle_grace = value;
	return count;
}

static ssize_t aacr_cycle_grace_show(struct device *dev,
				     struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->aacr_cycle_grace);
}

static const DEVICE_ATTR_RW(aacr_cycle_grace);


static ssize_t aacr_cycle_max_store(struct device *dev,
				    struct device_attribute *attr,
				    const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int value, ret = 0;

	ret = kstrtoint(buf, 0, &value);
	if (ret < 0)
		return ret;

	batt_drv->aacr_cycle_max = value;
	return count;
}

static ssize_t aacr_cycle_max_show(struct device *dev,
				     struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->aacr_cycle_max);
}

static const DEVICE_ATTR_RW(aacr_cycle_max);

static ssize_t aacr_algo_show(struct device *dev,
			      struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->aacr_algo);
}

static const DEVICE_ATTR_RO(aacr_algo);

/* Swelling  --------------------------------------------------------------- */

static ssize_t swelling_data_show(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	struct swelling_data *sd = &batt_drv->sd;
	int len = 0, i;

	len += scnprintf(&buf[len], PAGE_SIZE - len,
			 "temp/soc\tcharge(s)\tdischarge(s)\n");
	for (i = 0; i < BATT_TEMP_RECORD_THR ; i++) {
		len += scnprintf(&buf[len], PAGE_SIZE - len,
				 "%d/%d\t%llu\t%llu\n",
				 sd->temp_thr[i]/10, sd->soc_thr[i],
				 sd->chg[i], sd->dischg[i]);
	}

	return len;
}

static const DEVICE_ATTR_RO(swelling_data);

/* BHI --------------------------------------------------------------------- */

static ssize_t health_index_show(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 BHI_ROUND_INDEX(batt_drv->health_data.bhi_index));
}

static const DEVICE_ATTR_RO(health_index);

static ssize_t health_status_show(struct device *dev,
				  struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->health_data.bhi_status);
}

static const DEVICE_ATTR_RO(health_status);

static ssize_t health_impedance_index_show(struct device *dev,
				      struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 BHI_ROUND_INDEX(batt_drv->health_data.bhi_imp_index));
}

static const DEVICE_ATTR_RO(health_impedance_index);

static ssize_t health_capacity_index_show(struct device *dev,
				      struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n",
			 BHI_ROUND_INDEX(batt_drv->health_data.bhi_cap_index));
}

static const DEVICE_ATTR_RO(health_capacity_index);

static ssize_t health_index_stats_show(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	struct bhi_data *bhi_data = &batt_drv->health_data.bhi_data;
	struct health_data *health_data = &batt_drv->health_data;
	int len = 0, i;

	mutex_lock(&batt_drv->chg_lock);

	for (i = 0; i < BHI_ALGO_MAX; i++) {
		int health_index, health_status, cap_index, imp_index, sd_index;

		cap_index = bhi_calc_cap_index(i, batt_drv);
		imp_index = bhi_calc_imp_index(i, health_data);
		sd_index = bhi_calc_sd_index(i, health_data);
		health_index = bhi_calc_health_index(i, health_data, cap_index, imp_index, sd_index);
		health_status = bhi_calc_health_status(i, BHI_ROUND_INDEX(health_index), health_data);
		if (health_index < 0)
			continue;

		pr_debug("bhi: %d: %d, %d,%d,%d %d,%d,%d %d,%d\n", i,
			 health_status, health_index, cap_index, imp_index,
			 bhi_data->swell_cumulative,
			 bhi_health_get_capacity(i, bhi_data),
			 bhi_health_get_impedance(i, bhi_data),
			 bhi_data->battery_age,
			 bhi_data->cycle_count);


		len += scnprintf(&buf[len], PAGE_SIZE - len,
				 "%d: %d, %d,%d,%d %d,%d,%d %d,%d, %d\n",
				 i, health_status,
				 BHI_ROUND_INDEX(health_index),
				 BHI_ROUND_INDEX(cap_index),
				 BHI_ROUND_INDEX(imp_index),
				 bhi_data->swell_cumulative,
				 bhi_health_get_capacity(i, bhi_data),
				 bhi_health_get_impedance(i, bhi_data),
				 bhi_data->battery_age,
				 bhi_data->cycle_count,
				 batt_bpst_stats_update(batt_drv));
	}

	mutex_unlock(&batt_drv->chg_lock);

	return len;
}

static const DEVICE_ATTR_RO(health_index_stats);

static ssize_t health_algo_store(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int value, ret;

	ret = kstrtoint(buf, 0, &value);
	if (ret < 0)
		return ret;

	mutex_lock(&batt_drv->chg_lock);
	batt_drv->health_data.bhi_algo = value;
	ret = batt_bhi_stats_update_all(batt_drv);
	mutex_unlock(&batt_drv->chg_lock);

	if (ret < 0)
		return ret;

	return count;
}

static ssize_t health_algo_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->health_data.bhi_indi_cap);
}

static const DEVICE_ATTR_RW(health_algo);

static ssize_t health_indi_cap_store(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int value, ret;

	ret = kstrtoint(buf, 0, &value);
	if (ret < 0)
		return ret;

	if (value > 100 || value < 0)
		return count;

	batt_drv->health_data.bhi_indi_cap = value;

	return count;
}

static ssize_t health_indi_cap_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->health_data.bhi_indi_cap);
}

static const DEVICE_ATTR_RW(health_indi_cap);

/* CSI --------------------------------------------------------------------- */

static ssize_t charging_speed_store(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	int value, ret;

	ret = kstrtoint(buf, 0, &value);
	if (ret < 0)
		return ret;

	pr_info("fake_charging_speed: %d -> %d\n", batt_drv->fake_charging_speed, value);
	batt_drv->fake_charging_speed = value;

	return count;
}

static ssize_t charging_speed_show(struct device *dev,
				   struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->csi_current_speed);
}

static const DEVICE_ATTR_RW(charging_speed);

static ssize_t power_metrics_polling_rate_store(struct device *dev,
						struct device_attribute *attr,
						const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	unsigned int value, ret = 0;

	ret = kstrtouint(buf, 0, &value);
	if (ret < 0)
		return ret;
	if (value <= 0)
		return -EINVAL;

	batt_drv->power_metrics.polling_rate = value;
	return count;
}

static ssize_t power_metrics_polling_rate_show(struct device *dev,
					       struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->power_metrics.polling_rate);
}

static const DEVICE_ATTR_RW(power_metrics_polling_rate);

static ssize_t power_metrics_interval_store(struct device *dev,
					    struct device_attribute *attr,
					    const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	unsigned int value, ret = 0;
	const int polling_rate = batt_drv->power_metrics.polling_rate;

	ret = kstrtouint(buf, 0, &value);
	if (ret < 0)
		return ret;
	if ((value >= polling_rate * POWER_METRICS_MAX_DATA) || value < polling_rate)
		return -EINVAL;

	batt_drv->power_metrics.interval = value;
	return count;
}

static ssize_t power_metrics_interval_show(struct device *dev,
					   struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->power_metrics.interval);
}

static const DEVICE_ATTR_RW(power_metrics_interval);

static long power_metrics_delta_cc(struct batt_drv *batt_drv, int idx1, int idx2)
{
	return batt_drv->power_metrics.data[idx1].charge_count -
	    batt_drv->power_metrics.data[idx2].charge_count;
}

static long power_metrics_avg_vbat(struct batt_drv *batt_drv, int idx1, int idx2)
{
	unsigned long v1 = batt_drv->power_metrics.data[idx1].voltage;
	unsigned long v2 = batt_drv->power_metrics.data[idx2].voltage;

	return (v1 + v2) / 2;
}

static long power_metrics_delta_time(struct batt_drv *batt_drv, int idx1, int idx2)
{
	return batt_drv->power_metrics.data[idx1].time -
	    batt_drv->power_metrics.data[idx2].time;
}

static ssize_t power_metrics_power_show(struct device *dev,
					struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	const unsigned int polling_rate = batt_drv->power_metrics.polling_rate;
	const unsigned int interval = batt_drv->power_metrics.interval;
	const unsigned int pm_idx = batt_drv->power_metrics.idx;
	unsigned int step, idx, idx_prev, i;
	long cc, vbat, time, time_prev;
	long power_avg = 0;

	step = interval / polling_rate;
	if (step == 0)
		return scnprintf(buf, PAGE_SIZE, "Error interval.\n");

	idx_prev = pm_idx;
	for (i = 1; i <= step; i++) {
		if (i > pm_idx)
			idx = pm_idx + POWER_METRICS_MAX_DATA - i;
		else
			idx = pm_idx - i;

		if (batt_drv->power_metrics.data[idx].voltage == 0)
			return scnprintf(buf, PAGE_SIZE, "Not enough data.\n");
		if (power_metrics_delta_time(batt_drv, idx_prev, idx) <= 0)
			return scnprintf(buf, PAGE_SIZE, "Time stamp error.\n");

		time = power_metrics_delta_time(batt_drv, pm_idx, idx);
		if (time < interval) {
			/* P += (dCC * V / dT) * (dT / interval) */
			cc = power_metrics_delta_cc(batt_drv, idx_prev, idx);
			vbat = power_metrics_avg_vbat(batt_drv, idx_prev, idx);
			power_avg += (cc * vbat) / interval;
			idx_prev = idx;
			continue;
		}

		if (i == 1) {
			/* P = dCC * V / dT */
			cc = power_metrics_delta_cc(batt_drv, pm_idx, idx);
			vbat = power_metrics_avg_vbat(batt_drv, pm_idx, idx);
			power_avg = cc * vbat / time;
		} else {
			/* P += (dCC * V / dT) * (the left time to interval / interval) */
			cc = power_metrics_delta_cc(batt_drv, idx_prev, idx);
			vbat = power_metrics_avg_vbat(batt_drv, idx_prev, idx);
			time = power_metrics_delta_time(batt_drv, idx_prev, idx);
			time_prev = power_metrics_delta_time(batt_drv, pm_idx, idx_prev);
			power_avg += (cc * vbat * (interval - time_prev) / time ) / interval;
		}

		break;
	}

	return scnprintf(buf, PAGE_SIZE, "%ld\n", power_avg / 1000000);
}

static const DEVICE_ATTR_RO(power_metrics_power);

static ssize_t power_metrics_current_show(struct device *dev,
					  struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
	const unsigned int polling_rate = batt_drv->power_metrics.polling_rate;
	const unsigned int interval = batt_drv->power_metrics.interval;
	const unsigned int pm_idx = batt_drv->power_metrics.idx;
	unsigned int step, idx, idx_prev, i;
	long cc, time, time_prev;
	long current_avg = 0;

	step = interval / polling_rate;
	if (step == 0)
		return scnprintf(buf, PAGE_SIZE, "Error interval.\n");

	idx_prev = pm_idx;
	for (i = 1; i <= step; i++) {
		if (i > pm_idx)
			idx = pm_idx + POWER_METRICS_MAX_DATA - i;
		else
			idx = pm_idx - i;

		if (batt_drv->power_metrics.data[idx].voltage == 0)
			return scnprintf(buf, PAGE_SIZE, "Not enough data.\n");
		if (power_metrics_delta_time(batt_drv, idx_prev, idx) <= 0)
			return scnprintf(buf, PAGE_SIZE, "Time stamp error.\n");

		time = power_metrics_delta_time(batt_drv, pm_idx, idx);
		if (time < interval) {
			/* I += (dCC / dT) * (dT / interval) */
			cc = power_metrics_delta_cc(batt_drv, idx_prev, idx);
			current_avg += cc / interval;
			idx_prev = idx;
			continue;
		}

		if (i == 1) {
			/* I = dCC / dT */
			cc = power_metrics_delta_cc(batt_drv, pm_idx, idx);
			current_avg = cc / time;
		} else {
			 /* I += (dCC / dT) * (the left time to interval / interval) */
			cc = power_metrics_delta_cc(batt_drv, idx_prev, idx);
			time = power_metrics_delta_time(batt_drv, idx_prev, idx);
			time_prev = power_metrics_delta_time(batt_drv, pm_idx, idx_prev);
			current_avg += (cc * (interval - time_prev) / time) / interval;
		}

		break;
	}

	return scnprintf(buf, PAGE_SIZE, "%ld\n", current_avg);
}

static const DEVICE_ATTR_RO(power_metrics_current);

static ssize_t dev_sn_store(struct device *dev,
			    struct device_attribute *attr,
			    const char *buf, size_t count)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	memcpy(batt_drv->dev_sn, buf, strlen(buf));

	return count;
}

static ssize_t dev_sn_show(struct device *dev,
			   struct device_attribute *attr, char *buf)
{
	struct power_supply *psy = container_of(dev, struct power_supply, dev);
	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);

	return scnprintf(buf, PAGE_SIZE, "%s\n", batt_drv->dev_sn);
}

static const DEVICE_ATTR_RW(dev_sn);

/* ------------------------------------------------------------------------- */

static int batt_init_fs(struct batt_drv *batt_drv)
{
	int ret;

	/* stats */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_stats);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create charge_stats\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_stats_actual);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create charge_stats_actual\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_details);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create charge_details\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_ssoc_details);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create ssoc_details\n");

	/* adaptive charging */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_deadline);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create chg_deadline\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_stage);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create charge_stage\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_limit);
	if (ret != 0)
		dev_err(&batt_drv->psy->dev, "Failed to create charge_limit\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_time_to_ac);
	if (ret != 0)
		dev_err(&batt_drv->psy->dev, "Failed to create time_to_ac\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_ac_soc);
	if (ret != 0)
		dev_err(&batt_drv->psy->dev, "Failed to create ac_soc\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_deadline_dryrun);
	if (ret != 0)
		dev_err(&batt_drv->psy->dev, "Failed to create chg_deadline_dryrun\n");

	/* time to full */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_ttf_stats);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create ttf_stats\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_ttf_details);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create ttf_details\n");

	/* TRICKLE-DEFEND */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_bd_trickle_enable);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create bd_trickle_enable\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_bd_trickle_cnt);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create bd_trickle_cnt\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_bd_trickle_recharge_soc);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create bd_trickle_recharge_soc\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_bd_trickle_dry_run);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create bd_trickle_dry_run\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_bd_trickle_reset_sec);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create bd_trickle_reset_sec\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_bd_clear);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create bd_clear\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_pairing_state);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create pairing_state\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_cycle_counts);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create cycle_counts\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_full_estimate);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create chage_full_estimate\n");

	/* google_resistance and resistance */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_resistance_avg);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create resistance_avg\n");

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_resistance);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create resistance\n");

	/* monitoring */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charger_state);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create charger state\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charge_type);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create charge_type\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_constant_charge_current);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create constant charge current\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_constant_charge_voltage);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create constant charge voltage\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_fan_level);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create fan level\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_health_safety_margin);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create health safety margin\n");
	/* aacr */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_aacr_state);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create aacr state\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_aacr_cycle_grace);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create aacr cycle grace\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_aacr_cycle_max);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create aacr cycle max\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_aacr_algo);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create aacr algo\n");

	/* health and health index */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_swelling_data);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create swelling_data\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_health_index);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create health index\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_health_status);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create health status\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_health_capacity_index);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create health capacity index\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_health_index_stats);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create health index stats\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_health_impedance_index);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create health perf index\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_health_algo);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create health algo\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_health_indi_cap);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create health individual capacity\n");

	/* csi */
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_charging_speed);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create charging speed\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_power_metrics_polling_rate);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create power_metrics_polling_rate\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_power_metrics_interval);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create power_metrics_interval\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_power_metrics_power);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create power_metrics_power\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_power_metrics_current);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create power_metrics_current\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_dev_sn);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create dev sn\n");

	return 0;

}

static int batt_init_debugfs(struct batt_drv *batt_drv)
{
	struct dentry *de = NULL;

	de = debugfs_create_dir("google_battery", 0);
	if (IS_ERR_OR_NULL(de))
		return 0;

	debugfs_create_u32("debug_level", 0644, de, &debug_printk_prlog);
	debugfs_create_file("cycle_count_sync", 0600, de, batt_drv,
			    &cycle_count_bins_sync_fops);
	debugfs_create_file("ssoc_gdf", 0644, de, batt_drv, &debug_ssoc_gdf_fops);
	debugfs_create_file("ssoc_uic", 0644, de, batt_drv, &debug_ssoc_uic_fops);
	debugfs_create_file("ssoc_rls", 0444, de, batt_drv, &debug_ssoc_rls_fops);
	debugfs_create_file("ssoc_uicurve", 0644, de, batt_drv,
			    &debug_ssoc_uicurve_cstr_fops);
	debugfs_create_file("force_psy_update", 0400, de, batt_drv,
			    &debug_force_psy_update_fops);
	debugfs_create_file("pairing_state", 0200, de, batt_drv, &debug_pairing_fops);
	debugfs_create_file("temp", 0400, de, batt_drv, &debug_fake_temp_fops);
	debugfs_create_u32("battery_present", 0600, de,
			   &batt_drv->fake_battery_present);

	/* history */
	debugfs_create_file("blf_state", 0400, de, batt_drv, &debug_blf_state_fops);
	debugfs_create_u32("blf_collect_now", 0600, de, &batt_drv->blf_collect_now);

	/* defender */
	debugfs_create_u32("fake_capacity", 0600, de,
			    &batt_drv->fake_capacity);

	/* aacr test */
	debugfs_create_u32("fake_aacr_cc", 0600, de,
			    &batt_drv->fake_aacr_cc);

	/* health charging (adaptive charging) */
	debugfs_create_file("chg_health_thr_soc", 0600, de, batt_drv,
			    &debug_chg_health_thr_soc_fops);
	debugfs_create_file("chg_health_rest_rate", 0600, de, batt_drv,
			    &debug_chg_health_rest_rate_fops);
	debugfs_create_file("chg_health_rest_rate_before_trigger", 0600, de, batt_drv,
			    &debug_chg_health_rest_rate_before_trigger_fops);
	debugfs_create_file("chg_health_stage", 0600, de, batt_drv,
			    &debug_chg_health_stage_fops);

	/* charging table */
	debugfs_create_file("chg_raw_profile", 0644, de, batt_drv,
			    &debug_chg_raw_profile_fops);

	/* battery virtual sensor*/
	debugfs_create_u32("batt_vs_w", 0600, de, &batt_drv->batt_vs_w);

	/* power metrics */
	debugfs_create_file("power_metrics", 0400, de, batt_drv, &debug_power_metrics_fops);

	/* bhi fullcapnom count */
	debugfs_create_u32("bhi_w_ci", 0644, de, &batt_drv->health_data.bhi_w_ci);
	debugfs_create_u32("bhi_w_pi", 0644, de, &batt_drv->health_data.bhi_w_pi);
	debugfs_create_u32("bhi_w_sd", 0644, de, &batt_drv->health_data.bhi_w_sd);
	debugfs_create_u32("act_impedance", 0644, de,
			   &batt_drv->health_data.bhi_data.act_impedance);
	debugfs_create_u32("bhi_debug_cycle_count", 0644, de,
			   &batt_drv->health_data.bhi_debug_cycle_count);
	debugfs_create_u32("bhi_debug_cap_idx", 0644, de,
			   &batt_drv->health_data.bhi_debug_cap_index);
	debugfs_create_u32("bhi_debug_imp_idx", 0644, de,
			   &batt_drv->health_data.bhi_debug_imp_index);
	debugfs_create_u32("bhi_debug_sd_idx", 0644, de,
			   &batt_drv->health_data.bhi_debug_sd_index);
	debugfs_create_u32("bhi_debug_health_idx", 0644, de,
			   &batt_drv->health_data.bhi_debug_health_index);
	debugfs_create_file("bhi_debug_status", 0644, de, batt_drv,
			   &debug_bhi_status_fops);

	/* google_resistance, tuning */
	debugfs_create_u32("ravg_temp_low", 0644, de,
			   &batt_drv->health_data.bhi_data.res_state.res_temp_low);
	debugfs_create_u32("ravg_temp_high", 0644, de,
			   &batt_drv->health_data.bhi_data.res_state.res_temp_high);
	debugfs_create_u32("ravg_soc_low", 0644, de,
			   &batt_drv->health_data.bhi_data.res_state.ravg_soc_low);
	debugfs_create_u32("ravg_soc_high", 0644, de,
			   &batt_drv->health_data.bhi_data.res_state.ravg_soc_high);
	debugfs_create_file("ravg", 0400, de,  batt_drv, &debug_ravg_fops);

	/* shutdown flag */
	debugfs_create_u32("boot_to_os_attempts", 0660, de, &batt_drv->boot_to_os_attempts);

	return 0;
}

/* bpst detection */
static int batt_bpst_init_fs(struct batt_drv *batt_drv)
{
	int ret;

	if (!batt_drv->bpst_state.bpst_enable)
		return 0;

	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_bpst_reset);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create bpst_reset\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_bpst_detect_disable);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create bpst_detect_disable\n");

	return 0;

}

static int batt_bpst_init_debugfs(struct batt_drv *batt_drv)
{
	struct dentry *de = NULL;

	de = debugfs_create_dir("bpst", 0);
	if (IS_ERR_OR_NULL(de))
		return 0;

	debugfs_create_file("bpst_sbd_status", 0600, de, batt_drv,
			    &debug_bpst_sbd_status_fops);
	debugfs_create_u32("bpst_count_threshold", 0600, de,
			    &batt_drv->bpst_state.bpst_count_threshold);
	debugfs_create_u32("bpst_chg_rate", 0600, de,
			    &batt_drv->bpst_state.bpst_chg_rate);

	return 0;
}

/* ------------------------------------------------------------------------- */

/* could also use battery temperature, age */
static bool gbatt_check_dead_battery(const struct batt_drv *batt_drv)
{
	return ssoc_get_capacity(&batt_drv->ssoc_state) == 0;
}

#define VBATT_CRITICAL_LEVEL		3300000
#define VBATT_CRITICAL_DEADLINE_SEC	40

static bool gbatt_check_critical_level(const struct batt_drv *batt_drv,
				       int fg_status)
{
	const struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	const int soc = ssoc_get_real(ssoc_state);

	if (fg_status == POWER_SUPPLY_STATUS_UNKNOWN)
		return true;

	if (soc == 0 && ssoc_state->buck_enabled == 1 &&
	    fg_status == POWER_SUPPLY_STATUS_DISCHARGING) {
		const ktime_t now = get_boot_sec();
		int vbatt;

		/* disable the check */
		if (now > VBATT_CRITICAL_DEADLINE_SEC || batt_drv->batt_critical_voltage == 0)
			return true;

		vbatt = GPSY_GET_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_VOLTAGE_NOW);
		if (vbatt == -EAGAIN)
			return false;

		return (vbatt < 0) ? : vbatt < batt_drv->batt_critical_voltage;
	}

	return false;
}

#define SSOC_LEVEL_FULL		SSOC_SPOOF
#define SSOC_LEVEL_HIGH		80
#define SSOC_LEVEL_NORMAL	30
#define SSOC_LEVEL_LOW		0

/*
 * could also use battery temperature, age.
 * NOTE: this implementation looks at the SOC% but it might be looking to
 * other quantities or flags.
 * NOTE: CRITICAL_LEVEL implies BATTERY_DEAD but BATTERY_DEAD doesn't imply
 * CRITICAL.
 */
static int gbatt_get_capacity_level(const struct batt_drv *batt_drv,
				    int fg_status)
{
	const struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	const int soc = ssoc_get_real(ssoc_state);
	int capacity_level;

	if (soc >= SSOC_LEVEL_FULL) {
		capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
	} else if (soc > SSOC_LEVEL_HIGH) {
		capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_HIGH;
	} else if (soc > SSOC_LEVEL_NORMAL) {
		capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
	} else if (soc > SSOC_LEVEL_LOW) {
		capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
	} else if (ssoc_state->buck_enabled == 0) {
		capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
	} else if (ssoc_state->buck_enabled == -1) {
		/* only at startup, this should not happen */
		capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
	} else if (gbatt_check_critical_level(batt_drv, fg_status)) {
		capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
	} else {
		capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
	}

	return capacity_level;
}

static int gbatt_get_temp(const struct batt_drv *batt_drv, int *temp)
{
	int err = 0;
	union power_supply_propval val;

	if (batt_drv->fake_temp) {
		*temp = batt_drv->fake_temp;
	} else if (!batt_drv->fg_psy) {
		err = -EINVAL;
	} else {
		err = power_supply_get_property(batt_drv->fg_psy,
						POWER_SUPPLY_PROP_TEMP, &val);
		if (err == 0)
			*temp = val.intval;
	}

	return err;
}

static int batt_do_md5(const u8 *data, unsigned int len, u8 *result)
{
	struct crypto_shash *tfm;
	struct shash_desc *shash;
	int size, ret = 0;

	tfm = crypto_alloc_shash("md5", 0, 0);
	if (IS_ERR(tfm)) {
		pr_err("Error MD5 transform: %ld\n", PTR_ERR(tfm));
		return PTR_ERR(tfm);
	}

	size = sizeof(struct shash_desc) + crypto_shash_descsize(tfm);
	shash = kmalloc(size, GFP_KERNEL);
	if (!shash)
		return -ENOMEM;

	shash->tfm = tfm;
	ret = crypto_shash_digest(shash, data, len, result);
	kfree(shash);
	crypto_free_shash(tfm);

	return ret;
}

/* called with a lock on ->chg_lock */
static enum batt_paired_state batt_check_pairing_state(struct batt_drv *batt_drv)
{
	char dev_info[GBMS_DINF_LEN];
	char mfg_info[GBMS_MINF_LEN];
	u8 *dev_info_check = batt_drv->dev_info_check;
	int ret, len;

	len = strlen(batt_drv->dev_sn);

	/* No dev_sn, return current state */
	if (len == 0)
		return batt_drv->pairing_state;

	ret = gbms_storage_read(GBMS_TAG_DINF, dev_info, GBMS_DINF_LEN);
	if (ret < 0) {
		pr_err("Read device pairing info failed, ret=%d\n", ret);
		return BATT_PAIRING_READ_ERROR;
	}

	if (batt_drv->dev_info_check[0] == 0) {
		char data[DEV_SN_LENGTH + GBMS_MINF_LEN];

		ret = gbms_storage_read(GBMS_TAG_MINF, mfg_info, GBMS_MINF_LEN);
		if (ret < 0) {
			pr_err("read mfg info. fail, ret=%d\n", ret);
			return BATT_PAIRING_READ_ERROR;
		}

		memcpy(data, batt_drv->dev_sn, len);
		memcpy(&data[len], mfg_info, GBMS_MINF_LEN);

		ret = batt_do_md5(data, len + GBMS_MINF_LEN, dev_info_check);
		if (ret < 0) {
			pr_err("execute batt_do_md5 fail, ret=%d\n", ret);
			return BATT_PAIRING_MISMATCH;
		}
	}

	/* new battery: pair the battery to this device */
	if (dev_info[0] == 0xFF) {

		ret = gbms_storage_write(GBMS_TAG_DINF, dev_info_check, GBMS_DINF_LEN);
		if (ret < 0) {
			pr_err("Pairing to this device failed, ret=%d\n", ret);
			return BATT_PAIRING_WRITE_ERROR;
		}

	/* recycled battery */
	} else if (strncmp(dev_info, dev_info_check, strlen(dev_info_check))) {
		pr_warn("Battery paired to a different device\n");

		return BATT_PAIRING_MISMATCH;
	}

	return BATT_PAIRING_PAIRED;
}

/*  TODO: handle history collection, use storage */
static int batt_hist_data_collect(void *h, int idx)
{
	int cnt;

	cnt = gbms_storage_read(GBMS_TAG_CLHI, h, 0);
	if (cnt > 0)
		cnt = gbms_storage_write_data(GBMS_TAG_HIST, h, cnt, idx);

	return cnt;
}

/* TODO: handle history collection, use storage */
static void batt_hist_free_data(void *p)
{
	if (p)
		kfree(p);
}

/* save data in hours */
#define SAVE_UNIT 3600
static void gbatt_save_sd(struct swelling_data *sd)
{
	u16 sd_saved[BATT_SD_SAVE_SIZE];
	bool update_save_data = false;
	int i, j, ret = 0;

	/* Change seconds to hours */
	for (i = 0; i < BATT_TEMP_RECORD_THR; i++) {
		j = i + SD_DISCHG_START;

		sd_saved[i] = sd->chg[i] / SAVE_UNIT < BATT_SD_MAX_HOURS ?
			      sd->chg[i] / SAVE_UNIT : BATT_SD_MAX_HOURS;

		sd_saved[j] = sd->dischg[i] / SAVE_UNIT < BATT_SD_MAX_HOURS ?
			      sd->dischg[i] / SAVE_UNIT : BATT_SD_MAX_HOURS;

		if (sd_saved[i] > sd->saved[i] ||
		    sd_saved[j] > sd->saved[j]) {
			sd->saved[i] = sd_saved[i];
			sd->saved[j] = sd_saved[j];
			update_save_data = true;
		}
	}

	if (!update_save_data)
		return;

	ret = gbms_storage_write(GBMS_TAG_STRD, &sd->saved, sizeof(sd->saved));
	if (ret < 0)
		pr_warn("Failed to save swelling data, ret=%d\n", ret);
}

static void gbatt_record_over_temp(struct batt_drv *batt_drv)
{
	struct swelling_data *sd = &batt_drv->sd;
	struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	const bool charge = batt_drv->fg_status == POWER_SUPPLY_STATUS_CHARGING ||
			    (batt_drv->fg_status == POWER_SUPPLY_STATUS_FULL &&
			    !batt_drv->chg_done);
	const int temp = batt_drv->batt_temp;
	const int soc = ssoc_get_real(ssoc_state);
	const ktime_t now = get_boot_sec();
	const ktime_t elap = now - sd->last_update;
	bool update_data = false;
	int i;

	for (i = 0; i < BATT_TEMP_RECORD_THR; i++) {
		/*
		 *  thresholds table:
		 *  | i        | 0      | 1      | 2      |
		 *  |----------|--------|--------|--------|
		 *  | temp_thr | 30degC | 35degC | 40degC |
		 *  | soc_thr  | 90%    | 90%    | 95%    |
		 */
		if (temp < sd->temp_thr[i] || soc < sd->soc_thr[i])
			continue;

		if (charge)
			sd->chg[i] += elap;
		else
			sd->dischg[i] += elap;

		update_data = true;
	}

	if (update_data)
		gbatt_save_sd(&batt_drv->sd);

	sd->last_update = now;
}

static int gbatt_save_capacity(struct batt_ssoc_state *ssoc_state)
{
	const int ui_soc = ssoc_get_capacity(ssoc_state);
	const int gdf_soc = ssoc_get_real(ssoc_state);
	int ret = 0, save_now;

	if (!ssoc_state->save_soc_available)
		return ret;

	if (ui_soc == gdf_soc)
		save_now = 0;
	else
		save_now = ui_soc;

	if (ssoc_state->save_soc != (u16)save_now) {
		ssoc_state->save_soc = (u16)save_now;
		ret = gbms_storage_write(GBMS_TAG_RSOC, &ssoc_state->save_soc,
							sizeof(ssoc_state->save_soc));
	}

	return ret;
}

/* battery history data collection */
static int batt_history_data_work(struct batt_drv *batt_drv)
{
	int cycle_cnt, idx, ret;

	/* TODO: google_battery caches cycle count, should use that */
	cycle_cnt = GPSY_GET_PROP(batt_drv->fg_psy,
				  POWER_SUPPLY_PROP_CYCLE_COUNT);
	if (cycle_cnt < 0)
		return -EIO;

	if (batt_drv->blf_collect_now) {
		pr_info("MSC_HIST cycle_cnt:%d->%d saved_cnt=%d\n",
			cycle_cnt, batt_drv->blf_collect_now,
			batt_drv->hist_data_saved_cnt);

		cycle_cnt = batt_drv->blf_collect_now;
		batt_drv->hist_data_saved_cnt = cycle_cnt - 1;
		batt_drv->blf_collect_now = 0;
	}

	if (cycle_cnt <= batt_drv->hist_data_saved_cnt)
		return 0;

	idx = cycle_cnt / batt_drv->hist_delta_cycle_cnt;

	/* save in last when over max cycles */
	if (idx >= batt_drv->hist_data_max_cnt)
		idx = batt_drv->hist_data_max_cnt - 1;

	ret = batt_hist_data_collect(batt_drv->hist_data, idx);
	if (ret < 0)
		return ret;

	batt_drv->hist_data_saved_cnt = cycle_cnt;

	pr_info("MSC_HIST Update data with cnt:%d\n", cycle_cnt);

	return 0;
}

/* TODO: read from the HIST tag */
#define BATT_ONE_HIST_LEN	12

static int google_battery_init_hist_work(struct batt_drv *batt_drv )
{
	const int one_hist_len = BATT_ONE_HIST_LEN; /* TODO: read from the tag */
	int cnt;

	/*
	 * Determine the max number of history entries
	 * NOTE: gbms_storage will return -EPROBE_DEFER during init
	 */
	cnt = gbms_storage_read_data(GBMS_TAG_HIST, NULL, 0, 0);
	if (cnt == -EPROBE_DEFER)
		return -EAGAIN;

	if (cnt <= 0) {
		pr_err("MSC_HIST collect history data not available (%d)\n", cnt);
		batt_drv->blf_state = BATT_LFCOLLECT_NOT_AVAILABLE;
		return -ENODATA;
	}

	batt_drv->hist_data = kzalloc(one_hist_len, GFP_KERNEL);
	if (!batt_drv->hist_data) {
		pr_err("MSC_HIST cannot allocate buffer of size=%d\n",
		       one_hist_len);
		batt_drv->blf_state = BATT_LFCOLLECT_NOT_AVAILABLE;
	} else {
		batt_drv->blf_state = BATT_LFCOLLECT_COLLECT;
		batt_drv->hist_data_max_cnt = cnt;
		batt_drv->hist_data_saved_cnt = -1;
	}

	pr_info("MSC_HIST init_hist_work done, state:%d, cnt:%d",
		 batt_drv->blf_state, cnt);

	return 0;
}

#define BOOT_TO_OS_ATTEMPTS 3

static int batt_init_shutdown_flag(struct batt_drv *batt_drv)
{
	u8 data;
	int ret;

	ret = gbms_storage_read(GBMS_TAG_SUFG, &data, sizeof(data));
	if (ret < 0)
		return -EIO;

	batt_drv->boot_to_os_attempts = data;

	/* reset battery shutdown flag */
	data = 0;
	ret = gbms_storage_write(GBMS_TAG_SUFG, &data, sizeof(data));

	return (ret < 0) ? -EIO : 0;
}

static int batt_set_shutdown_flag(struct batt_drv *batt_drv)
{
	u8 data = batt_drv->boot_to_os_attempts;
	int ret;

	if (data == 0)
		data = BOOT_TO_OS_ATTEMPTS;

	ret = gbms_storage_write(GBMS_TAG_SUFG, &data, sizeof(data));

	return (ret < 0) ? -EIO : 0;
}

/*
 * poll the battery, run SOC%, dead battery, critical.
 * scheduled from psy_changed and from timer
 */

#define UPDATE_INTERVAL_AT_FULL_FACTOR	4

static void google_battery_work(struct work_struct *work)
{
	struct batt_drv *batt_drv =
	    container_of(work, struct batt_drv, batt_work.work);
	struct power_supply *fg_psy = batt_drv->fg_psy;
	struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	int update_interval = batt_drv->batt_update_interval;
	const int prev_ssoc = ssoc_get_capacity(ssoc_state);
	int present, fg_status, batt_temp, ret;
	bool notify_psy_changed = false;

	pr_debug("battery work item\n");

	__pm_stay_awake(batt_drv->batt_ws);

	/* chg_lock protect msc_logic */
	mutex_lock(&batt_drv->chg_lock);

	present = GPSY_GET_PROP(fg_psy, POWER_SUPPLY_PROP_PRESENT);
	if (present && !batt_drv->batt_present) {
		pr_debug("%s: change of battery state %d->%d\n",
			 __func__, batt_drv->batt_present, present);

		batt_drv->batt_present = true;
		notify_psy_changed = true;
	} else if (!present && batt_drv->batt_present) {
		pr_debug("%s: change of battery state %d->%d\n",
			 __func__, batt_drv->batt_present, present);

		batt_drv->batt_present = false;

		/* add debounce? */
		notify_psy_changed = true;
		mutex_unlock(&batt_drv->chg_lock);
		goto reschedule;
	}

	fg_status = GPSY_GET_INT_PROP(fg_psy, POWER_SUPPLY_PROP_STATUS, &ret);
	if (ret < 0) {
		mutex_unlock(&batt_drv->chg_lock);
		goto reschedule;
	}

	/* batt_lock protect SSOC code etc. */
	mutex_lock(&batt_drv->batt_lock);

	/* TODO: poll rate should be min between ->batt_update_interval and
	 * whatever ssoc_work() decides (typically rls->rl_delta_max_time)
	 */
	ret = ssoc_work(ssoc_state, fg_psy);
	if (ret < 0) {
		update_interval = BATT_WORK_ERROR_RETRY_MS;
	} else {
		bool full;
		int ssoc, level;

		/* handle charge/recharge */
		batt_rl_update_status(batt_drv);

		ssoc = ssoc_get_capacity(ssoc_state);
		if (prev_ssoc != ssoc) {
			pr_debug("%s: change of ssoc %d->%d\n", __func__,
				 prev_ssoc, ssoc);

			dump_ssoc_state(ssoc_state, batt_drv->ssoc_log);
			batt_log_csi_ttf_info(batt_drv);
			notify_psy_changed = true;
		}

		/* TODO(b/138860602): clear ->chg_done to enforce the
		 * same behavior during the transition 99 -> 100 -> Full
		 */

		level = gbatt_get_capacity_level(batt_drv, fg_status);
		if (level != batt_drv->capacity_level) {
			pr_debug("%s: change of capacity level %d->%d\n",
				 __func__, batt_drv->capacity_level,
				 level);

			/* set battery critical shutdown */
			if (level == POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL) {
				ret = batt_set_shutdown_flag(batt_drv);
				if (ret < 0)
					pr_warn("failed to write shutdown flag, ret=%d\n", ret);
			}

			batt_drv->capacity_level = level;
			notify_psy_changed = true;
		}

		if (batt_drv->dead_battery) {
			batt_drv->dead_battery = gbatt_check_dead_battery(batt_drv);
			if (!batt_drv->dead_battery) {
				pr_debug("%s: dead_battery 1->0\n", __func__);
				notify_psy_changed = true;
			}
		}

		/* fuel gauge triggered recharge logic. */
		full = (ssoc == SSOC_FULL);
		if (full && !batt_drv->batt_full) {
			batt_log_csi_ttf_info(batt_drv);
			batt_chg_stats_pub(batt_drv, "100%", false, true);
		}
		batt_drv->batt_full = full;

		/* update resistance all the time and capacity on disconnect */
		ret = bhi_imp_data_update(&batt_drv->health_data.bhi_data, fg_psy);
		if (ret < 0 && ret != -ENODATA)
			pr_warn("cannot update perf index ret=%d\n", ret);

		/* restore SSOC after reboot */
		ret = gbatt_save_capacity(&batt_drv->ssoc_state);
		if (ret < 0)
			pr_warn("write save_soc fail, ret=%d\n", ret);

		/* debounce fg_status changes at 100% */
		if (fg_status != batt_drv->fg_status) {

			pr_debug("%s: ssoc=%d full=%d change of fg_status %d->%d\n",
				 __func__, ssoc, full, batt_drv->fg_status, fg_status);
			if (!full)
				notify_psy_changed = true;
		}

		/* slow down the updates at full */
		if (full && batt_drv->chg_done)
			update_interval *= UPDATE_INTERVAL_AT_FULL_FACTOR;
	}

	/* notifications for this are debounced  */
	batt_drv->fg_status = fg_status;

	/* TODO: poll other data here if needed */

	ret = gbatt_get_temp(batt_drv, &batt_temp);
	if (ret == 0 && batt_temp != batt_drv->batt_temp) {
		const int limit = batt_drv->batt_update_high_temp_threshold;

		batt_drv->batt_temp = batt_temp;
		if (batt_drv->batt_temp > limit) {
			pr_debug("%s: temperature over limit %d > %d\n",
				 __func__, batt_temp, limit);
			notify_psy_changed = true;
		}
	}

	if (batt_drv->sd.is_enable)
		gbatt_record_over_temp(batt_drv);

	mutex_unlock(&batt_drv->batt_lock);

	/*
	 * wait for timeout or state equal to CHARGING, FULL or UNKNOWN
	 * (which will likely not happen) even on ssoc error. msc_logic
	 * hold poll_ws wakelock during this time.
	 * Delay the estimates for time to full for BATT_WORK_DEBOUNCE_RETRY_MS
	 * after the device start charging.
	 */
	if (batt_drv->batt_fast_update_cnt) {

		if (fg_status != POWER_SUPPLY_STATUS_DISCHARGING &&
		    fg_status != POWER_SUPPLY_STATUS_NOT_CHARGING) {
			batt_drv->batt_fast_update_cnt = 0;
			update_interval = BATT_WORK_DEBOUNCE_RETRY_MS;
		} else {
			update_interval = BATT_WORK_FAST_RETRY_MS;
			batt_drv->batt_fast_update_cnt -= 1;
		}
	} else if (batt_drv->ttf_debounce) {
		batt_drv->ttf_debounce = 0;
		batt_log_csi_ttf_info(batt_drv);
	}

	/* acquired in msc_logic */
	if (batt_drv->batt_fast_update_cnt == 0)
		__pm_relax(batt_drv->poll_ws);

	/* set a connect */
	if (batt_drv->health_data.bhi_data.res_state.estimate_requested)
		batt_res_work(batt_drv);

	/* check only once and when/if the pairing state is reset */
	if (batt_drv->pairing_state == BATT_PAIRING_ENABLED) {
		enum batt_paired_state state;

		state = batt_check_pairing_state(batt_drv);
		switch (state) {
		/* somethig is wrong with eeprom comms, HW problem? */
		case BATT_PAIRING_READ_ERROR:
			break;
		/* somethig is wrong with eeprom, HW problem? */
		case BATT_PAIRING_WRITE_ERROR:
			break;
		default:
			batt_drv->pairing_state = state;
			break;
		}
	}

	mutex_unlock(&batt_drv->chg_lock);

	/* TODO: we might not need to do this all the time */
	batt_cycle_count_update(batt_drv, ssoc_get_real(ssoc_state));

reschedule:

	if (notify_psy_changed)
		power_supply_changed(batt_drv->psy);

	if (batt_drv->blf_state == BATT_LFCOLLECT_ENABLED) {

		ret = google_battery_init_hist_work(batt_drv);
		if (ret == -EAGAIN)
			update_interval = BATT_WORK_DEBOUNCE_RETRY_MS;

		if (batt_drv->blf_state == BATT_LFCOLLECT_COLLECT) {
			ret = batt_history_data_work(batt_drv);
			if (ret < 0)
				pr_err("BHI: cannot prime history (%d)\n", ret);

			mutex_lock(&batt_drv->chg_lock);
			ret = batt_bhi_stats_update_all(batt_drv);
			if (ret < 0)
				pr_err("BHI: cannot init stats (%d)\n", ret);
			mutex_unlock(&batt_drv->chg_lock);
		}
	}

	if (batt_drv->blf_state == BATT_LFCOLLECT_COLLECT) {
		ret = batt_history_data_work(batt_drv);
		if (ret == -ENOENT) {
			batt_drv->blf_state = BATT_LFCOLLECT_NOT_AVAILABLE;
			pr_info("MSC_HIST Battery data collection disabled\n");
		}  else if (ret < 0) {
			pr_debug("MSC_HIST cannot collect battery data %d\n", ret);
		}
	}

	if (update_interval) {
		pr_debug("rerun battery work in %d ms\n", update_interval);
		schedule_delayed_work(&batt_drv->batt_work,
				      msecs_to_jiffies(update_interval));
	}


	__pm_relax(batt_drv->batt_ws);
}

static void power_metrics_data_work(struct work_struct *work)
{
	struct batt_drv *batt_drv = container_of(work, struct batt_drv,
						 power_metrics.work.work);
	const unsigned int idx = batt_drv->power_metrics.idx;
	unsigned long cc, vbat;
	unsigned int next_work = batt_drv->power_metrics.polling_rate * 1000;
	ktime_t now = get_boot_sec();

	if (!batt_drv->fg_psy)
		goto error;

	cc = GPSY_GET_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_CHARGE_COUNTER);
	vbat = GPSY_GET_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_VOLTAGE_NOW);

	if ((cc < 0) || (vbat < 0)) {
		if ((cc == -EAGAIN) || (vbat == -EAGAIN))
			next_work = 100;
		goto error;
	}

	if ((idx == 0) && (batt_drv->power_metrics.data[idx].voltage == 0))
		batt_drv->power_metrics.idx = 0;
	else
		batt_drv->power_metrics.idx++;
	if (batt_drv->power_metrics.idx >= POWER_METRICS_MAX_DATA)
		batt_drv->power_metrics.idx = 0;

	batt_drv->power_metrics.data[batt_drv->power_metrics.idx].charge_count = cc;
	batt_drv->power_metrics.data[batt_drv->power_metrics.idx].voltage = vbat;
	batt_drv->power_metrics.data[batt_drv->power_metrics.idx].time = now;

error:
	schedule_delayed_work(&batt_drv->power_metrics.work, msecs_to_jiffies(next_work));
}

/* ------------------------------------------------------------------------- */

/*
 * Keep the number of properties under UEVENT_NUM_ENVP (minus # of
 * standard uevent variables) i.e 26.
 *
 * Removed the following from sysnodes
 * GBMS_PROP_ADAPTER_DETAILS			gbms
 * POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT	gbms
 * POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE	gbms
 *
 * POWER_SUPPLY_PROP_CHARGE_TYPE,
 * POWER_SUPPLY_PROP_CURRENT_AVG,
 * POWER_SUPPLY_PROP_VOLTAGE_AVG,
 * POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
 * POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
 * POWER_SUPPLY_PROP_VOLTAGE_OCV,
 */

static enum power_supply_property gbatt_battery_props[] = {
	POWER_SUPPLY_PROP_CAPACITY,
	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
	POWER_SUPPLY_PROP_CHARGE_COUNTER,
	POWER_SUPPLY_PROP_CHARGE_FULL,
	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
	POWER_SUPPLY_PROP_CURRENT_AVG,
	POWER_SUPPLY_PROP_CURRENT_NOW,
	POWER_SUPPLY_PROP_CYCLE_COUNT,
	POWER_SUPPLY_PROP_HEALTH,
	POWER_SUPPLY_PROP_PRESENT,
	POWER_SUPPLY_PROP_SERIAL_NUMBER,
	POWER_SUPPLY_PROP_STATUS,
	POWER_SUPPLY_PROP_TEMP,
	POWER_SUPPLY_PROP_TECHNOLOGY,
	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,	/* No need for this? */
	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
	POWER_SUPPLY_PROP_VOLTAGE_NOW,		/* 23 */
	POWER_SUPPLY_PROP_VOLTAGE_OCV,

	/*  hard limit to 26 */
};

static bool temp_defend_dry_run(struct gvotable_election *temp_dryrun_votable)
{
	bool dry_run = 1;

	if (!temp_dryrun_votable)
		temp_dryrun_votable =
			gvotable_election_get_handle(VOTABLE_TEMP_DRYRUN);
	if (temp_dryrun_votable)
		dry_run = !!gvotable_get_current_int_vote(temp_dryrun_votable);

	return dry_run;
}

/*
 * status is:
 * . _UNKNOWN during init
 * . _DISCHARGING when not connected
 * when connected to a power supply status is
 * . _FULL (until disconnect) after the charger flags DONE if SSOC=100%
 * . _CHARGING if FG reports _FULL but SSOC < 100% (should not happen)
 * . _CHARGING if FG reports _NOT_CHARGING
 * . _NOT_CHARGING if FG report _DISCHARGING
 * . same as FG state otherwise
 */
static int gbatt_get_status(struct batt_drv *batt_drv,
			    union power_supply_propval *val)
{
	int err, ssoc;

	if (batt_drv->ssoc_state.buck_enabled == 0) {
		val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
		return 0;
	}

	if (batt_drv->ssoc_state.buck_enabled == -1) {
		val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
		return 0;
	}

	/* ->buck_enabled = 1, from here ownward device is connected */

	if (batt_drv->batt_health == POWER_SUPPLY_HEALTH_OVERHEAT &&
	    !temp_defend_dry_run(batt_drv->temp_dryrun_votable)) {
		val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
		return 0;
	}

	if (batt_drv->msc_state == MSC_HEALTH_PAUSE) {
		/* Expect AC to discharge in PAUSE. However, UI must persist */
		val->intval = POWER_SUPPLY_STATUS_CHARGING;
		return 0;
	}

	if (!batt_drv->fg_psy)
		return -EINVAL;

	ssoc = ssoc_get_capacity(&batt_drv->ssoc_state);

	/* FULL when the charger said so and SSOC == 100% */
	if (batt_drv->chg_done && ssoc == SSOC_FULL) {
		val->intval = POWER_SUPPLY_STATUS_FULL;
		return 0;
	}

	err = power_supply_get_property(batt_drv->fg_psy,
					POWER_SUPPLY_PROP_STATUS,
					val);
	if (err != 0)
		return err;

	if (val->intval == POWER_SUPPLY_STATUS_FULL) {

		/* not full unless the charger says so */
		if (!batt_drv->chg_done)
			val->intval = POWER_SUPPLY_STATUS_CHARGING;

		/* NOTE: FG driver could flag FULL before GDF is at 100% when
		 * gauge is not tuned or when capacity estimates are wrong.
		 */
		if (ssoc != SSOC_FULL)
			val->intval = POWER_SUPPLY_STATUS_CHARGING;

	} else if (val->intval == POWER_SUPPLY_STATUS_NOT_CHARGING) {
		/* smooth transition between charging and full */
		val->intval = POWER_SUPPLY_STATUS_CHARGING;
	} else if (val->intval == POWER_SUPPLY_STATUS_DISCHARGING) {
		/* connected and discharging is NOT charging */
		val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
	}

	return 0;
}

/* lock batt_drv->batt_lock */
static int gbatt_get_capacity(struct batt_drv *batt_drv)
{
	struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	int capacity;

	if (batt_drv->fake_capacity >= 0 && batt_drv->fake_capacity <= 100)
		capacity = batt_drv->fake_capacity;
	else
		capacity = ssoc_get_capacity(ssoc_state);

	return capacity;
}


static void gbatt_reset_curve(struct batt_drv *batt_drv, int ssoc_cap)
{
	struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	const qnum_t cap = qnum_fromint(ssoc_cap);
	const qnum_t gdf = ssoc_state->ssoc_gdf;
	enum ssoc_uic_type type;

	if (gdf < cap) {
		type = SSOC_UIC_TYPE_DSG;
	} else {
		type = SSOC_UIC_TYPE_CHG;
	}

	pr_info("reset curve at gdf=%d.%d cap=%d.%d type=%d\n",
		qnum_toint(gdf), qnum_fracdgt(gdf),
		qnum_toint(cap), qnum_fracdgt(cap),
		type);

	/* current is the drop point on the discharge curve */
	ssoc_change_curve_at_gdf(ssoc_state, gdf, cap, type);
	ssoc_work(ssoc_state, batt_drv->fg_psy);
	dump_ssoc_state(ssoc_state, batt_drv->ssoc_log);
}

/* splice the curve at point when the SSOC is removed */
static void gbatt_set_capacity(struct batt_drv *batt_drv, int capacity)
{
	if (capacity < 0)
		capacity = -EINVAL;

	if (batt_drv->batt_health != POWER_SUPPLY_HEALTH_OVERHEAT) {
		/* just set the value if not in overheat  */
	} else if (capacity < 0 && batt_drv->fake_capacity >= 0) {
		gbatt_reset_curve(batt_drv, batt_drv->fake_capacity);
	} else if (capacity > 0) {
		/* TODO: convergence to the new capacity? */
	}

	batt_drv->fake_capacity = capacity;
}

static int gbatt_set_health(struct batt_drv *batt_drv, int health)
{
	if (health > POWER_SUPPLY_HEALTH_HOT ||
	    health < POWER_SUPPLY_HEALTH_UNKNOWN)
		return -EINVAL;

	batt_drv->batt_health = health;

	/* disable health charging if in overheat */
	if (health == POWER_SUPPLY_HEALTH_OVERHEAT)
		msc_logic_health(batt_drv);

	return 0;
}

#define RESTORE_SOC_THRESHOLD	5
static int gbatt_restore_capacity(struct batt_drv *batt_drv)
{
	struct batt_ssoc_state *ssoc_state = &batt_drv->ssoc_state;
	int ret = 0, save_soc, gdf_soc;

	ret = gbms_storage_read(GBMS_TAG_RSOC, &ssoc_state->save_soc,
						sizeof(ssoc_state->save_soc));

	if (ret < 0)
		return ret;

	if (ssoc_state->save_soc) {
		save_soc = (int)ssoc_state->save_soc;
		gdf_soc = qnum_toint(ssoc_state->ssoc_gdf);
		pr_info("save_soc:%d, gdf:%d", save_soc, gdf_soc);

		if ((save_soc < gdf_soc) ||
		    (save_soc - gdf_soc) > RESTORE_SOC_THRESHOLD)
			return ret;

		gbatt_reset_curve(batt_drv, save_soc);
	}

	return ret;
}

#define TTF_REPORT_MAX_RATIO	300
static int gbatt_get_property(struct power_supply *psy,
				 enum power_supply_property psp,
				 union power_supply_propval *val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)
					power_supply_get_drvdata(psy);
	int rc, err = 0;

	pm_runtime_get_sync(batt_drv->device);
	if (!batt_drv->init_complete || !batt_drv->resume_complete) {
		pm_runtime_put_sync(batt_drv->device);
		return -EAGAIN;
	}
	pm_runtime_put_sync(batt_drv->device);

	switch (psp) {
	case GBMS_PROP_ADAPTER_DETAILS:
		val->intval = batt_drv->ce_data.adapter_details.v;
		break;

	case GBMS_PROP_DEAD_BATTERY:
		val->intval = batt_drv->dead_battery;
		break;
	/*
	 * ng charging:
	 * 1) write to GBMS_PROP_CHARGE_CHARGER_STATE,
	 * 2) read POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and
	 *    POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
	 */
	case GBMS_PROP_CHARGE_CHARGER_STATE:
		val->intval = batt_drv->chg_state.v;
		break;

	case POWER_SUPPLY_PROP_CYCLE_COUNT:
		if (batt_drv->cycle_count < 0)
			err = batt_drv->cycle_count;
		else
			val->intval = batt_drv->cycle_count;
		break;

	case POWER_SUPPLY_PROP_CAPACITY:
		mutex_lock(&batt_drv->batt_lock);
		val->intval = gbatt_get_capacity(batt_drv);
		mutex_unlock(&batt_drv->batt_lock);
		break;

	case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
		if (batt_drv->fake_capacity >= 0 &&
				batt_drv->fake_capacity <= 100)
			val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
		else
			val->intval = batt_drv->capacity_level;
		break;

	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
		mutex_lock(&batt_drv->chg_lock);
		val->intval = batt_drv->cc_max;
		mutex_unlock(&batt_drv->chg_lock);
		break;
	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
		mutex_lock(&batt_drv->chg_lock);
		val->intval = batt_drv->fv_uv;
		mutex_unlock(&batt_drv->chg_lock);
		break;

	/*
	 * POWER_SUPPLY_PROP_CHARGE_DONE comes from the charger BUT battery
	 * has also an idea about it.
	 *	mutex_lock(&batt_drv->chg_lock);
	 *	val->intval = batt_drv->chg_done;
	 *	mutex_unlock(&batt_drv->chg_lock);
	 */

	/*
	 * compat: POWER_SUPPLY_PROP_CHARGE_TYPE comes from the charger so
	 * using the last value reported from the CHARGER. This (of course)
	 * means that NG charging needs to be enabled.
	 */
	case POWER_SUPPLY_PROP_CHARGE_TYPE:
		mutex_lock(&batt_drv->chg_lock);
		val->intval = batt_drv->chg_state.f.chg_type;
		mutex_unlock(&batt_drv->chg_lock);
		break;

	case POWER_SUPPLY_PROP_STATUS:
		err = gbatt_get_status(batt_drv, val);
		break;

	/* health */
	case POWER_SUPPLY_PROP_HEALTH:
		if (batt_drv->batt_health == POWER_SUPPLY_HEALTH_OVERHEAT &&
		    temp_defend_dry_run(batt_drv->temp_dryrun_votable)) {
			val->intval = POWER_SUPPLY_HEALTH_GOOD;
		} else if (batt_drv->batt_health !=
			   POWER_SUPPLY_HEALTH_UNKNOWN) {
			val->intval = batt_drv->batt_health;
		} else if (!batt_drv->fg_psy) {
			val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
		} else {
			rc = power_supply_get_property(batt_drv->fg_psy,
							psp, val);
			if (rc < 0)
				val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
			batt_drv->soh = val->intval;
		}
		if (batt_drv->report_health != val->intval) {
			/* Log health change for debug */
			logbuffer_log(batt_drv->ttf_stats.ttf_log,
				      "h:%d->%d batt_health:%d dry_run:%d soh:%d",
				      batt_drv->report_health, val->intval, batt_drv->batt_health,
				      temp_defend_dry_run(batt_drv->temp_dryrun_votable),
				      batt_drv->soh);
			batt_drv->report_health = val->intval;
		}
		break;

	/* cannot set err, negative estimate will revert to HAL */
	case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: {
		ktime_t res;
		int max_ratio;

		max_ratio = batt_ttf_estimate(&res, batt_drv);
		if (max_ratio >= TTF_REPORT_MAX_RATIO) {
			val->intval = 0;
		} else if (max_ratio >= 0) {
			if (res < 0)
				res = 0;
			val->intval = res;
		} else if (!batt_drv->fg_psy) {
			val->intval = -1;
		} else {
			rc = power_supply_get_property(batt_drv->fg_psy,
							psp, val);
			if (rc < 0)
				val->intval = -1;
		}
	} break;

	case POWER_SUPPLY_PROP_TEMP:
		err = gbatt_get_temp(batt_drv, &val->intval);
		break;

	case POWER_SUPPLY_PROP_CURRENT_AVG:
	case POWER_SUPPLY_PROP_CURRENT_NOW:
		if (!batt_drv->fg_psy)
			return -EINVAL;
		err = power_supply_get_property(batt_drv->fg_psy, psp, val);
		if (err == 0)
			val->intval = -val->intval;
		break;

	/* Can force the state here */
	case POWER_SUPPLY_PROP_PRESENT:
		if (batt_drv->fake_battery_present != -1) {
			val->intval = batt_drv->fake_battery_present;
		} else if (batt_drv->fg_psy) {

			/* TODO: use the cached value? */
			rc = power_supply_get_property(batt_drv->fg_psy,
						       psp, val);
			if (rc < 0)
				val->intval = 0;
		} else {
			err = -EINVAL;
		}
		break;

	case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
		if (batt_drv->topoff)
			val->intval = batt_drv->topoff;
		else
			val->intval = -1;
		break;

	default:
		if (!batt_drv->fg_psy)
			return -EINVAL;
		err = power_supply_get_property(batt_drv->fg_psy, psp, val);
		break;
	}

	if (err < 0) {
		pr_debug("gbatt: get_prop cannot read psp=%d\n", psp);
		return err;
	}

	return 0;
}

static int gbatt_set_property(struct power_supply *psy,
				 enum power_supply_property psp,
				 const union power_supply_propval *val)
{
	struct batt_drv *batt_drv = (struct batt_drv *)
					power_supply_get_drvdata(psy);
	int ret = 0;

	pm_runtime_get_sync(batt_drv->device);
	if (!batt_drv->init_complete || !batt_drv->resume_complete) {
		pm_runtime_put_sync(batt_drv->device);
		return -EAGAIN;
	}
	pm_runtime_put_sync(batt_drv->device);

	switch (psp) {
	case GBMS_PROP_ADAPTER_DETAILS:
		mutex_lock(&batt_drv->stats_lock);
		batt_drv->ce_data.adapter_details.v = val->intval;
		mutex_unlock(&batt_drv->stats_lock);
	break;

	/* NG Charging, where it all begins */
	case GBMS_PROP_CHARGE_CHARGER_STATE:
		mutex_lock(&batt_drv->chg_lock);
		batt_drv->chg_state.v = gbms_propval_int64val(val);
		ret = batt_chg_logic(batt_drv);
		mutex_unlock(&batt_drv->chg_lock);
		break;

	case POWER_SUPPLY_PROP_CAPACITY:
		mutex_lock(&batt_drv->chg_lock);
		if (val->intval != batt_drv->fake_capacity) {
			gbatt_set_capacity(batt_drv, val->intval);
			if (batt_drv->psy)
				power_supply_changed(batt_drv->psy);
		}
		mutex_unlock(&batt_drv->chg_lock);
		break;

	case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
		if (val->intval <= 0)
			batt_drv->ttf_stats.ttf_fake = -1;
		else
			batt_drv->ttf_stats.ttf_fake = val->intval;
		pr_info("time_to_full = %lld\n", batt_drv->ttf_stats.ttf_fake);
		if (batt_drv->psy)
			power_supply_changed(batt_drv->psy);
		break;
	case POWER_SUPPLY_PROP_HEALTH:
		mutex_lock(&batt_drv->chg_lock);
		if (batt_drv->batt_health != val->intval) {
			ret = gbatt_set_health(batt_drv, val->intval);
			if (ret == 0 && batt_drv->psy)
				power_supply_changed(batt_drv->psy);
		}
		mutex_unlock(&batt_drv->chg_lock);
		break;
	default:
		ret = -EINVAL;
		break;
	}

	if (ret < 0) {
		pr_debug("gbatt: get_prop cannot write psp=%d\n", psp);
		return ret;
	}


	return 0;
}

static int gbatt_property_is_writeable(struct power_supply *psy,
					  enum power_supply_property psp)
{
	switch (psp) {
	case GBMS_PROP_CHARGE_CHARGER_STATE:
	case POWER_SUPPLY_PROP_CAPACITY:
	case GBMS_PROP_ADAPTER_DETAILS:
	case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
	case POWER_SUPPLY_PROP_HEALTH:
		return 1;
	default:
		break;
	}

	return 0;
}

static struct power_supply_desc gbatt_psy_desc = {
	.name = "battery",
	.type = POWER_SUPPLY_TYPE_BATTERY,
	.get_property = gbatt_get_property,
	.set_property = gbatt_set_property,
	.property_is_writeable = gbatt_property_is_writeable,
	.properties = gbatt_battery_props,
	.num_properties = ARRAY_SIZE(gbatt_battery_props),
};

/* ------------------------------------------------------------------------ */

static int batt_init_sd(struct swelling_data *sd)
{
	int ret, i, j;

	if (!sd->is_enable)
		return 0;

	ret = gbms_storage_read(GBMS_TAG_STRD, &sd->saved,
				sizeof(sd->saved));
	if (ret < 0)
		return ret;

	if (sd->saved[SD_CHG_START] == 0xFFFF) {
		/* Empty EEPROM, initial sd_saved */
		for (i = 0; i < BATT_SD_SAVE_SIZE; i++)
			sd->saved[i] = 0;
	} else {
		/* Available data, restore */
		for (i = 0; i < BATT_TEMP_RECORD_THR; i++) {
			j = i + SD_DISCHG_START;
			sd->chg[i] = sd->saved[i] * SAVE_UNIT;
			sd->dischg[i] = sd->saved[j] * SAVE_UNIT;
		}
	}

	return ret;
}

/* bhi_init */
static int batt_bhi_init(struct batt_drv *batt_drv)
{
	struct health_data *health_data = &batt_drv->health_data;
	int ret;

	/* see enum bhi_algo */
	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-algo-ver",
				   &health_data->bhi_algo);
	if (ret < 0)
		health_data->bhi_algo = BHI_ALGO_DISABLED;
	/* default weights */
	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-w_ci",
				   &health_data->bhi_w_ci);
	if (ret < 0)
		health_data->bhi_w_ci = 100;
	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-w_pi",
				   &health_data->bhi_w_pi);
	if (ret < 0)
		health_data->bhi_w_pi = 0;
	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-w_sd",
				   &health_data->bhi_w_sd);
	if (ret < 0)
		health_data->bhi_w_sd = 0;
	/* default thresholds */
	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-status-marginal",
				   &health_data->marginal_threshold);
	if (ret < 0)
		health_data->marginal_threshold = BHI_MARGINAL_THRESHOLD_DEFAULT;

	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-status-need-rep",
				   &health_data->need_rep_threshold);
	if (ret < 0)
		health_data->need_rep_threshold = BHI_NEED_REP_THRESHOLD_DEFAULT;
	/* cycle count thresholds */
	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-cycle-count-marginal",
				   &health_data->cycle_count_marginal_threshold);
	if (ret < 0)
		health_data->cycle_count_marginal_threshold = BHI_CC_MARGINAL_THRESHOLD_DEFAULT;

	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-cycle-count-need-rep",
				   &health_data->cycle_count_need_rep_threshold);
	if (ret < 0)
		health_data->cycle_count_need_rep_threshold = BHI_CC_NEED_REP_THRESHOLD_DEFAULT;

	/* algorithm BHI_ALGO_INDI capacity threshold */
	ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-indi-cap",
				   &health_data->bhi_indi_cap);
	if (ret < 0)
		health_data->bhi_indi_cap = BHI_INDI_CAP_DEFAULT;

	/* design is the value used to build the charge table */
	health_data->bhi_data.capacity_design = batt_drv->battery_capacity;

	/* debug data initialization */
	health_data->bhi_debug_cycle_count = 0;
	health_data->bhi_debug_cap_index = 0;
	health_data->bhi_debug_imp_index = 0;
	health_data->bhi_debug_sd_index = 0;
	health_data->bhi_debug_health_index = 0;

	return 0;
}


static int batt_prop_iter(int index, gbms_tag_t *tag, void *ptr)
{
	static gbms_tag_t keys[] = {GBMS_TAG_HCNT};
	const int count = ARRAY_SIZE(keys);

	if (index >= 0 && index < count) {
		*tag = keys[index];
		return 0;
	}

	return -ENOENT;
}

static int batt_prop_read(gbms_tag_t tag, void *buff, size_t size, void *ptr)
{
	struct batt_drv *batt_drv = ptr;
	int index, ret = 0;

	switch (tag) {
	case GBMS_TAG_HCNT:
		if (size != sizeof(u16))
			return -ERANGE;
		/* history needs to be enabled for this */
		index = hist_get_index(batt_drv->hist_data_saved_cnt, batt_drv);
		if (index < 0)
			return index;
		*(u16 *)buff = index;
		break;
	default:
		ret = -ENOENT;
		break;
	}

	return ret;
}

static struct gbms_storage_desc batt_prop_dsc = {
	.iter = batt_prop_iter,
	.read = batt_prop_read,
};


static void google_battery_init_work(struct work_struct *work)
{
	struct batt_drv *batt_drv = container_of(work, struct batt_drv,
						 init_work.work);
	struct device_node *node = batt_drv->device->of_node;
	struct power_supply *fg_psy = batt_drv->fg_psy;
	const char *batt_vs_tz_name = NULL;
	int ret = 0;

	batt_rl_reset(batt_drv);
	batt_drv->dead_battery = true; /* clear in batt_work() */
	batt_drv->capacity_level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
	batt_drv->ssoc_state.buck_enabled = -1;
	batt_drv->hold_taper_ws = false;
	batt_drv->fake_temp = 0;
	batt_drv->fake_battery_present = -1;
	batt_drv->boot_to_os_attempts = 0;
	batt_reset_chg_drv_state(batt_drv);

	mutex_init(&batt_drv->chg_lock);
	mutex_init(&batt_drv->batt_lock);
	mutex_init(&batt_drv->stats_lock);
	mutex_init(&batt_drv->cc_data.lock);
	mutex_init(&batt_drv->bpst_state.lock);

	if (!batt_drv->fg_psy) {

		fg_psy = power_supply_get_by_name(batt_drv->fg_psy_name);
		if (!fg_psy) {
			pr_info("failed to get \"%s\" power supply, retrying...\n",
				batt_drv->fg_psy_name);
			goto retry_init_work;
		}

		batt_drv->fg_psy = fg_psy;
	}

	if (!batt_drv->batt_present) {
		ret = GPSY_GET_PROP(fg_psy, POWER_SUPPLY_PROP_PRESENT);
		if (ret == -EAGAIN)
			goto retry_init_work;

		batt_drv->batt_present = (ret > 0);
		if (!batt_drv->batt_present)
			pr_warn("battery not present (ret=%d)\n", ret);
	}

	ret = of_property_read_u32(node, "google,recharge-soc-threshold",
				   &batt_drv->ssoc_state.rl_soc_threshold);
	if (ret < 0)
		batt_drv->ssoc_state.rl_soc_threshold =
				DEFAULT_BATT_DRV_RL_SOC_THRESHOLD;

	ret = of_property_read_u32(node, "google,bd-trickle-recharge-soc",
				   &batt_drv->ssoc_state.bd_trickle_recharge_soc);
	if (ret < 0)
		batt_drv->ssoc_state.bd_trickle_recharge_soc =
				DEFAULT_BD_TRICKLE_RL_SOC_THRESHOLD;

	batt_drv->ssoc_state.bd_trickle_dry_run = false;

	ret = of_property_read_u32(node, "google,bd-trickle-reset-sec",
				   &batt_drv->ssoc_state.bd_trickle_reset_sec);
	if (ret < 0)
		batt_drv->ssoc_state.bd_trickle_reset_sec =
				DEFAULT_BD_TRICKLE_RESET_SEC;

	batt_drv->ssoc_state.bd_trickle_enable =
		of_property_read_bool(node, "google,bd-trickle-enable");

	ret = of_property_read_u32(node, "google,ssoc-delta",
				   &batt_drv->ssoc_state.ssoc_delta);
	if (ret < 0)
		batt_drv->ssoc_state.ssoc_delta = SSOC_DELTA;

	ret = of_property_read_u32(node, "google,health-safety-margin",
				   &batt_drv->health_safety_margin);
	if (ret < 0)
		batt_drv->health_safety_margin = DEFAULT_HEALTH_SAFETY_MARGIN;

	ret = of_property_read_u32_array(node, "google,temp-record-thr",
					 batt_drv->sd.temp_thr,
					 BATT_TEMP_RECORD_THR);
	if (ret == 0) {
		ret = of_property_read_u32_array(node, "google,soc-record-thr",
						 batt_drv->sd.soc_thr,
						 BATT_TEMP_RECORD_THR);
		if (ret == 0)
			batt_drv->sd.is_enable = true;
	}

	ret = batt_init_sd(&batt_drv->sd);
	if (ret < 0) {
		pr_err("Unable to read swelling data, ret=%d\n", ret);
		batt_drv->sd.is_enable = false;
	}

	/* init bpst setting */
	ret = batt_init_bpst_profile(batt_drv);
	if (ret < 0)
		pr_err("bpst profile disabled, ret=%d\n", ret);

	/* init shutdown flag */
	ret = batt_init_shutdown_flag(batt_drv);
	if (ret < 0)
		pr_err("failed to init shutdown flag, ret=%d\n", ret);

	/* cycle count is cached: read here bc SSOC, chg_profile might use it */
	batt_update_cycle_count(batt_drv);

	ret = ssoc_init(&batt_drv->ssoc_state, node, fg_psy);
	if (ret < 0 && batt_drv->batt_present)
		goto retry_init_work;

	dump_ssoc_state(&batt_drv->ssoc_state, batt_drv->ssoc_log);

	ret = gbatt_restore_capacity(batt_drv);
	if (ret < 0)
		pr_warn("unable to restore capacity, ret=%d\n", ret);
	else
		batt_drv->ssoc_state.save_soc_available = true;

	/* could read EEPROM and history here */

	/* chg_profile will use cycle_count when aacr is enabled */
	ret = batt_init_chg_profile(batt_drv);
	if (ret == -EPROBE_DEFER)
		goto retry_init_work;

	if (ret < 0) {
		pr_err("charging profile disabled, ret=%d\n", ret);
	} else if (batt_drv->battery_capacity) {
		google_battery_dump_profile(&batt_drv->chg_profile);
	}

	cev_stats_init(&batt_drv->ce_data, &batt_drv->chg_profile);
	cev_stats_init(&batt_drv->ce_qual, &batt_drv->chg_profile);

	batt_drv->fg_nb.notifier_call = psy_changed;
	ret = power_supply_reg_notifier(&batt_drv->fg_nb);
	if (ret < 0)
		pr_err("cannot register power supply notifer, ret=%d\n",
			ret);

	batt_drv->batt_ws = wakeup_source_register(NULL, "google-battery");
	batt_drv->taper_ws = wakeup_source_register(NULL, "Taper");
	batt_drv->poll_ws = wakeup_source_register(NULL, "Poll");
	batt_drv->msc_ws = wakeup_source_register(NULL, "MSC");
	if (!batt_drv->batt_ws || !batt_drv->taper_ws ||
			!batt_drv->poll_ws || !batt_drv->msc_ws)
		pr_err("failed to register wakeup sources\n");

	mutex_lock(&batt_drv->cc_data.lock);
	ret = batt_cycle_count_load(&batt_drv->cc_data);
	if (ret < 0)
		pr_err("cannot restore bin count ret=%d\n", ret);
	mutex_unlock(&batt_drv->cc_data.lock);

	batt_drv->fake_capacity = (batt_drv->batt_present) ? -EINVAL
						: DEFAULT_BATT_FAKE_CAPACITY;

	/* charging configuration */
	ret = of_property_read_u32(node, "google,update-interval",
				   &batt_drv->batt_update_interval);
	if (ret < 0)
		batt_drv->batt_update_interval = DEFAULT_BATT_UPDATE_INTERVAL;

	/* high temperature notify configuration */
	ret = of_property_read_u32(batt_drv->device->of_node,
				   "google,update-high-temp-threshold",
				   &batt_drv->batt_update_high_temp_threshold);
	if (ret < 0)
		batt_drv->batt_update_high_temp_threshold =
					DEFAULT_HIGH_TEMP_UPDATE_THRESHOLD;
	/* charge statistics */
	ret = of_property_read_u32(node, "google,chg-stats-qual-time",
				   &batt_drv->chg_sts_qual_time);
	if (ret < 0)
		batt_drv->chg_sts_qual_time =
					DEFAULT_CHG_STATS_MIN_QUAL_TIME;

	ret = of_property_read_u32(node, "google,chg-stats-delta-soc",
				   &batt_drv->chg_sts_delta_soc);
	if (ret < 0)
		batt_drv->chg_sts_delta_soc =
					DEFAULT_CHG_STATS_MIN_DELTA_SOC;

	/* time to full */
	ret = ttf_stats_init(&batt_drv->ttf_stats, batt_drv->device,
			     batt_drv->battery_capacity);
	if (ret < 0)
		pr_info("time to full not available\n");

	/* TTF log is used report more things nowadays */
	batt_drv->ttf_stats.ttf_log = logbuffer_register("ttf");
	if (IS_ERR(batt_drv->ttf_stats.ttf_log)) {
		ret = PTR_ERR(batt_drv->ttf_stats.ttf_log);
		dev_err(batt_drv->device, "failed to create ttf_log, ret=%d\n", ret);

		batt_drv->ttf_stats.ttf_log = NULL;
	}

	/* RAVG: google_resistance  */
	ret = batt_res_load_data(&batt_drv->health_data.bhi_data.res_state,
				 batt_drv->fg_psy);
	if (ret < 0)
		dev_warn(batt_drv->device, "RAVG not available (%d)\n", ret);
	batt_res_dump_logs(&batt_drv->health_data.bhi_data.res_state);

	/* health based charging, triggers */
	batt_drv->chg_health.always_on_soc = -1;

	ret = of_property_read_u32(batt_drv->device->of_node,
				   "google,chg-rest-soc",
				   &batt_drv->chg_health.rest_soc);
	if (ret < 0)
		batt_drv->chg_health.rest_soc = -1;

	ret = of_property_read_u32(batt_drv->device->of_node,
				   "google,chg-rest-rate",
				   &batt_drv->chg_health.rest_rate);
	if (ret < 0)
		batt_drv->chg_health.rest_rate = 0;

	ret = of_property_read_u32(batt_drv->device->of_node,
				   "google,chg-rest-rate-before-trigger",
				   &batt_drv->chg_health.rest_rate_before_trigger);
	if (ret < 0)
		batt_drv->chg_health.rest_rate_before_trigger = HEALTH_CHG_RATE_BEFORE_TRIGGER;

	/* override setting google,battery-roundtrip = 0 in device tree */
	batt_drv->disable_votes =
		of_property_read_bool(node, "google,disable-votes");
	if (batt_drv->disable_votes)
		pr_info("battery votes disabled\n");

	/* pairing battery vs. device */
	if (of_property_read_bool(node, "google,eeprom-pairing"))
		batt_drv->pairing_state = BATT_PAIRING_ENABLED;
	else
		batt_drv->pairing_state = BATT_PAIRING_DISABLED;

	/* use delta cycle count to adjust collecting period */
	ret = of_property_read_u32(batt_drv->device->of_node,
					"google,history-delta-cycle-count",
					&batt_drv->hist_delta_cycle_cnt);
	if (ret < 0)
		batt_drv->hist_delta_cycle_cnt = HCC_DEFAULT_DELTA_CYCLE_CNT;

	ret = of_property_read_u32(batt_drv->device->of_node, "google,batt-voltage-critical",
				   &batt_drv->batt_critical_voltage);
	if (ret < 0)
		batt_drv->batt_critical_voltage = VBATT_CRITICAL_LEVEL;

	/* battery virtual sensor */
	ret = of_property_read_string(batt_drv->device->of_node,
				      "google,batt-vs-tz-name",
				      &batt_vs_tz_name);
	if (ret == 0) {
		batt_drv->batt_vs_tz =
		    thermal_zone_device_register(batt_vs_tz_name, 0, 0,
						 batt_drv, &batt_vs_tz_ops, NULL, 0, 0);
		if (IS_ERR(batt_drv->batt_vs_tz)) {
			pr_err("batt_vs tz register failed. err:%ld\n",
			       PTR_ERR(batt_drv->batt_vs_tz));
			batt_drv->batt_vs_tz = NULL;
		} else {
			thermal_zone_device_update(batt_drv->batt_vs_tz, THERMAL_DEVICE_UP);
		}
		batt_drv->batt_vs_w = 88;

		pr_info("google,batt-vs-tz-name is %s\n", batt_vs_tz_name);
	}

	/* single battery disconnect */
	(void)batt_bpst_init_debugfs(batt_drv);

	/* these don't require nvm storage */
	ret = gbms_storage_register(&batt_prop_dsc, "battery", batt_drv);
	if (ret == -EBUSY)
		ret = 0;

	/* use delta cycle count != 0 to enable collecting history */
	if (batt_drv->hist_delta_cycle_cnt)
		batt_drv->blf_state = BATT_LFCOLLECT_ENABLED;

	/* google_battery expose history via a standard device */
	batt_drv->history = gbms_storage_create_device("battery_history",
						       GBMS_TAG_HIST);
	if (!batt_drv->history)
		pr_err("history not available\n");

	/* BHI: might need RAVG and battery history */
	ret = batt_bhi_init(batt_drv);
	if (ret < 0) {
		dev_warn(batt_drv->device, "BHI: not supported (%d)\n", ret);
	} else {
		/* reload the last estimates,  */
		ret = batt_bhi_data_load(batt_drv);
		if (ret < 0)
			dev_err(batt_drv->device, "BHI: invalid data, starting fresh (%d)\n", ret);
	}

	/* power metrics */
	schedule_delayed_work(&batt_drv->power_metrics.work,
			      msecs_to_jiffies(batt_drv->power_metrics.polling_rate * 1000));

	pr_info("google_battery init_work done\n");

	batt_drv->init_complete = true;
	batt_drv->resume_complete = true;

	schedule_delayed_work(&batt_drv->batt_work, 0);

	return;

retry_init_work:
	schedule_delayed_work(&batt_drv->init_work,
			      msecs_to_jiffies(BATT_DELAY_INIT_MS));
}

static struct thermal_zone_of_device_ops google_battery_tz_ops = {
	.get_temp = google_battery_tz_get_cycle_count,
};

static int batt_ravg_init(struct batt_res *res_state, struct device_node *node)
{
	int ret;

	if (of_property_read_bool(node, "google,no-ravg"))
		return -ENOENT;

	/* Resistance Estimation configuration */
	ret = of_property_read_u32(node, "google,res-temp-hi",
				   &res_state->res_temp_high);
	if (ret < 0)
		res_state->res_temp_high = DEFAULT_RES_TEMP_HIGH;

	ret = of_property_read_u32(node, "google,res-temp-lo",
				   &res_state->res_temp_low);
	if (ret < 0)
		res_state->res_temp_low = DEFAULT_RES_TEMP_LOW;

	ret = of_property_read_u32(node, "google,res-soc-thresh",
				   &res_state->ravg_soc_high);
	if (ret < 0)
		res_state->ravg_soc_high = DEFAULT_RAVG_SOC_HIGH;
	ret = of_property_read_u32(node, "google,ravg-soc-low",
				   &res_state->ravg_soc_low);
	if (ret < 0)
		res_state->ravg_soc_low = DEFAULT_RAVG_SOC_LOW;

	ret = of_property_read_u32(node, "google,res-filt-length",
				   &res_state->estimate_filter);
	if (ret < 0)
		res_state->estimate_filter = DEFAULT_RES_FILT_LEN;

	return 0;
}

static int google_battery_probe(struct platform_device *pdev)
{
	const char *fg_psy_name, *psy_name = NULL;
	struct batt_drv *batt_drv;
	int ret;
	struct power_supply_config psy_cfg = {};

	batt_drv = devm_kzalloc(&pdev->dev, sizeof(*batt_drv), GFP_KERNEL);
	if (!batt_drv)
		return -ENOMEM;

	batt_drv->device = &pdev->dev;

	ret = of_property_read_string(pdev->dev.of_node, "google,fg-psy-name",
				      &fg_psy_name);
	if (ret != 0) {
		pr_err("cannot read google,fg-psy-name, ret=%d\n", ret);
		return -EINVAL;
	}

	batt_drv->fg_psy_name = devm_kstrdup(&pdev->dev, fg_psy_name,
					     GFP_KERNEL);
	if (!batt_drv->fg_psy_name)
		return -ENOMEM;

	/* change name and type for debug/test */
	if (of_property_read_bool(pdev->dev.of_node, "google,psy-type-unknown"))
		gbatt_psy_desc.type = POWER_SUPPLY_TYPE_UNKNOWN;

	ret = of_property_read_string(pdev->dev.of_node,
				      "google,psy-name", &psy_name);
	if (ret == 0) {
		gbatt_psy_desc.name =
		    devm_kstrdup(&pdev->dev, psy_name, GFP_KERNEL);
	}

	INIT_DELAYED_WORK(&batt_drv->init_work, google_battery_init_work);
	INIT_DELAYED_WORK(&batt_drv->batt_work, google_battery_work);
	INIT_DELAYED_WORK(&batt_drv->power_metrics.work, power_metrics_data_work);
	platform_set_drvdata(pdev, batt_drv);

	psy_cfg.drv_data = batt_drv;
	psy_cfg.of_node = pdev->dev.of_node;

	batt_drv->psy = devm_power_supply_register(batt_drv->device,
						   &gbatt_psy_desc, &psy_cfg);
	if (IS_ERR(batt_drv->psy)) {
		ret = PTR_ERR(batt_drv->psy);
		if (ret == -EPROBE_DEFER)
			return -EPROBE_DEFER;

		/* TODO: fail with -ENODEV */
		dev_err(batt_drv->device,
			"Couldn't register as power supply, ret=%d\n", ret);
	}

	batt_drv->ssoc_log = logbuffer_register("ssoc");
	if (IS_ERR(batt_drv->ssoc_log)) {
		ret = PTR_ERR(batt_drv->ssoc_log);
		dev_err(batt_drv->device,
			"failed to create ssoc_log, ret=%d\n", ret);
		batt_drv->ssoc_log = NULL;
	}

	/* RAVG: google_resistance */
	ret = batt_ravg_init(&batt_drv->health_data.bhi_data.res_state,
			     pdev->dev.of_node);
	if (ret < 0)
		dev_info(batt_drv->device, "RAVG: not available\n");

	batt_drv->tz_dev = thermal_zone_of_sensor_register(batt_drv->device,
				0, batt_drv, &google_battery_tz_ops);
	if (IS_ERR(batt_drv->tz_dev)) {
		pr_err("battery tz register failed. err:%ld\n",
			PTR_ERR(batt_drv->tz_dev));
		ret = PTR_ERR(batt_drv->tz_dev);
		batt_drv->tz_dev = NULL;
	} else {
		thermal_zone_device_update(batt_drv->tz_dev, THERMAL_DEVICE_UP);
	}

	batt_drv->fan_level = -1;
	batt_drv->fan_last_level = -1;
	batt_drv->fan_level_votable =
		gvotable_create_int_election(NULL, gvotable_comparator_int_max,
					     fan_level_cb, batt_drv);
	if (IS_ERR_OR_NULL(batt_drv->fan_level_votable)) {
		ret = PTR_ERR(batt_drv->fan_level_votable);
		dev_err(batt_drv->device, "Fail to create fan_level_votable\n");
		batt_drv->fan_level_votable = NULL;
	} else {
		gvotable_set_vote2str(batt_drv->fan_level_votable,
				      gvotable_v2s_int);
		gvotable_election_set_name(batt_drv->fan_level_votable,
					   VOTABLE_FAN_LEVEL);
		gvotable_cast_long_vote(batt_drv->fan_level_votable,
					"DEFAULT", FAN_LVL_UNKNOWN, true);
	}

	/* charge speed interface: status and type */
	batt_drv->csi_status_votable =
		gvotable_create_int_election(NULL, gvotable_comparator_int_min,
					     csi_status_cb, batt_drv);
	if (IS_ERR_OR_NULL(batt_drv->csi_status_votable)) {
		ret = PTR_ERR(batt_drv->csi_status_votable);
		batt_drv->csi_status_votable = NULL;
	}

	gvotable_set_default(batt_drv->csi_status_votable, (void *)CSI_STATUS_UNKNOWN);
	gvotable_set_vote2str(batt_drv->csi_status_votable, gvotable_v2s_int);
	gvotable_election_set_name(batt_drv->csi_status_votable, VOTABLE_CSI_STATUS);

	batt_drv->csi_type_votable =
		gvotable_create_int_election(NULL, gvotable_comparator_int_min,
					     csi_type_cb, batt_drv);
	if (IS_ERR_OR_NULL(batt_drv->csi_type_votable)) {
		ret = PTR_ERR(batt_drv->csi_type_votable);
		batt_drv->csi_type_votable = NULL;
	}

	gvotable_set_default(batt_drv->csi_type_votable, (void *)CSI_TYPE_UNKNOWN);
	gvotable_set_vote2str(batt_drv->csi_type_votable, gvotable_v2s_int);
	gvotable_election_set_name(batt_drv->csi_type_votable, VOTABLE_CSI_TYPE);

	/* AACR server side */
	batt_drv->aacr_cycle_grace = AACR_START_CYCLE_DEFAULT;
	batt_drv->aacr_cycle_max = AACR_MAX_CYCLE_DEFAULT;
	batt_drv->aacr_state = BATT_AACR_DISABLED;

	/* create the sysfs node */
	batt_init_fs(batt_drv);
	batt_bpst_init_fs(batt_drv);

	/* debugfs */
	(void)batt_init_debugfs(batt_drv);

	/* give time to fg driver to start */
	schedule_delayed_work(&batt_drv->init_work,
					msecs_to_jiffies(BATT_DELAY_INIT_MS));

	/* power metrics */
	batt_drv->power_metrics.polling_rate = 30;
	batt_drv->power_metrics.interval = 120;

	return 0;
}

static int google_battery_remove(struct platform_device *pdev)
{
	struct batt_drv *batt_drv = platform_get_drvdata(pdev);

	if (!batt_drv)
		return 0;

	if (batt_drv->ssoc_log)
		logbuffer_unregister(batt_drv->ssoc_log);
	if (batt_drv->ttf_stats.ttf_log)
		logbuffer_unregister(batt_drv->ttf_stats.ttf_log);
	if (batt_drv->tz_dev)
		thermal_zone_of_sensor_unregister(batt_drv->device,
				batt_drv->tz_dev);
	if (batt_drv->history)
		gbms_storage_cleanup_device(batt_drv->history);

	if (batt_drv->fg_psy)
		power_supply_put(batt_drv->fg_psy);

	batt_hist_free_data(batt_drv->hist_data);

	gbms_free_chg_profile(&batt_drv->chg_profile);

	wakeup_source_unregister(batt_drv->msc_ws);
	wakeup_source_unregister(batt_drv->batt_ws);
	wakeup_source_unregister(batt_drv->taper_ws);
	wakeup_source_unregister(batt_drv->poll_ws);

	gvotable_destroy_election(batt_drv->fan_level_votable);
	gvotable_destroy_election(batt_drv->csi_status_votable);
	gvotable_destroy_election(batt_drv->csi_type_votable);

	batt_drv->fan_level_votable = NULL;
	batt_drv->csi_status_votable = NULL;
	batt_drv->csi_type_votable = NULL;

	return 0;
}

#ifdef SUPPORT_PM_SLEEP
static int gbatt_pm_suspend(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct batt_drv *batt_drv = platform_get_drvdata(pdev);

	pm_runtime_get_sync(batt_drv->device);
	batt_drv->resume_complete = false;
	pm_runtime_put_sync(batt_drv->device);

	return 0;
}

static int gbatt_pm_resume(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct batt_drv *batt_drv = platform_get_drvdata(pdev);

	pm_runtime_get_sync(batt_drv->device);
	batt_drv->resume_complete = true;
	pm_runtime_put_sync(batt_drv->device);

	mod_delayed_work(system_wq, &batt_drv->batt_work, 0);

	return 0;
}

static const struct dev_pm_ops gbatt_pm_ops = {
	SET_SYSTEM_SLEEP_PM_OPS(gbatt_pm_suspend, gbatt_pm_resume)
};
#endif


static const struct of_device_id google_charger_of_match[] = {
	{.compatible = "google,battery"},
	{},
};
MODULE_DEVICE_TABLE(of, google_charger_of_match);


static struct platform_driver google_battery_driver = {
	.driver = {
		   .name = "google,battery",
		   .owner = THIS_MODULE,
		   .of_match_table = google_charger_of_match,
		   .probe_type = PROBE_PREFER_ASYNCHRONOUS,
#ifdef SUPPORT_PM_SLEEP
		   .pm = &gbatt_pm_ops,
#endif
		   },
	.probe = google_battery_probe,
	.remove = google_battery_remove,
};

module_platform_driver(google_battery_driver);

MODULE_DESCRIPTION("Google Battery Driver");
MODULE_AUTHOR("AleX Pelosi <apelosi@google.com>");
MODULE_LICENSE("GPL");
