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/hid.h>
17 #include <linux/hwmon.h>
18 #include <linux/jiffies.h>
19 #include <linux/module.h>
20 #include <linux/mutex.h>
21 #include <linux/seq_file.h>
22 #include <asm/unaligned.h>
24 #define USB_VENDOR_ID_AQUACOMPUTER 0x0c70
25 #define USB_PRODUCT_ID_AQUAERO 0xf001
26 #define USB_PRODUCT_ID_FARBWERK 0xf00a
27 #define USB_PRODUCT_ID_QUADRO 0xf00d
28 #define USB_PRODUCT_ID_D5NEXT 0xf00e
29 #define USB_PRODUCT_ID_FARBWERK360 0xf010
30 #define USB_PRODUCT_ID_OCTO 0xf011
31 #define USB_PRODUCT_ID_HIGHFLOWNEXT 0xf012
32 #define USB_PRODUCT_ID_LEAKSHIELD 0xf014
33 #define USB_PRODUCT_ID_AQUASTREAMXT 0xf0b6
34 #define USB_PRODUCT_ID_AQUASTREAMULT 0xf00b
35 #define USB_PRODUCT_ID_POWERADJUST3 0xf0bd
38 d5next, farbwerk, farbwerk360, octo, quadro,
39 highflownext, aquaero, poweradjust3, aquastreamult,
40 aquastreamxt, leakshield
43 static const char *const aqc_device_names[] = {
45 [farbwerk] = "farbwerk",
46 [farbwerk360] = "farbwerk360",
49 [highflownext] = "highflownext",
50 [leakshield] = "leakshield",
51 [aquastreamxt] = "aquastreamxt",
52 [aquaero] = "aquaero",
53 [aquastreamult] = "aquastreamultimate",
54 [poweradjust3] = "poweradjust3"
57 #define DRIVER_NAME "aquacomputer_d5next"
59 #define STATUS_REPORT_ID 0x01
60 #define STATUS_UPDATE_INTERVAL (2 * HZ) /* In seconds */
61 #define SERIAL_PART_OFFSET 2
63 #define CTRL_REPORT_ID 0x03
64 #define AQUAERO_CTRL_REPORT_ID 0x0b
66 /* The HID report that the official software always sends
67 * after writing values, currently same for all devices
69 #define SECONDARY_CTRL_REPORT_ID 0x02
70 #define SECONDARY_CTRL_REPORT_SIZE 0x0B
72 static u8 secondary_ctrl_report[] = {
73 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x34, 0xC6
76 /* Secondary HID report values for Aquaero */
77 #define AQUAERO_SECONDARY_CTRL_REPORT_ID 0x06
78 #define AQUAERO_SECONDARY_CTRL_REPORT_SIZE 0x07
80 static u8 aquaero_secondary_ctrl_report[] = {
81 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
84 /* Report IDs for legacy devices */
85 #define AQUASTREAMXT_STATUS_REPORT_ID 0x04
87 #define POWERADJUST3_STATUS_REPORT_ID 0x03
89 /* Data types for reading and writing control reports */
93 /* Info, sensor sizes and offsets for most Aquacomputer devices */
94 #define AQC_SERIAL_START 0x3
95 #define AQC_FIRMWARE_VERSION 0xD
97 #define AQC_SENSOR_SIZE 0x02
98 #define AQC_SENSOR_NA 0x7FFF
99 #define AQC_FAN_PERCENT_OFFSET 0x00
100 #define AQC_FAN_VOLTAGE_OFFSET 0x02
101 #define AQC_FAN_CURRENT_OFFSET 0x04
102 #define AQC_FAN_POWER_OFFSET 0x06
103 #define AQC_FAN_SPEED_OFFSET 0x08
105 /* Specs of the Aquaero fan controllers */
106 #define AQUAERO_SERIAL_START 0x07
107 #define AQUAERO_FIRMWARE_VERSION 0x0B
108 #define AQUAERO_NUM_FANS 4
109 #define AQUAERO_NUM_SENSORS 8
110 #define AQUAERO_NUM_VIRTUAL_SENSORS 8
111 #define AQUAERO_NUM_CALC_VIRTUAL_SENSORS 4
112 #define AQUAERO_NUM_FLOW_SENSORS 2
113 #define AQUAERO_CTRL_REPORT_SIZE 0xa93
114 #define AQUAERO_CTRL_PRESET_ID 0x5c
115 #define AQUAERO_CTRL_PRESET_SIZE 0x02
116 #define AQUAERO_CTRL_PRESET_START 0x55c
118 /* Sensor report offsets for Aquaero fan controllers */
119 #define AQUAERO_SENSOR_START 0x65
120 #define AQUAERO_VIRTUAL_SENSOR_START 0x85
121 #define AQUAERO_CALC_VIRTUAL_SENSOR_START 0x95
122 #define AQUAERO_FLOW_SENSORS_START 0xF9
123 #define AQUAERO_FAN_VOLTAGE_OFFSET 0x04
124 #define AQUAERO_FAN_CURRENT_OFFSET 0x06
125 #define AQUAERO_FAN_POWER_OFFSET 0x08
126 #define AQUAERO_FAN_SPEED_OFFSET 0x00
127 static u16 aquaero_sensor_fan_offsets[] = { 0x167, 0x173, 0x17f, 0x18B };
129 /* Control report offsets for the Aquaero fan controllers */
130 #define AQUAERO_TEMP_CTRL_OFFSET 0xdb
131 #define AQUAERO_FAN_CTRL_MIN_PWR_OFFSET 0x04
132 #define AQUAERO_FAN_CTRL_MAX_PWR_OFFSET 0x06
133 #define AQUAERO_FAN_CTRL_SRC_OFFSET 0x10
134 static u16 aquaero_ctrl_fan_offsets[] = { 0x20c, 0x220, 0x234, 0x248 };
136 /* Specs of the D5 Next pump */
137 #define D5NEXT_NUM_FANS 2
138 #define D5NEXT_NUM_SENSORS 1
139 #define D5NEXT_NUM_VIRTUAL_SENSORS 8
140 #define D5NEXT_CTRL_REPORT_SIZE 0x329
142 /* Sensor report offsets for the D5 Next pump */
143 #define D5NEXT_POWER_CYCLES 0x18
144 #define D5NEXT_COOLANT_TEMP 0x57
145 #define D5NEXT_PUMP_OFFSET 0x6c
146 #define D5NEXT_FAN_OFFSET 0x5f
147 #define D5NEXT_5V_VOLTAGE 0x39
148 #define D5NEXT_12V_VOLTAGE 0x37
149 #define D5NEXT_VIRTUAL_SENSORS_START 0x3f
150 static u16 d5next_sensor_fan_offsets[] = { D5NEXT_PUMP_OFFSET, D5NEXT_FAN_OFFSET };
152 /* Control report offsets for the D5 Next pump */
153 #define D5NEXT_TEMP_CTRL_OFFSET 0x2D /* Temperature sensor offsets location */
154 static u16 d5next_ctrl_fan_offsets[] = { 0x97, 0x42 }; /* Pump and fan speed (from 0-100%) */
156 /* Specs of the Aquastream Ultimate pump */
157 /* Pump does not follow the standard structure, so only consider the fan */
158 #define AQUASTREAMULT_NUM_FANS 1
159 #define AQUASTREAMULT_NUM_SENSORS 2
161 /* Sensor report offsets for the Aquastream Ultimate pump */
162 #define AQUASTREAMULT_SENSOR_START 0x2D
163 #define AQUASTREAMULT_PUMP_OFFSET 0x51
164 #define AQUASTREAMULT_PUMP_VOLTAGE 0x3D
165 #define AQUASTREAMULT_PUMP_CURRENT 0x53
166 #define AQUASTREAMULT_PUMP_POWER 0x55
167 #define AQUASTREAMULT_FAN_OFFSET 0x41
168 #define AQUASTREAMULT_PRESSURE_OFFSET 0x57
169 #define AQUASTREAMULT_FLOW_SENSOR_OFFSET 0x37
170 #define AQUASTREAMULT_FAN_VOLTAGE_OFFSET 0x02
171 #define AQUASTREAMULT_FAN_CURRENT_OFFSET 0x00
172 #define AQUASTREAMULT_FAN_POWER_OFFSET 0x04
173 #define AQUASTREAMULT_FAN_SPEED_OFFSET 0x06
174 static u16 aquastreamult_sensor_fan_offsets[] = { AQUASTREAMULT_FAN_OFFSET };
176 /* Spec and sensor report offset for the Farbwerk RGB controller */
177 #define FARBWERK_NUM_SENSORS 4
178 #define FARBWERK_SENSOR_START 0x2f
180 /* Specs of the Farbwerk 360 RGB controller */
181 #define FARBWERK360_NUM_SENSORS 4
182 #define FARBWERK360_NUM_VIRTUAL_SENSORS 16
183 #define FARBWERK360_CTRL_REPORT_SIZE 0x682
185 /* Sensor report offsets for the Farbwerk 360 */
186 #define FARBWERK360_SENSOR_START 0x32
187 #define FARBWERK360_VIRTUAL_SENSORS_START 0x3a
189 /* Control report offsets for the Farbwerk 360 */
190 #define FARBWERK360_TEMP_CTRL_OFFSET 0x8
192 /* Specs of the Octo fan controller */
193 #define OCTO_NUM_FANS 8
194 #define OCTO_NUM_SENSORS 4
195 #define OCTO_NUM_VIRTUAL_SENSORS 16
196 #define OCTO_CTRL_REPORT_SIZE 0x65F
198 /* Sensor report offsets for the Octo */
199 #define OCTO_POWER_CYCLES 0x18
200 #define OCTO_SENSOR_START 0x3D
201 #define OCTO_VIRTUAL_SENSORS_START 0x45
202 static u16 octo_sensor_fan_offsets[] = { 0x7D, 0x8A, 0x97, 0xA4, 0xB1, 0xBE, 0xCB, 0xD8 };
204 /* Control report offsets for the Octo */
205 #define OCTO_TEMP_CTRL_OFFSET 0xA
206 /* Fan speed offsets (0-100%) */
207 static u16 octo_ctrl_fan_offsets[] = { 0x5B, 0xB0, 0x105, 0x15A, 0x1AF, 0x204, 0x259, 0x2AE };
209 /* Specs of Quadro fan controller */
210 #define QUADRO_NUM_FANS 4
211 #define QUADRO_NUM_SENSORS 4
212 #define QUADRO_NUM_VIRTUAL_SENSORS 16
213 #define QUADRO_NUM_FLOW_SENSORS 1
214 #define QUADRO_CTRL_REPORT_SIZE 0x3c1
216 /* Sensor report offsets for the Quadro */
217 #define QUADRO_POWER_CYCLES 0x18
218 #define QUADRO_SENSOR_START 0x34
219 #define QUADRO_VIRTUAL_SENSORS_START 0x3c
220 #define QUADRO_FLOW_SENSOR_OFFSET 0x6e
221 static u16 quadro_sensor_fan_offsets[] = { 0x70, 0x7D, 0x8A, 0x97 };
223 /* Control report offsets for the Quadro */
224 #define QUADRO_TEMP_CTRL_OFFSET 0xA
225 #define QUADRO_FLOW_PULSES_CTRL_OFFSET 0x6
226 static u16 quadro_ctrl_fan_offsets[] = { 0x37, 0x8c, 0xe1, 0x136 }; /* Fan speed offsets (0-100%) */
228 /* Specs of High Flow Next flow sensor */
229 #define HIGHFLOWNEXT_NUM_SENSORS 2
230 #define HIGHFLOWNEXT_NUM_FLOW_SENSORS 1
232 /* Sensor report offsets for the High Flow Next */
233 #define HIGHFLOWNEXT_SENSOR_START 85
234 #define HIGHFLOWNEXT_FLOW 81
235 #define HIGHFLOWNEXT_WATER_QUALITY 89
236 #define HIGHFLOWNEXT_POWER 91
237 #define HIGHFLOWNEXT_CONDUCTIVITY 95
238 #define HIGHFLOWNEXT_5V_VOLTAGE 97
239 #define HIGHFLOWNEXT_5V_VOLTAGE_USB 99
241 /* Specs of the Leakshield */
242 #define LEAKSHIELD_NUM_SENSORS 2
244 /* Sensor report offsets for Leakshield */
245 #define LEAKSHIELD_PRESSURE_ADJUSTED 285
246 #define LEAKSHIELD_TEMPERATURE_1 265
247 #define LEAKSHIELD_TEMPERATURE_2 287
248 #define LEAKSHIELD_PRESSURE_MIN 291
249 #define LEAKSHIELD_PRESSURE_TARGET 293
250 #define LEAKSHIELD_PRESSURE_MAX 295
251 #define LEAKSHIELD_PUMP_RPM_IN 101
252 #define LEAKSHIELD_FLOW_IN 111
253 #define LEAKSHIELD_RESERVOIR_VOLUME 313
254 #define LEAKSHIELD_RESERVOIR_FILLED 311
256 /* Specs of the Aquastream XT pump */
257 #define AQUASTREAMXT_SERIAL_START 0x3a
258 #define AQUASTREAMXT_FIRMWARE_VERSION 0x32
259 #define AQUASTREAMXT_NUM_FANS 2
260 #define AQUASTREAMXT_NUM_SENSORS 3
261 #define AQUASTREAMXT_FAN_STOPPED 0x4
262 #define AQUASTREAMXT_PUMP_CONVERSION_CONST 45000000
263 #define AQUASTREAMXT_FAN_CONVERSION_CONST 5646000
264 #define AQUASTREAMXT_SENSOR_REPORT_SIZE 0x42
266 /* Sensor report offsets and info for Aquastream XT */
267 #define AQUASTREAMXT_SENSOR_START 0xd
268 #define AQUASTREAMXT_FAN_VOLTAGE_OFFSET 0x7
269 #define AQUASTREAMXT_FAN_STATUS_OFFSET 0x1d
270 #define AQUASTREAMXT_PUMP_VOLTAGE_OFFSET 0x9
271 #define AQUASTREAMXT_PUMP_CURR_OFFSET 0xb
272 static u16 aquastreamxt_sensor_fan_offsets[] = { 0x13, 0x1b };
274 /* Specs of the Poweradjust 3 */
275 #define POWERADJUST3_NUM_SENSORS 1
276 #define POWERADJUST3_SENSOR_REPORT_SIZE 0x32
278 /* Sensor report offsets for the Poweradjust 3 */
279 #define POWERADJUST3_SENSOR_START 0x03
281 /* Labels for D5 Next */
282 static const char *const label_d5next_temp[] = {
286 static const char *const label_d5next_speeds[] = {
291 static const char *const label_d5next_power[] = {
296 static const char *const label_d5next_voltages[] = {
303 static const char *const label_d5next_current[] = {
308 /* Labels for Aquaero, Farbwerk, Farbwerk 360 and Octo and Quadro temperature sensors */
309 static const char *const label_temp_sensors[] = {
320 static const char *const label_virtual_temp_sensors[] = {
339 static const char *const label_aquaero_calc_temp_sensors[] = {
340 "Calc. virtual sensor 1",
341 "Calc. virtual sensor 2",
342 "Calc. virtual sensor 3",
343 "Calc. virtual sensor 4"
346 /* Labels for Octo and Quadro (except speed) */
347 static const char *const label_fan_speed[] = {
358 static const char *const label_fan_power[] = {
369 static const char *const label_fan_voltage[] = {
380 static const char *const label_fan_current[] = {
391 /* Labels for Quadro fan speeds */
392 static const char *const label_quadro_speeds[] = {
400 /* Labels for Aquaero fan speeds */
401 static const char *const label_aquaero_speeds[] = {
406 "Flow sensor 1 [dL/h]",
407 "Flow sensor 2 [dL/h]"
410 /* Labels for High Flow Next */
411 static const char *const label_highflownext_temp_sensors[] = {
416 static const char *const label_highflownext_fan_speed[] = {
419 "Conductivity [nS/cm]",
422 static const char *const label_highflownext_power[] = {
426 static const char *const label_highflownext_voltage[] = {
431 /* Labels for Leakshield */
432 static const char *const label_leakshield_temp_sensors[] = {
437 static const char *const label_leakshield_fan_speed[] = {
439 "User-Provided Pump Speed",
440 "User-Provided Flow [dL/h]",
441 "Reservoir Volume [ml]",
442 "Reservoir Filled [ml]",
445 /* Labels for Aquastream XT */
446 static const char *const label_aquastreamxt_temp_sensors[] = {
452 /* Labels for Aquastream Ultimate */
453 static const char *const label_aquastreamult_temp[] = {
458 static const char *const label_aquastreamult_speeds[] = {
465 static const char *const label_aquastreamult_power[] = {
470 static const char *const label_aquastreamult_voltages[] = {
475 static const char *const label_aquastreamult_current[] = {
480 /* Labels for Poweradjust 3 */
481 static const char *const label_poweradjust3_temp_sensors[] = {
485 struct aqc_fan_structure_offsets {
492 /* Fan structure offsets for Aquaero */
493 static struct aqc_fan_structure_offsets aqc_aquaero_fan_structure = {
494 .voltage = AQUAERO_FAN_VOLTAGE_OFFSET,
495 .curr = AQUAERO_FAN_CURRENT_OFFSET,
496 .power = AQUAERO_FAN_POWER_OFFSET,
497 .speed = AQUAERO_FAN_SPEED_OFFSET
500 /* Fan structure offsets for Aquastream Ultimate */
501 static struct aqc_fan_structure_offsets aqc_aquastreamult_fan_structure = {
502 .voltage = AQUASTREAMULT_FAN_VOLTAGE_OFFSET,
503 .curr = AQUASTREAMULT_FAN_CURRENT_OFFSET,
504 .power = AQUASTREAMULT_FAN_POWER_OFFSET,
505 .speed = AQUASTREAMULT_FAN_SPEED_OFFSET
508 /* Fan structure offsets for all devices except those above */
509 static struct aqc_fan_structure_offsets aqc_general_fan_structure = {
510 .voltage = AQC_FAN_VOLTAGE_OFFSET,
511 .curr = AQC_FAN_CURRENT_OFFSET,
512 .power = AQC_FAN_POWER_OFFSET,
513 .speed = AQC_FAN_SPEED_OFFSET
517 struct hid_device *hdev;
518 struct device *hwmon_dev;
519 struct dentry *debugfs;
520 struct mutex mutex; /* Used for locking access when reading and writing PWM values */
524 int status_report_id; /* Used for legacy devices, report is stored in buffer */
526 int secondary_ctrl_report_id;
527 int secondary_ctrl_report_size;
528 u8 *secondary_ctrl_report;
537 u16 *fan_sensor_offsets;
538 u16 *fan_ctrl_offsets;
539 int num_temp_sensors;
540 int temp_sensor_start_offset;
541 int num_virtual_temp_sensors;
542 int virtual_temp_sensor_start_offset;
543 int num_calc_virt_temp_sensors;
544 int calc_virt_temp_sensor_start_offset;
545 u16 temp_ctrl_offset;
546 u16 power_cycle_count_offset;
547 int num_flow_sensors;
548 u8 flow_sensors_start_offset;
549 u8 flow_pulses_ctrl_offset;
550 struct aqc_fan_structure_offsets *fan_structure;
552 /* General info, same across all devices */
553 u8 serial_number_start_offset;
554 u32 serial_number[2];
555 u8 firmware_version_offset;
556 u16 firmware_version;
558 /* How many times the device was powered on, if available */
562 s32 temp_input[20]; /* Max 4 physical and 16 virtual or 8 physical and 12 virtual */
564 u32 speed_input_min[1];
565 u32 speed_input_target[1];
566 u32 speed_input_max[1];
568 u16 voltage_input[8];
569 u16 current_input[8];
572 const char *const *temp_label;
573 const char *const *virtual_temp_label;
574 const char *const *calc_virt_temp_label; /* For Aquaero */
575 const char *const *speed_label;
576 const char *const *power_label;
577 const char *const *voltage_label;
578 const char *const *current_label;
580 unsigned long updated;
583 /* Converts from centi-percent */
584 static int aqc_percent_to_pwm(u16 val)
586 return DIV_ROUND_CLOSEST(val * 255, 100 * 100);
589 /* Converts to centi-percent */
590 static int aqc_pwm_to_percent(long val)
592 if (val < 0 || val > 255)
595 return DIV_ROUND_CLOSEST(val * 100 * 100, 255);
598 /* Converts raw value for Aquastream XT pump speed to RPM */
599 static int aqc_aquastreamxt_convert_pump_rpm(u16 val)
602 return DIV_ROUND_CLOSEST(AQUASTREAMXT_PUMP_CONVERSION_CONST, val);
606 /* Converts raw value for Aquastream XT fan speed to RPM */
607 static int aqc_aquastreamxt_convert_fan_rpm(u16 val)
610 return DIV_ROUND_CLOSEST(AQUASTREAMXT_FAN_CONVERSION_CONST, val);
614 /* Expects the mutex to be locked */
615 static int aqc_get_ctrl_data(struct aqc_data *priv)
619 memset(priv->buffer, 0x00, priv->buffer_size);
620 ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size,
621 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
628 /* Expects the mutex to be locked */
629 static int aqc_send_ctrl_data(struct aqc_data *priv)
634 /* Checksum is not needed for Aquaero */
635 if (priv->kind != aquaero) {
636 /* Init and xorout value for CRC-16/USB is 0xffff */
637 checksum = crc16(0xffff, priv->buffer + priv->checksum_start,
638 priv->checksum_length);
641 /* Place the new checksum at the end of the report */
642 put_unaligned_be16(checksum, priv->buffer + priv->checksum_offset);
645 /* Send the patched up report back to the device */
646 ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size,
647 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
651 /* The official software sends this report after every change, so do it here as well */
652 ret = hid_hw_raw_request(priv->hdev, priv->secondary_ctrl_report_id,
653 priv->secondary_ctrl_report, priv->secondary_ctrl_report_size,
654 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
658 /* Refreshes the control buffer and stores value at offset in val */
659 static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val, int type)
663 mutex_lock(&priv->mutex);
665 ret = aqc_get_ctrl_data(priv);
667 goto unlock_and_return;
671 *val = (s16)get_unaligned_be16(priv->buffer + offset);
674 *val = priv->buffer[offset];
681 mutex_unlock(&priv->mutex);
685 static int aqc_set_ctrl_vals(struct aqc_data *priv, int *offsets, long *vals, int *types, int len)
689 mutex_lock(&priv->mutex);
691 ret = aqc_get_ctrl_data(priv);
693 goto unlock_and_return;
695 for (i = 0; i < len; i++) {
698 put_unaligned_be16((s16)vals[i], priv->buffer + offsets[i]);
701 priv->buffer[offsets[i]] = (u8)vals[i];
709 goto unlock_and_return;
711 ret = aqc_send_ctrl_data(priv);
714 mutex_unlock(&priv->mutex);
718 static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int type)
720 return aqc_set_ctrl_vals(priv, &offset, &val, &type, 1);
723 static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel)
725 const struct aqc_data *priv = data;
729 if (channel < priv->num_temp_sensors) {
731 case hwmon_temp_label:
732 case hwmon_temp_input:
734 case hwmon_temp_offset:
735 if (priv->temp_ctrl_offset != 0)
744 priv->num_temp_sensors + priv->num_virtual_temp_sensors +
745 priv->num_calc_virt_temp_sensors)
747 case hwmon_temp_label:
748 case hwmon_temp_input:
755 if (priv->fan_ctrl_offsets && channel < priv->num_fans) {
757 case hwmon_pwm_input:
766 case hwmon_fan_input:
767 case hwmon_fan_label:
768 switch (priv->kind) {
771 * Special case to support pump RPM, fan RPM,
772 * pressure and flow sensor
778 /* Special case to support flow sensor, water quality
785 /* Special case for Leakshield sensors */
791 /* Special case to support flow sensors */
792 if (channel < priv->num_fans + priv->num_flow_sensors)
796 if (channel < priv->num_fans)
801 case hwmon_fan_pulses:
802 /* Special case for Quadro flow sensor */
803 if (priv->kind == quadro && channel == priv->num_fans)
808 case hwmon_fan_target:
809 /* Special case for Leakshield pressure sensor */
810 if (priv->kind == leakshield && channel == 0)
818 switch (priv->kind) {
820 /* Special case to support pump and fan power */
825 /* Special case to support one power sensor */
832 if (channel < priv->num_fans)
838 switch (priv->kind) {
840 /* Special case to support pump and fan current */
845 /* Special case to support pump current */
850 if (channel < priv->num_fans)
856 switch (priv->kind) {
858 /* Special case to support +5V and +12V voltage sensors */
859 if (channel < priv->num_fans + 2)
864 /* Special case to support two voltage sensors */
869 if (channel < priv->num_fans)
881 /* Read device sensors by manually requesting the sensor report (legacy way) */
882 static int aqc_legacy_read(struct aqc_data *priv)
884 int ret, i, sensor_value;
886 mutex_lock(&priv->mutex);
888 memset(priv->buffer, 0x00, priv->buffer_size);
889 ret = hid_hw_raw_request(priv->hdev, priv->status_report_id, priv->buffer,
890 priv->buffer_size, HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
892 goto unlock_and_return;
894 /* Temperature sensor readings */
895 for (i = 0; i < priv->num_temp_sensors; i++) {
896 sensor_value = get_unaligned_le16(priv->buffer + priv->temp_sensor_start_offset +
897 i * AQC_SENSOR_SIZE);
898 priv->temp_input[i] = sensor_value * 10;
901 /* Special-case sensor readings */
902 switch (priv->kind) {
904 /* Info provided with every report */
905 priv->serial_number[0] = get_unaligned_le16(priv->buffer +
906 priv->serial_number_start_offset);
907 priv->firmware_version =
908 get_unaligned_le16(priv->buffer + priv->firmware_version_offset);
910 /* Read pump speed in RPM */
911 sensor_value = get_unaligned_le16(priv->buffer + priv->fan_sensor_offsets[0]);
912 priv->speed_input[0] = aqc_aquastreamxt_convert_pump_rpm(sensor_value);
914 /* Read fan speed in RPM, if available */
915 sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_FAN_STATUS_OFFSET);
916 if (sensor_value == AQUASTREAMXT_FAN_STOPPED) {
917 priv->speed_input[1] = 0;
920 get_unaligned_le16(priv->buffer + priv->fan_sensor_offsets[1]);
921 priv->speed_input[1] = aqc_aquastreamxt_convert_fan_rpm(sensor_value);
924 /* Calculation derived from linear regression */
925 sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_PUMP_CURR_OFFSET);
926 priv->current_input[0] = DIV_ROUND_CLOSEST(sensor_value * 176, 100) - 52;
928 sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_PUMP_VOLTAGE_OFFSET);
929 priv->voltage_input[0] = DIV_ROUND_CLOSEST(sensor_value * 1000, 61);
931 sensor_value = get_unaligned_le16(priv->buffer + AQUASTREAMXT_FAN_VOLTAGE_OFFSET);
932 priv->voltage_input[1] = DIV_ROUND_CLOSEST(sensor_value * 1000, 63);
938 priv->updated = jiffies;
941 mutex_unlock(&priv->mutex);
945 static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
946 int channel, long *val)
949 struct aqc_data *priv = dev_get_drvdata(dev);
951 if (time_after(jiffies, priv->updated + STATUS_UPDATE_INTERVAL)) {
952 if (priv->status_report_id != 0) {
953 /* Legacy devices require manual reads */
954 ret = aqc_legacy_read(priv);
965 case hwmon_temp_input:
966 if (priv->temp_input[channel] == -ENODATA)
969 *val = priv->temp_input[channel];
971 case hwmon_temp_offset:
973 aqc_get_ctrl_val(priv, priv->temp_ctrl_offset +
974 channel * AQC_SENSOR_SIZE, val, AQC_BE16);
986 case hwmon_fan_input:
987 if (priv->speed_input[channel] == -ENODATA)
990 *val = priv->speed_input[channel];
993 *val = priv->speed_input_min[channel];
996 *val = priv->speed_input_max[channel];
998 case hwmon_fan_target:
999 *val = priv->speed_input_target[channel];
1001 case hwmon_fan_pulses:
1002 ret = aqc_get_ctrl_val(priv, priv->flow_pulses_ctrl_offset,
1012 *val = priv->power_input[channel];
1015 switch (priv->kind) {
1017 ret = aqc_get_ctrl_val(priv,
1018 AQUAERO_CTRL_PRESET_START + channel * AQUAERO_CTRL_PRESET_SIZE,
1022 *val = aqc_percent_to_pwm(*val);
1025 ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel],
1030 *val = aqc_percent_to_pwm(ret);
1035 *val = priv->voltage_input[channel];
1038 *val = priv->current_input[channel];
1047 static int aqc_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
1048 int channel, const char **str)
1050 struct aqc_data *priv = dev_get_drvdata(dev);
1052 /* Number of sensors that are not calculated */
1053 int num_non_calc_sensors = priv->num_temp_sensors + priv->num_virtual_temp_sensors;
1057 if (channel < priv->num_temp_sensors) {
1058 *str = priv->temp_label[channel];
1060 if (priv->kind == aquaero && channel >= num_non_calc_sensors)
1062 priv->calc_virt_temp_label[channel - num_non_calc_sensors];
1064 *str = priv->virtual_temp_label[channel - priv->num_temp_sensors];
1068 *str = priv->speed_label[channel];
1071 *str = priv->power_label[channel];
1074 *str = priv->voltage_label[channel];
1077 *str = priv->current_label[channel];
1086 static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
1090 /* Arrays for setting multiple values at once in the control report */
1091 int ctrl_values_offsets[4];
1092 long ctrl_values[4];
1093 int ctrl_values_types[4];
1094 struct aqc_data *priv = dev_get_drvdata(dev);
1099 case hwmon_temp_offset:
1100 /* Limit temp offset to +/- 15K as in the official software */
1101 val = clamp_val(val, -15000, 15000) / 10;
1103 aqc_set_ctrl_val(priv, priv->temp_ctrl_offset +
1104 channel * AQC_SENSOR_SIZE, val, AQC_BE16);
1114 case hwmon_fan_pulses:
1115 val = clamp_val(val, 10, 1000);
1116 ret = aqc_set_ctrl_val(priv, priv->flow_pulses_ctrl_offset,
1127 case hwmon_pwm_input:
1128 pwm_value = aqc_pwm_to_percent(val);
1132 switch (priv->kind) {
1134 /* Write pwm value to preset corresponding to the channel */
1135 ctrl_values_offsets[0] = AQUAERO_CTRL_PRESET_START +
1136 channel * AQUAERO_CTRL_PRESET_SIZE;
1137 ctrl_values[0] = pwm_value;
1138 ctrl_values_types[0] = AQC_BE16;
1140 /* Write preset number in fan control source */
1141 ctrl_values_offsets[1] = priv->fan_ctrl_offsets[channel] +
1142 AQUAERO_FAN_CTRL_SRC_OFFSET;
1143 ctrl_values[1] = AQUAERO_CTRL_PRESET_ID + channel;
1144 ctrl_values_types[1] = AQC_BE16;
1146 /* Set minimum power to 0 to allow the fan to turn off */
1147 ctrl_values_offsets[2] = priv->fan_ctrl_offsets[channel] +
1148 AQUAERO_FAN_CTRL_MIN_PWR_OFFSET;
1150 ctrl_values_types[2] = AQC_BE16;
1152 /* Set maximum power to 255 to allow the fan to reach max speed */
1153 ctrl_values_offsets[3] = priv->fan_ctrl_offsets[channel] +
1154 AQUAERO_FAN_CTRL_MAX_PWR_OFFSET;
1155 ctrl_values[3] = aqc_pwm_to_percent(255);
1156 ctrl_values_types[3] = AQC_BE16;
1158 ret = aqc_set_ctrl_vals(priv, ctrl_values_offsets, ctrl_values,
1159 ctrl_values_types, 4);
1164 ret = aqc_set_ctrl_val(priv, priv->fan_ctrl_offsets[channel],
1165 pwm_value, AQC_BE16);
1182 static const struct hwmon_ops aqc_hwmon_ops = {
1183 .is_visible = aqc_is_visible,
1185 .read_string = aqc_read_string,
1189 static const struct hwmon_channel_info * const aqc_info[] = {
1190 HWMON_CHANNEL_INFO(temp,
1191 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1192 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1193 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1194 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1195 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1196 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1197 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1198 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET,
1199 HWMON_T_INPUT | HWMON_T_LABEL,
1200 HWMON_T_INPUT | HWMON_T_LABEL,
1201 HWMON_T_INPUT | HWMON_T_LABEL,
1202 HWMON_T_INPUT | HWMON_T_LABEL,
1203 HWMON_T_INPUT | HWMON_T_LABEL,
1204 HWMON_T_INPUT | HWMON_T_LABEL,
1205 HWMON_T_INPUT | HWMON_T_LABEL,
1206 HWMON_T_INPUT | HWMON_T_LABEL,
1207 HWMON_T_INPUT | HWMON_T_LABEL,
1208 HWMON_T_INPUT | HWMON_T_LABEL,
1209 HWMON_T_INPUT | HWMON_T_LABEL,
1210 HWMON_T_INPUT | HWMON_T_LABEL),
1211 HWMON_CHANNEL_INFO(fan,
1212 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
1214 HWMON_F_INPUT | HWMON_F_LABEL,
1215 HWMON_F_INPUT | HWMON_F_LABEL,
1216 HWMON_F_INPUT | HWMON_F_LABEL,
1217 HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_PULSES,
1218 HWMON_F_INPUT | HWMON_F_LABEL,
1219 HWMON_F_INPUT | HWMON_F_LABEL,
1220 HWMON_F_INPUT | HWMON_F_LABEL),
1221 HWMON_CHANNEL_INFO(power,
1222 HWMON_P_INPUT | HWMON_P_LABEL,
1223 HWMON_P_INPUT | HWMON_P_LABEL,
1224 HWMON_P_INPUT | HWMON_P_LABEL,
1225 HWMON_P_INPUT | HWMON_P_LABEL,
1226 HWMON_P_INPUT | HWMON_P_LABEL,
1227 HWMON_P_INPUT | HWMON_P_LABEL,
1228 HWMON_P_INPUT | HWMON_P_LABEL,
1229 HWMON_P_INPUT | HWMON_P_LABEL),
1230 HWMON_CHANNEL_INFO(pwm,
1239 HWMON_CHANNEL_INFO(in,
1240 HWMON_I_INPUT | HWMON_I_LABEL,
1241 HWMON_I_INPUT | HWMON_I_LABEL,
1242 HWMON_I_INPUT | HWMON_I_LABEL,
1243 HWMON_I_INPUT | HWMON_I_LABEL,
1244 HWMON_I_INPUT | HWMON_I_LABEL,
1245 HWMON_I_INPUT | HWMON_I_LABEL,
1246 HWMON_I_INPUT | HWMON_I_LABEL,
1247 HWMON_I_INPUT | HWMON_I_LABEL),
1248 HWMON_CHANNEL_INFO(curr,
1249 HWMON_C_INPUT | HWMON_C_LABEL,
1250 HWMON_C_INPUT | HWMON_C_LABEL,
1251 HWMON_C_INPUT | HWMON_C_LABEL,
1252 HWMON_C_INPUT | HWMON_C_LABEL,
1253 HWMON_C_INPUT | HWMON_C_LABEL,
1254 HWMON_C_INPUT | HWMON_C_LABEL,
1255 HWMON_C_INPUT | HWMON_C_LABEL,
1256 HWMON_C_INPUT | HWMON_C_LABEL),
1260 static const struct hwmon_chip_info aqc_chip_info = {
1261 .ops = &aqc_hwmon_ops,
1265 static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size)
1267 int i, j, sensor_value;
1268 struct aqc_data *priv;
1270 if (report->id != STATUS_REPORT_ID)
1273 priv = hid_get_drvdata(hdev);
1275 /* Info provided with every report */
1276 priv->serial_number[0] = get_unaligned_be16(data + priv->serial_number_start_offset);
1277 priv->serial_number[1] = get_unaligned_be16(data + priv->serial_number_start_offset +
1278 SERIAL_PART_OFFSET);
1279 priv->firmware_version = get_unaligned_be16(data + priv->firmware_version_offset);
1281 /* Physical temperature sensor readings */
1282 for (i = 0; i < priv->num_temp_sensors; i++) {
1283 sensor_value = get_unaligned_be16(data +
1284 priv->temp_sensor_start_offset +
1285 i * AQC_SENSOR_SIZE);
1286 if (sensor_value == AQC_SENSOR_NA)
1287 priv->temp_input[i] = -ENODATA;
1289 priv->temp_input[i] = sensor_value * 10;
1292 /* Virtual temperature sensor readings */
1293 for (j = 0; j < priv->num_virtual_temp_sensors; j++) {
1294 sensor_value = get_unaligned_be16(data +
1295 priv->virtual_temp_sensor_start_offset +
1296 j * AQC_SENSOR_SIZE);
1297 if (sensor_value == AQC_SENSOR_NA)
1298 priv->temp_input[i] = -ENODATA;
1300 priv->temp_input[i] = sensor_value * 10;
1304 /* Fan speed and related readings */
1305 for (i = 0; i < priv->num_fans; i++) {
1306 priv->speed_input[i] =
1307 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
1308 priv->fan_structure->speed);
1309 priv->power_input[i] =
1310 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
1311 priv->fan_structure->power) * 10000;
1312 priv->voltage_input[i] =
1313 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
1314 priv->fan_structure->voltage) * 10;
1315 priv->current_input[i] =
1316 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
1317 priv->fan_structure->curr);
1320 /* Flow sensor readings */
1321 for (j = 0; j < priv->num_flow_sensors; j++) {
1322 priv->speed_input[i] = get_unaligned_be16(data + priv->flow_sensors_start_offset +
1323 j * AQC_SENSOR_SIZE);
1327 if (priv->power_cycle_count_offset != 0)
1328 priv->power_cycles = get_unaligned_be32(data + priv->power_cycle_count_offset);
1330 /* Special-case sensor readings */
1331 switch (priv->kind) {
1333 /* Read calculated virtual temp sensors */
1334 i = priv->num_temp_sensors + priv->num_virtual_temp_sensors;
1335 for (j = 0; j < priv->num_calc_virt_temp_sensors; j++) {
1336 sensor_value = get_unaligned_be16(data +
1337 priv->calc_virt_temp_sensor_start_offset +
1338 j * AQC_SENSOR_SIZE);
1339 if (sensor_value == AQC_SENSOR_NA)
1340 priv->temp_input[i] = -ENODATA;
1342 priv->temp_input[i] = sensor_value * 10;
1347 priv->speed_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_OFFSET);
1348 priv->speed_input[2] = get_unaligned_be16(data + AQUASTREAMULT_PRESSURE_OFFSET);
1349 priv->speed_input[3] = get_unaligned_be16(data + AQUASTREAMULT_FLOW_SENSOR_OFFSET);
1351 priv->power_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_POWER) * 10000;
1353 priv->voltage_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_VOLTAGE) * 10;
1355 priv->current_input[1] = get_unaligned_be16(data + AQUASTREAMULT_PUMP_CURRENT);
1358 priv->voltage_input[2] = get_unaligned_be16(data + D5NEXT_5V_VOLTAGE) * 10;
1359 priv->voltage_input[3] = get_unaligned_be16(data + D5NEXT_12V_VOLTAGE) * 10;
1362 /* If external temp sensor is not connected, its power reading is also N/A */
1363 if (priv->temp_input[1] == -ENODATA)
1364 priv->power_input[0] = -ENODATA;
1366 priv->power_input[0] =
1367 get_unaligned_be16(data + HIGHFLOWNEXT_POWER) * 1000000;
1369 priv->voltage_input[0] = get_unaligned_be16(data + HIGHFLOWNEXT_5V_VOLTAGE) * 10;
1370 priv->voltage_input[1] =
1371 get_unaligned_be16(data + HIGHFLOWNEXT_5V_VOLTAGE_USB) * 10;
1373 priv->speed_input[1] = get_unaligned_be16(data + HIGHFLOWNEXT_WATER_QUALITY);
1374 priv->speed_input[2] = get_unaligned_be16(data + HIGHFLOWNEXT_CONDUCTIVITY);
1377 priv->speed_input[0] =
1378 ((s16)get_unaligned_be16(data + LEAKSHIELD_PRESSURE_ADJUSTED)) * 100;
1379 priv->speed_input_min[0] = get_unaligned_be16(data + LEAKSHIELD_PRESSURE_MIN) * 100;
1380 priv->speed_input_target[0] =
1381 get_unaligned_be16(data + LEAKSHIELD_PRESSURE_TARGET) * 100;
1382 priv->speed_input_max[0] = get_unaligned_be16(data + LEAKSHIELD_PRESSURE_MAX) * 100;
1384 priv->speed_input[1] = get_unaligned_be16(data + LEAKSHIELD_PUMP_RPM_IN);
1385 if (priv->speed_input[1] == AQC_SENSOR_NA)
1386 priv->speed_input[1] = -ENODATA;
1388 priv->speed_input[2] = get_unaligned_be16(data + LEAKSHIELD_FLOW_IN);
1389 if (priv->speed_input[2] == AQC_SENSOR_NA)
1390 priv->speed_input[2] = -ENODATA;
1392 priv->speed_input[3] = get_unaligned_be16(data + LEAKSHIELD_RESERVOIR_VOLUME);
1393 priv->speed_input[4] = get_unaligned_be16(data + LEAKSHIELD_RESERVOIR_FILLED);
1395 /* Second temp sensor is not positioned after the first one, read it here */
1396 priv->temp_input[1] = get_unaligned_be16(data + LEAKSHIELD_TEMPERATURE_2) * 10;
1402 priv->updated = jiffies;
1407 #ifdef CONFIG_DEBUG_FS
1409 static int serial_number_show(struct seq_file *seqf, void *unused)
1411 struct aqc_data *priv = seqf->private;
1413 seq_printf(seqf, "%05u-%05u\n", priv->serial_number[0], priv->serial_number[1]);
1417 DEFINE_SHOW_ATTRIBUTE(serial_number);
1419 static int firmware_version_show(struct seq_file *seqf, void *unused)
1421 struct aqc_data *priv = seqf->private;
1423 seq_printf(seqf, "%u\n", priv->firmware_version);
1427 DEFINE_SHOW_ATTRIBUTE(firmware_version);
1429 static int power_cycles_show(struct seq_file *seqf, void *unused)
1431 struct aqc_data *priv = seqf->private;
1433 seq_printf(seqf, "%u\n", priv->power_cycles);
1437 DEFINE_SHOW_ATTRIBUTE(power_cycles);
1439 static void aqc_debugfs_init(struct aqc_data *priv)
1443 scnprintf(name, sizeof(name), "%s_%s-%s", "aquacomputer", priv->name,
1444 dev_name(&priv->hdev->dev));
1446 priv->debugfs = debugfs_create_dir(name, NULL);
1448 if (priv->serial_number_start_offset != 0)
1449 debugfs_create_file("serial_number", 0444, priv->debugfs, priv,
1450 &serial_number_fops);
1451 if (priv->firmware_version_offset != 0)
1452 debugfs_create_file("firmware_version", 0444, priv->debugfs, priv,
1453 &firmware_version_fops);
1454 if (priv->power_cycle_count_offset != 0)
1455 debugfs_create_file("power_cycles", 0444, priv->debugfs, priv, &power_cycles_fops);
1460 static void aqc_debugfs_init(struct aqc_data *priv)
1466 static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
1468 struct aqc_data *priv;
1471 priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL);
1476 hid_set_drvdata(hdev, priv);
1478 priv->updated = jiffies - STATUS_UPDATE_INTERVAL;
1480 ret = hid_parse(hdev);
1484 ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
1488 ret = hid_hw_open(hdev);
1492 switch (hdev->product) {
1493 case USB_PRODUCT_ID_AQUAERO:
1495 * Aquaero presents itself as three HID devices under the same product ID:
1496 * "aquaero keyboard/mouse", "aquaero System Control" and "aquaero Device",
1497 * which is the one we want to communicate with. Unlike most other Aquacomputer
1498 * devices, Aquaero does not return meaningful data when explicitly requested
1499 * using GET_FEATURE_REPORT.
1501 * The difference between "aquaero Device" and the other two is in the collections
1502 * they present. The two other devices have the type of the second element in
1503 * their respective collections set to 1, while the real device has it set to 0.
1505 if (hdev->collection[1].type != 0) {
1507 goto fail_and_close;
1510 priv->kind = aquaero;
1512 priv->num_fans = AQUAERO_NUM_FANS;
1513 priv->fan_sensor_offsets = aquaero_sensor_fan_offsets;
1514 priv->fan_ctrl_offsets = aquaero_ctrl_fan_offsets;
1516 priv->num_temp_sensors = AQUAERO_NUM_SENSORS;
1517 priv->temp_sensor_start_offset = AQUAERO_SENSOR_START;
1518 priv->num_virtual_temp_sensors = AQUAERO_NUM_VIRTUAL_SENSORS;
1519 priv->virtual_temp_sensor_start_offset = AQUAERO_VIRTUAL_SENSOR_START;
1520 priv->num_calc_virt_temp_sensors = AQUAERO_NUM_CALC_VIRTUAL_SENSORS;
1521 priv->calc_virt_temp_sensor_start_offset = AQUAERO_CALC_VIRTUAL_SENSOR_START;
1522 priv->num_flow_sensors = AQUAERO_NUM_FLOW_SENSORS;
1523 priv->flow_sensors_start_offset = AQUAERO_FLOW_SENSORS_START;
1525 priv->buffer_size = AQUAERO_CTRL_REPORT_SIZE;
1526 priv->temp_ctrl_offset = AQUAERO_TEMP_CTRL_OFFSET;
1528 priv->temp_label = label_temp_sensors;
1529 priv->virtual_temp_label = label_virtual_temp_sensors;
1530 priv->calc_virt_temp_label = label_aquaero_calc_temp_sensors;
1531 priv->speed_label = label_aquaero_speeds;
1532 priv->power_label = label_fan_power;
1533 priv->voltage_label = label_fan_voltage;
1534 priv->current_label = label_fan_current;
1536 case USB_PRODUCT_ID_D5NEXT:
1537 priv->kind = d5next;
1539 priv->num_fans = D5NEXT_NUM_FANS;
1540 priv->fan_sensor_offsets = d5next_sensor_fan_offsets;
1541 priv->fan_ctrl_offsets = d5next_ctrl_fan_offsets;
1543 priv->num_temp_sensors = D5NEXT_NUM_SENSORS;
1544 priv->temp_sensor_start_offset = D5NEXT_COOLANT_TEMP;
1545 priv->num_virtual_temp_sensors = D5NEXT_NUM_VIRTUAL_SENSORS;
1546 priv->virtual_temp_sensor_start_offset = D5NEXT_VIRTUAL_SENSORS_START;
1547 priv->temp_ctrl_offset = D5NEXT_TEMP_CTRL_OFFSET;
1549 priv->buffer_size = D5NEXT_CTRL_REPORT_SIZE;
1551 priv->power_cycle_count_offset = D5NEXT_POWER_CYCLES;
1553 priv->temp_label = label_d5next_temp;
1554 priv->virtual_temp_label = label_virtual_temp_sensors;
1555 priv->speed_label = label_d5next_speeds;
1556 priv->power_label = label_d5next_power;
1557 priv->voltage_label = label_d5next_voltages;
1558 priv->current_label = label_d5next_current;
1560 case USB_PRODUCT_ID_FARBWERK:
1561 priv->kind = farbwerk;
1565 priv->num_temp_sensors = FARBWERK_NUM_SENSORS;
1566 priv->temp_sensor_start_offset = FARBWERK_SENSOR_START;
1568 priv->temp_label = label_temp_sensors;
1570 case USB_PRODUCT_ID_FARBWERK360:
1571 priv->kind = farbwerk360;
1575 priv->num_temp_sensors = FARBWERK360_NUM_SENSORS;
1576 priv->temp_sensor_start_offset = FARBWERK360_SENSOR_START;
1577 priv->num_virtual_temp_sensors = FARBWERK360_NUM_VIRTUAL_SENSORS;
1578 priv->virtual_temp_sensor_start_offset = FARBWERK360_VIRTUAL_SENSORS_START;
1579 priv->temp_ctrl_offset = FARBWERK360_TEMP_CTRL_OFFSET;
1581 priv->buffer_size = FARBWERK360_CTRL_REPORT_SIZE;
1583 priv->temp_label = label_temp_sensors;
1584 priv->virtual_temp_label = label_virtual_temp_sensors;
1586 case USB_PRODUCT_ID_OCTO:
1589 priv->num_fans = OCTO_NUM_FANS;
1590 priv->fan_sensor_offsets = octo_sensor_fan_offsets;
1591 priv->fan_ctrl_offsets = octo_ctrl_fan_offsets;
1593 priv->num_temp_sensors = OCTO_NUM_SENSORS;
1594 priv->temp_sensor_start_offset = OCTO_SENSOR_START;
1595 priv->num_virtual_temp_sensors = OCTO_NUM_VIRTUAL_SENSORS;
1596 priv->virtual_temp_sensor_start_offset = OCTO_VIRTUAL_SENSORS_START;
1597 priv->temp_ctrl_offset = OCTO_TEMP_CTRL_OFFSET;
1599 priv->buffer_size = OCTO_CTRL_REPORT_SIZE;
1601 priv->power_cycle_count_offset = OCTO_POWER_CYCLES;
1603 priv->temp_label = label_temp_sensors;
1604 priv->virtual_temp_label = label_virtual_temp_sensors;
1605 priv->speed_label = label_fan_speed;
1606 priv->power_label = label_fan_power;
1607 priv->voltage_label = label_fan_voltage;
1608 priv->current_label = label_fan_current;
1610 case USB_PRODUCT_ID_QUADRO:
1611 priv->kind = quadro;
1613 priv->num_fans = QUADRO_NUM_FANS;
1614 priv->fan_sensor_offsets = quadro_sensor_fan_offsets;
1615 priv->fan_ctrl_offsets = quadro_ctrl_fan_offsets;
1617 priv->num_temp_sensors = QUADRO_NUM_SENSORS;
1618 priv->temp_sensor_start_offset = QUADRO_SENSOR_START;
1619 priv->num_virtual_temp_sensors = QUADRO_NUM_VIRTUAL_SENSORS;
1620 priv->virtual_temp_sensor_start_offset = QUADRO_VIRTUAL_SENSORS_START;
1621 priv->num_flow_sensors = QUADRO_NUM_FLOW_SENSORS;
1622 priv->flow_sensors_start_offset = QUADRO_FLOW_SENSOR_OFFSET;
1624 priv->temp_ctrl_offset = QUADRO_TEMP_CTRL_OFFSET;
1626 priv->buffer_size = QUADRO_CTRL_REPORT_SIZE;
1628 priv->flow_pulses_ctrl_offset = QUADRO_FLOW_PULSES_CTRL_OFFSET;
1629 priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;
1631 priv->temp_label = label_temp_sensors;
1632 priv->virtual_temp_label = label_virtual_temp_sensors;
1633 priv->speed_label = label_quadro_speeds;
1634 priv->power_label = label_fan_power;
1635 priv->voltage_label = label_fan_voltage;
1636 priv->current_label = label_fan_current;
1638 case USB_PRODUCT_ID_HIGHFLOWNEXT:
1639 priv->kind = highflownext;
1643 priv->num_temp_sensors = HIGHFLOWNEXT_NUM_SENSORS;
1644 priv->temp_sensor_start_offset = HIGHFLOWNEXT_SENSOR_START;
1645 priv->num_flow_sensors = HIGHFLOWNEXT_NUM_FLOW_SENSORS;
1646 priv->flow_sensors_start_offset = HIGHFLOWNEXT_FLOW;
1648 priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;
1650 priv->temp_label = label_highflownext_temp_sensors;
1651 priv->speed_label = label_highflownext_fan_speed;
1652 priv->power_label = label_highflownext_power;
1653 priv->voltage_label = label_highflownext_voltage;
1655 case USB_PRODUCT_ID_LEAKSHIELD:
1657 * Choose the right Leakshield device, because
1658 * the other one acts as a keyboard
1660 if (hdev->type != 2) {
1662 goto fail_and_close;
1665 priv->kind = leakshield;
1668 priv->num_temp_sensors = LEAKSHIELD_NUM_SENSORS;
1669 priv->temp_sensor_start_offset = LEAKSHIELD_TEMPERATURE_1;
1671 priv->temp_label = label_leakshield_temp_sensors;
1672 priv->speed_label = label_leakshield_fan_speed;
1674 case USB_PRODUCT_ID_AQUASTREAMXT:
1675 priv->kind = aquastreamxt;
1677 priv->num_fans = AQUASTREAMXT_NUM_FANS;
1678 priv->fan_sensor_offsets = aquastreamxt_sensor_fan_offsets;
1680 priv->num_temp_sensors = AQUASTREAMXT_NUM_SENSORS;
1681 priv->temp_sensor_start_offset = AQUASTREAMXT_SENSOR_START;
1682 priv->buffer_size = AQUASTREAMXT_SENSOR_REPORT_SIZE;
1684 priv->temp_label = label_aquastreamxt_temp_sensors;
1685 priv->speed_label = label_d5next_speeds;
1686 priv->voltage_label = label_d5next_voltages;
1687 priv->current_label = label_d5next_current;
1689 case USB_PRODUCT_ID_AQUASTREAMULT:
1690 priv->kind = aquastreamult;
1692 priv->num_fans = AQUASTREAMULT_NUM_FANS;
1693 priv->fan_sensor_offsets = aquastreamult_sensor_fan_offsets;
1695 priv->num_temp_sensors = AQUASTREAMULT_NUM_SENSORS;
1696 priv->temp_sensor_start_offset = AQUASTREAMULT_SENSOR_START;
1698 priv->temp_label = label_aquastreamult_temp;
1699 priv->speed_label = label_aquastreamult_speeds;
1700 priv->power_label = label_aquastreamult_power;
1701 priv->voltage_label = label_aquastreamult_voltages;
1702 priv->current_label = label_aquastreamult_current;
1704 case USB_PRODUCT_ID_POWERADJUST3:
1705 priv->kind = poweradjust3;
1709 priv->num_temp_sensors = POWERADJUST3_NUM_SENSORS;
1710 priv->temp_sensor_start_offset = POWERADJUST3_SENSOR_START;
1711 priv->buffer_size = POWERADJUST3_SENSOR_REPORT_SIZE;
1713 priv->temp_label = label_poweradjust3_temp_sensors;
1719 switch (priv->kind) {
1721 priv->serial_number_start_offset = AQUAERO_SERIAL_START;
1722 priv->firmware_version_offset = AQUAERO_FIRMWARE_VERSION;
1724 priv->fan_structure = &aqc_aquaero_fan_structure;
1726 priv->ctrl_report_id = AQUAERO_CTRL_REPORT_ID;
1727 priv->secondary_ctrl_report_id = AQUAERO_SECONDARY_CTRL_REPORT_ID;
1728 priv->secondary_ctrl_report_size = AQUAERO_SECONDARY_CTRL_REPORT_SIZE;
1729 priv->secondary_ctrl_report = aquaero_secondary_ctrl_report;
1732 priv->status_report_id = POWERADJUST3_STATUS_REPORT_ID;
1735 priv->serial_number_start_offset = AQUASTREAMXT_SERIAL_START;
1736 priv->firmware_version_offset = AQUASTREAMXT_FIRMWARE_VERSION;
1738 priv->status_report_id = AQUASTREAMXT_STATUS_REPORT_ID;
1741 priv->serial_number_start_offset = AQC_SERIAL_START;
1742 priv->firmware_version_offset = AQC_FIRMWARE_VERSION;
1744 priv->ctrl_report_id = CTRL_REPORT_ID;
1745 priv->secondary_ctrl_report_id = SECONDARY_CTRL_REPORT_ID;
1746 priv->secondary_ctrl_report_size = SECONDARY_CTRL_REPORT_SIZE;
1747 priv->secondary_ctrl_report = secondary_ctrl_report;
1749 if (priv->kind == aquastreamult)
1750 priv->fan_structure = &aqc_aquastreamult_fan_structure;
1752 priv->fan_structure = &aqc_general_fan_structure;
1756 if (priv->buffer_size != 0) {
1757 priv->checksum_start = 0x01;
1758 priv->checksum_length = priv->buffer_size - 3;
1759 priv->checksum_offset = priv->buffer_size - 2;
1762 priv->name = aqc_device_names[priv->kind];
1764 priv->buffer = devm_kzalloc(&hdev->dev, priv->buffer_size, GFP_KERNEL);
1765 if (!priv->buffer) {
1767 goto fail_and_close;
1770 mutex_init(&priv->mutex);
1772 priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, priv->name, priv,
1773 &aqc_chip_info, NULL);
1775 if (IS_ERR(priv->hwmon_dev)) {
1776 ret = PTR_ERR(priv->hwmon_dev);
1777 goto fail_and_close;
1780 aqc_debugfs_init(priv);
1791 static void aqc_remove(struct hid_device *hdev)
1793 struct aqc_data *priv = hid_get_drvdata(hdev);
1795 debugfs_remove_recursive(priv->debugfs);
1796 hwmon_device_unregister(priv->hwmon_dev);
1802 static const struct hid_device_id aqc_table[] = {
1803 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_AQUAERO) },
1804 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_D5NEXT) },
1805 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_FARBWERK) },
1806 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_FARBWERK360) },
1807 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_OCTO) },
1808 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_QUADRO) },
1809 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_HIGHFLOWNEXT) },
1810 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_LEAKSHIELD) },
1811 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_AQUASTREAMXT) },
1812 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_AQUASTREAMULT) },
1813 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_POWERADJUST3) },
1817 MODULE_DEVICE_TABLE(hid, aqc_table);
1819 static struct hid_driver aqc_driver = {
1820 .name = DRIVER_NAME,
1821 .id_table = aqc_table,
1823 .remove = aqc_remove,
1824 .raw_event = aqc_raw_event,
1827 static int __init aqc_init(void)
1829 return hid_register_driver(&aqc_driver);
1832 static void __exit aqc_exit(void)
1834 hid_unregister_driver(&aqc_driver);
1837 /* Request to initialize after the HID bus to ensure it's not being loaded before */
1838 late_initcall(aqc_init);
1839 module_exit(aqc_exit);
1841 MODULE_LICENSE("GPL");
1842 MODULE_AUTHOR("Aleksa Savic <savicaleksa83@gmail.com>");
1843 MODULE_AUTHOR("Jack Doan <me@jackdoan.com>");
1844 MODULE_DESCRIPTION("Hwmon driver for Aquacomputer devices");