hwmon: qti_amoled_ecm: return avg_current as 0 upon error exceptions

Avg_current is an unsigned 16-bit data and assigning it a negative
value would make it being shown as a very big positive value which
doesn't make sense for ECM current measurement. Instead, assign it
to 0 upon error exceptions and print out corresponding messages.

Change-Id: I438667e40d63e4142860b7de4e7cf7495d3c424e
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
This commit is contained in:
Fenglin Wu 2021-03-09 07:40:48 +08:00
parent be60e6e783
commit ba6fb533f2

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*/
#define pr_fmt(fmt) "AMOLED_ECM: %s: " fmt, __func__
@ -337,9 +337,9 @@ static void ecm_average_work(struct work_struct *work)
mutex_lock(&ecm->sdam_lock);
if (!data->num_m_samples || !data->m_cumulative) {
pr_warn("Invalid data, num_m_samples=%u m_cumulative:%u\n",
pr_warn_ratelimited("Invalid data, num_m_samples=%u m_cumulative:%u\n",
data->num_m_samples, data->m_cumulative);
data->avg_current = -EINVAL;
data->avg_current = 0;
} else {
data->avg_current = data->m_cumulative / data->num_m_samples;
pr_debug("avg_current=%u mA\n", data->avg_current);
@ -510,11 +510,14 @@ static int handle_ecm_abort(struct amoled_ecm *ecm)
switch (mode) {
case ECM_MODE_MULTI_FRAMES:
data->avg_current = -EIO;
pr_warn_ratelimited("Multiple frames mode is not supported\n");
data->avg_current = 0;
break;
case ECM_MODE_CONTINUOUS:
if (data->num_m_samples < ECM_MIN_M_SAMPLES) {
data->avg_current = -EIO;
pr_warn_ratelimited("Too few samples %u for continuous mode\n",
data->num_m_samples);
data->avg_current = 0;
break;
}
@ -522,7 +525,8 @@ static int handle_ecm_abort(struct amoled_ecm *ecm)
schedule_delayed_work(&ecm->average_work, 0);
break;
default:
data->avg_current = -EINVAL;
pr_err_ratelimited("Invalid ECM operation mode: %u\n", mode);
data->avg_current = 0;
return -EINVAL;
}