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

Commit ba6fb533 authored by Fenglin Wu's avatar Fenglin Wu
Browse files

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: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent be60e6e7
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
// 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;
	}