13
13
14
14
#include <linux/crc16.h>
15
15
#include <linux/debugfs.h>
16
+ #include <linux/delay.h>
16
17
#include <linux/hid.h>
17
18
#include <linux/hwmon.h>
18
19
#include <linux/jiffies.h>
20
+ #include <linux/ktime.h>
19
21
#include <linux/module.h>
20
22
#include <linux/mutex.h>
21
23
#include <linux/seq_file.h>
@@ -63,6 +65,8 @@ static const char *const aqc_device_names[] = {
63
65
#define CTRL_REPORT_ID 0x03
64
66
#define AQUAERO_CTRL_REPORT_ID 0x0b
65
67
68
+ #define CTRL_REPORT_DELAY 200 /* ms */
69
+
66
70
/* The HID report that the official software always sends
67
71
* after writing values, currently same for all devices
68
72
*/
@@ -527,6 +531,9 @@ struct aqc_data {
527
531
int secondary_ctrl_report_size ;
528
532
u8 * secondary_ctrl_report ;
529
533
534
+ ktime_t last_ctrl_report_op ;
535
+ int ctrl_report_delay ; /* Delay between two ctrl report operations, in ms */
536
+
530
537
int buffer_size ;
531
538
u8 * buffer ;
532
539
int checksum_start ;
@@ -611,17 +618,35 @@ static int aqc_aquastreamxt_convert_fan_rpm(u16 val)
611
618
return 0 ;
612
619
}
613
620
621
+ static void aqc_delay_ctrl_report (struct aqc_data * priv )
622
+ {
623
+ /*
624
+ * If previous read or write is too close to this one, delay the current operation
625
+ * to give the device enough time to process the previous one.
626
+ */
627
+ if (priv -> ctrl_report_delay ) {
628
+ s64 delta = ktime_ms_delta (ktime_get (), priv -> last_ctrl_report_op );
629
+
630
+ if (delta < priv -> ctrl_report_delay )
631
+ msleep (priv -> ctrl_report_delay - delta );
632
+ }
633
+ }
634
+
614
635
/* Expects the mutex to be locked */
615
636
static int aqc_get_ctrl_data (struct aqc_data * priv )
616
637
{
617
638
int ret ;
618
639
640
+ aqc_delay_ctrl_report (priv );
641
+
619
642
memset (priv -> buffer , 0x00 , priv -> buffer_size );
620
643
ret = hid_hw_raw_request (priv -> hdev , priv -> ctrl_report_id , priv -> buffer , priv -> buffer_size ,
621
644
HID_FEATURE_REPORT , HID_REQ_GET_REPORT );
622
645
if (ret < 0 )
623
646
ret = - ENODATA ;
624
647
648
+ priv -> last_ctrl_report_op = ktime_get ();
649
+
625
650
return ret ;
626
651
}
627
652
@@ -631,6 +656,8 @@ static int aqc_send_ctrl_data(struct aqc_data *priv)
631
656
int ret ;
632
657
u16 checksum ;
633
658
659
+ aqc_delay_ctrl_report (priv );
660
+
634
661
/* Checksum is not needed for Aquaero */
635
662
if (priv -> kind != aquaero ) {
636
663
/* Init and xorout value for CRC-16/USB is 0xffff */
@@ -646,12 +673,16 @@ static int aqc_send_ctrl_data(struct aqc_data *priv)
646
673
ret = hid_hw_raw_request (priv -> hdev , priv -> ctrl_report_id , priv -> buffer , priv -> buffer_size ,
647
674
HID_FEATURE_REPORT , HID_REQ_SET_REPORT );
648
675
if (ret < 0 )
649
- return ret ;
676
+ goto record_access_and_ret ;
650
677
651
678
/* The official software sends this report after every change, so do it here as well */
652
679
ret = hid_hw_raw_request (priv -> hdev , priv -> secondary_ctrl_report_id ,
653
680
priv -> secondary_ctrl_report , priv -> secondary_ctrl_report_size ,
654
681
HID_FEATURE_REPORT , HID_REQ_SET_REPORT );
682
+
683
+ record_access_and_ret :
684
+ priv -> last_ctrl_report_op = ktime_get ();
685
+
655
686
return ret ;
656
687
}
657
688
@@ -1524,6 +1555,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
1524
1555
1525
1556
priv -> buffer_size = AQUAERO_CTRL_REPORT_SIZE ;
1526
1557
priv -> temp_ctrl_offset = AQUAERO_TEMP_CTRL_OFFSET ;
1558
+ priv -> ctrl_report_delay = CTRL_REPORT_DELAY ;
1527
1559
1528
1560
priv -> temp_label = label_temp_sensors ;
1529
1561
priv -> virtual_temp_label = label_virtual_temp_sensors ;
@@ -1547,6 +1579,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
1547
1579
priv -> temp_ctrl_offset = D5NEXT_TEMP_CTRL_OFFSET ;
1548
1580
1549
1581
priv -> buffer_size = D5NEXT_CTRL_REPORT_SIZE ;
1582
+ priv -> ctrl_report_delay = CTRL_REPORT_DELAY ;
1550
1583
1551
1584
priv -> power_cycle_count_offset = D5NEXT_POWER_CYCLES ;
1552
1585
@@ -1597,6 +1630,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
1597
1630
priv -> temp_ctrl_offset = OCTO_TEMP_CTRL_OFFSET ;
1598
1631
1599
1632
priv -> buffer_size = OCTO_CTRL_REPORT_SIZE ;
1633
+ priv -> ctrl_report_delay = CTRL_REPORT_DELAY ;
1600
1634
1601
1635
priv -> power_cycle_count_offset = OCTO_POWER_CYCLES ;
1602
1636
@@ -1624,6 +1658,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
1624
1658
priv -> temp_ctrl_offset = QUADRO_TEMP_CTRL_OFFSET ;
1625
1659
1626
1660
priv -> buffer_size = QUADRO_CTRL_REPORT_SIZE ;
1661
+ priv -> ctrl_report_delay = CTRL_REPORT_DELAY ;
1627
1662
1628
1663
priv -> flow_pulses_ctrl_offset = QUADRO_FLOW_PULSES_CTRL_OFFSET ;
1629
1664
priv -> power_cycle_count_offset = QUADRO_POWER_CYCLES ;
0 commit comments