All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xingjiang Qiao <nanpuyue@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Jean Delvare <jdelvare@suse.com>,
	Michael Shych <michaelsh@nvidia.com>,
	Xingjiang Qiao <nanpuyue@gmail.com>,
	linux-hwmon@vger.kernel.org
Subject: [PATCH v3 2/2] hwmon: (emc2305) fix pwm never being able to set lower
Date: Tue,  6 Dec 2022 13:53:31 +0800	[thread overview]
Message-ID: <20221206055331.170459-2-nanpuyue@gmail.com> (raw)
In-Reply-To: <20221205173611.145571-1-nanpuyue@gmail.com>

There are fields 'last_hwmon_state' and 'last_thermal_state' in the
structure 'emc2305_cdev_data', which respectively store the cooling state
set by the 'hwmon' and 'thermal' subsystem, and the driver author hopes
that if the state set by 'hwmon' is lower than the value set by 'thermal',
the driver will just save it without actually setting the pwm. Currently,
the 'last_thermal_state' also be updated by 'hwmon', which will cause the
cooling state to never be set to a lower value. This patch fixes that.

Signed-off-by: Xingjiang Qiao <nanpuyue@gmail.com>
---
 drivers/hwmon/emc2305.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/drivers/hwmon/emc2305.c b/drivers/hwmon/emc2305.c
index 9a78ca22541e..e0f6eb8d72fc 100644
--- a/drivers/hwmon/emc2305.c
+++ b/drivers/hwmon/emc2305.c
@@ -171,22 +171,12 @@ static int emc2305_get_max_state(struct thermal_cooling_device *cdev, unsigned l
 	return 0;
 }
 
-static int emc2305_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
+static int emc2305_set_cur_state_shim(struct emc2305_data *data, int cdev_idx, unsigned long state)
 {
-	int cdev_idx, ret;
-	struct emc2305_data *data = cdev->devdata;
+	int ret;
 	struct i2c_client *client = data->client;
 	u8 val, i;
 
-	if (state > data->max_state)
-		return -EINVAL;
-
-	cdev_idx =  emc2305_get_cdev_idx(cdev);
-	if (cdev_idx < 0)
-		return cdev_idx;
-
-	/* Save thermal state. */
-	data->cdev_data[cdev_idx].last_thermal_state = state;
 	state = max_t(unsigned long, state, data->cdev_data[cdev_idx].last_hwmon_state);
 
 	val = EMC2305_PWM_STATE2DUTY(state, data->max_state, EMC2305_FAN_MAX);
@@ -211,6 +201,27 @@ static int emc2305_set_cur_state(struct thermal_cooling_device *cdev, unsigned l
 	return 0;
 }
 
+static int emc2305_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
+{
+	int cdev_idx, ret;
+	struct emc2305_data *data = cdev->devdata;
+
+	if (state > data->max_state)
+		return -EINVAL;
+
+	cdev_idx =  emc2305_get_cdev_idx(cdev);
+	if (cdev_idx < 0)
+		return cdev_idx;
+
+	/* Save thermal state. */
+	data->cdev_data[cdev_idx].last_thermal_state = state;
+	ret = emc2305_set_cur_state_shim(data, cdev_idx, state);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static const struct thermal_cooling_device_ops emc2305_cooling_ops = {
 	.get_max_state = emc2305_get_max_state,
 	.get_cur_state = emc2305_get_cur_state,
@@ -401,7 +412,7 @@ emc2305_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int ch
 				 */
 				if (data->cdev_data[cdev_idx].last_hwmon_state >=
 				    data->cdev_data[cdev_idx].last_thermal_state)
-					return emc2305_set_cur_state(data->cdev_data[cdev_idx].cdev,
+					return emc2305_set_cur_state_shim(data, cdev_idx,
 							data->cdev_data[cdev_idx].last_hwmon_state);
 				return 0;
 			}
-- 
2.38.1


  parent reply	other threads:[~2022-12-06  5:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 17:36 [PATCH 1/2] hwmon: (emc2305) fix unable to probe emc2301/2/3/4 Xingjiang Qiao
2022-12-05 17:36 ` [PATCH 2/2] hwmon: (emc2305) fix pwm never being able to set lower Xingjiang Qiao
2022-12-05 18:27   ` Michael Shych
2022-12-05 19:28     ` Xingjiang Qiao
2022-12-05 18:27   ` Guenter Roeck
2022-12-06  5:30   ` Xingjiang Qiao
2022-12-05 18:15 ` [PATCH 1/2] hwmon: (emc2305) fix unable to probe emc2301/2/3/4 Guenter Roeck
2022-12-05 18:40   ` Michael Shych
2022-12-05 19:00 ` [PATCH v2 " Xingjiang Qiao
2022-12-06  5:53 ` [PATCH v3 1/2] hwmon: (emc2305) fix unable to probe emc2301/2/3 Xingjiang Qiao
2022-12-06  7:03   ` Guenter Roeck
2022-12-06 12:01     ` Xingjiang Qiao
2022-12-06 22:39   ` Guenter Roeck
2022-12-06  5:53 ` Xingjiang Qiao [this message]
2022-12-06 22:46   ` [PATCH v3 2/2] hwmon: (emc2305) fix pwm never being able to set lower Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221206055331.170459-2-nanpuyue@gmail.com \
    --to=nanpuyue@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=michaelsh@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.