diff mbox series

hwmon: (aquacomputer_d5next) Add support for Quadro flow sensor pulses

Message ID 20221125215515.31380-1-savicaleksa83@gmail.com (mailing list archive)
State Superseded
Headers show
Series hwmon: (aquacomputer_d5next) Add support for Quadro flow sensor pulses | expand

Commit Message

Aleksa Savic Nov. 25, 2022, 9:55 p.m. UTC
Add support for reading and writing flow sensor pulses value on
the Aquacomputer Quadro. Implemented by Leonard Anderweit [1].

[1] https://github.com/aleksamagicka/aquacomputer_d5next-hwmon/pull/45

Originally-from: Leonard Anderweit <leonard.anderweit@gmail.com>
Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
---
 Documentation/hwmon/aquacomputer_d5next.rst |  3 +-
 drivers/hwmon/aquacomputer_d5next.c         | 68 ++++++++++++++++-----
 2 files changed, 55 insertions(+), 16 deletions(-)

Comments

Guenter Roeck Nov. 26, 2022, 1:49 a.m. UTC | #1
On 11/25/22 13:55, Aleksa Savic wrote:
> Add support for reading and writing flow sensor pulses value on
> the Aquacomputer Quadro. Implemented by Leonard Anderweit [1].
> 
> [1] https://github.com/aleksamagicka/aquacomputer_d5next-hwmon/pull/45
> 
> Originally-from: Leonard Anderweit <leonard.anderweit@gmail.com>
> Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
> ---
>   Documentation/hwmon/aquacomputer_d5next.rst |  3 +-
>   drivers/hwmon/aquacomputer_d5next.c         | 68 ++++++++++++++++-----
>   2 files changed, 55 insertions(+), 16 deletions(-)
> 
> diff --git a/Documentation/hwmon/aquacomputer_d5next.rst b/Documentation/hwmon/aquacomputer_d5next.rst
> index 15226346434d..637bdbc8fcad 100644
> --- a/Documentation/hwmon/aquacomputer_d5next.rst
> +++ b/Documentation/hwmon/aquacomputer_d5next.rst
> @@ -39,7 +39,7 @@ current.
>   
>   The Quadro exposes four physical and sixteen virtual temperature sensors, a flow
>   sensor and four PWM controllable fans, along with their speed (in RPM), power,
> -voltage and current.
> +voltage and current. Flow sensor pulses are also available.
>   
>   The Farbwerk and Farbwerk 360 expose four temperature sensors. Additionally,
>   sixteen virtual temperature sensors of the Farbwerk 360 are exposed.
> @@ -64,6 +64,7 @@ Sysfs entries
>   temp[1-20]_input Physical/virtual temperature sensors (in millidegrees Celsius)
>   temp[1-4]_offset Temperature sensor correction offset (in millidegrees Celsius)
>   fan[1-8]_input   Pump/fan speed (in RPM) / Flow speed (in dL/h)
> +fan5_pulses      Quadro flow sensor pulses
>   power[1-8]_input Pump/fan power (in micro Watts)
>   in[0-7]_input    Pump/fan voltage (in milli Volts)
>   curr[1-8]_input  Pump/fan current (in milli Amperes)
> diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c
> index 49d3f9876fe8..77a3ac33d4ac 100644
> --- a/drivers/hwmon/aquacomputer_d5next.c
> +++ b/drivers/hwmon/aquacomputer_d5next.c
> @@ -136,6 +136,7 @@ static u8 quadro_sensor_fan_offsets[] = { 0x70, 0x7D, 0x8A, 0x97 };
>   
>   /* Control report offsets for the Quadro */
>   #define QUADRO_TEMP_CTRL_OFFSET		0xA
> +#define QUADRO_FLOW_PULSES_CTRL_OFFSET	0x6
>   static u16 quadro_ctrl_fan_offsets[] = { 0x37, 0x8c, 0xe1, 0x136 }; /* Fan speed offsets (0-100%) */
>   
>   /* Specs of High Flow Next flow sensor */
> @@ -303,6 +304,7 @@ struct aqc_data {
>   	u16 temp_ctrl_offset;
>   	u16 power_cycle_count_offset;
>   	u8 flow_sensor_offset;
> +	u8 flow_pulses_ctrl_offset;
>   
>   	/* General info, same across all devices */
>   	u32 serial_number[2];
> @@ -461,20 +463,32 @@ static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u3
>   		}
>   		break;
>   	case hwmon_fan:
> -		switch (priv->kind) {
> -		case highflownext:
> -			/* Special case to support flow sensor, water quality and conductivity */
> -			if (channel < 3)
> -				return 0444;
> -			break;
> -		case quadro:
> -			/* Special case to support flow sensor */
> -			if (channel < priv->num_fans + 1)
> -				return 0444;
> +		switch (attr) {
> +		case hwmon_fan_input:
> +		case hwmon_fan_label:
> +			switch (priv->kind) {
> +			case highflownext:
> +				/* Special case to support flow sensor, water quality
> +				 * and conductivity
> +				 */
> +				if (channel < 3)
> +					return 0444;
> +				break;
> +			case quadro:
> +				/* Special case to support flow sensor */
> +				if (channel < priv->num_fans + 1)
> +					return 0444;
> +				break;
> +			default:
> +				if (channel < priv->num_fans)
> +					return 0444;
> +				break;
> +			}
>   			break;
> -		default:
> -			if (channel < priv->num_fans)
> -				return 0444;
> +		case hwmon_fan_pulses:
> +			/* Special case for Quadro flow sensor */
> +			if (priv->kind == quadro && channel == priv->num_fans)
> +				return 0644;
>   			break;

I think "default:" is now missing here.

Guenter

>   		}
>   		break;
> @@ -552,7 +566,18 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
>   		}
>   		break;
>   	case hwmon_fan:
> -		*val = priv->speed_input[channel];
> +		switch (attr) {
> +		case hwmon_fan_input:
> +			*val = priv->speed_input[channel];
> +			break;
> +		case hwmon_fan_pulses:
> +			ret = aqc_get_ctrl_val(priv, priv->flow_pulses_ctrl_offset, val);
> +			if (ret < 0)
> +				return ret;
> +			break;
> +		default:
> +			break;
> +		}
>   		break;
>   	case hwmon_power:
>   		*val = priv->power_input[channel];
> @@ -632,6 +657,18 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
>   			return -EOPNOTSUPP;
>   		}
>   		break;
> +	case hwmon_fan:
> +		switch (attr) {
> +		case hwmon_fan_pulses:
> +			val = clamp_val(val, 10, 1000);
> +			ret = aqc_set_ctrl_val(priv, priv->flow_pulses_ctrl_offset, val);
> +			if (ret < 0)
> +				return ret;
> +			break;
> +		default:
> +			break;
> +		}
> +		break;
>   	case hwmon_pwm:
>   		switch (attr) {
>   		case hwmon_pwm_input:
> @@ -691,7 +728,7 @@ static const struct hwmon_channel_info *aqc_info[] = {
>   			   HWMON_F_INPUT | HWMON_F_LABEL,
>   			   HWMON_F_INPUT | HWMON_F_LABEL,
>   			   HWMON_F_INPUT | HWMON_F_LABEL,
> -			   HWMON_F_INPUT | HWMON_F_LABEL,
> +			   HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_PULSES,
>   			   HWMON_F_INPUT | HWMON_F_LABEL,
>   			   HWMON_F_INPUT | HWMON_F_LABEL,
>   			   HWMON_F_INPUT | HWMON_F_LABEL),
> @@ -1000,6 +1037,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
>   		priv->buffer_size = QUADRO_CTRL_REPORT_SIZE;
>   
>   		priv->flow_sensor_offset = QUADRO_FLOW_SENSOR_OFFSET;
> +		priv->flow_pulses_ctrl_offset = QUADRO_FLOW_PULSES_CTRL_OFFSET;
>   		priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;
>   
>   		priv->temp_label = label_temp_sensors;
Aleksa Savic Nov. 26, 2022, 7:06 a.m. UTC | #2
On 2022-11-26 02:49:27 GMT+01:00, Guenter Roeck wrote:
> 
> I think "default:" is now missing here.
> 
> Guenter
> 
> 

Right, thanks! Sending a v2.

Aleksa
diff mbox series

Patch

diff --git a/Documentation/hwmon/aquacomputer_d5next.rst b/Documentation/hwmon/aquacomputer_d5next.rst
index 15226346434d..637bdbc8fcad 100644
--- a/Documentation/hwmon/aquacomputer_d5next.rst
+++ b/Documentation/hwmon/aquacomputer_d5next.rst
@@ -39,7 +39,7 @@  current.
 
 The Quadro exposes four physical and sixteen virtual temperature sensors, a flow
 sensor and four PWM controllable fans, along with their speed (in RPM), power,
-voltage and current.
+voltage and current. Flow sensor pulses are also available.
 
 The Farbwerk and Farbwerk 360 expose four temperature sensors. Additionally,
 sixteen virtual temperature sensors of the Farbwerk 360 are exposed.
@@ -64,6 +64,7 @@  Sysfs entries
 temp[1-20]_input Physical/virtual temperature sensors (in millidegrees Celsius)
 temp[1-4]_offset Temperature sensor correction offset (in millidegrees Celsius)
 fan[1-8]_input   Pump/fan speed (in RPM) / Flow speed (in dL/h)
+fan5_pulses      Quadro flow sensor pulses
 power[1-8]_input Pump/fan power (in micro Watts)
 in[0-7]_input    Pump/fan voltage (in milli Volts)
 curr[1-8]_input  Pump/fan current (in milli Amperes)
diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c
index 49d3f9876fe8..77a3ac33d4ac 100644
--- a/drivers/hwmon/aquacomputer_d5next.c
+++ b/drivers/hwmon/aquacomputer_d5next.c
@@ -136,6 +136,7 @@  static u8 quadro_sensor_fan_offsets[] = { 0x70, 0x7D, 0x8A, 0x97 };
 
 /* Control report offsets for the Quadro */
 #define QUADRO_TEMP_CTRL_OFFSET		0xA
+#define QUADRO_FLOW_PULSES_CTRL_OFFSET	0x6
 static u16 quadro_ctrl_fan_offsets[] = { 0x37, 0x8c, 0xe1, 0x136 }; /* Fan speed offsets (0-100%) */
 
 /* Specs of High Flow Next flow sensor */
@@ -303,6 +304,7 @@  struct aqc_data {
 	u16 temp_ctrl_offset;
 	u16 power_cycle_count_offset;
 	u8 flow_sensor_offset;
+	u8 flow_pulses_ctrl_offset;
 
 	/* General info, same across all devices */
 	u32 serial_number[2];
@@ -461,20 +463,32 @@  static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u3
 		}
 		break;
 	case hwmon_fan:
-		switch (priv->kind) {
-		case highflownext:
-			/* Special case to support flow sensor, water quality and conductivity */
-			if (channel < 3)
-				return 0444;
-			break;
-		case quadro:
-			/* Special case to support flow sensor */
-			if (channel < priv->num_fans + 1)
-				return 0444;
+		switch (attr) {
+		case hwmon_fan_input:
+		case hwmon_fan_label:
+			switch (priv->kind) {
+			case highflownext:
+				/* Special case to support flow sensor, water quality
+				 * and conductivity
+				 */
+				if (channel < 3)
+					return 0444;
+				break;
+			case quadro:
+				/* Special case to support flow sensor */
+				if (channel < priv->num_fans + 1)
+					return 0444;
+				break;
+			default:
+				if (channel < priv->num_fans)
+					return 0444;
+				break;
+			}
 			break;
-		default:
-			if (channel < priv->num_fans)
-				return 0444;
+		case hwmon_fan_pulses:
+			/* Special case for Quadro flow sensor */
+			if (priv->kind == quadro && channel == priv->num_fans)
+				return 0644;
 			break;
 		}
 		break;
@@ -552,7 +566,18 @@  static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
 		}
 		break;
 	case hwmon_fan:
-		*val = priv->speed_input[channel];
+		switch (attr) {
+		case hwmon_fan_input:
+			*val = priv->speed_input[channel];
+			break;
+		case hwmon_fan_pulses:
+			ret = aqc_get_ctrl_val(priv, priv->flow_pulses_ctrl_offset, val);
+			if (ret < 0)
+				return ret;
+			break;
+		default:
+			break;
+		}
 		break;
 	case hwmon_power:
 		*val = priv->power_input[channel];
@@ -632,6 +657,18 @@  static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
 			return -EOPNOTSUPP;
 		}
 		break;
