/* 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
}
/* 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;
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;
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);
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;
*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;
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;
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;
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;
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;
}