From 5e6831edcc6be7e7afb922184090c39f6375309c Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Tue, 17 May 2022 23:30:46 +0200
Subject: [PATCH 327/463] power: supply: rk818-battery: Drop dependency on
 framebuffer

It was bizarre anyway. Framebuffer is barely used on Linux anyway,
so this is not a great way to check for system inactivity.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 drivers/power/supply/rk818_battery.c | 43 ++++------------------------
 1 file changed, 5 insertions(+), 38 deletions(-)

diff --git a/drivers/power/supply/rk818_battery.c b/drivers/power/supply/rk818_battery.c
index 741195e77da6f..cc409b7aafb56 100644
--- a/drivers/power/supply/rk818_battery.c
+++ b/drivers/power/supply/rk818_battery.c
@@ -217,7 +217,6 @@ struct rk818_battery {
 	bool				sleep_chrg_online;
 	u8				sleep_chrg_status;
 	bool				adc_allow_update;
-	int                             fb_blank;
 	bool				s2r; /*suspend to resume*/
 	u32				work_mode;
 	int				temperature;
@@ -1097,34 +1096,6 @@ static void rk818_bat_save_reboot_cnt(struct rk818_battery *di, u8 save_cnt)
 	rk818_bat_write(di, RK818_REBOOT_CNT_REG, save_cnt);
 }
 
-static int rk818_bat_fb_notifier(struct notifier_block *nb,
-				 unsigned long event, void *data)
-{
-	struct rk818_battery *di;
-	struct fb_event *evdata = data;
-
-	if (event != FB_EARLY_EVENT_BLANK && event != FB_EVENT_BLANK)
-		return NOTIFY_OK;
-
-	di = container_of(nb, struct rk818_battery, fb_nb);
-	di->fb_blank = *(int *)evdata->data;
-
-	return 0;
-}
-
-static int rk818_bat_register_fb_notify(struct rk818_battery *di)
-{
-	memset(&di->fb_nb, 0, sizeof(di->fb_nb));
-	di->fb_nb.notifier_call = rk818_bat_fb_notifier;
-
-	return fb_register_client(&di->fb_nb);
-}
-
-static int rk818_bat_unregister_fb_notify(struct rk818_battery *di)
-{
-	return fb_unregister_client(&di->fb_nb);
-}
-
 static u8 rk818_bat_get_halt_cnt(struct rk818_battery *di)
 {
 	return rk818_bat_read(di, RK818_HALT_CNT_REG);
@@ -1512,7 +1483,7 @@ static void rk818_bat_calc_zero_linek(struct rk818_battery *di)
 	int ocv_cap, dead_cap, xsoc;
 	int ocv_soc, dead_soc;
 	int pwroff_vol;
-	int i, cnt, vol_old, vol_now;
+	int i, cnt = 0, vol_old, vol_now;
 	int org_linek = 0, min_gap_xsoc;
 
 	if ((abs(di->current_avg) < 500) && (di->dsoc > 10))
@@ -1884,7 +1855,7 @@ static void rk818_bat_debug_info(struct rk818_battery *di)
 	    "Dsoc=%d, Rsoc=%d, Vavg=%d, Iavg=%d, Cap=%d, Fcc=%d, d=%d\n"
 	    "K=%d, Mode=%s, Oldcap=%d, Is=%d, Ip=%d, Vs=%d\n"
 	    "fb_temp=%d, bat_temp=%d, sample_res=%d, USB=%d, DC=%d\n"
-	    "off:i=0x%x, c=0x%x, p=%d, Rbat=%d, age_ocv_cap=%d, fb=%d, hot=%d\n"
+	    "off:i=0x%x, c=0x%x, p=%d, Rbat=%d, age_ocv_cap=%d, hot=%d\n"
 	    "adp:finish=%lu, boot_min=%lu, sleep_min=%lu, adc=%d, Vsys=%d\n"
 	    "bat:%s, meet: soc=%d, calc: dsoc=%d, rsoc=%d, Vocv=%d\n"
 	    "pwr: dsoc=%d, rsoc=%d, vol=%d, halt: st=%d, cnt=%d, reboot=%d\n"
@@ -1901,7 +1872,7 @@ static void rk818_bat_debug_info(struct rk818_battery *di)
 	    di->pdata->sample_res, di->usb_in, di->ac_in,
 	    rk818_bat_get_ioffset(di),
 	    rk818_bat_get_coffset(di), di->poffset, di->bat_res,
-	    di->age_adjust_cap, di->fb_blank, !!(thermal & HOTDIE_STS),
+	    di->age_adjust_cap, !!(thermal & HOTDIE_STS),
 	    base2min(di->finish_base),
 	    base2min(di->boot_base), di->sleep_sum_sec / 60,
 	    di->adc_allow_update,
@@ -2495,13 +2466,12 @@ static void rk818_bat_rsoc_daemon(struct rk818_battery *di)
 	int est_vol, remain_cap;
 	static unsigned long sec;
 
-	if ((di->remain_cap < 0) && (di->fb_blank != 0)) {
+	if (di->remain_cap < 0) {
 		if (!sec)
 			sec = get_boot_sec();
-		// wake_lock_timeout(&di->wake_lock,
-		// 		  (di->pdata->monitor_sec + 1) * HZ);
 
 		DBG("sec=%ld, hold_sec=%ld\n", sec, base2sec(sec));
+
 		if (base2sec(sec) >= 60) {
 			sec = 0;
 			di->dbg_cap_low0++;
@@ -2511,7 +2481,6 @@ static void rk818_bat_rsoc_daemon(struct rk818_battery *di)
 			rk818_bat_init_capacity(di, remain_cap);
 			BAT_INFO("adjust cap below 0 --> %d, rsoc=%d\n",
 				 di->remain_cap, di->rsoc);
-			// wake_unlock(&di->wake_lock);
 		}
 	} else {
 		sec = 0;
@@ -3331,7 +3300,6 @@ static int rk818_battery_probe(struct platform_device *pdev)
 	rk818_bat_init_info(di);
 	rk818_bat_init_fg(di);
 	rk818_bat_init_sysfs(di);
-	rk818_bat_register_fb_notify(di);
 	//wake_lock_init(&di->wake_lock, WAKE_LOCK_SUSPEND, "rk818_bat_lock");
 	di->bat_monitor_wq = alloc_ordered_workqueue("%s",
 			WQ_MEM_RECLAIM | WQ_FREEZABLE, "rk818-bat-monitor-wq");
@@ -3465,7 +3433,6 @@ static void rk818_battery_shutdown(struct platform_device *dev)
 
 	cancel_delayed_work_sync(&di->bat_delay_work);
 	cancel_delayed_work_sync(&di->calib_delay_work);
-	rk818_bat_unregister_fb_notify(di);
 	del_timer(&di->caltimer);
 	if (base2sec(di->boot_base) < REBOOT_PERIOD_SEC)
 		cnt = rk818_bat_check_reboot(di);
-- 
2.46.0

