1 // SPDX-License-Identifier: GPL-2.0+
3 * hwmon driver for Aquacomputer devices (D5 Next, Farbwerk, Farbwerk 360, Octo,
4 * Quadro, High Flow Next)
6 * Aquacomputer devices send HID reports (with ID 0x01) every second to report
9 * Copyright 2021 Aleksa Savic <savicaleksa83@gmail.com>
10 * Copyright 2022 Jack Doan <me@jackdoan.com>
13 #include <linux/crc16.h>
14 #include <linux/debugfs.h>
15 #include <linux/hid.h>
16 #include <linux/hwmon.h>
17 #include <linux/jiffies.h>
18 #include <linux/module.h>
19 #include <linux/mutex.h>
20 #include <linux/seq_file.h>
21 #include <asm/unaligned.h>
23 #define USB_VENDOR_ID_AQUACOMPUTER 0x0c70
24 #define USB_PRODUCT_ID_FARBWERK 0xf00a
25 #define USB_PRODUCT_ID_QUADRO 0xf00d
26 #define USB_PRODUCT_ID_D5NEXT 0xf00e
27 #define USB_PRODUCT_ID_FARBWERK360 0xf010
28 #define USB_PRODUCT_ID_OCTO 0xf011
29 #define USB_PRODUCT_ID_HIGHFLOWNEXT 0xf012
31 enum kinds { d5next, farbwerk, farbwerk360, octo, quadro, highflownext };
33 static const char *const aqc_device_names[] = {
35 [farbwerk] = "farbwerk",
36 [farbwerk360] = "farbwerk360",
39 [highflownext] = "highflownext"
42 #define DRIVER_NAME "aquacomputer_d5next"
44 #define STATUS_REPORT_ID 0x01
45 #define STATUS_UPDATE_INTERVAL (2 * HZ) /* In seconds */
46 #define SERIAL_FIRST_PART 3
47 #define SERIAL_SECOND_PART 5
48 #define FIRMWARE_VERSION 13
50 #define CTRL_REPORT_ID 0x03
52 /* The HID report that the official software always sends
53 * after writing values, currently same for all devices
55 #define SECONDARY_CTRL_REPORT_ID 0x02
56 #define SECONDARY_CTRL_REPORT_SIZE 0x0B
58 static u8 secondary_ctrl_report[] = {
59 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x34, 0xC6
62 /* Register offsets for all Aquacomputer devices */
63 #define AQC_TEMP_SENSOR_SIZE 0x02
64 #define AQC_TEMP_SENSOR_DISCONNECTED 0x7FFF
65 #define AQC_FAN_PERCENT_OFFSET 0x00
66 #define AQC_FAN_VOLTAGE_OFFSET 0x02
67 #define AQC_FAN_CURRENT_OFFSET 0x04
68 #define AQC_FAN_POWER_OFFSET 0x06
69 #define AQC_FAN_SPEED_OFFSET 0x08
71 /* Register offsets for the D5 Next pump */
72 #define D5NEXT_POWER_CYCLES 0x18
73 #define D5NEXT_COOLANT_TEMP 0x57
74 #define D5NEXT_NUM_FANS 2
75 #define D5NEXT_NUM_SENSORS 1
76 #define D5NEXT_NUM_VIRTUAL_SENSORS 8
77 #define D5NEXT_VIRTUAL_SENSORS_START 0x3f
78 #define D5NEXT_PUMP_OFFSET 0x6c
79 #define D5NEXT_FAN_OFFSET 0x5f
80 #define D5NEXT_5V_VOLTAGE 0x39
81 #define D5NEXT_12V_VOLTAGE 0x37
82 #define D5NEXT_CTRL_REPORT_SIZE 0x329
83 static u8 d5next_sensor_fan_offsets[] = { D5NEXT_PUMP_OFFSET, D5NEXT_FAN_OFFSET };
85 /* Pump and fan speed registers in D5 Next control report (from 0-100%) */
86 static u16 d5next_ctrl_fan_offsets[] = { 0x97, 0x42 };
88 /* Register offsets for the Farbwerk RGB controller */
89 #define FARBWERK_NUM_SENSORS 4
90 #define FARBWERK_SENSOR_START 0x2f
92 /* Register offsets for the Farbwerk 360 RGB controller */
93 #define FARBWERK360_NUM_SENSORS 4
94 #define FARBWERK360_SENSOR_START 0x32
95 #define FARBWERK360_NUM_VIRTUAL_SENSORS 16
96 #define FARBWERK360_VIRTUAL_SENSORS_START 0x3a
98 /* Register offsets for the Octo fan controller */
99 #define OCTO_POWER_CYCLES 0x18
100 #define OCTO_NUM_FANS 8
101 #define OCTO_NUM_SENSORS 4
102 #define OCTO_SENSOR_START 0x3D
103 #define OCTO_NUM_VIRTUAL_SENSORS 16
104 #define OCTO_VIRTUAL_SENSORS_START 0x45
105 #define OCTO_CTRL_REPORT_SIZE 0x65F
106 static u8 octo_sensor_fan_offsets[] = { 0x7D, 0x8A, 0x97, 0xA4, 0xB1, 0xBE, 0xCB, 0xD8 };
108 /* Fan speed registers in Octo control report (from 0-100%) */
109 static u16 octo_ctrl_fan_offsets[] = { 0x5B, 0xB0, 0x105, 0x15A, 0x1AF, 0x204, 0x259, 0x2AE };
111 /* Register offsets for the Quadro fan controller */
112 #define QUADRO_POWER_CYCLES 0x18
113 #define QUADRO_NUM_FANS 4
114 #define QUADRO_NUM_SENSORS 4
115 #define QUADRO_SENSOR_START 0x34
116 #define QUADRO_NUM_VIRTUAL_SENSORS 16
117 #define QUADRO_VIRTUAL_SENSORS_START 0x3c
118 #define QUADRO_CTRL_REPORT_SIZE 0x3c1
119 #define QUADRO_FLOW_SENSOR_OFFSET 0x6e
120 static u8 quadro_sensor_fan_offsets[] = { 0x70, 0x7D, 0x8A, 0x97 };
122 /* Fan speed registers in Quadro control report (from 0-100%) */
123 static u16 quadro_ctrl_fan_offsets[] = { 0x37, 0x8c, 0xe1, 0x136 };
125 /* Register offsets for the High Flow Next */
126 #define HIGHFLOWNEXT_NUM_SENSORS 2
127 #define HIGHFLOWNEXT_SENSOR_START 85
128 #define HIGHFLOWNEXT_FLOW 81
129 #define HIGHFLOWNEXT_WATER_QUALITY 89
130 #define HIGHFLOWNEXT_POWER 91
131 #define HIGHFLOWNEXT_CONDUCTIVITY 95
132 #define HIGHFLOWNEXT_5V_VOLTAGE 97
133 #define HIGHFLOWNEXT_5V_VOLTAGE_USB 99
135 /* Labels for D5 Next */
136 static const char *const label_d5next_temp[] = {
140 static const char *const label_d5next_speeds[] = {
145 static const char *const label_d5next_power[] = {
150 static const char *const label_d5next_voltages[] = {
157 static const char *const label_d5next_current[] = {
162 /* Labels for Farbwerk, Farbwerk 360 and Octo and Quadro temperature sensors */
163 static const char *const label_temp_sensors[] = {
170 static const char *const label_virtual_temp_sensors[] = {
189 /* Labels for Octo and Quadro (except speed) */
190 static const char *const label_fan_speed[] = {
201 static const char *const label_fan_power[] = {
212 static const char *const label_fan_voltage[] = {
223 static const char *const label_fan_current[] = {
234 /* Labels for Quadro fan speeds */
235 static const char *const label_quadro_speeds[] = {
243 /* Labels for High Flow Next */
244 static const char *const label_highflownext_temp_sensors[] = {
249 static const char *const label_highflownext_fan_speed[] = {
252 "Conductivity [nS/cm]",
255 static const char *const label_highflownext_power[] = {
259 static const char *const label_highflownext_voltage[] = {
265 struct hid_device *hdev;
266 struct device *hwmon_dev;
267 struct dentry *debugfs;
268 struct mutex mutex; /* Used for locking access when reading and writing PWM values */
279 u8 *fan_sensor_offsets;
280 u16 *fan_ctrl_offsets;
281 int num_temp_sensors;
282 int temp_sensor_start_offset;
283 int num_virtual_temp_sensors;
284 int virtual_temp_sensor_start_offset;
285 u16 power_cycle_count_offset;
286 u8 flow_sensor_offset;
288 /* General info, same across all devices */
289 u32 serial_number[2];
290 u16 firmware_version;
292 /* How many times the device was powered on, if available */
296 s32 temp_input[20]; /* Max 4 physical and 16 virtual */
299 u16 voltage_input[8];
300 u16 current_input[8];
303 const char *const *temp_label;
304 const char *const *virtual_temp_label;
305 const char *const *speed_label;
306 const char *const *power_label;
307 const char *const *voltage_label;
308 const char *const *current_label;
310 unsigned long updated;
313 /* Converts from centi-percent */
314 static int aqc_percent_to_pwm(u16 val)
316 return DIV_ROUND_CLOSEST(val * 255, 100 * 100);
319 /* Converts to centi-percent */
320 static int aqc_pwm_to_percent(long val)
322 if (val < 0 || val > 255)
325 return DIV_ROUND_CLOSEST(val * 100 * 100, 255);
328 /* Expects the mutex to be locked */
329 static int aqc_get_ctrl_data(struct aqc_data *priv)
333 memset(priv->buffer, 0x00, priv->buffer_size);
334 ret = hid_hw_raw_request(priv->hdev, CTRL_REPORT_ID, priv->buffer, priv->buffer_size,
335 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
342 /* Expects the mutex to be locked */
343 static int aqc_send_ctrl_data(struct aqc_data *priv)
348 /* Init and xorout value for CRC-16/USB is 0xffff */
349 checksum = crc16(0xffff, priv->buffer + priv->checksum_start, priv->checksum_length);
352 /* Place the new checksum at the end of the report */
353 put_unaligned_be16(checksum, priv->buffer + priv->checksum_offset);
355 /* Send the patched up report back to the device */
356 ret = hid_hw_raw_request(priv->hdev, CTRL_REPORT_ID, priv->buffer, priv->buffer_size,
357 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
361 /* The official software sends this report after every change, so do it here as well */
362 ret = hid_hw_raw_request(priv->hdev, SECONDARY_CTRL_REPORT_ID, secondary_ctrl_report,
363 SECONDARY_CTRL_REPORT_SIZE, HID_FEATURE_REPORT,
368 /* Refreshes the control buffer and returns value at offset */
369 static int aqc_get_ctrl_val(struct aqc_data *priv, int offset)
373 mutex_lock(&priv->mutex);
375 ret = aqc_get_ctrl_data(priv);
377 goto unlock_and_return;
379 ret = get_unaligned_be16(priv->buffer + offset);
382 mutex_unlock(&priv->mutex);
386 static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val)
390 mutex_lock(&priv->mutex);
392 ret = aqc_get_ctrl_data(priv);
394 goto unlock_and_return;
396 put_unaligned_be16((u16)val, priv->buffer + offset);
398 ret = aqc_send_ctrl_data(priv);
401 mutex_unlock(&priv->mutex);
405 static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel)
407 const struct aqc_data *priv = data;
411 if (channel < priv->num_temp_sensors + priv->num_virtual_temp_sensors)
415 if (priv->fan_ctrl_offsets && channel < priv->num_fans) {
417 case hwmon_pwm_input:
425 switch (priv->kind) {
427 /* Special case to support flow sensor, water quality and conductivity */
432 /* Special case to support flow sensor */
433 if (channel < priv->num_fans + 1)
437 if (channel < priv->num_fans)
443 switch (priv->kind) {
445 /* Special case to support one power sensor */
450 if (channel < priv->num_fans)
456 if (channel < priv->num_fans)
460 switch (priv->kind) {
462 /* Special case to support +5V and +12V voltage sensors */
463 if (channel < priv->num_fans + 2)
467 /* Special case to support two voltage sensors */
472 if (channel < priv->num_fans)
484 static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
485 int channel, long *val)
488 struct aqc_data *priv = dev_get_drvdata(dev);
490 if (time_after(jiffies, priv->updated + STATUS_UPDATE_INTERVAL))
495 if (priv->temp_input[channel] == -ENODATA)
498 *val = priv->temp_input[channel];
501 *val = priv->speed_input[channel];
504 *val = priv->power_input[channel];
507 if (priv->fan_ctrl_offsets) {
508 ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel]);
512 *val = aqc_percent_to_pwm(ret);
516 *val = priv->voltage_input[channel];
519 *val = priv->current_input[channel];
528 static int aqc_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
529 int channel, const char **str)
531 struct aqc_data *priv = dev_get_drvdata(dev);
535 if (channel < priv->num_temp_sensors)
536 *str = priv->temp_label[channel];
538 *str = priv->virtual_temp_label[channel - priv->num_temp_sensors];
541 *str = priv->speed_label[channel];
544 *str = priv->power_label[channel];
547 *str = priv->voltage_label[channel];
550 *str = priv->current_label[channel];
559 static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
563 struct aqc_data *priv = dev_get_drvdata(dev);
568 case hwmon_pwm_input:
569 if (priv->fan_ctrl_offsets) {
570 pwm_value = aqc_pwm_to_percent(val);
574 ret = aqc_set_ctrl_val(priv, priv->fan_ctrl_offsets[channel],
591 static const struct hwmon_ops aqc_hwmon_ops = {
592 .is_visible = aqc_is_visible,
594 .read_string = aqc_read_string,
598 static const struct hwmon_channel_info *aqc_info[] = {
599 HWMON_CHANNEL_INFO(temp,
600 HWMON_T_INPUT | HWMON_T_LABEL,
601 HWMON_T_INPUT | HWMON_T_LABEL,
602 HWMON_T_INPUT | HWMON_T_LABEL,
603 HWMON_T_INPUT | HWMON_T_LABEL,
604 HWMON_T_INPUT | HWMON_T_LABEL,
605 HWMON_T_INPUT | HWMON_T_LABEL,
606 HWMON_T_INPUT | HWMON_T_LABEL,
607 HWMON_T_INPUT | HWMON_T_LABEL,
608 HWMON_T_INPUT | HWMON_T_LABEL,
609 HWMON_T_INPUT | HWMON_T_LABEL,
610 HWMON_T_INPUT | HWMON_T_LABEL,
611 HWMON_T_INPUT | HWMON_T_LABEL,
612 HWMON_T_INPUT | HWMON_T_LABEL,
613 HWMON_T_INPUT | HWMON_T_LABEL,
614 HWMON_T_INPUT | HWMON_T_LABEL,
615 HWMON_T_INPUT | HWMON_T_LABEL,
616 HWMON_T_INPUT | HWMON_T_LABEL,
617 HWMON_T_INPUT | HWMON_T_LABEL,
618 HWMON_T_INPUT | HWMON_T_LABEL,
619 HWMON_T_INPUT | HWMON_T_LABEL),
620 HWMON_CHANNEL_INFO(fan,
621 HWMON_F_INPUT | HWMON_F_LABEL,
622 HWMON_F_INPUT | HWMON_F_LABEL,
623 HWMON_F_INPUT | HWMON_F_LABEL,
624 HWMON_F_INPUT | HWMON_F_LABEL,
625 HWMON_F_INPUT | HWMON_F_LABEL,
626 HWMON_F_INPUT | HWMON_F_LABEL,
627 HWMON_F_INPUT | HWMON_F_LABEL,
628 HWMON_F_INPUT | HWMON_F_LABEL),
629 HWMON_CHANNEL_INFO(power,
630 HWMON_P_INPUT | HWMON_P_LABEL,
631 HWMON_P_INPUT | HWMON_P_LABEL,
632 HWMON_P_INPUT | HWMON_P_LABEL,
633 HWMON_P_INPUT | HWMON_P_LABEL,
634 HWMON_P_INPUT | HWMON_P_LABEL,
635 HWMON_P_INPUT | HWMON_P_LABEL,
636 HWMON_P_INPUT | HWMON_P_LABEL,
637 HWMON_P_INPUT | HWMON_P_LABEL),
638 HWMON_CHANNEL_INFO(pwm,
647 HWMON_CHANNEL_INFO(in,
648 HWMON_I_INPUT | HWMON_I_LABEL,
649 HWMON_I_INPUT | HWMON_I_LABEL,
650 HWMON_I_INPUT | HWMON_I_LABEL,
651 HWMON_I_INPUT | HWMON_I_LABEL,
652 HWMON_I_INPUT | HWMON_I_LABEL,
653 HWMON_I_INPUT | HWMON_I_LABEL,
654 HWMON_I_INPUT | HWMON_I_LABEL,
655 HWMON_I_INPUT | HWMON_I_LABEL),
656 HWMON_CHANNEL_INFO(curr,
657 HWMON_C_INPUT | HWMON_C_LABEL,
658 HWMON_C_INPUT | HWMON_C_LABEL,
659 HWMON_C_INPUT | HWMON_C_LABEL,
660 HWMON_C_INPUT | HWMON_C_LABEL,
661 HWMON_C_INPUT | HWMON_C_LABEL,
662 HWMON_C_INPUT | HWMON_C_LABEL,
663 HWMON_C_INPUT | HWMON_C_LABEL,
664 HWMON_C_INPUT | HWMON_C_LABEL),
668 static const struct hwmon_chip_info aqc_chip_info = {
669 .ops = &aqc_hwmon_ops,
673 static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size)
675 int i, j, sensor_value;
676 struct aqc_data *priv;
678 if (report->id != STATUS_REPORT_ID)
681 priv = hid_get_drvdata(hdev);
683 /* Info provided with every report */
684 priv->serial_number[0] = get_unaligned_be16(data + SERIAL_FIRST_PART);
685 priv->serial_number[1] = get_unaligned_be16(data + SERIAL_SECOND_PART);
686 priv->firmware_version = get_unaligned_be16(data + FIRMWARE_VERSION);
688 /* Physical temperature sensor readings */
689 for (i = 0; i < priv->num_temp_sensors; i++) {
690 sensor_value = get_unaligned_be16(data +
691 priv->temp_sensor_start_offset +
692 i * AQC_TEMP_SENSOR_SIZE);
693 if (sensor_value == AQC_TEMP_SENSOR_DISCONNECTED)
694 priv->temp_input[i] = -ENODATA;
696 priv->temp_input[i] = sensor_value * 10;
699 /* Virtual temperature sensor readings */
700 for (j = 0; j < priv->num_virtual_temp_sensors; j++) {
701 sensor_value = get_unaligned_be16(data +
702 priv->virtual_temp_sensor_start_offset +
703 j * AQC_TEMP_SENSOR_SIZE);
704 if (sensor_value == AQC_TEMP_SENSOR_DISCONNECTED)
705 priv->temp_input[i] = -ENODATA;
707 priv->temp_input[i] = sensor_value * 10;
711 /* Fan speed and related readings */
712 for (i = 0; i < priv->num_fans; i++) {
713 priv->speed_input[i] =
714 get_unaligned_be16(data + priv->fan_sensor_offsets[i] + AQC_FAN_SPEED_OFFSET);
715 priv->power_input[i] =
716 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
717 AQC_FAN_POWER_OFFSET) * 10000;
718 priv->voltage_input[i] =
719 get_unaligned_be16(data + priv->fan_sensor_offsets[i] +
720 AQC_FAN_VOLTAGE_OFFSET) * 10;
721 priv->current_input[i] =
722 get_unaligned_be16(data + priv->fan_sensor_offsets[i] + AQC_FAN_CURRENT_OFFSET);
725 if (priv->power_cycle_count_offset != 0)
726 priv->power_cycles = get_unaligned_be32(data + priv->power_cycle_count_offset);
728 /* Special-case sensor readings */
729 switch (priv->kind) {
731 priv->voltage_input[2] = get_unaligned_be16(data + D5NEXT_5V_VOLTAGE) * 10;
732 priv->voltage_input[3] = get_unaligned_be16(data + D5NEXT_12V_VOLTAGE) * 10;
735 priv->speed_input[4] = get_unaligned_be16(data + priv->flow_sensor_offset);
738 /* If external temp sensor is not connected, its power reading is also N/A */
739 if (priv->temp_input[1] == -ENODATA)
740 priv->power_input[0] = -ENODATA;
742 priv->power_input[0] =
743 get_unaligned_be16(data + HIGHFLOWNEXT_POWER) * 1000000;
745 priv->voltage_input[0] = get_unaligned_be16(data + HIGHFLOWNEXT_5V_VOLTAGE) * 10;
746 priv->voltage_input[1] =
747 get_unaligned_be16(data + HIGHFLOWNEXT_5V_VOLTAGE_USB) * 10;
749 priv->speed_input[0] = get_unaligned_be16(data + HIGHFLOWNEXT_FLOW);
750 priv->speed_input[1] = get_unaligned_be16(data + HIGHFLOWNEXT_WATER_QUALITY);
751 priv->speed_input[2] = get_unaligned_be16(data + HIGHFLOWNEXT_CONDUCTIVITY);
757 priv->updated = jiffies;
762 #ifdef CONFIG_DEBUG_FS
764 static int serial_number_show(struct seq_file *seqf, void *unused)
766 struct aqc_data *priv = seqf->private;
768 seq_printf(seqf, "%05u-%05u\n", priv->serial_number[0], priv->serial_number[1]);
772 DEFINE_SHOW_ATTRIBUTE(serial_number);
774 static int firmware_version_show(struct seq_file *seqf, void *unused)
776 struct aqc_data *priv = seqf->private;
778 seq_printf(seqf, "%u\n", priv->firmware_version);
782 DEFINE_SHOW_ATTRIBUTE(firmware_version);
784 static int power_cycles_show(struct seq_file *seqf, void *unused)
786 struct aqc_data *priv = seqf->private;
788 seq_printf(seqf, "%u\n", priv->power_cycles);
792 DEFINE_SHOW_ATTRIBUTE(power_cycles);
794 static void aqc_debugfs_init(struct aqc_data *priv)
798 scnprintf(name, sizeof(name), "%s_%s-%s", "aquacomputer", priv->name,
799 dev_name(&priv->hdev->dev));
801 priv->debugfs = debugfs_create_dir(name, NULL);
802 debugfs_create_file("serial_number", 0444, priv->debugfs, priv, &serial_number_fops);
803 debugfs_create_file("firmware_version", 0444, priv->debugfs, priv, &firmware_version_fops);
805 if (priv->power_cycle_count_offset != 0)
806 debugfs_create_file("power_cycles", 0444, priv->debugfs, priv, &power_cycles_fops);
811 static void aqc_debugfs_init(struct aqc_data *priv)
817 static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
819 struct aqc_data *priv;
822 priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL);
827 hid_set_drvdata(hdev, priv);
829 priv->updated = jiffies - STATUS_UPDATE_INTERVAL;
831 ret = hid_parse(hdev);
835 ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
839 ret = hid_hw_open(hdev);
843 switch (hdev->product) {
844 case USB_PRODUCT_ID_D5NEXT:
847 priv->num_fans = D5NEXT_NUM_FANS;
848 priv->fan_sensor_offsets = d5next_sensor_fan_offsets;
849 priv->fan_ctrl_offsets = d5next_ctrl_fan_offsets;
850 priv->num_temp_sensors = D5NEXT_NUM_SENSORS;
851 priv->temp_sensor_start_offset = D5NEXT_COOLANT_TEMP;
852 priv->num_virtual_temp_sensors = D5NEXT_NUM_VIRTUAL_SENSORS;
853 priv->virtual_temp_sensor_start_offset = D5NEXT_VIRTUAL_SENSORS_START;
854 priv->power_cycle_count_offset = D5NEXT_POWER_CYCLES;
855 priv->buffer_size = D5NEXT_CTRL_REPORT_SIZE;
857 priv->temp_label = label_d5next_temp;
858 priv->virtual_temp_label = label_virtual_temp_sensors;
859 priv->speed_label = label_d5next_speeds;
860 priv->power_label = label_d5next_power;
861 priv->voltage_label = label_d5next_voltages;
862 priv->current_label = label_d5next_current;
864 case USB_PRODUCT_ID_FARBWERK:
865 priv->kind = farbwerk;
868 priv->num_temp_sensors = FARBWERK_NUM_SENSORS;
869 priv->temp_sensor_start_offset = FARBWERK_SENSOR_START;
870 priv->temp_label = label_temp_sensors;
872 case USB_PRODUCT_ID_FARBWERK360:
873 priv->kind = farbwerk360;
876 priv->num_temp_sensors = FARBWERK360_NUM_SENSORS;
877 priv->temp_sensor_start_offset = FARBWERK360_SENSOR_START;
878 priv->num_virtual_temp_sensors = FARBWERK360_NUM_VIRTUAL_SENSORS;
879 priv->virtual_temp_sensor_start_offset = FARBWERK360_VIRTUAL_SENSORS_START;
881 priv->temp_label = label_temp_sensors;
882 priv->virtual_temp_label = label_virtual_temp_sensors;
884 case USB_PRODUCT_ID_OCTO:
887 priv->num_fans = OCTO_NUM_FANS;
888 priv->fan_sensor_offsets = octo_sensor_fan_offsets;
889 priv->fan_ctrl_offsets = octo_ctrl_fan_offsets;
890 priv->num_temp_sensors = OCTO_NUM_SENSORS;
891 priv->temp_sensor_start_offset = OCTO_SENSOR_START;
892 priv->num_virtual_temp_sensors = OCTO_NUM_VIRTUAL_SENSORS;
893 priv->virtual_temp_sensor_start_offset = OCTO_VIRTUAL_SENSORS_START;
894 priv->power_cycle_count_offset = OCTO_POWER_CYCLES;
895 priv->buffer_size = OCTO_CTRL_REPORT_SIZE;
897 priv->temp_label = label_temp_sensors;
898 priv->virtual_temp_label = label_virtual_temp_sensors;
899 priv->speed_label = label_fan_speed;
900 priv->power_label = label_fan_power;
901 priv->voltage_label = label_fan_voltage;
902 priv->current_label = label_fan_current;
904 case USB_PRODUCT_ID_QUADRO:
907 priv->num_fans = QUADRO_NUM_FANS;
908 priv->fan_sensor_offsets = quadro_sensor_fan_offsets;
909 priv->fan_ctrl_offsets = quadro_ctrl_fan_offsets;
910 priv->num_temp_sensors = QUADRO_NUM_SENSORS;
911 priv->temp_sensor_start_offset = QUADRO_SENSOR_START;
912 priv->num_virtual_temp_sensors = QUADRO_NUM_VIRTUAL_SENSORS;
913 priv->virtual_temp_sensor_start_offset = QUADRO_VIRTUAL_SENSORS_START;
914 priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;
915 priv->buffer_size = QUADRO_CTRL_REPORT_SIZE;
916 priv->flow_sensor_offset = QUADRO_FLOW_SENSOR_OFFSET;
918 priv->temp_label = label_temp_sensors;
919 priv->virtual_temp_label = label_virtual_temp_sensors;
920 priv->speed_label = label_quadro_speeds;
921 priv->power_label = label_fan_power;
922 priv->voltage_label = label_fan_voltage;
923 priv->current_label = label_fan_current;
925 case USB_PRODUCT_ID_HIGHFLOWNEXT:
926 priv->kind = highflownext;
929 priv->num_temp_sensors = HIGHFLOWNEXT_NUM_SENSORS;
930 priv->temp_sensor_start_offset = HIGHFLOWNEXT_SENSOR_START;
931 priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;
933 priv->temp_label = label_highflownext_temp_sensors;
934 priv->speed_label = label_highflownext_fan_speed;
935 priv->power_label = label_highflownext_power;
936 priv->voltage_label = label_highflownext_voltage;
942 if (priv->buffer_size != 0) {
943 priv->checksum_start = 0x01;
944 priv->checksum_length = priv->buffer_size - 3;
945 priv->checksum_offset = priv->buffer_size - 2;
948 priv->name = aqc_device_names[priv->kind];
950 priv->buffer = devm_kzalloc(&hdev->dev, priv->buffer_size, GFP_KERNEL);
956 mutex_init(&priv->mutex);
958 priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, priv->name, priv,
959 &aqc_chip_info, NULL);
961 if (IS_ERR(priv->hwmon_dev)) {
962 ret = PTR_ERR(priv->hwmon_dev);
966 aqc_debugfs_init(priv);
977 static void aqc_remove(struct hid_device *hdev)
979 struct aqc_data *priv = hid_get_drvdata(hdev);
981 debugfs_remove_recursive(priv->debugfs);
982 hwmon_device_unregister(priv->hwmon_dev);
988 static const struct hid_device_id aqc_table[] = {
989 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_D5NEXT) },
990 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_FARBWERK) },
991 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_FARBWERK360) },
992 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_OCTO) },
993 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_QUADRO) },
994 { HID_USB_DEVICE(USB_VENDOR_ID_AQUACOMPUTER, USB_PRODUCT_ID_HIGHFLOWNEXT) },
998 MODULE_DEVICE_TABLE(hid, aqc_table);
1000 static struct hid_driver aqc_driver = {
1001 .name = DRIVER_NAME,
1002 .id_table = aqc_table,
1004 .remove = aqc_remove,
1005 .raw_event = aqc_raw_event,
1008 static int __init aqc_init(void)
1010 return hid_register_driver(&aqc_driver);
1013 static void __exit aqc_exit(void)
1015 hid_unregister_driver(&aqc_driver);
1018 /* Request to initialize after the HID bus to ensure it's not being loaded before */
1019 late_initcall(aqc_init);
1020 module_exit(aqc_exit);
1022 MODULE_LICENSE("GPL");
1023 MODULE_AUTHOR("Aleksa Savic <savicaleksa83@gmail.com>");
1024 MODULE_AUTHOR("Jack Doan <me@jackdoan.com>");
1025 MODULE_DESCRIPTION("Hwmon driver for Aquacomputer devices");