Merge "drivers: thermal: bcl_soc: Read charge depletion percentage"

This commit is contained in:
qctecmdr 2020-03-14 18:50:57 -07:00 • committed by Gerrit - the friendly Code Review server
commit dfc05db44e
3 changed files with 29 additions and 16 deletions

View file

@ -947,7 +947,7 @@ static const struct thermal_cooling_device_ops psy_tcd_ops = {
.set_cur_state = ps_set_cur_charge_cntl_limit,
};
static int psy_register_cooler(struct power_supply *psy)
static int psy_register_cooler(struct device *dev, struct power_supply *psy)
{
int i;
@ -955,7 +955,13 @@ static int psy_register_cooler(struct power_supply *psy)
for (i = 0; i < psy->desc->num_properties; i++) {
if (psy->desc->properties[i] ==
POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) {
psy->tcd = thermal_cooling_device_register(
if (dev)
psy->tcd = thermal_of_cooling_device_register(
dev_of_node(dev),
(char *)psy->desc->name,
psy, &psy_tcd_ops);
else
psy->tcd = thermal_cooling_device_register(
(char *)psy->desc->name,
psy, &psy_tcd_ops);
return PTR_ERR_OR_ZERO(psy->tcd);
@ -980,7 +986,7 @@ static void psy_unregister_thermal(struct power_supply *psy)
{
}
static int psy_register_cooler(struct power_supply *psy)
static int psy_register_cooler(struct device *dev, struct power_supply *psy)
{
return 0;
}
@ -1063,7 +1069,7 @@ __power_supply_register(struct device *parent,
if (rc)
goto register_thermal_failed;
rc = psy_register_cooler(psy);
rc = psy_register_cooler(parent, psy);
if (rc)
goto register_cooler_failed;

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
*/
#define pr_fmt(fmt) "%s:%s " fmt, KBUILD_MODNAME, __func__
@ -34,6 +34,7 @@
#define BCL_VBAT_ADC_LOW 0x48
#define BCL_VBAT_COMP_LOW 0x49
#define BCL_VBAT_COMP_TLOW 0x4A
#define BCL_VBAT_CONV_REQ 0x72
#define BCL_IRQ_L0 0x1
#define BCL_IRQ_L1 0x2
@ -503,11 +504,17 @@ static void bcl_vbat_init(struct platform_device *pdev,
enum bcl_dev_type type, struct bcl_device *bcl_perph)
{
struct bcl_peripheral_data *vbat = &bcl_perph->param[type];
unsigned int val = 0;
int ret;
mutex_init(&vbat->state_trans_lock);
vbat->dev = bcl_perph;
vbat->irq_num = 0;
vbat->irq_enabled = false;
vbat->tz_dev = NULL;
ret = bcl_read_register(bcl_perph, BCL_VBAT_CONV_REQ, &val);
if (ret || !val)
return;
vbat->tz_dev = thermal_zone_device_register("vbat", 3, 0, vbat,
&vbat_tzd_ops, &vbat_tzp, 0, 0);
if (IS_ERR(vbat->tz_dev)) {

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
*/
#define pr_fmt(fmt) "%s:%s " fmt, KBUILD_MODNAME, __func__
@ -36,13 +36,13 @@ static struct bcl_device *bcl_perph;
static int bcl_set_soc(void *data, int low, int high)
{
if (low == bcl_perph->trip_temp)
if (high == bcl_perph->trip_temp)
return 0;
mutex_lock(&bcl_perph->state_trans_lock);
pr_debug("low soc threshold:%d\n", low);
bcl_perph->trip_temp = low;
if (low == INT_MIN) {
pr_debug("socd threshold:%d\n", high);
bcl_perph->trip_temp = high;
if (high == INT_MAX) {
bcl_perph->irq_enabled = false;
goto unlock_and_exit;
}
@ -60,7 +60,7 @@ static int bcl_read_soc(void *data, int *val)
union power_supply_propval ret = {0,};
int err = 0;
*val = 100;
*val = 0;
if (!batt_psy)
batt_psy = power_supply_get_by_name("battery");
if (batt_psy) {
@ -71,7 +71,7 @@ static int bcl_read_soc(void *data, int *val)
err);
return err;
}
*val = ret.intval;
*val = 100 - ret.intval;
}
pr_debug("soc:%d\n", *val);
@ -80,21 +80,21 @@ static int bcl_read_soc(void *data, int *val)
static void bcl_evaluate_soc(struct work_struct *work)
{
int battery_percentage;
int battery_depletion;
if (!bcl_perph->tz_dev)
return;
if (bcl_read_soc(NULL, &battery_percentage))
if (bcl_read_soc(NULL, &battery_depletion))
return;
mutex_lock(&bcl_perph->state_trans_lock);
if (!bcl_perph->irq_enabled)
goto eval_exit;
if (battery_percentage > bcl_perph->trip_temp)
if (battery_depletion < bcl_perph->trip_temp)
goto eval_exit;
bcl_perph->trip_val = battery_percentage;
bcl_perph->trip_val = battery_depletion;
mutex_unlock(&bcl_perph->state_trans_lock);
of_thermal_handle_trip_temp(bcl_perph->dev,
bcl_perph->tz_dev, bcl_perph->trip_val);