-
Notifications
You must be signed in to change notification settings - Fork 8
/
aquacomputer_d5next.c
3337 lines (2889 loc) · 97 KB
/
aquacomputer_d5next.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0+
/*
* hwmon driver for Aquacomputer devices (D5 Next, Farbwerk, Farbwerk 360, Octo,
* Quadro, High Flow Next, Aquaero, Leakshield, Aquastream XT, Aquastream Ultimate,
* Poweradjust 3, High Flow USB, MPS Flow family)
*
* Aquacomputer devices send HID reports (with ID 0x01) every second to report
* sensor values, except for devices that communicate through the
* legacy way (currently, Aquastream XT, Poweradjust 3 and High Flow USB).
*
* Copyright 2021 Aleksa Savic <savicaleksa83@gmail.com>
* Copyright 2022 Jack Doan <me@jackdoan.com>
*/
#include <linux/crc16.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/hid.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/jiffies.h>
#include <linux/ktime.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/seq_file.h>
#include <linux/usb.h>
#include <asm/unaligned.h>
#define USB_VENDOR_ID_AQUACOMPUTER 0x0c70
#define USB_PRODUCT_ID_AQUAERO 0xf001
#define USB_PRODUCT_ID_FARBWERK 0xf00a
#define USB_PRODUCT_ID_QUADRO 0xf00d
#define USB_PRODUCT_ID_D5NEXT 0xf00e
#define USB_PRODUCT_ID_FARBWERK360 0xf010
#define USB_PRODUCT_ID_OCTO 0xf011
#define USB_PRODUCT_ID_HIGHFLOWNEXT 0xf012
#define USB_PRODUCT_ID_LEAKSHIELD 0xf014
#define USB_PRODUCT_ID_AQUASTREAMXT 0xf0b6
#define USB_PRODUCT_ID_AQUASTREAMULT 0xf00b
#define USB_PRODUCT_ID_POWERADJUST3 0xf0bd
#define USB_PRODUCT_ID_HIGHFLOW 0xf003
enum kinds {
aquaero, d5next, farbwerk, farbwerk360, octo,
quadro, highflownext, leakshield, aquastreamxt,
aquastreamult, poweradjust3, highflow
};
enum aquaero_hw_kinds { unknown, aquaero5, aquaero6 };
static const char *const aqc_device_names[] = {
[aquaero] = "aquaero",
[d5next] = "d5next",
[farbwerk] = "farbwerk",
[farbwerk360] = "farbwerk360",
[octo] = "octo",
[quadro] = "quadro",
[highflownext] = "highflownext",
[leakshield] = "leakshield",
[aquastreamxt] = "aquastreamxt",
[aquastreamult] = "aquastreamultimate",
[poweradjust3] = "poweradjust3",
[highflow] = "highflow" /* Covers MPS Flow devices */
};
#define DRIVER_NAME "aquacomputer_d5next"
#define STATUS_REPORT_ID 0x01
#define STATUS_UPDATE_INTERVAL (2 * HZ) /* In seconds */
#define SERIAL_PART_OFFSET 2
#define CTRL_REPORT_ID 0x03
#define AQUAERO_CTRL_REPORT_ID 0x0b
#define CTRL_REPORT_DELAY 200 /* ms */
/*
* The HID report that the official software always sends
* after writing values, same for all devices, except Aquaero
*/
#define SECONDARY_CTRL_REPORT_ID 0x02
#define SECONDARY_CTRL_REPORT_SIZE 0x0B
static u8 secondary_ctrl_report[] = {
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x34, 0xC6
};
/* Secondary HID report values for Aquaero */
#define AQUAERO_SECONDARY_CTRL_REPORT_ID 0x06
#define AQUAERO_SECONDARY_CTRL_REPORT_SIZE 0x07
static u8 aquaero_secondary_ctrl_report[] = {
0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00
};
/* Secondary HID report values for Aquastream XT */
#define AQUASTREAMXT_SECONDARY_CTRL_REPORT_ID 0x02
#define AQUASTREAMXT_SECONDARY_CTRL_REPORT_SIZE 0x04
static u8 aquastreamxt_secondary_ctrl_report[] = {
0x02, 0x05, 0x00, 0x00
};
/* Data types for reading and writing control reports */
#define AQC_8 0
#define AQC_BE16 1
#define AQC_LE16 2
#define FAN_CURVE_HOLD_MIN_POWER_BIT_POS 1
#define FAN_CURVE_START_BOOST_BIT_POS 2
/* Report IDs for legacy devices */
#define AQUASTREAMXT_STATUS_REPORT_ID 0x04
#define AQUASTREAMXT_CTRL_REPORT_ID 0x06
#define POWERADJUST3_STATUS_REPORT_ID 0x03
#define HIGHFLOW_STATUS_REPORT_ID 0x02
/* Info, sensor sizes and offsets for most Aquacomputer devices */
#define AQC_SERIAL_START 0x03
#define AQC_FIRMWARE_VERSION 0x0D
#define AQC_POWER_CYCLES 0x18
#define AQC_SENSOR_SIZE 0x02
#define AQC_SENSOR_NA 0x7FFF
#define AQC_FAN_PERCENT_OFFSET 0x00
#define AQC_FAN_VOLTAGE_OFFSET 0x02
#define AQC_FAN_CURRENT_OFFSET 0x04
#define AQC_FAN_POWER_OFFSET 0x06
#define AQC_FAN_SPEED_OFFSET 0x08
#define AQC_FAN_CTRL_CURVE_NUM_POINTS 16
/* Report offsets for fan control */
#define AQC_FAN_CTRL_PWM_OFFSET 0x01
#define AQC_FAN_CTRL_TEMP_SELECT_OFFSET 0x03
#define AQC_FAN_CTRL_TEMP_CURVE_START 0x15
#define AQC_FAN_CTRL_PWM_CURVE_START 0x35
/* Specs of the Aquaero fan controllers */
#define AQUAERO_SERIAL_START 0x07
#define AQUAERO_FIRMWARE_VERSION 0x0B
#define AQUAERO_HARDWARE_VERSION 0x0F
#define AQUAERO_NUM_FANS 4
#define AQUAERO_NUM_SENSORS 8
#define AQUAERO_NUM_AQUABUS_SENSORS 20
#define AQUAERO_NUM_VIRTUAL_SENSORS 8
#define AQUAERO_NUM_CALC_VIRTUAL_SENSORS 4
#define AQUAERO_NUM_FLOW_SENSORS 2
#define AQUAERO_NUM_AQUABUS_FLOW_SENSORS 12
#define AQUAERO_CTRL_REPORT_SIZE 0xa93
#define AQUAERO_CTRL_PRESET_ID 0x5c
#define AQUAERO_CTRL_PRESET_SIZE 0x02
#define AQUAERO_CTRL_PRESET_START 0x55c
#define AQUAERO_5_HW_VERSION 5600
#define AQUAERO_6_HW_VERSION 6000
/* Sensor report offsets for Aquaero fan controllers */
#define AQUAERO_SENSOR_START 0x65
#define AQUAERO_VIRTUAL_SENSOR_START 0x85
#define AQUAERO_CALC_VIRTUAL_SENSOR_START 0x95
#define AQUAERO_AQUABUS_SENSOR_START 0x9D
#define AQUAERO_FLOW_SENSORS_START 0xF9
#define AQUAERO_AQUABUS_FLOW_SENSORS_START 0xFD
#define AQUAERO_FAN_VOLTAGE_OFFSET 0x04
#define AQUAERO_FAN_CURRENT_OFFSET 0x06
#define AQUAERO_FAN_POWER_OFFSET 0x08
#define AQUAERO_FAN_SPEED_OFFSET 0x00
static u16 aquaero_sensor_fan_offsets[] = { 0x167, 0x173, 0x17f, 0x18B };
#define AQUAERO_CURRENT_UPTIME_OFFSET 0x11
#define AQUAERO_TOTAL_UPTIME_OFFSET 0x15
/* Control report offsets for the Aquaero fan controllers */
#define AQUAERO_TEMP_CTRL_OFFSET 0xdb
#define AQUAERO_FAN_CTRL_MIN_RPM_OFFSET 0x00
#define AQUAERO_FAN_CTRL_MAX_RPM_OFFSET 0x02
#define AQUAERO_FAN_CTRL_MIN_PWR_OFFSET 0x04
#define AQUAERO_FAN_CTRL_MAX_PWR_OFFSET 0x06
#define AQUAERO_FAN_CTRL_MODE_OFFSET 0x0f
#define AQUAERO_FAN_CTRL_SRC_OFFSET 0x10
static u16 aquaero_ctrl_fan_offsets[] = { 0x20c, 0x220, 0x234, 0x248 };
/* Specs of the D5 Next pump */
#define D5NEXT_NUM_FANS 2
#define D5NEXT_NUM_SENSORS 1
#define D5NEXT_NUM_VIRTUAL_SENSORS 8
#define D5NEXT_CTRL_REPORT_SIZE 0x329
/* Sensor report offsets for the D5 Next pump */
#define D5NEXT_COOLANT_TEMP 0x57
#define D5NEXT_PUMP_OFFSET 0x6c
#define D5NEXT_FAN_OFFSET 0x5f
#define D5NEXT_5V_VOLTAGE 0x39
#define D5NEXT_12V_VOLTAGE 0x37
#define D5NEXT_VIRTUAL_SENSORS_START 0x3f
static u16 d5next_sensor_fan_offsets[] = { D5NEXT_PUMP_OFFSET, D5NEXT_FAN_OFFSET };
/* Control report offsets for the D5 Next pump */
#define D5NEXT_TEMP_CTRL_OFFSET 0x2D /* Temperature sensor offsets location */
static u16 d5next_ctrl_fan_offsets[] = { 0x96, 0x41 }; /* Pump and fan speed (from 0-100%) */
/* Fan curve "hold min power" and "start boost" offsets, only for the fan, first value is unused */
static u8 d5next_ctrl_fan_curve_hold_start_offsets[] = { 0x00, 0x2F };
/* Fan curve min power */
static u8 d5next_ctrl_fan_curve_min_power_offsets[] = { 0x39, 0x30 };
/* Fan curve max power */
static u8 d5next_ctrl_fan_curve_max_power_offsets[] = { 0x3B, 0x32 };
/* Fan curve fallback power */
static u8 d5next_ctrl_fan_curve_fallback_power_offsets[] = { 0x3D, 0x34 };
/* Specs of the Aquastream Ultimate pump */
/* Pump does not follow the standard structure, so only consider the fan */
#define AQUASTREAMULT_NUM_FANS 1
#define AQUASTREAMULT_NUM_SENSORS 2
/* Sensor report offsets for the Aquastream Ultimate pump */
#define AQUASTREAMULT_SENSOR_START 0x2D
#define AQUASTREAMULT_PUMP_OFFSET 0x51
#define AQUASTREAMULT_PUMP_VOLTAGE 0x3D
#define AQUASTREAMULT_PUMP_CURRENT 0x53
#define AQUASTREAMULT_PUMP_POWER 0x55
#define AQUASTREAMULT_FAN_OFFSET 0x41
#define AQUASTREAMULT_PRESSURE_OFFSET 0x57
#define AQUASTREAMULT_FLOW_SENSOR_OFFSET 0x37
#define AQUASTREAMULT_FAN_VOLTAGE_OFFSET 0x02
#define AQUASTREAMULT_FAN_CURRENT_OFFSET 0x00
#define AQUASTREAMULT_FAN_POWER_OFFSET 0x04
#define AQUASTREAMULT_FAN_SPEED_OFFSET 0x06
static u16 aquastreamult_sensor_fan_offsets[] = { AQUASTREAMULT_FAN_OFFSET };
/* Spec and sensor report offset for the Farbwerk RGB controller */
#define FARBWERK_NUM_SENSORS 4
#define FARBWERK_SENSOR_START 0x2f
/* Specs of the Farbwerk 360 RGB controller */
#define FARBWERK360_NUM_SENSORS 4
#define FARBWERK360_NUM_VIRTUAL_SENSORS 16
#define FARBWERK360_CTRL_REPORT_SIZE 0x682
/* Sensor report offsets for the Farbwerk 360 */
#define FARBWERK360_SENSOR_START 0x32
#define FARBWERK360_VIRTUAL_SENSORS_START 0x3a
/* Control report offsets for the Farbwerk 360 */
#define FARBWERK360_TEMP_CTRL_OFFSET 0x8
/* Specs of the Octo fan controller */
#define OCTO_NUM_FANS 8
#define OCTO_NUM_SENSORS 4
#define OCTO_NUM_VIRTUAL_SENSORS 16
#define OCTO_NUM_FLOW_SENSORS 1
#define OCTO_CTRL_REPORT_SIZE 0x65F
/* Sensor report offsets for the Octo */
#define OCTO_SENSOR_START 0x3D
#define OCTO_VIRTUAL_SENSORS_START 0x45
#define OCTO_FLOW_SENSOR_OFFSET 0x7B
static u16 octo_sensor_fan_offsets[] = { 0x7D, 0x8A, 0x97, 0xA4, 0xB1, 0xBE, 0xCB, 0xD8 };
/* Control report offsets for the Octo */
#define OCTO_TEMP_CTRL_OFFSET 0xA
#define OCTO_FLOW_PULSES_CTRL_OFFSET 0x6
/* Fan speed offsets (0-100%) */
static u16 octo_ctrl_fan_offsets[] = { 0x5A, 0xAF, 0x104, 0x159, 0x1AE, 0x203, 0x258, 0x2AD };
/* Fan curve "hold min power" and "start boost" offsets */
static u8 octo_ctrl_fan_curve_hold_start_offsets[] = {
0x12, 0x1B, 0x24, 0x2D, 0x36, 0x3F, 0x48, 0x51
};
static u8 octo_ctrl_fan_curve_min_power_offsets[] = {
0x13, 0x1C, 0x25, 0x2E, 0x37, 0x40, 0x49, 0x52
};
static u8 octo_ctrl_fan_curve_max_power_offsets[] = {
0x15, 0x1E, 0x27, 0x30, 0x39, 0x42, 0x4B, 0x54
};
static u8 octo_ctrl_fan_curve_fallback_power_offsets[] = {
0x17, 0x20, 0x29, 0x32, 0x3B, 0x44, 0x4D, 0x56
};
/* Specs of Quadro fan controller */
#define QUADRO_NUM_FANS 4
#define QUADRO_NUM_SENSORS 4
#define QUADRO_NUM_VIRTUAL_SENSORS 16
#define QUADRO_NUM_FLOW_SENSORS 1
#define QUADRO_CTRL_REPORT_SIZE 0x3c1
/* Sensor report offsets for the Quadro */
#define QUADRO_SENSOR_START 0x34
#define QUADRO_VIRTUAL_SENSORS_START 0x3c
#define QUADRO_FLOW_SENSOR_OFFSET 0x6e
static u16 quadro_sensor_fan_offsets[] = { 0x70, 0x7D, 0x8A, 0x97 };
/* Control report offsets for the Quadro */
#define QUADRO_TEMP_CTRL_OFFSET 0xA
#define QUADRO_FLOW_PULSES_CTRL_OFFSET 0x6
/* Fan speed offsets (0-100%) */
static u16 quadro_ctrl_fan_offsets[] = { 0x36, 0x8b, 0xe0, 0x135 };
/* Fan curve "hold min power" and "start boost" offsets */
static u8 quadro_ctrl_fan_curve_hold_start_offsets[] = { 0x12, 0x1B, 0x24, 0x2D };
static u8 quadro_ctrl_fan_curve_min_power_offsets[] = { 0x13, 0x1C, 0x25, 0x2E };
static u8 quadro_ctrl_fan_curve_max_power_offsets[] = { 0x15, 0x1E, 0x27, 0x30 };
static u8 quadro_ctrl_fan_curve_fallback_power_offsets[] = { 0x17, 0x20, 0x29, 0x32 };
/* Specs of High Flow Next flow sensor */
#define HIGHFLOWNEXT_NUM_SENSORS 2
#define HIGHFLOWNEXT_NUM_FLOW_SENSORS 1
/* Sensor report offsets for the High Flow Next */
#define HIGHFLOWNEXT_SENSOR_START 85
#define HIGHFLOWNEXT_FLOW 81
#define HIGHFLOWNEXT_WATER_QUALITY 89
#define HIGHFLOWNEXT_POWER 91
#define HIGHFLOWNEXT_CONDUCTIVITY 95
#define HIGHFLOWNEXT_5V_VOLTAGE 97
#define HIGHFLOWNEXT_5V_VOLTAGE_USB 99
/* Specs of the Leakshield */
#define LEAKSHIELD_NUM_SENSORS 2
#define LEAKSHIELD_USB_REPORT_LENGTH 49
#define LEAKSHIELD_USB_REPORT_ENDPOINT 2
/* Sensor report offsets for Leakshield */
#define LEAKSHIELD_PRESSURE_ADJUSTED 285
#define LEAKSHIELD_TEMPERATURE_1 265
#define LEAKSHIELD_TEMPERATURE_2 287
#define LEAKSHIELD_PRESSURE_MIN 291
#define LEAKSHIELD_PRESSURE_TARGET 293
#define LEAKSHIELD_PRESSURE_MAX 295
#define LEAKSHIELD_PUMP_RPM_IN 101
#define LEAKSHIELD_FLOW_IN 111
#define LEAKSHIELD_RESERVOIR_VOLUME 313
#define LEAKSHIELD_RESERVOIR_FILLED 311
/* USB control report offsets and info for Leakshield */
#define LEAKSHIELD_USB_REPORT_PUMP_RPM_OFFSET 1
#define LEAKSHIELD_USB_REPORT_FLOW_RPM_UNIT_OFFSET 33
#define LEAKSHIELD_USB_REPORT_FLOW_OFFSET 3
#define LEAKSHIELD_USB_REPORT_FLOW_UNIT_OFFSET 34
#define LEAKSHIELD_USB_REPORT_UNIT_RPM 0x03
#define LEAKSHIELD_USB_REPORT_UNIT_DL_PER_H 0x0C
/* USB bulk message to report pump RPM and flow rate for pressure calculations */
static u8 leakshield_usb_report_template[] = {
0x4, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff,
0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff,
0x7f, 0xff, 0x7f, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0
};
/* Specs of the Aquastream XT pump */
#define AQUASTREAMXT_SERIAL_START 0x3a
#define AQUASTREAMXT_FIRMWARE_VERSION 0x32
#define AQUASTREAMXT_NUM_FANS 2
#define AQUASTREAMXT_NUM_SENSORS 3
#define AQUASTREAMXT_FAN_STOPPED 0x4
#define AQUASTREAMXT_PUMP_CONVERSION_CONST 45000000
#define AQUASTREAMXT_FAN_CONVERSION_CONST 5646000
#define AQUASTREAMXT_PUMP_MIN_RPM 3000
#define AQUASTREAMXT_PUMP_MAX_RPM 6000
#define AQUASTREAMXT_SENSOR_REPORT_SIZE 0x42
#define AQUASTREAMXT_CTRL_REPORT_SIZE 0x34
/* Sensor report offsets and info for Aquastream XT */
#define AQUASTREAMXT_SENSOR_START 0xd
#define AQUASTREAMXT_FAN_VOLTAGE_OFFSET 0x7
#define AQUASTREAMXT_FAN_STATUS_OFFSET 0x1d
#define AQUASTREAMXT_PUMP_VOLTAGE_OFFSET 0x9
#define AQUASTREAMXT_PUMP_CURR_OFFSET 0xb
static u16 aquastreamxt_sensor_fan_offsets[] = { 0x13, 0x1b };
/* Control report offsets for Aquastream XT */
#define AQUASTREAMXT_PUMP_MODE_CTRL_OFFSET 0x3
#define AQUASTREAMXT_PUMP_MODE_CTRL_MANUAL 0x14
#define AQUASTREAMXT_FAN_MODE_CTRL_OFFSET 0x1a
#define AQUASTREAMXT_FAN_MODE_CTRL_MANUAL 0x1
static u16 aquastreamxt_ctrl_fan_offsets[] = { 0x8, 0x1b };
/* Specs of the Poweradjust 3 */
#define POWERADJUST3_SERIAL_START 0x27
#define POWERADJUST3_FIRMWARE_VERSION 0x21
#define POWERADJUST3_NUM_FANS 1
#define POWERADJUST3_NUM_SENSORS 2
#define POWERADJUST3_NUM_FLOW_SENSORS 1
#define POWERADJUST3_SENSOR_REPORT_SIZE 0x32
/* Sensor report offsets for the Poweradjust 3 */
#define POWERADJUST3_SENSOR_START 0x01
#define POWERADJUST3_FAN_CURR_OFFSET 0x05
#define POWERADJUST3_FAN_VOLTAGE_OFFSET 0x07
#define POWERADJUST3_FLOW_SENSOR_OFFSET 0x09
#define POWERADJUST3_FAN_SPEED_OFFSET 0x0b
/* Specs of the High Flow USB */
#define HIGHFLOW_NUM_SENSORS 2
#define HIGHFLOW_NUM_FLOW_SENSORS 1
#define HIGHFLOW_SENSOR_REPORT_SIZE 0x76
/* Sensor report offsets for the High Flow USB */
#define HIGHFLOW_FIRMWARE_VERSION 0x3
#define HIGHFLOW_SERIAL_START 0x9
#define HIGHFLOW_FLOW_SENSOR_OFFSET 0x23
#define HIGHFLOW_SENSOR_START 0x2b
/* Labels for D5 Next */
static const char *const label_d5next_temp[] = {
"Coolant temp"
};
static const char *const label_d5next_speeds[] = {
"Pump speed",
"Fan speed"
};
static const char *const label_d5next_power[] = {
"Pump power",
"Fan power"
};
static const char *const label_d5next_voltages[] = {
"Pump voltage",
"Fan voltage",
"+5V voltage",
"+12V voltage"
};
static const char *const label_d5next_current[] = {
"Pump current",
"Fan current"
};
/* Labels for Aquaero, Farbwerk, Farbwerk 360, Octo and Quadro temperature sensors */
static const char *const label_temp_sensors[] = {
"Sensor 1",
"Sensor 2",
"Sensor 3",
"Sensor 4",
"Sensor 5",
"Sensor 6",
"Sensor 7",
"Sensor 8"
};
static const char *const label_virtual_temp_sensors[] = {
"Virtual sensor 1",
"Virtual sensor 2",
"Virtual sensor 3",
"Virtual sensor 4",
"Virtual sensor 5",
"Virtual sensor 6",
"Virtual sensor 7",
"Virtual sensor 8",
"Virtual sensor 9",
"Virtual sensor 10",
"Virtual sensor 11",
"Virtual sensor 12",
"Virtual sensor 13",
"Virtual sensor 14",
"Virtual sensor 15",
"Virtual sensor 16",
};
static const char *const label_aquaero_calc_temp_sensors[] = {
"Calc. virtual sensor 1",
"Calc. virtual sensor 2",
"Calc. virtual sensor 3",
"Calc. virtual sensor 4"
};
static const char *const label_aquaero_aquabus_temp_sensors[] = {
"Aquabus sensor 1",
"Aquabus sensor 2",
"Aquabus sensor 3",
"Aquabus sensor 4",
"Aquabus sensor 5",
"Aquabus sensor 6",
"Aquabus sensor 7",
"Aquabus sensor 8",
"Aquabus sensor 9",
"Aquabus sensor 10",
"Aquabus sensor 11",
"Aquabus sensor 12",
"Aquabus sensor 13",
"Aquabus sensor 14",
"Aquabus sensor 15",
"Aquabus sensor 16",
"Aquabus sensor 17",
"Aquabus sensor 18",
"Aquabus sensor 19",
"Aquabus sensor 20"
};
static const char *const label_fan_power[] = {
"Fan 1 power",
"Fan 2 power",
"Fan 3 power",
"Fan 4 power",
"Fan 5 power",
"Fan 6 power",
"Fan 7 power",
"Fan 8 power"
};
static const char *const label_fan_voltage[] = {
"Fan 1 voltage",
"Fan 2 voltage",
"Fan 3 voltage",
"Fan 4 voltage",
"Fan 5 voltage",
"Fan 6 voltage",
"Fan 7 voltage",
"Fan 8 voltage"
};
static const char *const label_fan_current[] = {
"Fan 1 current",
"Fan 2 current",
"Fan 3 current",
"Fan 4 current",
"Fan 5 current",
"Fan 6 current",
"Fan 7 current",
"Fan 8 current"
};
/* Labels for Quadro fan speeds */
static const char *const label_quadro_speeds[] = {
"Fan 1 speed",
"Fan 2 speed",
"Fan 3 speed",
"Fan 4 speed",
"Flow speed [dL/h]"
};
/* Labels for Octo */
static const char *const label_octo_speeds[] = {
"Fan 1 speed",
"Fan 2 speed",
"Fan 3 speed",
"Fan 4 speed",
"Fan 5 speed",
"Fan 6 speed",
"Fan 7 speed",
"Fan 8 speed",
"Flow speed [dL/h]",
};
/* Labels for Aquaero fan speeds */
static const char *const label_aquaero_speeds[] = {
"Fan 1 speed",
"Fan 2 speed",
"Fan 3 speed",
"Fan 4 speed",
"Flow sensor 1 [dL/h]",
"Flow sensor 2 [dL/h]",
"Aquabus flow 1 [dL/h]",
"Aquabus flow 2 [dL/h]",
"Aquabus flow 3 [dL/h]",
"Aquabus flow 4 [dL/h]",
"Aquabus flow 5 [dL/h]",
"Aquabus flow 6 [dL/h]",
"Aquabus flow 7 [dL/h]",
"Aquabus flow 8 [dL/h]",
"Aquabus flow 9 [dL/h]",
"Aquabus flow 10 [dL/h]",
"Aquabus flow 11 [dL/h]",
"Aquabus flow 12 [dL/h]"
};
/* Labels for High Flow Next */
static const char *const label_highflownext_temp_sensors[] = {
"Coolant temp",
"External sensor"
};
static const char *const label_highflownext_fan_speed[] = {
"Flow [dL/h]",
"Water quality [%]",
"Conductivity [nS/cm]",
};
static const char *const label_highflownext_power[] = {
"Dissipated power",
};
static const char *const label_highflownext_voltage[] = {
"+5V voltage",
"+5V USB voltage"
};
/* Labels for Leakshield */
static const char *const label_leakshield_temp_sensors[] = {
"Temperature 1",
"Temperature 2"
};
static const char *const label_leakshield_fan_speed[] = {
"Pressure [ubar]",
"User-Provided Pump Speed",
"User-Provided Flow [dL/h]",
"Reservoir Volume [ml]",
"Reservoir Filled [ml]",
};
/* Labels for Aquastream XT */
static const char *const label_aquastreamxt_temp_sensors[] = {
"Fan IC temp",
"External sensor",
"Coolant temp"
};
/* Labels for Aquastream Ultimate */
static const char *const label_aquastreamult_temp[] = {
"Coolant temp",
"External temp"
};
static const char *const label_aquastreamult_speeds[] = {
"Fan speed",
"Pump speed",
"Pressure [mbar]",
"Flow speed [dL/h]"
};
static const char *const label_aquastreamult_power[] = {
"Fan power",
"Pump power"
};
static const char *const label_aquastreamult_voltages[] = {
"Fan voltage",
"Pump voltage"
};
static const char *const label_aquastreamult_current[] = {
"Fan current",
"Pump current"
};
/* Labels for Poweradjust 3 */
static const char *const label_poweradjust3_temp_sensors[] = {
"Fan IC temp",
"External sensor"
};
static const char *const label_poweradjust3_speeds[] = {
"Fan speed",
"Flow speed [dL/h]"
};
static const char *const label_poweradjust3_voltages[] = {
"Fan voltage"
};
static const char *const label_poweradjust3_current[] = {
"Fan current"
};
/* Labels for Highflow */
static const char *const label_highflow_temp[] = {
"External temp",
"Internal temp"
};
static const char *const label_highflow_speeds[] = {
"Flow speed [dL/h]"
};
struct aqc_fan_structure_offsets {
u8 voltage;
u8 curr;
u8 power;
u8 speed;
};
/* Fan structure offsets for Aquaero */
static struct aqc_fan_structure_offsets aqc_aquaero_fan_structure = {
.voltage = AQUAERO_FAN_VOLTAGE_OFFSET,
.curr = AQUAERO_FAN_CURRENT_OFFSET,
.power = AQUAERO_FAN_POWER_OFFSET,
.speed = AQUAERO_FAN_SPEED_OFFSET
};
/* Fan structure offsets for Aquastream Ultimate */
static struct aqc_fan_structure_offsets aqc_aquastreamult_fan_structure = {
.voltage = AQUASTREAMULT_FAN_VOLTAGE_OFFSET,
.curr = AQUASTREAMULT_FAN_CURRENT_OFFSET,
.power = AQUASTREAMULT_FAN_POWER_OFFSET,
.speed = AQUASTREAMULT_FAN_SPEED_OFFSET
};
/* Fan structure offsets for all devices except those above */
static struct aqc_fan_structure_offsets aqc_general_fan_structure = {
.voltage = AQC_FAN_VOLTAGE_OFFSET,
.curr = AQC_FAN_CURRENT_OFFSET,
.power = AQC_FAN_POWER_OFFSET,
.speed = AQC_FAN_SPEED_OFFSET
};
struct aqc_data {
struct hid_device *hdev;
struct device *hwmon_dev;
struct dentry *debugfs;
struct mutex mutex; /* Used for locking access when reading and writing PWM values */
enum kinds kind;
const char *name;
const struct attribute_group *groups[8]; /* For max 8 fans */
int status_report_id; /* Used for legacy devices, report is stored in buffer */
int ctrl_report_id;
int secondary_ctrl_report_id;
int secondary_ctrl_report_size;
u8 *secondary_ctrl_report;
ktime_t last_ctrl_report_op;
int ctrl_report_delay; /* Delay between two ctrl report operations, in ms */
int buffer_size;
/*
* Used for writing reports (where supported) and reading
* sensor reports on legacy devices
*/
u8 *buffer;
int checksum_start;
int checksum_length;
int checksum_offset;
int num_fans;
u16 *fan_sensor_offsets;
u16 *fan_ctrl_offsets;
int num_temp_sensors;
int temp_sensor_start_offset;
int num_virtual_temp_sensors;
int virtual_temp_sensor_start_offset;
int num_calc_virt_temp_sensors;
int calc_virt_temp_sensor_start_offset;
int num_aquabus_temp_sensors;
int aquabus_temp_sensor_start_offset;
u16 temp_ctrl_offset;
u16 power_cycle_count_offset;
int num_flow_sensors;
u8 flow_sensors_start_offset;
int num_aquabus_flow_sensors;
u8 aquabus_flow_sensors_start_offset;
u8 flow_pulses_ctrl_offset;
struct aqc_fan_structure_offsets *fan_structure;
u8 *fan_curve_min_power_offsets;
u8 *fan_curve_max_power_offsets;
/* Used for both "hold min power" and "start boost" parameters */
u8 *fan_curve_hold_start_offsets;
u8 *fan_curve_fallback_power_offsets;
/* For differentiating between Aquaero 5 and 6 */
enum aquaero_hw_kinds aquaero_hw_kind;
int aquaero_hw_version;
/* Completion for tracking if hardware version was received */
struct completion aquaero_sensor_report_received;
/* General info, available across all devices */
u8 serial_number_start_offset;
u32 serial_number[2];
u8 firmware_version_offset;
u16 firmware_version;
/* How many times the device was powered on */
u32 power_cycles;
/* Aquaero only, in seconds */
u32 current_uptime;
u32 total_uptime;
/*
* Sensor values. temp_input has a maximum of 4 physical + 16 virtual + 20 aquabus,
* or 8 physical + 12 virtual + 20 aquabus sensors, depending on the device
*/
s32 temp_input[40];
s32 speed_input[20]; /* Max 8 physical + 12 aquabus */
u32 speed_input_min[20];
u32 speed_input_target[1];
u32 speed_input_max[20];
u32 power_input[8];
u16 voltage_input[8];
u16 current_input[8];
/* Label values */
const char *const *temp_label;
const char *const *virtual_temp_label;
const char *const *calc_virtual_temp_label; /* For Aquaero */
const char *const *aquabus_temp_label; /* For Aquaero */
const char *const *speed_label;
const char *const *power_label;
const char *const *voltage_label;
const char *const *current_label;
unsigned long updated;
};
/* Converts from centi-percent */
static int aqc_percent_to_pwm(u16 val)
{
return DIV_ROUND_CLOSEST(val * 255, 100 * 100);
}
/* Converts to centi-percent */
static int aqc_pwm_to_percent(long val)
{
return DIV_ROUND_CLOSEST(val * 100 * 100, 255);
}
/* Gets bit value on given position in an int */
static int aqc_get_bit_at_pos(int val, int pos)
{
return (val >> pos) & 1;
}
/* Sets bit value on given position in an int */
static int aqc_set_bit_at_pos(int val, int pos, int bit_value)
{
return (val & ~(1 << pos)) | (bit_value << pos);
}
/* Converts RPM to Aquastream XT PWM representation */
static int aqc_aquastreamxt_rpm_to_pwm(long val)
{
return DIV_ROUND_CLOSEST((val - AQUASTREAMXT_PUMP_MIN_RPM) * 255,
AQUASTREAMXT_PUMP_MAX_RPM - AQUASTREAMXT_PUMP_MIN_RPM);
}
/* Converts to RPM between 3000 and 6000, where the output is a multiple of 60 */
static int aqc_aquastreamxt_pwm_to_rpm(long val)
{
return DIV_ROUND_CLOSEST(val * 50, 255) * 60 + AQUASTREAMXT_PUMP_MIN_RPM;
}
/* Converts raw value for Aquastream XT pump speed to RPM */
static int aqc_aquastreamxt_convert_pump_rpm(u16 val)
{
if (val > 0)
return DIV_ROUND_CLOSEST(AQUASTREAMXT_PUMP_CONVERSION_CONST, val);
return 0;
}
/* Converts raw value for Aquastream XT fan speed to RPM */
static int aqc_aquastreamxt_convert_fan_rpm(u16 val)
{
if (val > 0)
return DIV_ROUND_CLOSEST(AQUASTREAMXT_FAN_CONVERSION_CONST, val);
return 0;
}
static void aqc_delay_ctrl_report(struct aqc_data *priv)
{
/*
* If previous read or write is too close to this one, delay the current operation
* to give the device enough time to process the previous one.
*/
if (priv->ctrl_report_delay) {
s64 delta = ktime_ms_delta(ktime_get(), priv->last_ctrl_report_op);
if (delta < priv->ctrl_report_delay)
msleep(priv->ctrl_report_delay - delta);
}
}
/* Expects the mutex to be locked */
static int aqc_get_ctrl_data(struct aqc_data *priv)
{
int ret;
aqc_delay_ctrl_report(priv);
memset(priv->buffer, 0x00, priv->buffer_size);
ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size,
HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
if (ret < 0)
ret = -ENODATA;
priv->last_ctrl_report_op = ktime_get();
return ret;
}
/* Expects the mutex to be locked */
static int aqc_send_ctrl_data(struct aqc_data *priv)
{
int ret;
u16 checksum;
aqc_delay_ctrl_report(priv);
/* Checksum is not needed for Aquaero and Aquastream XT */
if (priv->kind != aquaero && priv->kind != aquastreamxt) {
/* Init and xorout value for CRC-16/USB is 0xffff */
checksum =
crc16(0xffff, priv->buffer + priv->checksum_start, priv->checksum_length);
checksum ^= 0xffff;
/* Place the new checksum at the end of the report */
put_unaligned_be16(checksum, priv->buffer + priv->checksum_offset);
}
/* Send the patched up report back to the device */
ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size,
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
if (ret < 0)
goto record_access_and_ret;
/* The official software sends this report after every change, so do it here as well */
ret =
hid_hw_raw_request(priv->hdev, priv->secondary_ctrl_report_id,
priv->secondary_ctrl_report, priv->secondary_ctrl_report_size,
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
record_access_and_ret:
priv->last_ctrl_report_op = ktime_get();
return ret;
}
/* Refreshes the control buffer and stores value at offset in val */
static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val, int type)
{
int ret;
mutex_lock(&priv->mutex);
ret = aqc_get_ctrl_data(priv);
if (ret < 0)
goto unlock_and_return;
switch (type) {
case AQC_LE16:
*val = (s16)get_unaligned_le16(priv->buffer + offset);
break;
case AQC_BE16:
*val = (s16)get_unaligned_be16(priv->buffer + offset);
break;
case AQC_8:
*val = priv->buffer[offset];
break;
default:
ret = -EINVAL;
break;
}
unlock_and_return:
mutex_unlock(&priv->mutex);
return ret;
}
static int aqc_set_buffer_val(u8 *buffer, int offset, long val, int type)
{
switch (type) {
case AQC_LE16:
put_unaligned_le16((u16)val, buffer + offset);
return 0;
case AQC_BE16:
put_unaligned_be16((u16)val, buffer + offset);
return 0;
case AQC_8:
buffer[offset] = (u8)val;
return 0;
default:
return -EINVAL;
}
}
/* Refreshes the control buffer, updates values at offsets and writes buffer to device */
static int aqc_set_ctrl_vals(struct aqc_data *priv, int *offsets, long *values, int *types, int len)
{
int ret, i;
mutex_lock(&priv->mutex);
ret = aqc_get_ctrl_data(priv);
if (ret < 0)
goto unlock_and_return;
for (i = 0; i < len; i++) {
ret = aqc_set_buffer_val(priv->buffer, offsets[i], values[i], types[i]);
if (ret < 0)
goto unlock_and_return;
}
ret = aqc_send_ctrl_data(priv);
unlock_and_return:
mutex_unlock(&priv->mutex);
return ret;
}
/* Refreshes the control buffer, updates value at offset and writes buffer to device */
static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int type)
{
return aqc_set_ctrl_vals(priv, &offset, &val, &type, 1);
}
static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel)
{
const struct aqc_data *priv = data;