/* 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 <linux/rtc.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 bm_date {
	u8 bm_y;
	u8 bm_m;
	u8 bm_d;
	u8 reserve;
};

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 */

	/* battery manufacture date */
	struct bm_date bm_date;		/* from eeprom SN */
	u8 act_date[BATT_EEPROM_TAG_XYMD_LEN];

};

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;
	int min_speed = csi_stats->csi_speed_min;
	int max_speed = csi_stats->csi_speed_max;
	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 (current_speed < 0)
			return;

		if (min_speed == max_speed && max_speed == 0)
			min_speed = max_speed = current_speed;
		else if (current_speed < min_speed)
			min_speed = current_speed;
		else if (current_speed > max_speed)
			max_speed = current_speed;

		csi_stats->csi_speed_min = min_speed;
		csi_stats->csi_speed_max = max_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->csi_speed_min + csi_stats->csi_speed_max) / 2) :
					  (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)
		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) / 1000;
	if (cc_max && cc_max < nominal_demand)
		nominal_demand = cc_max;

	chg_speed = ibatt * 100 / nominal_demand;

	pr_debug("chg_speed=%d ibatt=%d nominal_demand=%d cc_max=%d",
		 chg_speed, ibatt, nominal_demand, cc_max);

	/* 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 -------------------------------------------------------------------- */

/*
 * Format of XYMD:
 *   XYMD[0]: YEAR (1 CHARACTER, NUMERIC; LAST DIGIT OF YEAR)
 *   XYMD[1]: Month(1 Character ASCII,Alphanumeric;1-9 For Han-Sept,A=Oct,B=Nov,C=Dec)
 *   XYMD[2]: Day(1 Character ASCII,Alphanumeric;1-9 For 1st-9th, A=10th,B=11th,...X=31st;
 *            skip the letter “I” and the letter”O”)
 */
static inline int date_to_xymd(u8 val)
{
	if (val >= 23)
		return (val - 23) + 0x50; /* 0x50 = 'P', 23th */
	else if (val >= 18)
		return (val - 18) + 0x4a; /* 0x4a = 'J', 18th*/
	else if (val >= 10)
		return (val - 10) + 0x41; /* 0x41 = 'A', 10th*/
	else
		return (val + 0x30);
}

static inline int xymd_to_date(u8 val)
{
	if (val >= 0x50)
		return (val - 0x50) + 23; /* 0x50 = 'P', 23th */
	else if (val >= 0x4a)
		return (val - 0x4a) + 18; /* 0x4a = 'J', 18th*/
	else if (val >= 0x41)
		return (val - 0x41) + 10; /* 0x41 = 'A', 10th*/
	else
		return (val - 0x30);
}

static int batt_get_manufacture_date(struct bhi_data *bhi_data)
{
	struct bm_date *date = &bhi_data->bm_date;
	u8 data[BATT_EEPROM_TAG_XYMD_LEN];
	int ret = 0;

	ret = gbms_storage_read(GBMS_TAG_MYMD, data, sizeof(data));
	if (ret < 0)
		return ret;

	/* format: YYMMDD */
	date->bm_y = xymd_to_date(data[0]) + 20;
	date->bm_m = xymd_to_date(data[1]);
	date->bm_d = xymd_to_date(data[2]);
	pr_debug("%s: battery manufacture date: 20%d-%d-%d\n",
		 __func__, date->bm_y, date->bm_m, date->bm_d);

	return 0;
}

static int batt_get_activation_date(struct bhi_data *bhi_data)
{
	int ret;

	ret = gbms_storage_read(GBMS_TAG_AYMD, &bhi_data->act_date,
				sizeof(bhi_data->act_date));
	if (ret < 0)
		return ret;

	if (bhi_data->act_date[0] == 0xff) {
		/*
		 * TODO: set a default value
		 * might be set by first_usage_date_show() from user space
		 */
		bhi_data->act_date[0] = 0x30; /* 0x30 = '0', 2020 */
		bhi_data->act_date[1] = 0x43; /* 0x43 = 'C', 12th */
		bhi_data->act_date[2] = 0x31; /* 0x31 = '1', 1st */
	}

	return 0;
}

#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);

