1 // SPDX-License-Identifier: GPL-2.0+
3 * hwmon driver for Aquacomputer devices (D5 Next, Farbwerk, Farbwerk 360, Octo,
4 * Quadro, High Flow Next, Aquaero, Aquastream Ultimate, Leakshield)
6 * Aquacomputer devices send HID reports (with ID 0x01) every second to report
7 * sensor values, except for devices that communicate through the
8 * legacy way (currently, Poweradjust 3).
10 * Copyright 2021 Aleksa Savic <savicaleksa83@gmail.com>
11 * Copyright 2022 Jack Doan <me@jackdoan.com>
14 #include <linux/crc16.h>
15 #include <linux/debugfs.h>
16 #include <linux/delay.h>
17 #include <linux/hid.h>
18 #include <linux/hwmon.h>
19 #include <linux/jiffies.h>
20 #include <linux/ktime.h>
21 #include <linux/module.h>
22 #include <linux/mutex.h>
23 #include <linux/seq_file.h>
24 #include <asm/unaligned.h>
26 #define USB_VENDOR_ID_AQUACOMPUTER 0x0c70
27 #define USB_PRODUCT_ID_AQUAERO 0xf001
28 #define USB_PRODUCT_ID_FARBWERK 0xf00a
29 #define USB_PRODUCT_ID_QUADRO 0xf00d
30 #define USB_PRODUCT_ID_D5NEXT 0xf00e
31 #define USB_PRODUCT_ID_FARBWERK360 0xf010
32 #define USB_PRODUCT_ID_OCTO 0xf011
33 #define USB_PRODUCT_ID_HIGHFLOWNEXT 0xf012
34 #define USB_PRODUCT_ID_LEAKSHIELD 0xf014
35 #define USB_PRODUCT_ID_AQUASTREAMXT 0xf0b6
36 #define USB_PRODUCT_ID_AQUASTREAMULT 0xf00b
37 #define USB_PRODUCT_ID_POWERADJUST3 0xf0bd
40 d5next, farbwerk, farbwerk360, octo, quadro,
41 highflownext, aquaero, poweradjust3, aquastreamult,
42 aquastreamxt, leakshield
45 static const char *const aqc_device_names[] = {
47 [farbwerk] = "farbwerk",
48 [farbwerk360] = "farbwerk360",
51 [highflownext] = "highflownext",
52 [leakshield] = "leakshield",
53 [aquastreamxt] = "aquastreamxt",
54 [aquaero] = "aquaero",
55 [aquastreamult] = "aquastreamultimate",
56 [poweradjust3] = "poweradjust3"
59 #define DRIVER_NAME "aquacomputer_d5next"
61 #define STATUS_REPORT_ID 0x01
62 #define STATUS_UPDATE_INTERVAL (2 * HZ) /* In seconds */
63 #define SERIAL_PART_OFFSET 2
65 #define CTRL_REPORT_ID 0x03
66 #define AQUAERO_CTRL_REPORT_ID 0x0b
68 #define CTRL_REPORT_DELAY 200 /* ms */
70 /* The HID report that the official software always sends
71 * after writing values, currently same for all devices
73 #define SECONDARY_CTRL_REPORT_ID 0x02
74 #define SECONDARY_CTRL_REPORT_SIZE 0x0B
76 static u8 secondary_ctrl_report[] = {
77 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x34, 0xC6
80 /* Secondary HID report values for Aquaero */
81 #define AQUAERO_SECONDARY_CTRL_REPORT_ID 0x06
82 #define AQUAERO_SECONDARY_CTRL_REPORT_SIZE 0x07
84 static u8 aquaero_secondary_ctrl_report[] = {
85 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
88 /* Report IDs for legacy devices */
89 #define AQUASTREAMXT_STATUS_REPORT_ID 0x04
91 #define POWERADJUST3_STATUS_REPORT_ID 0x03
93 /* Data types for reading and writing control reports */
97 /* Info, sensor sizes and offsets for most Aquacomputer devices */
98 #define AQC_SERIAL_START 0x3
99 #define AQC_FIRMWARE_VERSION 0xD
101 #define AQC_SENSOR_SIZE 0x02
102 #define AQC_SENSOR_NA 0x7FFF
103 #define AQC_FAN_PERCENT_OFFSET 0x00
104 #define AQC_FAN_VOLTAGE_OFFSET 0x02
105 #define AQC_FAN_CURRENT_OFFSET 0x04
106 #define AQC_FAN_POWER_OFFSET 0x06
107 #define AQC_FAN_SPEED_OFFSET 0x08
109 /* Specs of the Aquaero fan controllers */
110 #define AQUAERO_SERIAL_START 0x07
111 #define AQUAERO_FIRMWARE_VERSION 0x0B
112 #define AQUAERO_NUM_FANS 4
113 #define AQUAERO_NUM_SENSORS 8
114 #define AQUAERO_NUM_VIRTUAL_SENSORS 8
115 #define AQUAERO_NUM_CALC_VIRTUAL_SENSORS 4
116 #define AQUAERO_NUM_FLOW_SENSORS 2
117 #define AQUAERO_CTRL_REPORT_SIZE 0xa93
118 #define AQUAERO_CTRL_PRESET_ID 0x5c
119 #define AQUAERO_CTRL_PRESET_SIZE 0x02
120 #define AQUAERO_CTRL_PRESET_START 0x55c
122 /* Sensor report offsets for Aquaero fan controllers */
123 #define AQUAERO_SENSOR_START 0x65
124 #define AQUAERO_VIRTUAL_SENSOR_START 0x85
125 #define AQUAERO_CALC_VIRTUAL_SENSOR_START 0x95
126 #define AQUAERO_FLOW_SENSORS_START 0xF9
127 #define AQUAERO_FAN_VOLTAGE_OFFSET 0x04
128 #define AQUAERO_FAN_CURRENT_OFFSET 0x06
129 #define AQUAERO_FAN_POWER_OFFSET 0x08
130 #define AQUAERO_FAN_SPEED_OFFSET 0x00
131 static u16 aquaero_sensor_fan_offsets[] = { 0x167, 0x173, 0x17f, 0x18B };
133 /* Control report offsets for the Aquaero fan controllers */
134 #define AQUAERO_TEMP_CTRL_OFFSET 0xdb
135 #define AQUAERO_FAN_CTRL_MIN_PWR_OFFSET 0x04
136 #define AQUAERO_FAN_CTRL_MAX_PWR_OFFSET 0x06
137 #define AQUAERO_FAN_CTRL_SRC_OFFSET 0x10
138 static u16 aquaero_ctrl_fan_offsets[] = { 0x20c, 0x220, 0x234, 0x248 };
140 /* Specs of the D5 Next pump */
141 #define D5NEXT_NUM_FANS 2
142 #define D5NEXT_NUM_SENSORS 1
143 #define D5NEXT_NUM_VIRTUAL_SENSORS 8
144 #define D5NEXT_CTRL_REPORT_SIZE 0x329
146 /* Sensor report offsets for the D5 Next pump */
147 #define D5NEXT_POWER_CYCLES 0x18
148 #define D5NEXT_COOLANT_TEMP 0x57
149 #define D5NEXT_PUMP_OFFSET 0x6c
150 #define D5NEXT_FAN_OFFSET 0x5f
151 #define D5NEXT_5V_VOLTAGE 0x39
152 #define D5NEXT_12V_VOLTAGE 0x37
153 #define D5NEXT_VIRTUAL_SENSORS_START 0x3f
154 static u16 d5next_sensor_fan_offsets[] = { D5NEXT_PUMP_OFFSET, D5NEXT_FAN_OFFSET };
156 /* Control report offsets for the D5 Next pump */
157 #define D5NEXT_TEMP_CTRL_OFFSET 0x2D /* Temperature sensor offsets location */
158 static u16 d5next_ctrl_fan_offsets[] = { 0x97, 0x42 }; /* Pump and fan speed (from 0-100%) */
160 /* Specs of the Aquastream Ultimate pump */
161 /* Pump does not follow the standard structure, so only consider the fan */
162 #define AQUASTREAMULT_NUM_FANS 1
163 #define AQUASTREAMULT_NUM_SENSORS 2
165 /* Sensor report offsets for the Aquastream Ultimate pump */
166 #define AQUASTREAMULT_SENSOR_START 0x2D
167 #define AQUASTREAMULT_PUMP_OFFSET 0x51
168 #define AQUASTREAMULT_PUMP_VOLTAGE 0x3D
169 #define AQUASTREAMULT_PUMP_CURRENT 0x53
170 #define AQUASTREAMULT_PUMP_POWER 0x55
171 #define AQUASTREAMULT_FAN_OFFSET 0x41
172 #define AQUASTREAMULT_PRESSURE_OFFSET 0x57
173 #define AQUASTREAMULT_FLOW_SENSOR_OFFSET 0x37
174 #define AQUASTREAMULT_FAN_VOLTAGE_OFFSET 0x02
175 #define AQUASTREAMULT_FAN_CURRENT_OFFSET 0x00
176 #define AQUASTREAMULT_FAN_POWER_OFFSET 0x04
177 #define AQUASTREAMULT_FAN_SPEED_OFFSET 0x06
178 static u16 aquastreamult_sensor_fan_offsets[] = { AQUASTREAMULT_FAN_OFFSET };
180 /* Spec and sensor report offset for the Farbwerk RGB controller */
181 #define FARBWERK_NUM_SENSORS 4
182 #define FARBWERK_SENSOR_START 0x2f
184 /* Specs of the Farbwerk 360 RGB controller */
185 #define FARBWERK360_NUM_SENSORS 4
186 #define FARBWERK360_NUM_VIRTUAL_SENSORS 16
187 #define FARBWERK360_CTRL_REPORT_SIZE 0x682
189 /* Sensor report offsets for the Farbwerk 360 */
190 #define FARBWERK360_SENSOR_START 0x32
191 #define FARBWERK360_VIRTUAL_SENSORS_START 0x3a
193 /* Control report offsets for the Farbwerk 360 */
194 #define FARBWERK360_TEMP_CTRL_OFFSET 0x8
196 /* Specs of the Octo fan controller */
197 #define OCTO_NUM_FANS 8
198 #define OCTO_NUM_SENSORS 4
199 #define OCTO_NUM_VIRTUAL_SENSORS 16
200 #define OCTO_CTRL_REPORT_SIZE 0x65F
202 /* Sensor report offsets for the Octo */
203 #define OCTO_POWER_CYCLES 0x18
204 #define OCTO_SENSOR_START 0x3D
205 #define OCTO_VIRTUAL_SENSORS_START 0x45
206 static u16 octo_sensor_fan_offsets[] = { 0x7D, 0x8A, 0x97, 0xA4, 0xB1, 0xBE, 0xCB, 0xD8 };
208 /* Control report offsets for the Octo */
209 #define OCTO_TEMP_CTRL_OFFSET 0xA
210 /* Fan speed offsets (0-100%) */
211 static u16 octo_ctrl_fan_offsets[] = { 0x5B, 0xB0, 0x105, 0x15A, 0x1AF, 0x204, 0x259, 0x2AE };
213 /* Specs of Quadro fan controller */
214 #define QUADRO_NUM_FANS 4
215 #define QUADRO_NUM_SENSORS 4
216 #define QUADRO_NUM_VIRTUAL_SENSORS 16
217 #define QUADRO_NUM_FLOW_SENSORS 1
218 #define QUADRO_CTRL_REPORT_SIZE 0x3c1
220 /* Sensor report offsets for the Quadro */
221 #define QUADRO_POWER_CYCLES 0x18
222 #define QUADRO_SENSOR_START 0x34
223 #define QUADRO_VIRTUAL_SENSORS_START 0x3c
224 #define QUADRO_FLOW_SENSOR_OFFSET 0x6e
225 static u16 quadro_sensor_fan_offsets[] = { 0x70, 0x7D, 0x8A, 0x97 };
227 /* Control report offsets for the Quadro */
228 #define QUADRO_TEMP_CTRL_OFFSET 0xA
229 #define QUADRO_FLOW_PULSES_CTRL_OFFSET 0x6
230 static u16 quadro_ctrl_fan_offsets[] = { 0x37, 0x8c, 0xe1, 0x136 }; /* Fan speed offsets (0-100%) */
232 /* Specs of High Flow Next flow sensor */
233 #define HIGHFLOWNEXT_NUM_SENSORS 2
234 #define HIGHFLOWNEXT_NUM_FLOW_SENSORS 1
236 /* Sensor report offsets for the High Flow Next */
237 #define HIGHFLOWNEXT_SENSOR_START 85
238 #define HIGHFLOWNEXT_FLOW 81
239 #define HIGHFLOWNEXT_WATER_QUALITY 89
240 #define HIGHFLOWNEXT_POWER 91
241 #define HIGHFLOWNEXT_CONDUCTIVITY 95
242 #define HIGHFLOWNEXT_5V_VOLTAGE 97
243 #define HIGHFLOWNEXT_5V_VOLTAGE_USB 99
245 /* Specs of the Leakshield */
246 #define LEAKSHIELD_NUM_SENSORS 2
248 /* Sensor report offsets for Leakshield */
249 #define LEAKSHIELD_PRESSURE_ADJUSTED 285
250 #define LEAKSHIELD_TEMPERATURE_1 265
251 #define LEAKSHIELD_TEMPERATURE_2 287
252 #define LEAKSHIELD_PRESSURE_MIN 291
253 #define LEAKSHIELD_PRESSURE_TARGET 293
254 #define LEAKSHIELD_PRESSURE_MAX 295
255 #define LEAKSHIELD_PUMP_RPM_IN 101
256 #define LEAKSHIELD_FLOW_IN 111
257 #define LEAKSHIELD_RESERVOIR_VOLUME 313
258 #define LEAKSHIELD_RESERVOIR_FILLED 311
260 /* Specs of the Aquastream XT pump */
261 #define AQUASTREAMXT_SERIAL_START 0x3a
262 #define AQUASTREAMXT_FIRMWARE_VERSION 0x32
263 #define AQUASTREAMXT_NUM_FANS 2
264 #define AQUASTREAMXT_NUM_SENSORS 3
265 #define AQUASTREAMXT_FAN_STOPPED 0x4
266 #define AQUASTREAMXT_PUMP_CONVERSION_CONST 45000000
267 #define AQUASTREAMXT_FAN_CONVERSION_CONST 5646000
268 #define AQUASTREAMXT_SENSOR_REPORT_SIZE 0x42
270 /* Sensor report offsets and info for Aquastream XT */
271 #define AQUASTREAMXT_SENSOR_START 0xd
272 #define AQUASTREAMXT_FAN_VOLTAGE_OFFSET 0x7
273 #define AQUASTREAMXT_FAN_STATUS_OFFSET 0x1d
274 #define AQUASTREAMXT_PUMP_VOLTAGE_OFFSET 0x9
275 #define AQUASTREAMXT_PUMP_CURR_OFFSET 0xb
276 static u16 aquastreamxt_sensor_fan_offsets[] = { 0x13, 0x1b };
278 /* Specs of the Poweradjust 3 */
279 #define POWERADJUST3_NUM_SENSORS 1
280 #define POWERADJUST3_SENSOR_REPORT_SIZE 0x32
282 /* Sensor report offsets for the Poweradjust 3 */
283 #define POWERADJUST3_SENSOR_START 0x03
285 /* Labels for D5 Next */
286 static const char *const label_d5next_temp[] = {
290 static const char *const label_d5next_speeds[] = {
295 static const char *const label_d5next_power[] = {
300 static const char *const label_d5next_voltages[] = {
307 static const char *const label_d5next_current[] = {
312 /* Labels for Aquaero, Farbwerk, Farbwerk 360 and Octo and Quadro temperature sensors */
313 static const char *const label_temp_sensors[] = {
324 static const char *const label_virtual_temp_sensors[] = {
343 static const char *const label_aquaero_calc_temp_sensors[] = {
344 "Calc. virtual sensor 1",
345 "Calc. virtual sensor 2",
346 "Calc. virtual sensor 3",
347 "Calc. virtual sensor 4"
350 /* Labels for Octo and Quadro (except speed) */
351 static const char *const label_fan_speed[] = {
362 static const char *const label_fan_power[] = {
373 static const char *const label_fan_voltage[] = {
384 static const char *const label_fan_current[] = {
395 /* Labels for Quadro fan speeds */
396 static const char *const label_quadro_speeds[] = {
404 /* Labels for Aquaero fan speeds */
405 static const char *const label_aquaero_speeds[] = {
410 "Flow sensor 1 [dL/h]",
411 "Flow sensor 2 [dL/h]"
414 /* Labels for High Flow Next */
415 static const char *const label_highflownext_temp_sensors[] = {
420 static const char *const label_highflownext_fan_speed[] = {
423 "Conductivity [nS/cm]",
426 static const char *const label_highflownext_power[] = {
430 static const char *const label_highflownext_voltage[] = {
435 /* Labels for Leakshield */
436 static const char *const label_leakshield_temp_sensors[] = {
441 static const char *const label_leakshield_fan_speed[] = {
443 "User-Provided Pump Speed",
444 "User-Provided Flow [dL/h]",
445 "Reservoir Volume [ml]",
446 "Reservoir Filled [ml]",
449 /* Labels for Aquastream XT */
450 static const char *const label_aquastreamxt_temp_sensors[] = {
456 /* Labels for Aquastream Ultimate */
457 static const char *const label_aquastreamult_temp[] = {
462 static const char *const label_aquastreamult_speeds[] = {
469 static const char *const label_aquastreamult_power[] = {
474 static const char *const label_aquastreamult_voltages[] = {
479 static const char *const label_aquastreamult_current[] = {
484 /* Labels for Poweradjust 3 */
485 static const char *const label_poweradjust3_temp_sensors[] = {
489 struct aqc_fan_structure_offsets {
496 /* Fan structure offsets for Aquaero */
497 static struct aqc_fan_structure_offsets aqc_aquaero_fan_structure = {
498 .voltage = AQUAERO_FAN_VOLTAGE_OFFSET,
499 .curr = AQUAERO_FAN_CURRENT_OFFSET,
500 .power = AQUAERO_FAN_POWER_OFFSET,
501 .speed = AQUAERO_FAN_SPEED_OFFSET
504 /* Fan structure offsets for Aquastream Ultimate */
505 static struct aqc_fan_structure_offsets aqc_aquastreamult_fan_structure = {
506 .voltage = AQUASTREAMULT_FAN_VOLTAGE_OFFSET,
507 .curr = AQUASTREAMULT_FAN_CURRENT_OFFSET,
508 .power = AQUASTREAMULT_FAN_POWER_OFFSET,
509 .speed = AQUASTREAMULT_FAN_SPEED_OFFSET
512 /* Fan structure offsets for all devices except those above */
513 static struct aqc_fan_structure_offsets aqc_general_fan_structure = {
514 .voltage = AQC_FAN_VOLTAGE_OFFSET,
515 .curr = AQC_FAN_CURRENT_OFFSET,
516 .power = AQC_FAN_POWER_OFFSET,
517 .speed = AQC_FAN_SPEED_OFFSET
521 struct hid_device *hdev;
522 struct device *hwmon_dev;
523 struct dentry *debugfs;
524 struct mutex mutex; /* Used for locking access when reading and writing PWM values */
528 int status_report_id; /* Used for legacy devices, report is stored in buffer */
530 int secondary_ctrl_report_id;
531 int secondary_ctrl_report_size;
532 u8 *secondary_ctrl_report;
534 ktime_t last_ctrl_report_op;
535 int ctrl_report_delay; /* Delay between two ctrl report operations, in ms */
544 u16 *fan_sensor_offsets;
545 u16 *fan_ctrl_offsets;
546 int num_temp_sensors;
547 int temp_sensor_start_offset;
548 int num_virtual_temp_sensors;
549 int virtual_temp_sensor_start_offset;
550 int num_calc_virt_temp_sensors;
551 int calc_virt_temp_sensor_start_offset;
552 u16 temp_ctrl_offset;
553 u16 power_cycle_count_offset;
554 int num_flow_sensors;
555 u8 flow_sensors_start_offset;
556 u8 flow_pulses_ctrl_offset;
557 struct aqc_fan_structure_offsets *fan_structure;
559 /* General info, same across all devices */
560 u8 serial_number_start_offset;
561 u32 serial_number[2];
562 u8 firmware_version_offset;
563 u16 firmware_version;
565 /* How many times the device was powered on, if available */
569 s32 temp_input[20]; /* Max 4 physical and 16 virtual or 8 physical and 12 virtual */
571 u32 speed_input_min[1];
572 u32 speed_input_target[1];
573 u32 speed_input_max[1];
575 u16 voltage_input[8];
576 u16 current_input[8];
579 const char *const *temp_label;
580 const char *const *virtual_temp_label;
581 const char *const *calc_virt_temp_label; /* For Aquaero */
582 const char *const *speed_label;
583 const char *const *power_label;
584 const char *const *voltage_label;
585 const char *const *current_label;
587 unsigned long updated;
590 /* Converts from centi-percent */
591 static int aqc_percent_to_pwm(u16 val)
593 return DIV_ROUND_CLOSEST(val * 255, 100 * 100);
596 /* Converts to centi-percent */
597 static int aqc_pwm_to_percent(long val)
599 if (val < 0 || val > 255)
602 return DIV_ROUND_CLOSEST(val * 100 * 100, 255);
605 /* Converts raw value for Aquastream XT pump speed to RPM */
606 static int aqc_aquastreamxt_convert_pump_rpm(u16 val)
609 return DIV_ROUND_CLOSEST(AQUASTREAMXT_PUMP_CONVERSION_CONST, val);
613 /* Converts raw value for Aquastream XT fan speed to RPM */
614 static int aqc_aquastreamxt_convert_fan_rpm(u16 val)
617 return DIV_ROUND_CLOSEST(AQUASTREAMXT_FAN_CONVERSION_CONST, val);
621 static void aqc_delay_ctrl_report(struct aqc_data *priv)
624 * If previous read or write is too close to this one, delay the current operation
625 * to give the device enough time to process the previous one.
627 if (priv->ctrl_report_delay) {
628 s64 delta = ktime_ms_delta(ktime_get(), priv->last_ctrl_report_op);
630 if (delta < priv->ctrl_report_delay)
631 msleep(priv->ctrl_report_delay - delta);
635 /* Expects the mutex to be locked */
636 static int aqc_get_ctrl_data(struct aqc_data *priv)
640 aqc_delay_ctrl_report(priv);
642 memset(priv->buffer, 0x00, priv->buffer_size);
643 ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size,
644 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
648 priv->last_ctrl_report_op = ktime_get();
653 /* Expects the mutex to be locked */
654 static int aqc_send_ctrl_data(struct aqc_data *priv)
659 aqc_delay_ctrl_report(priv);
661 /* Checksum is not needed for Aquaero */
662 if (priv->kind != aquaero) {
663 /* Init and xorout value for CRC-16/USB is 0xffff */
664 checksum = crc16(0xffff, priv->buffer + priv->checksum_start,
665 priv->checksum_length);
668 /* Place the new checksum at the end of the report */
669 put_unaligned_be16(checksum, priv->buffer + priv->checksum_offset);
672 /* Send the patched up report back to the device */
673 ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size,
674 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
676 goto record_access_and_ret;
678 /* The official software sends this report after every change, so do it here as well */
679 ret = hid_hw_raw_request(priv->hdev, priv->secondary_ctrl_report_id,
680 priv->secondary_ctrl_report, priv->secondary_ctrl_report_size,
681 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
683 record_access_and_ret:
684 priv->last_ctrl_report_op = ktime_get();
689 /* Refreshes the control buffer and stores value at offset in val */
690 static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val, int type)
694 mutex_lock(&priv->mutex);
696 ret = aqc_get_ctrl_data(priv);
698 goto unlock_and_return;
702 *val = (s16)get_unaligned_be16(priv->buffer + offset);
705 *val = priv->buffer[offset];
712 mutex_unlock(&priv->mutex);
716 static int aqc_set_ctrl_vals(struct aqc_data *priv, int *offsets, long *vals, int *types, int len)
720 mutex_lock(&priv->mutex);
722 ret = aqc_get_ctrl_data(priv);
724 goto unlock_and_return;
726 for (i = 0; i < len; i++) {
729 put_unaligned_be16((s16)vals[i], priv->buffer + offsets[i]);
732 priv->buffer[offsets[i]] = (u8)vals[i];
740 goto unlock_and_return;
742 ret = aqc_send_ctrl_data(priv);
745 mutex_unlock(&priv->mutex);
749 static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int type)
751 return aqc_set_ctrl_vals(priv, &offset, &val, &type, 1);
754 static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel)
756 const struct aqc_data *priv = data;
760 if (channel < priv->num_temp_sensors) {
762 case hwmon_temp_label:
763 case hwmon_temp_input:
765 case hwmon_temp_offset:
766 if (priv->temp_ctrl_offset != 0)
775 priv->num_temp_sensors + priv->num_virtual_temp_sensors +
776 priv->num_calc_virt_temp_sensors)
778 case hwmon_temp_label:
779 case hwmon_temp_input:
786 if (priv->fan_ctrl_offsets && channel < priv->num_fans) {
788 case hwmon_pwm_input:
797 case hwmon_fan_input:
798 case hwmon_fan_label:
799 switch (priv->kind) {
802 * Special case to support pump RPM, fan RPM,
803 * pressure and flow sensor
809 /* Special case to support flow sensor, water quality
816 /* Special case for Leakshield sensors */
822 /* Special case to support flow sensors */
823 if (channel < priv->num_fans + priv->num_flow_sensors)
827 if (channel < priv->num_fans)
832 case hwmon_fan_pulses:
833 /* Special case for Quadro flow sensor */
834 if (priv->kind == quadro && channel == priv->num_fans)
839 case hwmon_fan_target:
840 /* Special case for Leakshield pressure sensor */
841 if (priv->kind == leakshield && channel == 0)
849 switch (priv->kind) {
851 /* Special case to support pump and fan power */
856 /* Special case to support one power sensor */
863 if (channel < priv->num_fans)
869 switch (priv->kind) {
871 /* Special case to support pump and fan current */
876 /* Special case to support pump current */
881 if (channel < priv->num_fans)
887 switch (priv->kind) {
889 /* Special case to support +5V and +12V voltage sensors */
890 if (channel < priv->num_fans + 2)
895 /* Special case to support two voltage sensors */
900 if (channel < priv->num_fans)
912 /* Read device sensors by manually requesting the sensor report (legacy way) */
913 static int aqc_legacy_read(struct aqc_data *priv)
915 int ret, i, sensor_value;
917 mutex_lock(&priv->mutex);
919 memset(priv->buffer, 0x00, priv->buffer_size);
920 ret = hid_hw_raw_request(priv->hdev, priv->status_report_id, priv->buffer,
921 priv->buffer_size, HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
923 goto unlock_and_return;
925 /* Temperature sensor readings */
926 for (i = 0; i < priv->num_temp_sensors; i++) {
927 sensor_value = get_unaligned_le16(priv->buffer + priv->temp_sensor_start_offset +
928 i * AQC_SENSOR_SIZE);
929 priv->temp_input[i] = sensor_value * 10;
932 /* Special-case sensor readings */
933 switch (priv->kind) {
935 /* Info provided with every report */
936 priv->serial_number[0] = get_unaligned_le16(priv->buffer +
937 priv->serial_number_start_offset);
938 priv->firmware_version =
939 get_unaligned_le16(priv->buffer + priv->firmware_version_offset);
941 /* Read pump speed in RPM */
942 sensor_value = get_unaligned_le16(priv->buffer + priv->fan_sensor_offsets[0]);
943 priv->speed_input[0] = aqc_aquastreamxt_convert_pump_rpm(sensor_value);
945 /* Read fan speed in RPM, if available */
946 sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_FAN_STATUS_OFFSET);
947 if (sensor_value == AQUASTREAMXT_FAN_STOPPED) {
948 priv->speed_input[1] = 0;
951 get_unaligned_le16(priv->buffer + priv->fan_sensor_offsets[1]);
952 priv->speed_input[1] = aqc_aquastreamxt_convert_fan_rpm(sensor_value);
955 /* Calculation derived from linear regression */
956 sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_PUMP_CURR_OFFSET);
957 priv->current_input[0] = DIV_ROUND_CLOSEST(sensor_value * 176, 100) - 52;
959 sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_PUMP_VOLTAGE_OFFSET);
960 priv->voltage_input[0] = DIV_ROUND_CLOSEST(sensor_value * 1000, 61);
962 sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_FAN_VOLTAGE_OFFSET);
963 priv->voltage_input[1] = DIV_ROUND_CLOSEST(sensor_value * 1000, 63);
969 priv->updated = jiffies;
972 mutex_unlock(&priv->mutex);
976 static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
977 int channel, long *val)
980 struct aqc_data *priv = dev_get_drvdata(dev);
982 if (time_after(jiffies, priv->updated + STATUS_UPDATE_INTERVAL)) {
983 if (priv->status_report_id != 0) {
984 /* Legacy devices require manual reads */
985 ret = aqc_legacy_read(priv);
996 case hwmon_temp_input:
997 if (priv->temp_input[channel] == -ENODATA)
1000 *val = priv->temp_input[channel];
1002 case hwmon_temp_offset:
1004 aqc_get_ctrl_val(priv, priv->temp_ctrl_offset +
1005 channel * AQC_SENSOR_SIZE, val, AQC_BE16);
1017 case hwmon_fan_input:
1018 if (priv->speed_input[channel] == -ENODATA)
1021 *val = priv->speed_input[channel];
1024 *val = priv->speed_input_min[channel];
1027 *val = priv->speed_input_max[channel];
1029 case hwmon_fan_target:
1030 *val = priv->speed_input_target[channel];
1032 case hwmon_fan_pulses:
1033 ret = aqc_get_ctrl_val(priv, priv->flow_pulses_ctrl_offset,
1043 *val = priv->power_input[channel];
1046 switch (priv->kind) {
1048 ret = aqc_get_ctrl_val(priv,
1049 AQUAERO_CTRL_PRESET_START + channel * AQUAERO_CTRL_PRESET_SIZE,
1053 *val = aqc_percent_to_pwm(*val);
1056 ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel],
1061 *val = aqc_percent_to_pwm(*val);
1066 *val = priv->voltage_input[channel];
1069 *val = priv->current_input[channel];
1078 static int aqc_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
1079 int channel, const char **str)
1081 struct aqc_data *priv = dev_get_drvdata(dev);
1083 /* Number of sensors that are not calculated */
1084 int num_non_calc_sensors = priv->num_temp_sensors + priv->num_virtual_temp_sensors;
1088 if (channel < priv->num_temp_sensors) {
1089 *str = priv->temp_label[channel];
1091 if (priv->kind == aquaero && channel >= num_non_calc_sensors)
1093 priv->calc_virt_temp_label[channel - num_non_calc_sensors];
1095 *str = priv->virtual_temp_label[channel - priv->num_temp_sensors];
1099 *str = priv->speed_label[channel];
1102 *str = priv->power_label[channel];
1105 *str = priv->voltage_label[channel];
1108 *str = priv->current_label[channel];
1117 static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
1121 /* Arrays for setting multiple values at once in the control report */
1122 int ctrl_values_offsets[4];
1123 long ctrl_values[4];
1124 int ctrl_values_types[4];
1125 struct aqc_data *priv = dev_get_drvdata(dev);
1130 case hwmon_temp_offset:
1131 /* Limit temp offset to +/- 15K as in the official software */
1132 val = clamp_val(val, -15000, 15000) / 10;
1134 aqc_set_ctrl_val(priv, priv->temp_ctrl_offset +
1135 channel * AQC_SENSOR_SIZE, val, AQC_BE16);
1145 case hwmon_fan_pulses:
1146 val = clamp_val(val, 10, 1000);
1147 ret = aqc_set_ctrl_val(priv, priv->flow_pulses_ctrl_offset,
1158 case hwmon_pwm_input:
1159 pwm_value = aqc_pwm_to_percent(val);
1163 switch (priv->kind) {
1165 /* Write pwm value to preset corresponding to the channel */
1166 ctrl_values_offsets[0] = AQUAERO_CTRL_PRESET_START +
1167 channel * AQUAERO_CTRL_PRESET_SIZE;
1168 ctrl_values[0] = pwm_value;
1169 ctrl_values_types[0] = AQC_BE16;
1171 /* Write preset number in fan control source */
1172 ctrl_values_offsets[1] = priv->fan_ctrl_offsets[channel] +
1173 AQUAERO_FAN_CTRL_SRC_OFFSET;
1174 ctrl_values[1] = AQUAERO_CTRL_PRESET_ID + channel;
1175 ctrl_values_types[1] = AQC_BE16;
1177 /* Set minimum power to 0 to allow the fan to turn off */
1178 ctrl_values_offsets[2] = priv->fan_ctrl_offsets[channel] +
1179 AQUAERO_FAN_CTRL_MIN_PWR_OFFSET;
1181 ctrl_values_types[2] = AQC_BE16;
1183 /* Set maximum power to 255 to allow the fan to reach max speed */
1184 ctrl_values_offsets[3] = priv->fan_ctrl_offsets[channel] +
1185 AQUAERO_FAN_CTRL_MAX_PWR_OFFSET;
1186 ctrl_values[3] = aqc_pwm_to_percent(255);
1187 ctrl_values_types[3] = AQC_BE16;
1189 ret = aqc_set_ctrl_vals(priv, ctrl_values_offsets, ctrl_values,
1190 ctrl_values_types, 4);
1195 ret = aqc_set_ctrl_val(priv, priv->fan_ctrl_offsets[channel],
1196 pwm_value, AQC_BE16);
1213 static const struct hwmon_ops aqc_hwmon_ops = {
1214 .is_visible = aqc_is_visible,
1216 .read_string = aqc_read_string,
1220 static const struct hwmon_channel_info * const aqc_info[] = {
1221 HWMON_CHANNEL_INFO(temp,
1222 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1223 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1224 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1225 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1226 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1227 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1228 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1229 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1230 HWMON_T_INPUT | HWMON_T_LABEL,
1231 HWMON_T_INPUT | HWMON_T_LABEL,
1232 HWMON_T_INPUT | HWMON_T_LABEL,
1233 HWMON_T_INPUT | HWMON_T_LABEL,
1234 HWMON_T_INPUT | HWMON_T_LABEL,
1235 HWMON_T_INPUT | HWMON_T_LABEL,
1236 HWMON_T_INPUT | HWMON_T_LABEL,
1237 HWMON_T_INPUT | HWMON_T_LABEL,
1238 HWMON_T_INPUT | HWMON_T_LABEL,
1239 HWMON_T_INPUT | HWMON_T_LABEL,
1240 HWMON_T_INPUT | HWMON_T_LABEL,
1241 HWMON_T_INPUT | HWMON_T_LABEL),
1242 HWMON_CHANNEL_INFO(fan,
1243 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
1245 HWMON_F_INPUT | HWMON_F_LABEL,
1246 HWMON_F_INPUT | HWMON_F_LABEL,
1247 HWMON_F_INPUT | HWMON_F_LABEL,
1248 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_PULSES,
1249 HWMON_F_INPUT | HWMON_F_LABEL,
1250 HWMON_F_INPUT | HWMON_F_LABEL,
1251 HWMON_F_INPUT | HWMON_F_LABEL),
1252 HWMON_CHANNEL_INFO(power,
1253 HWMON_P_INPUT | HWMON_P_LABEL,
1254 HWMON_P_INPUT | HWMON_P_LABEL,
1255 HWMON_P_INPUT | HWMON_P_LABEL,
1256 HWMON_P_INPUT | HWMON_P_LABEL,
1257 HWMON_P_INPUT | HWMON_P_LABEL,
1258 HWMON_P_INPUT | HWMON_P_LABEL,
1259 HWMON_P_INPUT | HWMON_P_LABEL,
1260 HWMON_P_INPUT | HWMON_P_LABEL),
1261 HWMON_CHANNEL_INFO(pwm,
1270 HWMON_CHANNEL_INFO(in,
1271 HWMON_I_INPUT | HWMON_I_LABEL,
1272 HWMON_I_INPUT | HWMON_I_LABEL,
1273 HWMON_I_INPUT | HWMON_I_LABEL,
1274 HWMON_I_INPUT | HWMON_I_LABEL,
1275 HWMON_I_INPUT | HWMON_I_LABEL,
1276 HWMON_I_INPUT | HWMON_I_LABEL,
1277 HWMON_I_INPUT | HWMON_I_LABEL,
1278 HWMON_I_INPUT | HWMON_I_LABEL),
1279 HWMON_CHANNEL_INFO(curr,
1280 HWMON_C_INPUT | HWMON_C_LABEL,
1281 HWMON_C_INPUT | HWMON_C_LABEL,
1282 HWMON_C_INPUT | HWMON_C_LABEL,
1283 HWMON_C_INPUT | HWMON_C_LABEL,
1284 HWMON_C_INPUT | HWMON_C_LABEL,
1285 HWMON_C_INPUT | HWMON_C_LABEL,
1286 HWMON_C_INPUT | HWMON_C_LABEL,
1287 HWMON_C_INPUT | HWMON_C_LABEL),
1291 static const struct hwmon_chip_info aqc_chip_info = {
1292 .ops = &aqc_hwmon_ops,
1296 static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size)
1298 int i, j, sensor_value;
1299 struct aqc_data *priv;
1301 if (report->id != STATUS_REPORT_ID)
1304 priv = hid_get_drvdata(hdev);
1306 /* Info provided with every report */
1307 priv->serial_number[0] = get_unaligned_be16(data + priv->serial_number_start_offset);
1308 priv->serial_number[1] = get_unaligned_be16(data + priv->serial_number_start_offset +
1309 SERIAL_PART_OFFSET);
1310 priv->firmware_version = get_unaligned_be16(data + priv->firmware_version_offset);
1312 /* Physical temperature sensor readings */
1313 for (i = 0; i < priv->num_temp_sensors; i++) {
1314 sensor_value = get_unaligned_be16(data +
1315 priv->temp_sensor_start_offset +
1316 i * AQC_SENSOR_SIZE);
1317 if (sensor_value == AQC_SENSOR_NA)
1318 priv->temp_input[i] = -ENODATA;
1320 priv->temp_input[i] = sensor_value * 10;
1323 /* Virtual temperature sensor readings */
1324 for (j = 0; j < priv->num_virtual_temp_sensors; j++) {
1325 sensor_value = get_unaligned_be16(data +
1326 priv->virtual_temp_sensor_start_offset +
1327 j * AQC_SENSOR_SIZE);
1328 if (sensor_value == AQC_SENSOR_NA)
1329 priv->temp_input[i] = -ENODATA;
1331 priv->temp_input[i] = sensor_value * 10;
1335 /* Fan speed and related readings */
1336 for (i = 0; i < priv->num_fans; i++) {
1337 priv->speed_input[i] =
1338 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
1339 priv->fan_structure->speed);
1340 priv->power_input[i] =
1341 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
1342 priv->fan_structure->power) * 10000;
1343 priv->voltage_input[i] =
1344 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
1345 priv->fan_structure->voltage) * 10;
1346 priv->current_input[i] =
1347 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
1348 priv->fan_structure->curr);
1351 /* Flow sensor readings */
1352 for (j = 0; j < priv->num_flow_sensors; j++) {
1353 priv->speed_input[i] = get_unaligned_be16(data + priv->flow_sensors_start_offset +
1354 j * AQC_SENSOR_SIZE);
1358 if (priv->power_cycle_count_offset != 0)
1359 priv->power_cycles = get_unaligned_be32(data + priv->power_cycle_count_offset);
1361 /* Special-case sensor readings */
1362 switch (priv->kind) {
1364 /* Read calculated virtual temp sensors */
1365 i = priv->num_temp_sensors + priv->num_virtual_temp_sensors;
1366 for (j = 0; j < priv->num_calc_virt_temp_sensors; j++) {
1367 sensor_value = get_unaligned_be16(data +
1368 priv->calc_virt_temp_sensor_start_offset +
1369 j * AQC_SENSOR_SIZE);
1370 if (sensor_value == AQC_SENSOR_NA)
1371 priv->temp_input[i] = -ENODATA;
1373 priv->temp_input[i] = sensor_value * 10;
1378 priv->speed_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_OFFSET);
1379 priv->speed_input[2] = get_unaligned_be16(data + AQUASTREAMULT_PRESSURE_OFFSET);
1380 priv->speed_input[3] = get_unaligned_be16(data + AQUASTREAMULT_FLOW_SENSOR_OFFSET);
1382 priv->power_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_POWER) * 10000;
1384 priv->voltage_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_VOLTAGE) * 10;
1386 priv->current_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_CURRENT);
1389 priv->voltage_input[2] = get_unaligned_be16(data + D5NEXT_5V_VOLTAGE) * 10;
1390 priv->voltage_input[3] = get_unaligned_be16(data + D5NEXT_12V_VOLTAGE) * 10;
1393 /* If external temp sensor is not connected, its power reading is also N/A */
1394 if (priv->temp_input[1] == -ENODATA)
1395 priv->power_input[0] = -ENODATA;
1397 priv->power_input[0] =
1398 get_unaligned_be16(data + HIGHFLOWNEXT_POWER) * 1000000;
1400 priv->voltage_input[0] = get_unaligned_be16(data + HIGHFLOWNEXT_5V_VOLTAGE) * 10;
1401 priv->voltage_input[1] =
1402 get_unaligned_be16(data + HIGHFLOWNEXT_5V_VOLTAGE_USB) * 10;
1404 priv->speed_input[1] = get_unaligned_be16(data + HIGHFLOWNEXT_WATER_QUALITY);
1405 priv->speed_input[2] = get_unaligned_be16(data + HIGHFLOWNEXT_CONDUCTIVITY);
1408 priv->speed_input[0] =
1409 ((s16)get_unaligned_be16(data + LEAKSHIELD_PRESSURE_ADJUSTED)) * 100;
1410 priv->speed_input_min[0] = get_unaligned_be16(data + LEAKSHIELD_PRESSURE_MIN) * 100;
1411 priv->speed_input_target[0] =
1412 get_unaligned_be16(data + LEAKSHIELD_PRESSURE_TARGET) * 100;
1413 priv->speed_input_max[0] = get_unaligned_be16(data + LEAKSHIELD_PRESSURE_MAX) * 100;
1415 priv->speed_input[1] = get_unaligned_be16(data + LEAKSHIELD_PUMP_RPM_IN);
1416 if (priv->speed_input[1] == AQC_SENSOR_NA)
1417 priv->speed_input[1] = -ENODATA;
1419 priv->speed_input[2] = get_unaligned_be16(data + LEAKSHIELD_FLOW_IN);
1420 if (priv->speed_input[2] == AQC_SENSOR_NA)
1421 priv->speed_input[2] = -ENODATA;
1423 priv->speed_input[3] = get_unaligned_be16(data + LEAKSHIELD_RESERVOIR_VOLUME);
1424 priv->speed_input[4] = get_unaligned_be16(data + LEAKSHIELD_RESERVOIR_FILLED);
1426 /* Second temp sensor is not positioned after the first one, read it here */
1427 priv->temp_input[1] = get_unaligned_be16(data + LEAKSHIELD_TEMPERATURE_2) * 10;
1433 priv->updated = jiffies;
1438 #ifdef CONFIG_DEBUG_FS
1440 static int serial_number_show(struct seq_file *seqf, void *unused)
1442 struct aqc_data *priv = seqf->private;
1444 seq_printf(seqf, "%05u-%05u\n", priv->serial_number[0], priv->serial_number[1]);
1448 DEFINE_SHOW_ATTRIBUTE(serial_number);
1450 static int firmware_version_show(struct seq_file *seqf, void *unused)
1452 struct aqc_data *priv = seqf->private;
1454 seq_printf(seqf, "%u\n", priv->firmware_version);
1458 DEFINE_SHOW_ATTRIBUTE(firmware_version);
1460 static int power_cycles_show(struct seq_file *seqf, void *unused)
1462 struct aqc_data *priv = seqf->private;
1464 seq_printf(seqf, "%u\n", priv->power_cycles);
1468 DEFINE_SHOW_ATTRIBUTE(power_cycles);
1470 static void aqc_debugfs_init(struct aqc_data *priv)
1474 scnprintf(name, sizeof(name), "%s_%s-%s", "aquacomputer", priv->name,
1475 dev_name(&priv->hdev->dev));
1477 priv->debugfs = debugfs_create_dir(name, NULL);
1479 if (priv->serial_number_start_offset != 0)
1480 debugfs_create_file("serial_number", 0444, priv->debugfs, priv,
1481 &serial_number_fops);
1482 if (priv->firmware_version_offset != 0)
1483 debugfs_create_file("firmware_version", 0444, priv->debugfs, priv,
1484 &firmware_version_fops);
1485 if (priv->power_cycle_count_offset != 0)
1486 debugfs_create_file("power_cycles", 0444, priv->debugfs, priv, &power_cycles_fops);
1491 static void aqc_debugfs_init(struct aqc_data *priv)
1497 static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
1499 struct aqc_data *priv;
1502 priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL);
1507 hid_set_drvdata(hdev, priv);
1509 priv->updated = jiffies - STATUS_UPDATE_INTERVAL;
1511 ret = hid_parse(hdev);
1515 ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
1519 ret = hid_hw_open(hdev);
1523 switch (hdev->product) {
1524 case USB_PRODUCT_ID_AQUAERO:
1526 * Aquaero presents itself as three HID devices under the same product ID:
1527 * "aquaero keyboard/mouse", "aquaero System Control" and "aquaero Device",
1528 * which is the one we want to communicate with. Unlike most other Aquacomputer
1529 * devices, Aquaero does not return meaningful data when explicitly requested
1530 * using GET_FEATURE_REPORT.
1532 * The difference between "aquaero Device" and the other two is in the collections
1533 * they present. The two other devices have the type of the second element in
1534 * their respective collections set to 1, while the real device has it set to 0.
1536 if (hdev->collection[1].type != 0) {
1538 goto fail_and_close;
1541 priv->kind = aquaero;
1543 priv->num_fans = AQUAERO_NUM_FANS;
1544 priv->fan_sensor_offsets = aquaero_sensor_fan_offsets;
1545 priv->fan_ctrl_offsets = aquaero_ctrl_fan_offsets;
1547 priv->num_temp_sensors = AQUAERO_NUM_SENSORS;
1548 priv->temp_sensor_start_offset = AQUAERO_SENSOR_START;
1549 priv->num_virtual_temp_sensors = AQUAERO_NUM_VIRTUAL_SENSORS;
1550 priv->virtual_temp_sensor_start_offset = AQUAERO_VIRTUAL_SENSOR_START;
1551 priv->num_calc_virt_temp_sensors = AQUAERO_NUM_CALC_VIRTUAL_SENSORS;
1552 priv->calc_virt_temp_sensor_start_offset = AQUAERO_CALC_VIRTUAL_SENSOR_START;
1553 priv->num_flow_sensors = AQUAERO_NUM_FLOW_SENSORS;
1554 priv->flow_sensors_start_offset = AQUAERO_FLOW_SENSORS_START;
1556 priv->buffer_size = AQUAERO_CTRL_REPORT_SIZE;
1557 priv->temp_ctrl_offset = AQUAERO_TEMP_CTRL_OFFSET;
1558 priv->ctrl_report_delay = CTRL_REPORT_DELAY;
1560 priv->temp_label = label_temp_sensors;
1561 priv->virtual_temp_label = label_virtual_temp_sensors;
1562 priv->calc_virt_temp_label = label_aquaero_calc_temp_sensors;
1563 priv->speed_label = label_aquaero_speeds;
1564 priv->power_label = label_fan_power;
1565 priv->voltage_label = label_fan_voltage;
1566 priv->current_label = label_fan_current;
1568 case USB_PRODUCT_ID_D5NEXT:
1569 priv->kind = d5next;
1571 priv->num_fans = D5NEXT_NUM_FANS;
1572 priv->fan_sensor_offsets = d5next_sensor_fan_offsets;
1573 priv->fan_ctrl_offsets = d5next_ctrl_fan_offsets;
1575 priv->num_temp_sensors = D5NEXT_NUM_SENSORS;
1576 priv->temp_sensor_start_offset = D5NEXT_COOLANT_TEMP;
1577 priv->num_virtual_temp_sensors = D5NEXT_NUM_VIRTUAL_SENSORS;
1578 priv->virtual_temp_sensor_start_offset = D5NEXT_VIRTUAL_SENSORS_START;
1579 priv->temp_ctrl_offset = D5NEXT_TEMP_CTRL_OFFSET;
1581 priv->buffer_size = D5NEXT_CTRL_REPORT_SIZE;
1582 priv->ctrl_report_delay = CTRL_REPORT_DELAY;
1584 priv->power_cycle_count_offset = D5NEXT_POWER_CYCLES;
1586 priv->temp_label = label_d5next_temp;
1587 priv->virtual_temp_label = label_virtual_temp_sensors;
1588 priv->speed_label = label_d5next_speeds;
1589 priv->power_label = label_d5next_power;
1590 priv->voltage_label = label_d5next_voltages;
1591 priv->current_label = label_d5next_current;
1593 case USB_PRODUCT_ID_FARBWERK:
1594 priv->kind = farbwerk;
1598 priv->num_temp_sensors = FARBWERK_NUM_SENSORS;
1599 priv->temp_sensor_start_offset = FARBWERK_SENSOR_START;
1601 priv->temp_label = label_temp_sensors;
1603 case USB_PRODUCT_ID_FARBWERK360:
1604 priv->kind = farbwerk360;
1608 priv->num_temp_sensors = FARBWERK360_NUM_SENSORS;
1609 priv->temp_sensor_start_offset = FARBWERK360_SENSOR_START;
1610 priv->num_virtual_temp_sensors = FARBWERK360_NUM_VIRTUAL_SENSORS;
1611 priv->virtual_temp_sensor_start_offset = FARBWERK360_VIRTUAL_SENSORS_START;
1612 priv->temp_ctrl_offset = FARBWERK360_TEMP_CTRL_OFFSET;
1614 priv->buffer_size = FARBWERK360_CTRL_REPORT_SIZE;
1616 priv->temp_label = label_temp_sensors;
1617 priv->virtual_temp_label = label_virtual_temp_sensors;
1619 case USB_PRODUCT_ID_OCTO:
1622 priv->num_fans = OCTO_NUM_FANS;
1623 priv->fan_sensor_offsets = octo_sensor_fan_offsets;
1624 priv->fan_ctrl_offsets = octo_ctrl_fan_offsets;
1626 priv->num_temp_sensors = OCTO_NUM_SENSORS;
1627 priv->temp_sensor_start_offset = OCTO_SENSOR_START;
1628 priv->num_virtual_temp_sensors = OCTO_NUM_VIRTUAL_SENSORS;
1629 priv->virtual_temp_sensor_start_offset = OCTO_VIRTUAL_SENSORS_START;
1630 priv->temp_ctrl_offset = OCTO_TEMP_CTRL_OFFSET;
1632 priv->buffer_size = OCTO_CTRL_REPORT_SIZE;
1633 priv->ctrl_report_delay = CTRL_REPORT_DELAY;
1635 priv->power_cycle_count_offset = OCTO_POWER_CYCLES;
1637 priv->temp_label = label_temp_sensors;
1638 priv->virtual_temp_label = label_virtual_temp_sensors;
1639 priv->speed_label = label_fan_speed;
1640 priv->power_label = label_fan_power;
1641 priv->voltage_label = label_fan_voltage;
1642 priv->current_label = label_fan_current;
1644 case USB_PRODUCT_ID_QUADRO:
1645 priv->kind = quadro;
1647 priv->num_fans = QUADRO_NUM_FANS;
1648 priv->fan_sensor_offsets = quadro_sensor_fan_offsets;
1649 priv->fan_ctrl_offsets = quadro_ctrl_fan_offsets;
1651 priv->num_temp_sensors = QUADRO_NUM_SENSORS;
1652 priv->temp_sensor_start_offset = QUADRO_SENSOR_START;
1653 priv->num_virtual_temp_sensors = QUADRO_NUM_VIRTUAL_SENSORS;
1654 priv->virtual_temp_sensor_start_offset = QUADRO_VIRTUAL_SENSORS_START;
1655 priv->num_flow_sensors = QUADRO_NUM_FLOW_SENSORS;
1656 priv->flow_sensors_start_offset = QUADRO_FLOW_SENSOR_OFFSET;
1658 priv->temp_ctrl_offset = QUADRO_TEMP_CTRL_OFFSET;
1660 priv->buffer_size = QUADRO_CTRL_REPORT_SIZE;
1661 priv->ctrl_report_delay = CTRL_REPORT_DELAY;
1663 priv->flow_pulses_ctrl_offset = QUADRO_FLOW_PULSES_CTRL_OFFSET;
1664 priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;
1666 priv->temp_label = label_temp_sensors;
1667 priv->virtual_temp_label = label_virtual_temp_sensors;
1668 priv->speed_label = label_quadro_speeds;
1669 priv->power_label = label_fan_power;
1670 priv->voltage_label = label_fan_voltage;
1671 priv->current_label = label_fan_current;
1673 case USB_PRODUCT_ID_HIGHFLOWNEXT:
1674 priv->kind = highflownext;
1678 priv->num_temp_sensors = HIGHFLOWNEXT_NUM_SENSORS;
1679 priv->temp_sensor_start_offset = HIGHFLOWNEXT_SENSOR_START;
1680 priv->num_flow_sensors = HIGHFLOWNEXT_NUM_FLOW_SENSORS;
1681 priv->flow_sensors_start_offset = HIGHFLOWNEXT_FLOW;
1683 priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;
1685 priv->temp_label = label_highflownext_temp_sensors;
1686 priv->speed_label = label_highflownext_fan_speed;
1687 priv->power_label = label_highflownext_power;
1688 priv->voltage_label = label_highflownext_voltage;
1690 case USB_PRODUCT_ID_LEAKSHIELD:
1692 * Choose the right Leakshield device, because
1693 * the other one acts as a keyboard
1695 if (hdev->type != 2) {
1697 goto fail_and_close;
1700 priv->kind = leakshield;
1703 priv->num_temp_sensors = LEAKSHIELD_NUM_SENSORS;
1704 priv->temp_sensor_start_offset = LEAKSHIELD_TEMPERATURE_1;
1706 priv->temp_label = label_leakshield_temp_sensors;
1707 priv->speed_label = label_leakshield_fan_speed;
1709 case USB_PRODUCT_ID_AQUASTREAMXT:
1710 priv->kind = aquastreamxt;
1712 priv->num_fans = AQUASTREAMXT_NUM_FANS;
1713 priv->fan_sensor_offsets = aquastreamxt_sensor_fan_offsets;
1715 priv->num_temp_sensors = AQUASTREAMXT_NUM_SENSORS;
1716 priv->temp_sensor_start_offset = AQUASTREAMXT_SENSOR_START;
1717 priv->buffer_size = AQUASTREAMXT_SENSOR_REPORT_SIZE;
1719 priv->temp_label = label_aquastreamxt_temp_sensors;
1720 priv->speed_label = label_d5next_speeds;
1721 priv->voltage_label = label_d5next_voltages;
1722 priv->current_label = label_d5next_current;
1724 case USB_PRODUCT_ID_AQUASTREAMULT:
1725 priv->kind = aquastreamult;
1727 priv->num_fans = AQUASTREAMULT_NUM_FANS;
1728 priv->fan_sensor_offsets = aquastreamult_sensor_fan_offsets;
1730 priv->num_temp_sensors = AQUASTREAMULT_NUM_SENSORS;
1731 priv->temp_sensor_start_offset = AQUASTREAMULT_SENSOR_START;
1733 priv->temp_label = label_aquastreamult_temp;
1734 priv->speed_label = label_aquastreamult_speeds;
1735 priv->power_label = label_aquastreamult_power;
1736 priv->voltage_label = label_aquastreamult_voltages;
1737 priv->current_label = label_aquastreamult_current;
1739 case USB_PRODUCT_ID_POWERADJUST3:
1740 priv->kind = poweradjust3;
1744 priv->num_temp_sensors = POWERADJUST3_NUM_SENSORS;
1745 priv->temp_sensor_start_offset = POWERADJUST3_SENSOR_START;
1746 priv->buffer_size = POWERADJUST3_SENSOR_REPORT_SIZE;
1748 priv->temp_label = label_poweradjust3_temp_sensors;
1754 switch (priv->kind) {
1756 priv->serial_number_start_offset = AQUAERO_SERIAL_START;
1757 priv->firmware_version_offset = AQUAERO_FIRMWARE_VERSION;
1759 priv->fan_structure = &aqc_aquaero_fan_structure;
1761 priv->ctrl_report_id = AQUAERO_CTRL_REPORT_ID;
1762 priv->secondary_ctrl_report_id = AQUAERO_SECONDARY_CTRL_REPORT_ID;
1763 priv->secondary_ctrl_report_size = AQUAERO_SECONDARY_CTRL_REPORT_SIZE;
1764 priv->secondary_ctrl_report = aquaero_secondary_ctrl_report;
1767 priv->status_report_id = POWERADJUST3_STATUS_REPORT_ID;
1770 priv->serial_number_start_offset = AQUASTREAMXT_SERIAL_START;
1771 priv->firmware_version_offset = AQUASTREAMXT_FIRMWARE_VERSION;
1773 priv->status_report_id = AQUASTREAMXT_STATUS_REPORT_ID;
1776 priv->serial_number_start_offset = AQC_SERIAL_START;
1777 priv->firmware_version_offset = AQC_FIRMWARE_VERSION;
1779 priv->ctrl_report_id = CTRL_REPORT_ID;
1780 priv->secondary_ctrl_report_id = SECONDARY_CTRL_REPORT_ID;
1781 priv->secondary_ctrl_report_size = SECONDARY_CTRL_REPORT_SIZE;
1782 priv->secondary_ctrl_report = secondary_ctrl_report;
1784 if (priv->kind == aquastreamult)
1785 priv->fan_structure = &aqc_aquastreamult_fan_structure;
1787 priv->fan_structure = &aqc_general_fan_structure;
1791 if (priv->buffer_size != 0) {
1792 priv->checksum_start = 0x01;
1793 priv->checksum_length = priv->buffer_size - 3;
1794 priv->checksum_offset = priv->buffer_size - 2;
1797 priv->name = aqc_device_names[priv->kind];
1799 priv->buffer = devm_kzalloc(&hdev->dev, priv->buffer_size, GFP_KERNEL);
1800 if (!priv->buffer) {
1802 goto fail_and_close;
1805 mutex_init(&priv->mutex);
1807 priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, priv->name, priv,
1808 &aqc_chip_info, NULL);
1810 if (IS_ERR(priv->hwmon_dev)) {
1811 ret = PTR_ERR(priv->hwmon_dev);
1812 goto fail_and_close;
1815 aqc_debugfs_init(priv);
1826 static void aqc_remove(struct hid_device *hdev)
1828 struct aqc_data *priv = hid_get_drvdata(hdev);
1830 debugfs_remove_recursive(priv->debugfs);
1831 hwmon_device_unregister(priv->hwmon_dev);
1837 static const struct hid_device_id aqc_table[] = {
1838 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_AQUAERO) },
1839 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_D5NEXT) },
1840 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_FARBWERK) },
1841 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_FARBWERK360) },
1842 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_OCTO) },
1843 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_QUADRO) },
1844 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_HIGHFLOWNEXT) },
1845 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_LEAKSHIELD) },
1846 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_AQUASTREAMXT) },
1847 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_AQUASTREAMULT) },
1848 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_POWERADJUST3) },
1852 MODULE_DEVICE_TABLE(hid, aqc_table);
1854 static struct hid_driver aqc_driver = {
1855 .name = DRIVER_NAME,
1856 .id_table = aqc_table,
1858 .remove = aqc_remove,
1859 .raw_event = aqc_raw_event,
1862 static int __init aqc_init(void)
1864 return hid_register_driver(&aqc_driver);
1867 static void __exit aqc_exit(void)
1869 hid_unregister_driver(&aqc_driver);
1872 /* Request to initialize after the HID bus to ensure it's not being loaded before */
1873 late_initcall(aqc_init);
1874 module_exit(aqc_exit);
1876 MODULE_LICENSE("GPL");
1877 MODULE_AUTHOR("Aleksa Savic <savicaleksa83@gmail.com>");
1878 MODULE_AUTHOR("Jack Doan <me@jackdoan.com>");
1879 MODULE_DESCRIPTION("Hwmon driver for Aquacomputer devices");