From 1e42f4cc4f4bd637e8af363c2b7f2d75bc12ad53 Mon Sep 17 00:00:00 2001 From: Manaf Meethalavalappu Pallikunhi Date: Wed, 15 Feb 2017 17:41:55 +0530 Subject: [PATCH 1/2] power: bcl: Fix battery SoC read and evaluation whenever BCL enabled Just after enabling BCL, reading and evaluating current battery SoC is bypassed. Because of this, during this same time if battery SoC is less than preset threshold, BCL doesn't mitigate until next battery SoC change notification comes. Fix battery SoC read and evaluation path whenever BCL is enabled. CRs-Fixed: 2007133 Change-Id: I65639ab078875dc3f6940fd1a89201af98e40881 Signed-off-by: Manaf Meethalavalappu Pallikunhi --- .../power/supply/qcom/battery_current_limit.c | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/power/supply/qcom/battery_current_limit.c b/drivers/power/supply/qcom/battery_current_limit.c index d2c25bfbf66c..cb8a707d0f37 100644 --- a/drivers/power/supply/qcom/battery_current_limit.c +++ b/drivers/power/supply/qcom/battery_current_limit.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -285,23 +285,13 @@ static void soc_mitigate(struct work_struct *work) update_cpu_freq(); } -static int power_supply_callback(struct notifier_block *nb, - unsigned long event, void *data) +static int get_and_evaluate_battery_soc(void) { - struct power_supply *psy = data; static struct power_supply *batt_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 NOTIFY_OK; - } - - if (strcmp(psy->desc->name, "battery")) - return NOTIFY_OK; - if (!batt_psy) batt_psy = power_supply_get_by_name("battery"); if (batt_psy) { @@ -325,6 +315,22 @@ static int power_supply_callback(struct notifier_block *nb, return NOTIFY_OK; } +static int power_supply_callback(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct power_supply *psy = data; + + if (gbcl->bcl_mode != BCL_DEVICE_ENABLED) { + pr_debug("BCL is not enabled\n"); + return NOTIFY_OK; + } + + if (strcmp(psy->desc->name, "battery")) + return NOTIFY_OK; + + return get_and_evaluate_battery_soc(); +} + static int bcl_get_battery_voltage(int *vbatt_mv) { static struct power_supply *psy; @@ -643,7 +649,7 @@ static void bcl_periph_mode_set(enum bcl_device_mode mode) * power state changes. Make sure we read the current SoC * and mitigate. */ - power_supply_callback(&gbcl->psy_nb, 1, gbcl); + get_and_evaluate_battery_soc(); ret = power_supply_reg_notifier(&gbcl->psy_nb); if (ret < 0) { pr_err("Unable to register soc notifier rc = %d\n", From 514e483a478b813f54daa0792b32d86b70a2b1a6 Mon Sep 17 00:00:00 2001 From: Manaf Meethalavalappu Pallikunhi Date: Wed, 15 Feb 2017 18:09:35 +0530 Subject: [PATCH 2/2] power: bcl_peripheral: Enable BCL LMH algorithm only once Currently BCL LMH algorithm enable request goes for every time BCL threshold enablement. It needs to be enabled only once. So Enable BCL LMH algorithm only once. Change-Id: I94c7326b7730830f71b71c92df21a589ddd2347b Signed-off-by: Manaf Meethalavalappu Pallikunhi --- drivers/power/supply/qcom/bcl_peripheral.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/qcom/bcl_peripheral.c b/drivers/power/supply/qcom/bcl_peripheral.c index cae4967f1ef4..2d237f27b062 100644 --- a/drivers/power/supply/qcom/bcl_peripheral.c +++ b/drivers/power/supply/qcom/bcl_peripheral.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -482,8 +482,10 @@ static int bcl_access_monitor_enable(bool enable) if (enable == bcl_perph->enabled) goto access_exit; - if ((bcl_perph_version == BCL_PMI8998) && !hw_enabled && enable) + if ((bcl_perph_version == BCL_PMI8998) && !hw_enabled && enable) { bcl_lmh_dcvs_enable(); + hw_enabled = true; + } for (; i < BCL_PARAM_MAX; i++) { perph_data = &bcl_perph->param[i];