Skip to content

Commit 5512c33

Browse files
committed
Merge tag 'hwmon-for-v6.5-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck: - Fix sporadic comunication errors in pmbus/bel-pfe and aquacomputer_d5next drivers * tag 'hwmon-for-v6.5-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (aquacomputer_d5next) Add selective 200ms delay after sending ctrl report hwmon: (pmbus/bel-pfe) Enable PMBUS_SKIP_STATUS_CHECK for pfe1100
2 parents 190bf7b + 56b930d commit 5512c33

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

drivers/hwmon/aquacomputer_d5next.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
#include <linux/crc16.h>
1515
#include <linux/debugfs.h>
16+
#include <linux/delay.h>
1617
#include <linux/hid.h>
1718
#include <linux/hwmon.h>
1819
#include <linux/jiffies.h>
20+
#include <linux/ktime.h>
1921
#include <linux/module.h>
2022
#include <linux/mutex.h>
2123
#include <linux/seq_file.h>
@@ -63,6 +65,8 @@ static const char *const aqc_device_names[] = {
6365
#define CTRL_REPORT_ID 0x03
6466
#define AQUAERO_CTRL_REPORT_ID 0x0b
6567

68+
#define CTRL_REPORT_DELAY 200 /* ms */
69+
6670
/* The HID report that the official software always sends
6771
* after writing values, currently same for all devices
6872
*/
@@ -527,6 +531,9 @@ struct aqc_data {
527531
int secondary_ctrl_report_size;
528532
u8 *secondary_ctrl_report;
529533

534+
ktime_t last_ctrl_report_op;
535+
int ctrl_report_delay; /* Delay between two ctrl report operations, in ms */
536+
530537
int buffer_size;
531538
u8 *buffer;
532539
int checksum_start;
@@ -611,17 +618,35 @@ static int aqc_aquastreamxt_convert_fan_rpm(u16 val)
611618
return 0;
612619
}
613620

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+
614635
/* Expects the mutex to be locked */
615636
static int aqc_get_ctrl_data(struct aqc_data *priv)
616637
{
617638
int ret;
618639

640+
aqc_delay_ctrl_report(priv);
641+
619642
memset(priv->buffer, 0x00, priv->buffer_size);
620643
ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size,
621644
HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
622645
if (ret < 0)
623646
ret = -ENODATA;
624647

648+
priv->last_ctrl_report_op = ktime_get();
649+
625650
return ret;
626651
}
627652

@@ -631,6 +656,8 @@ static int aqc_send_ctrl_data(struct aqc_data *priv)
631656
int ret;
632657
u16 checksum;
633658

659+
aqc_delay_ctrl_report(priv);
660+
634661
/* Checksum is not needed for Aquaero */
635662
if (priv->kind != aquaero) {
636663
/* Init and xorout value for CRC-16/USB is 0xffff */
@@ -646,12 +673,16 @@ static int aqc_send_ctrl_data(struct aqc_data *priv)
646673
ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size,
647674
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
648675
if (ret < 0)
649-
return ret;
676+
goto record_access_and_ret;
650677

651678
/* The official software sends this report after every change, so do it here as well */
652679
ret = hid_hw_raw_request(priv->hdev, priv->secondary_ctrl_report_id,
653680
priv->secondary_ctrl_report, priv->secondary_ctrl_report_size,
654681
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
682+
683+
record_access_and_ret:
684+
priv->last_ctrl_report_op = ktime_get();
685+
655686
return ret;
656687
}
657688

@@ -1524,6 +1555,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
15241555

15251556
priv->buffer_size = AQUAERO_CTRL_REPORT_SIZE;
15261557
priv->temp_ctrl_offset = AQUAERO_TEMP_CTRL_OFFSET;
1558+
priv->ctrl_report_delay = CTRL_REPORT_DELAY;
15271559

15281560
priv->temp_label = label_temp_sensors;
15291561
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)
15471579
priv->temp_ctrl_offset = D5NEXT_TEMP_CTRL_OFFSET;
15481580

15491581
priv->buffer_size = D5NEXT_CTRL_REPORT_SIZE;
1582+
priv->ctrl_report_delay = CTRL_REPORT_DELAY;
15501583

15511584
priv->power_cycle_count_offset = D5NEXT_POWER_CYCLES;
15521585

@@ -1597,6 +1630,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
15971630
priv->temp_ctrl_offset = OCTO_TEMP_CTRL_OFFSET;
15981631

15991632
priv->buffer_size = OCTO_CTRL_REPORT_SIZE;
1633+
priv->ctrl_report_delay = CTRL_REPORT_DELAY;
16001634

16011635
priv->power_cycle_count_offset = OCTO_POWER_CYCLES;
16021636

@@ -1624,6 +1658,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
16241658
priv->temp_ctrl_offset = QUADRO_TEMP_CTRL_OFFSET;
16251659

16261660
priv->buffer_size = QUADRO_CTRL_REPORT_SIZE;
1661+
priv->ctrl_report_delay = CTRL_REPORT_DELAY;
16271662

16281663
priv->flow_pulses_ctrl_offset = QUADRO_FLOW_PULSES_CTRL_OFFSET;
16291664
priv->power_cycle_count_offset = QUADRO_POWER_CYCLES;

drivers/hwmon/pmbus/bel-pfe.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
enum chips {pfe1100, pfe3000};
1818

1919
/*
20-
* Disable status check for pfe3000 devices, because some devices report
21-
* communication error (invalid command) for VOUT_MODE command (0x20)
22-
* although correct VOUT_MODE (0x16) is returned: it leads to incorrect
23-
* exponent in linear mode.
20+
* Disable status check because some devices report communication error
21+
* (invalid command) for VOUT_MODE command (0x20) although the correct
22+
* VOUT_MODE (0x16) is returned: it leads to incorrect exponent in linear
23+
* mode.
24+
* This affects both pfe3000 and pfe1100.
2425
*/
25-
static struct pmbus_platform_data pfe3000_plat_data = {
26+
static struct pmbus_platform_data pfe_plat_data = {
2627
.flags = PMBUS_SKIP_STATUS_CHECK,
2728
};
2829

@@ -94,16 +95,15 @@ static int pfe_pmbus_probe(struct i2c_client *client)
9495
int model;
9596

9697
model = (int)i2c_match_id(pfe_device_id, client)->driver_data;
98+
client->dev.platform_data = &pfe_plat_data;
9799

98100
/*
99101
* PFE3000-12-069RA devices may not stay in page 0 during device
100102
* probe which leads to probe failure (read status word failed).
101103
* So let's set the device to page 0 at the beginning.
102104
*/
103-
if (model == pfe3000) {
104-
client->dev.platform_data = &pfe3000_plat_data;
105+
if (model == pfe3000)
105106
i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
106-
}
107107

108108
return pmbus_do_probe(client, &pfe_driver_info[model]);
109109
}

0 commit comments

Comments
 (0)