Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76d0a35f authored by Ram Chandrasekar's avatar Ram Chandrasekar
Browse files

power: bcl: Unregister SoC when BCL is disabled



Unregister the State of Charge (SoC) change
notification, when BCL monitoring is disabled.
This potentially has a corner case, where SoC
change can still trigger mitigation when BCL
is disabled.

CRs-Fixed: 808567
Change-Id: Iea7237f0a9a86b7420084252bdea658cd93e7e2f
Signed-off-by: default avatarRam Chandrasekar <rkumbako@codeaurora.org>
parent cd2c69a8
Loading
Loading
Loading
Loading
+22 −8
Original line number Diff line number Diff line
@@ -187,7 +187,8 @@ enum bcl_threshold_state {

static struct bcl_context *gbcl;
static enum bcl_threshold_state bcl_vph_state = BCL_THRESHOLD_DISABLED,
		bcl_ibat_state = BCL_THRESHOLD_DISABLED;
		bcl_ibat_state = BCL_THRESHOLD_DISABLED,
		bcl_soc_state = BCL_THRESHOLD_DISABLED;
static DEFINE_MUTEX(bcl_notify_mutex);
static uint32_t bcl_hotplug_request, bcl_hotplug_mask, bcl_soc_hotplug_mask;
static uint32_t bcl_frequency_mask;
@@ -218,7 +219,7 @@ static void __ref bcl_handle_hotplug(struct work_struct *work)
	if (cpumask_empty(bcl_cpu_online_mask))
		bcl_update_online_mask();

	if  (battery_soc_val <= soc_low_threshold
	if  (bcl_soc_state == BCL_LOW_THRESHOLD
		|| bcl_vph_state == BCL_LOW_THRESHOLD)
		bcl_hotplug_request = bcl_soc_hotplug_mask;
	else if (bcl_ibat_state == BCL_HIGH_THRESHOLD)
@@ -300,7 +301,7 @@ static int bcl_cpufreq_callback(struct notifier_block *nfb,
	case CPUFREQ_INCOMPATIBLE:
		if (bcl_vph_state == BCL_LOW_THRESHOLD
			|| bcl_ibat_state == BCL_HIGH_THRESHOLD
			|| battery_soc_val <= soc_low_threshold) {
			|| bcl_soc_state == BCL_LOW_THRESHOLD) {
			max_freq = (gbcl->bcl_monitor_type
				== BCL_IBAT_MONITOR_TYPE) ? gbcl->btm_freq_max
				: gbcl->bcl_p_freq_max;
@@ -341,6 +342,12 @@ static void power_supply_callback(struct power_supply *psy)
	static struct power_supply *bms_psy;
	union power_supply_propval ret = {0,};
	int battery_percentage;
	enum bcl_threshold_state prev_soc_state;

	if (gbcl->bcl_mode != BCL_DEVICE_ENABLED) {
		pr_debug("BCL is not enabled\n");
		return;
	}

	if (!bms_psy)
		bms_psy = power_supply_get_by_name("bms");
@@ -350,6 +357,11 @@ static void power_supply_callback(struct power_supply *psy)
		battery_percentage = ret.intval;
		battery_soc_val = battery_percentage;
		pr_debug("Battery SOC reported:%d", battery_soc_val);
		prev_soc_state = bcl_soc_state;
		bcl_soc_state = (battery_soc_val <= soc_low_threshold) ?
					BCL_LOW_THRESHOLD : BCL_HIGH_THRESHOLD;
		if (bcl_soc_state == prev_soc_state)
			return;
		if (bcl_hotplug_enabled)
			schedule_work(&bcl_hotplug_work);
		update_cpu_freq();
@@ -667,6 +679,11 @@ static void bcl_periph_mode_set(enum bcl_device_mode mode)
	int ret = 0;

	if (mode == BCL_DEVICE_ENABLED) {
		ret = power_supply_register(gbcl->dev, &bcl_psy);
		if (ret < 0) {
			pr_err("Unable to register bcl_psy rc = %d\n", ret);
			return;
		}
		ret = msm_bcl_set_threshold(BCL_PARAM_CURRENT, BCL_HIGH_TRIP,
			&gbcl->ibat_high_thresh);
		if (ret) {
@@ -702,12 +719,14 @@ static void bcl_periph_mode_set(enum bcl_device_mode mode)
		}
		gbcl->btm_mode = BCL_VPH_MONITOR_MODE;
	} else {
		power_supply_unregister(&bcl_psy);
		ret = msm_bcl_disable();
		if (ret) {
			pr_err("Error disabling BCL\n");
			return;
		}
		gbcl->btm_mode = BCL_MONITOR_DISABLED;
		bcl_soc_state = BCL_THRESHOLD_DISABLED;
		bcl_vph_notify(BCL_HIGH_THRESHOLD);
		bcl_ibat_notify(BCL_LOW_THRESHOLD);
		bcl_hotplug_request = 0;
@@ -1740,11 +1759,6 @@ static int bcl_probe(struct platform_device *pdev)
	bcl_psy.set_property     = bcl_battery_set_property;
	bcl_psy.num_properties = 0;
	bcl_psy.external_power_changed = power_supply_callback;
	ret = power_supply_register(&pdev->dev, &bcl_psy);
	if (ret < 0) {
		pr_err("Unable to register bcl_psy rc = %d\n", ret);
		return ret;
	}

	gbcl = bcl;
	platform_set_drvdata(pdev, bcl);