+	case hwmon_fan:
+		switch (attr) {
+		case hwmon_fan_pulses:
+			val = clamp_val(val, 10, 1000);
+			ret = aqc_set_ctrl_val(priv, priv->flow_pulses_ctrl_offset, val);
+			if (ret < 0)
+				return ret;
+			break;
+		default:
+			break;
+		}
+		break;
 	case hwmon_pwm:
 		switch (attr) {
 		case hwmon_pwm_input:
@@ -691,7 +728,7 @@  static const struct hwmon_channel_info *aqc_info[] = {
 			   HWMON_F_INPUT | HWMON_F_LABEL,
 			   HWMON_F_INPUT | HWMON_F_LABEL,
 			   HWMON_F_INPUT | HWMON_F_LABEL,
-			   HWMON_F_INPUT | HWMON_F_LABEL,
+			   HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_PULSES,
 			   HWMON_F_INPUT | HWMON_F_LABEL,
 			   HWMON_F_INPUT | HWMON_F_LABEL,
 			   HWMON_F_INPUT | HWMON_F_LABEL),
@@ -1000,6 +1037,7 @@  static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
 		priv->buffer_size = QUADRO_CTRL_REPORT_SIZE;
 
 		priv->flow_sensor_offset = QUADRO_FLOW_SENSOR_OFFSET;
+		priv->flow_pulses_ctrl_offset = QUADRO_FLOW_PULSES_CTRL_OFFSET;
 		priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;
 
 		priv->temp_label = label_temp_sensors;