From: Leonard Anderweit <leonard.anderweit@gmail.com>
To: linux-hwmon@vger.kernel.org
Cc: Aleksa Savic <savicaleksa83@gmail.com>,
Jack Doan <me@jackdoan.com>, Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Leonard Anderweit <leonard.anderweit@gmail.com>
Subject: [PATCH 1/5] hwmon: (aquacomputer_d5next) Support one byte control values
Date: Sat, 11 Feb 2023 17:59:19 +0100 [thread overview]
Message-ID: <20230211165923.17807-2-leonard.anderweit@gmail.com> (raw)
In-Reply-To: <20230211165923.17807-1-leonard.anderweit@gmail.com>
Add support for one byte control values. This extends aqc_set_ctrl_val() and
aqc_get_ctrl_val() with a type. Currently supported types are AQC_8 (one byte)
and AQC_BE16 (two bytes big endian). More types will be added in the future.
Signed-off-by: Leonard Anderweit <leonard.anderweit@gmail.com>
---
drivers/hwmon/aquacomputer_d5next.c | 47 +++++++++++++++++++++++------
1 file changed, 37 insertions(+), 10 deletions(-)
diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c
index 12682a610ce7..d69c2396854c 100644
--- a/drivers/hwmon/aquacomputer_d5next.c
+++ b/drivers/hwmon/aquacomputer_d5next.c
@@ -70,6 +70,10 @@ static u8 secondary_ctrl_report[] = {
/* Report IDs for legacy devices */
#define POWERADJUST3_STATUS_REPORT_ID 0x03
+/* Data types for reading and writing control reports */
+#define AQC_8 0
+#define AQC_BE16 1
+
/* Info, sensor sizes and offsets for most Aquacomputer devices */
#define AQC_SERIAL_START 0x3
#define AQC_FIRMWARE_VERSION 0xD
@@ -544,7 +548,7 @@ static int aqc_send_ctrl_data(struct aqc_data *priv)
}
/* Refreshes the control buffer and stores value at offset in val */
-static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val)
+static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val, int type)
{
int ret;
@@ -554,14 +558,23 @@ static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val)
if (ret < 0)
goto unlock_and_return;
- *val = (s16)get_unaligned_be16(priv->buffer + offset);
+ switch (type) {
+ case AQC_BE16:
+ *val = (s16)get_unaligned_be16(priv->buffer + offset);
+ break;
+ case AQC_8:
+ *val = priv->buffer[offset];
+ break;
+ default:
+ ret = -EINVAL;
+ }
unlock_and_return:
mutex_unlock(&priv->mutex);
return ret;
}
-static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val)
+static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int type)
{
int ret;
@@ -571,7 +584,18 @@ static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val)
if (ret < 0)
goto unlock_and_return;
- put_unaligned_be16((s16)val, priv->buffer + offset);
+ switch (type) {
+ case AQC_BE16:
+ put_unaligned_be16((s16)val, priv->buffer + offset);
+ break;
+ case AQC_8:
+ priv->buffer[offset] = (u8)val;
+ break;
+ default:
+ ret = -EINVAL;
+ }
+ if (ret < 0)
+ goto unlock_and_return;
ret = aqc_send_ctrl_data(priv);
@@ -775,7 +799,7 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
case hwmon_temp_offset:
ret =
aqc_get_ctrl_val(priv, priv->temp_ctrl_offset +
- channel * AQC_SENSOR_SIZE, val);
+ channel * AQC_SENSOR_SIZE, val, AQC_BE16);
if (ret < 0)
return ret;
@@ -791,7 +815,8 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
*val = priv->speed_input[channel];
break;
case hwmon_fan_pulses:
- ret = aqc_get_ctrl_val(priv, priv->flow_pulses_ctrl_offset, val);
+ ret = aqc_get_ctrl_val(priv, priv->flow_pulses_ctrl_offset,
+ val, AQC_BE16);
if (ret < 0)
return ret;
break;
@@ -804,7 +829,8 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
break;
case hwmon_pwm:
if (priv->fan_ctrl_offsets) {
- ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel], val);
+ ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel],
+ val, AQC_BE16);
if (ret < 0)
return ret;
@@ -877,7 +903,7 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
val = clamp_val(val, -15000, 15000) / 10;
ret =
aqc_set_ctrl_val(priv, priv->temp_ctrl_offset +
- channel * AQC_SENSOR_SIZE, val);
+ channel * AQC_SENSOR_SIZE, val, AQC_BE16);
if (ret < 0)
return ret;
break;
@@ -889,7 +915,8 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
switch (attr) {
case hwmon_fan_pulses:
val = clamp_val(val, 10, 1000);
- ret = aqc_set_ctrl_val(priv, priv->flow_pulses_ctrl_offset, val);
+ ret = aqc_set_ctrl_val(priv, priv->flow_pulses_ctrl_offset,
+ val, AQC_BE16);
if (ret < 0)
return ret;
break;
@@ -906,7 +933,7 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
return pwm_value;
ret = aqc_set_ctrl_val(priv, priv->fan_ctrl_offsets[channel],
- pwm_value);
+ pwm_value, AQC_BE16);
if (ret < 0)
return ret;
}
--
2.39.1
next prev parent reply other threads:[~2023-02-11 16:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-11 16:59 [PATCH 0/5] hwmon: (aquacomputer_d5next) Add Aquacomputer Aquaero control Leonard Anderweit
2023-02-11 16:59 ` Leonard Anderweit [this message]
2023-02-11 16:59 ` [PATCH 2/5] hwmon: (aquacomputer_d5next) Support writing multiple control values at once Leonard Anderweit
2023-02-11 16:59 ` [PATCH 3/5] hwmon: (aquacomputer_d5next) Add temperature offset control for Aquaero Leonard Anderweit
2023-02-11 18:08 ` Guenter Roeck
2023-02-11 18:54 ` Aleksa Savic
2023-02-11 19:48 ` Leonard Anderweit
2023-02-11 20:48 ` Guenter Roeck
2023-02-11 21:17 ` Aleksa Savic
2023-02-11 16:59 ` [PATCH 4/5] hwmon: (aquacomputer_d5next) Add fan PWM " Leonard Anderweit
2023-02-11 16:59 ` [PATCH 5/5] hwmon: (aquacomputer_d5next) Add PWM mode " Leonard Anderweit
2023-02-11 17:41 ` Guenter Roeck
2023-02-11 19:06 ` Aleksa Savic
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=20230211165923.17807-2-leonard.anderweit@gmail.com \
--to=leonard.anderweit@gmail.com \
--cc=corbet@lwn.net \
--cc=jdelvare@suse.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=me@jackdoan.com \
--cc=savicaleksa83@gmail.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.