static ssize_t debug_set_first_usage_date(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;
	struct bhi_data *bhi_data = &batt_drv->health_data.bhi_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;

	/* reset device activation date */
	if (val == 1) {
		u8 act_date[BATT_EEPROM_TAG_XYMD_LEN];

		memset(act_date, 0xff, sizeof(act_date));
		ret = gbms_storage_write(GBMS_TAG_AYMD, act_date, sizeof(act_date));
		if (ret < 0)
			return -EINVAL;

		/* set a default value */
		bhi_data->act_date[0] = 0x30; /* 0x30 = '0', 2020 */
		bhi_data->act_date[1] = 0x43; /* 0x43 = 'C', 12th */
		bhi_data->act_date[2] = 0x31; /* 0x31 = '1', 1st */
	}

	return count;
}

BATTERY_DEBUG_ATTRIBUTE(debug_first_usage_date_fops, 0, debug_set_first_usage_date);

/* 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);

static ssize_t manufacturing_date_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 bm_date *date = &batt_drv->health_data.bhi_data.bm_date;
	struct rtc_time tm;

	tm.tm_year = date->bm_y + 100;	// base is 1900
	tm.tm_mon = date->bm_m - 1;	// 0 is Jan ... 11 is Dec
	tm.tm_mday = date->bm_d;	// 1st ... 31th

	return scnprintf(buf, PAGE_SIZE, "%lld\n", rtc_tm_to_time64(&tm));
}

static const DEVICE_ATTR_RO(manufacturing_date);

static ssize_t first_usage_date_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 bhi_data *bhi_data = &batt_drv->health_data.bhi_data;
	int value, ret;

	ret = kstrtoint(buf, 0, &value);
	if (ret < 0)
		return ret;

	/* set: YYMMDD */
	if (value > 0) {
		u8 act_date[BATT_EEPROM_TAG_XYMD_LEN];
		uint32_t date = value;

		ret = gbms_storage_read(GBMS_TAG_AYMD, act_date, sizeof(act_date));
		if (ret < 0)
			return -EINVAL;

		if (act_date[0] != 0xff)
			return count > 0 ? count : 0;

		act_date[0] = date_to_xymd((date >> 16) & 0xff - 20);
		act_date[1] = date_to_xymd((date >> 8) & 0xff);
		act_date[2] = date_to_xymd(date & 0xff);

		ret = gbms_storage_write(GBMS_TAG_AYMD, act_date, sizeof(act_date));
		if (ret < 0)
			return -EINVAL;

		/* update bhi_data->act_date */
		memcpy(&bhi_data->act_date, act_date, sizeof(act_date));
	}

	return count > 0 ? count : 0;
}

static ssize_t first_usage_date_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 bm_date date;
	struct rtc_time tm;

	/* format: YYMMDD */
	date.bm_y = xymd_to_date(bhi_data->act_date[0]) + 20;
	date.bm_m = xymd_to_date(bhi_data->act_date[1]);
	date.bm_d = xymd_to_date(bhi_data->act_date[2]);

	tm.tm_year = date.bm_y + 100;	// base is 1900
	tm.tm_mon = date.bm_m - 1;	// 0 is Jan ... 11 is Dec
	tm.tm_mday = date.bm_d;		// 1st ... 31th

	return scnprintf(buf, PAGE_SIZE, "%lld\n", rtc_tm_to_time64(&tm));
}

static const DEVICE_ATTR_RW(first_usage_date);

/* 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");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_manufacturing_date);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create manufacturing date\n");
	ret = device_create_file(&batt_drv->psy->dev, &dev_attr_first_usage_date);
	if (ret)
		dev_err(&batt_drv->psy->dev, "Failed to create first usage date\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);
	debugfs_create_file("reset_first_usage_date", 0644, de, batt_drv,
			    &debug_first_usage_date_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;

	/* Date of manufacturing of the battery */
	ret = batt_get_manufacture_date(&batt_drv->health_data.bhi_data);
	if (ret < 0)
		pr_warn("cannot get battery manufacture date, ret=%d\n", ret);

	/* Date of first use of the battery */
	if (!batt_drv->health_data.bhi_data.act_date[0]) {
		ret = batt_get_activation_date(&batt_drv->health_data.bhi_data);
		if (ret < 0)
			pr_warn("cannot get battery activation date, ret=%d\n", ret);;
	}

	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");
