1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * corsair-psu.c - Linux driver for Corsair power supplies with HID sensors interface
4 * Copyright (C) 2020 Wilken Gottwalt <wilken.gottwalt@posteo.net>
7 #include <linux/completion.h>
8 #include <linux/debugfs.h>
9 #include <linux/errno.h>
10 #include <linux/hid.h>
11 #include <linux/hwmon.h>
12 #include <linux/hwmon-sysfs.h>
13 #include <linux/jiffies.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/mutex.h>
17 #include <linux/slab.h>
18 #include <linux/types.h>
21 * Corsair protocol for PSUs
23 * message size = 64 bytes (request and response, little endian)
25 * [length][command][param0][param1][paramX]...
27 * [echo of length][echo of command][data0][data1][dataX]...
29 * - commands are byte sized opcodes
30 * - length is the sum of all bytes of the commands/params
31 * - the micro-controller of most of these PSUs support concatenation in the request and reply,
32 * but it is better to not rely on this (it is also hard to parse)
33 * - the driver uses raw events to be accessible from userspace (though this is not really
34 * supported, it is just there for convenience, may be removed in the future)
35 * - a reply always starts with the length and command in the same order the request used it
36 * - length of the reply data is specific to the command used
37 * - some of the commands work on a rail and can be switched to a specific rail (0 = 12v,
39 * - the format of the init command 0xFE is swapped length/command bytes
40 * - parameter bytes amount and values are specific to the command (rail setting is the only
41 * one for now that uses non-zero values)
42 * - the driver supports debugfs for values not fitting into the hwmon class
43 * - not every device class (HXi or RMi) supports all commands
44 * - if configured wrong the PSU resets or shuts down, often before actually hitting the
45 * - reported critical temperature
48 #define DRIVER_NAME "corsair-psu"
50 #define REPLY_SIZE 16 /* max length of a reply to a single command */
51 #define CMD_BUFFER_SIZE 64
52 #define CMD_TIMEOUT_MS 250
53 #define SECONDS_PER_HOUR (60 * 60)
54 #define SECONDS_PER_DAY (SECONDS_PER_HOUR * 24)
55 #define RAIL_COUNT 3 /* 3v3 + 5v + 12v */
57 #define OCP_MULTI_RAIL 0x02
59 #define PSU_CMD_SELECT_RAIL 0x00 /* expects length 2 */
60 #define PSU_CMD_FAN_PWM 0x3B /* the rest of the commands expect length 3 */
61 #define PSU_CMD_RAIL_VOLTS_HCRIT 0x40
62 #define PSU_CMD_RAIL_VOLTS_LCRIT 0x44
63 #define PSU_CMD_RAIL_AMPS_HCRIT 0x46
64 #define PSU_CMD_TEMP_HCRIT 0x4F
65 #define PSU_CMD_IN_VOLTS 0x88
66 #define PSU_CMD_IN_AMPS 0x89
67 #define PSU_CMD_RAIL_VOLTS 0x8B
68 #define PSU_CMD_RAIL_AMPS 0x8C
69 #define PSU_CMD_TEMP0 0x8D
70 #define PSU_CMD_TEMP1 0x8E
71 #define PSU_CMD_FAN 0x90
72 #define PSU_CMD_RAIL_WATTS 0x96
73 #define PSU_CMD_VEND_STR 0x99
74 #define PSU_CMD_PROD_STR 0x9A
75 #define PSU_CMD_TOTAL_UPTIME 0xD1
76 #define PSU_CMD_UPTIME 0xD2
77 #define PSU_CMD_OCPMODE 0xD8
78 #define PSU_CMD_TOTAL_WATTS 0xEE
79 #define PSU_CMD_FAN_PWM_ENABLE 0xF0
80 #define PSU_CMD_INIT 0xFE
82 #define L_IN_VOLTS "v_in"
83 #define L_OUT_VOLTS_12V "v_out +12v"
84 #define L_OUT_VOLTS_5V "v_out +5v"
85 #define L_OUT_VOLTS_3_3V "v_out +3.3v"
86 #define L_IN_AMPS "curr in"
87 #define L_AMPS_12V "curr +12v"
88 #define L_AMPS_5V "curr +5v"
89 #define L_AMPS_3_3V "curr +3.3v"
90 #define L_FAN "psu fan"
91 #define L_TEMP0 "vrm temp"
92 #define L_TEMP1 "case temp"
93 #define L_WATTS "power total"
94 #define L_WATTS_12V "power +12v"
95 #define L_WATTS_5V "power +5v"
96 #define L_WATTS_3_3V "power +3.3v"
98 static const char *const label_watts[] = {
105 static const char *const label_volts[] = {
112 static const char *const label_amps[] = {
119 struct corsairpsu_data {
120 struct hid_device *hdev;
121 struct device *hwmon_dev;
122 struct dentry *debugfs;
123 struct completion wait_completion;
124 struct mutex lock; /* for locking access to cmd_buffer */
126 char vendor[REPLY_SIZE];
127 char product[REPLY_SIZE];
128 long temp_crit[TEMP_COUNT];
129 long in_crit[RAIL_COUNT];
130 long in_lcrit[RAIL_COUNT];
131 long curr_crit[RAIL_COUNT];
132 u8 temp_crit_support;
135 u8 curr_crit_support;
136 bool in_curr_cmd_support; /* not all commands are supported on every PSU */
139 /* some values are SMBus LINEAR11 data which need a conversion */
140 static int corsairpsu_linear11_to_int(const u16 val, const int scale)
142 const int exp = ((s16)val) >> 11;
143 const int mant = (((s16)(val & 0x7ff)) << 5) >> 5;
144 const int result = mant * scale;
146 return (exp >= 0) ? (result << exp) : (result >> -exp);
149 /* the micro-controller uses percentage values to control pwm */
150 static int corsairpsu_dutycycle_to_pwm(const long dutycycle)
152 const int result = (256 << 16) / 100;
154 return (result * dutycycle) >> 16;
157 static int corsairpsu_usb_cmd(struct corsairpsu_data *priv, u8 p0, u8 p1, u8 p2, void *data)
162 memset(priv->cmd_buffer, 0, CMD_BUFFER_SIZE);
163 priv->cmd_buffer[0] = p0;
164 priv->cmd_buffer[1] = p1;
165 priv->cmd_buffer[2] = p2;
167 reinit_completion(&priv->wait_completion);
169 ret = hid_hw_output_report(priv->hdev, priv->cmd_buffer, CMD_BUFFER_SIZE);
173 time = wait_for_completion_timeout(&priv->wait_completion,
174 msecs_to_jiffies(CMD_TIMEOUT_MS));
179 * at the start of the reply is an echo of the send command/length in the same order it
180 * was send, not every command is supported on every device class, if a command is not
181 * supported, the length value in the reply is okay, but the command value is set to 0
183 if (p0 != priv->cmd_buffer[0] || p1 != priv->cmd_buffer[1])
187 memcpy(data, priv->cmd_buffer + 2, REPLY_SIZE);
192 static int corsairpsu_init(struct corsairpsu_data *priv)
195 * PSU_CMD_INIT uses swapped length/command and expects 2 parameter bytes, this command
196 * actually generates a reply, but we don't need it
198 return corsairpsu_usb_cmd(priv, PSU_CMD_INIT, 3, 0, NULL);
201 static int corsairpsu_fwinfo(struct corsairpsu_data *priv)
205 ret = corsairpsu_usb_cmd(priv, 3, PSU_CMD_VEND_STR, 0, priv->vendor);
209 ret = corsairpsu_usb_cmd(priv, 3, PSU_CMD_PROD_STR, 0, priv->product);
216 static int corsairpsu_request(struct corsairpsu_data *priv, u8 cmd, u8 rail, void *data)
220 mutex_lock(&priv->lock);
222 case PSU_CMD_RAIL_VOLTS_HCRIT:
223 case PSU_CMD_RAIL_VOLTS_LCRIT:
224 case PSU_CMD_RAIL_AMPS_HCRIT:
225 case PSU_CMD_RAIL_VOLTS:
226 case PSU_CMD_RAIL_AMPS:
227 case PSU_CMD_RAIL_WATTS:
228 ret = corsairpsu_usb_cmd(priv, 2, PSU_CMD_SELECT_RAIL, rail, NULL);
236 ret = corsairpsu_usb_cmd(priv, 3, cmd, 0, data);
239 mutex_unlock(&priv->lock);
243 static int corsairpsu_get_value(struct corsairpsu_data *priv, u8 cmd, u8 rail, long *val)
249 ret = corsairpsu_request(priv, cmd, rail, data);
254 * the biggest value here comes from the uptime command and to exceed MAXINT total uptime
255 * needs to be about 68 years, the rest are u16 values and the biggest value coming out of
256 * the LINEAR11 conversion are the watts values which are about 1500 for the strongest psu
257 * supported (HX1500i)
259 tmp = ((long)data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0];
261 case PSU_CMD_RAIL_VOLTS_HCRIT:
262 case PSU_CMD_RAIL_VOLTS_LCRIT:
263 case PSU_CMD_RAIL_AMPS_HCRIT:
264 case PSU_CMD_TEMP_HCRIT:
265 case PSU_CMD_IN_VOLTS:
266 case PSU_CMD_IN_AMPS:
267 case PSU_CMD_RAIL_VOLTS:
268 case PSU_CMD_RAIL_AMPS:
271 *val = corsairpsu_linear11_to_int(tmp & 0xFFFF, 1000);
274 *val = corsairpsu_linear11_to_int(tmp & 0xFFFF, 1);
276 case PSU_CMD_FAN_PWM_ENABLE:
277 *val = corsairpsu_linear11_to_int(tmp & 0xFFFF, 1);
279 * 0 = automatic mode, means the micro-controller controls the fan using a plan
280 * which can be modified, but changing this plan is not supported by this
281 * driver, the matching PWM mode is automatic fan speed control = PWM 2
282 * 1 = fixed mode, fan runs at a fixed speed represented by a percentage
283 * value 0-100, this matches the PWM manual fan speed control = PWM 1
284 * technically there is no PWM no fan speed control mode, it would be a combination
290 case PSU_CMD_FAN_PWM:
291 *val = corsairpsu_linear11_to_int(tmp & 0xFFFF, 1);
292 *val = corsairpsu_dutycycle_to_pwm(*val);
294 case PSU_CMD_RAIL_WATTS:
295 case PSU_CMD_TOTAL_WATTS:
296 *val = corsairpsu_linear11_to_int(tmp & 0xFFFF, 1000000);
298 case PSU_CMD_TOTAL_UPTIME:
300 case PSU_CMD_OCPMODE:
311 static void corsairpsu_get_criticals(struct corsairpsu_data *priv)
316 for (rail = 0; rail < TEMP_COUNT; ++rail) {
317 if (!corsairpsu_get_value(priv, PSU_CMD_TEMP_HCRIT, rail, &tmp)) {
318 priv->temp_crit_support |= BIT(rail);
319 priv->temp_crit[rail] = tmp;
323 for (rail = 0; rail < RAIL_COUNT; ++rail) {
324 if (!corsairpsu_get_value(priv, PSU_CMD_RAIL_VOLTS_HCRIT, rail, &tmp)) {
325 priv->in_crit_support |= BIT(rail);
326 priv->in_crit[rail] = tmp;
329 if (!corsairpsu_get_value(priv, PSU_CMD_RAIL_VOLTS_LCRIT, rail, &tmp)) {
330 priv->in_lcrit_support |= BIT(rail);
331 priv->in_lcrit[rail] = tmp;
334 if (!corsairpsu_get_value(priv, PSU_CMD_RAIL_AMPS_HCRIT, rail, &tmp)) {
335 priv->curr_crit_support |= BIT(rail);
336 priv->curr_crit[rail] = tmp;
341 static void corsairpsu_check_cmd_support(struct corsairpsu_data *priv)
345 priv->in_curr_cmd_support = !corsairpsu_get_value(priv, PSU_CMD_IN_AMPS, 0, &tmp);
348 static umode_t corsairpsu_hwmon_temp_is_visible(const struct corsairpsu_data *priv, u32 attr,
354 case hwmon_temp_input:
355 case hwmon_temp_label:
356 case hwmon_temp_crit:
357 if (channel > 0 && !(priv->temp_crit_support & BIT(channel - 1)))
367 static umode_t corsairpsu_hwmon_fan_is_visible(const struct corsairpsu_data *priv, u32 attr,
371 case hwmon_fan_input:
372 case hwmon_fan_label:
379 static umode_t corsairpsu_hwmon_pwm_is_visible(const struct corsairpsu_data *priv, u32 attr,
383 case hwmon_pwm_input:
384 case hwmon_pwm_enable:
391 static umode_t corsairpsu_hwmon_power_is_visible(const struct corsairpsu_data *priv, u32 attr,
395 case hwmon_power_input:
396 case hwmon_power_label:
403 static umode_t corsairpsu_hwmon_in_is_visible(const struct corsairpsu_data *priv, u32 attr,
412 if (channel > 0 && !(priv->in_crit_support & BIT(channel - 1)))
416 if (channel > 0 && !(priv->in_lcrit_support & BIT(channel - 1)))
426 static umode_t corsairpsu_hwmon_curr_is_visible(const struct corsairpsu_data *priv, u32 attr,
432 case hwmon_curr_input:
433 if (channel == 0 && !priv->in_curr_cmd_support)
436 case hwmon_curr_label:
437 case hwmon_curr_crit:
438 if (channel > 0 && !(priv->curr_crit_support & BIT(channel - 1)))
448 static umode_t corsairpsu_hwmon_ops_is_visible(const void *data, enum hwmon_sensor_types type,
449 u32 attr, int channel)
451 const struct corsairpsu_data *priv = data;
455 return corsairpsu_hwmon_temp_is_visible(priv, attr, channel);
457 return corsairpsu_hwmon_fan_is_visible(priv, attr, channel);
459 return corsairpsu_hwmon_pwm_is_visible(priv, attr, channel);
461 return corsairpsu_hwmon_power_is_visible(priv, attr, channel);
463 return corsairpsu_hwmon_in_is_visible(priv, attr, channel);
465 return corsairpsu_hwmon_curr_is_visible(priv, attr, channel);
471 static int corsairpsu_hwmon_temp_read(struct corsairpsu_data *priv, u32 attr, int channel,
474 int err = -EOPNOTSUPP;
477 case hwmon_temp_input:
478 return corsairpsu_get_value(priv, channel ? PSU_CMD_TEMP1 : PSU_CMD_TEMP0,
480 case hwmon_temp_crit:
481 *val = priv->temp_crit[channel];
491 static int corsairpsu_hwmon_pwm_read(struct corsairpsu_data *priv, u32 attr, int channel, long *val)
494 case hwmon_pwm_input:
495 return corsairpsu_get_value(priv, PSU_CMD_FAN_PWM, 0, val);
496 case hwmon_pwm_enable:
497 return corsairpsu_get_value(priv, PSU_CMD_FAN_PWM_ENABLE, 0, val);
505 static int corsairpsu_hwmon_power_read(struct corsairpsu_data *priv, u32 attr, int channel,
508 if (attr == hwmon_power_input) {
511 return corsairpsu_get_value(priv, PSU_CMD_TOTAL_WATTS, 0, val);
513 return corsairpsu_get_value(priv, PSU_CMD_RAIL_WATTS, channel - 1, val);
522 static int corsairpsu_hwmon_in_read(struct corsairpsu_data *priv, u32 attr, int channel, long *val)
524 int err = -EOPNOTSUPP;
530 return corsairpsu_get_value(priv, PSU_CMD_IN_VOLTS, 0, val);
532 return corsairpsu_get_value(priv, PSU_CMD_RAIL_VOLTS, channel - 1, val);
538 *val = priv->in_crit[channel - 1];
542 *val = priv->in_lcrit[channel - 1];
550 static int corsairpsu_hwmon_curr_read(struct corsairpsu_data *priv, u32 attr, int channel,
553 int err = -EOPNOTSUPP;
556 case hwmon_curr_input:
559 return corsairpsu_get_value(priv, PSU_CMD_IN_AMPS, 0, val);
561 return corsairpsu_get_value(priv, PSU_CMD_RAIL_AMPS, channel - 1, val);
566 case hwmon_curr_crit:
567 *val = priv->curr_crit[channel - 1];
577 static int corsairpsu_hwmon_ops_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
578 int channel, long *val)
580 struct corsairpsu_data *priv = dev_get_drvdata(dev);
584 return corsairpsu_hwmon_temp_read(priv, attr, channel, val);
586 if (attr == hwmon_fan_input)
587 return corsairpsu_get_value(priv, PSU_CMD_FAN, 0, val);
590 return corsairpsu_hwmon_pwm_read(priv, attr, channel, val);
592 return corsairpsu_hwmon_power_read(priv, attr, channel, val);
594 return corsairpsu_hwmon_in_read(priv, attr, channel, val);
596 return corsairpsu_hwmon_curr_read(priv, attr, channel, val);
602 static int corsairpsu_hwmon_ops_read_string(struct device *dev, enum hwmon_sensor_types type,
603 u32 attr, int channel, const char **str)
605 if (type == hwmon_temp && attr == hwmon_temp_label) {
606 *str = channel ? L_TEMP1 : L_TEMP0;
608 } else if (type == hwmon_fan && attr == hwmon_fan_label) {
611 } else if (type == hwmon_power && attr == hwmon_power_label && channel < 4) {
612 *str = label_watts[channel];
614 } else if (type == hwmon_in && attr == hwmon_in_label && channel < 4) {
615 *str = label_volts[channel];
617 } else if (type == hwmon_curr && attr == hwmon_curr_label && channel < 4) {
618 *str = label_amps[channel];
625 static const struct hwmon_ops corsairpsu_hwmon_ops = {
626 .is_visible = corsairpsu_hwmon_ops_is_visible,
627 .read = corsairpsu_hwmon_ops_read,
628 .read_string = corsairpsu_hwmon_ops_read_string,
631 static const struct hwmon_channel_info *const corsairpsu_info[] = {
632 HWMON_CHANNEL_INFO(chip,
633 HWMON_C_REGISTER_TZ),
634 HWMON_CHANNEL_INFO(temp,
635 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
636 HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT),
637 HWMON_CHANNEL_INFO(fan,
638 HWMON_F_INPUT | HWMON_F_LABEL),
639 HWMON_CHANNEL_INFO(pwm,
640 HWMON_PWM_INPUT | HWMON_PWM_ENABLE),
641 HWMON_CHANNEL_INFO(power,
642 HWMON_P_INPUT | HWMON_P_LABEL,
643 HWMON_P_INPUT | HWMON_P_LABEL,
644 HWMON_P_INPUT | HWMON_P_LABEL,
645 HWMON_P_INPUT | HWMON_P_LABEL),
646 HWMON_CHANNEL_INFO(in,
647 HWMON_I_INPUT | HWMON_I_LABEL,
648 HWMON_I_INPUT | HWMON_I_LABEL | HWMON_I_LCRIT | HWMON_I_CRIT,
649 HWMON_I_INPUT | HWMON_I_LABEL | HWMON_I_LCRIT | HWMON_I_CRIT,
650 HWMON_I_INPUT | HWMON_I_LABEL | HWMON_I_LCRIT | HWMON_I_CRIT),
651 HWMON_CHANNEL_INFO(curr,
652 HWMON_C_INPUT | HWMON_C_LABEL,
653 HWMON_C_INPUT | HWMON_C_LABEL | HWMON_C_CRIT,
654 HWMON_C_INPUT | HWMON_C_LABEL | HWMON_C_CRIT,
655 HWMON_C_INPUT | HWMON_C_LABEL | HWMON_C_CRIT),
659 static const struct hwmon_chip_info corsairpsu_chip_info = {
660 .ops = &corsairpsu_hwmon_ops,
661 .info = corsairpsu_info,
664 #ifdef CONFIG_DEBUG_FS
666 static void print_uptime(struct seq_file *seqf, u8 cmd)
668 struct corsairpsu_data *priv = seqf->private;
672 ret = corsairpsu_get_value(priv, cmd, 0, &val);
674 seq_puts(seqf, "N/A\n");
678 if (val > SECONDS_PER_DAY) {
679 seq_printf(seqf, "%ld day(s), %02ld:%02ld:%02ld\n", val / SECONDS_PER_DAY,
680 val % SECONDS_PER_DAY / SECONDS_PER_HOUR, val % SECONDS_PER_HOUR / 60,
685 seq_printf(seqf, "%02ld:%02ld:%02ld\n", val % SECONDS_PER_DAY / SECONDS_PER_HOUR,
686 val % SECONDS_PER_HOUR / 60, val % 60);
689 static int uptime_show(struct seq_file *seqf, void *unused)
691 print_uptime(seqf, PSU_CMD_UPTIME);
695 DEFINE_SHOW_ATTRIBUTE(uptime);
697 static int uptime_total_show(struct seq_file *seqf, void *unused)
699 print_uptime(seqf, PSU_CMD_TOTAL_UPTIME);
703 DEFINE_SHOW_ATTRIBUTE(uptime_total);
705 static int vendor_show(struct seq_file *seqf, void *unused)
707 struct corsairpsu_data *priv = seqf->private;
709 seq_printf(seqf, "%s\n", priv->vendor);
713 DEFINE_SHOW_ATTRIBUTE(vendor);
715 static int product_show(struct seq_file *seqf, void *unused)
717 struct corsairpsu_data *priv = seqf->private;
719 seq_printf(seqf, "%s\n", priv->product);
723 DEFINE_SHOW_ATTRIBUTE(product);
725 static int ocpmode_show(struct seq_file *seqf, void *unused)
727 struct corsairpsu_data *priv = seqf->private;
732 * The rail mode is switchable on the fly. The RAW interface can be used for this. But it
733 * will not be included here, because I consider it somewhat dangerous for the health of the
734 * PSU. The returned value can be a bogus one, if the PSU is in the process of switching and
735 * getting of the value itself can also fail during this. Because of this every other value
736 * than OCP_MULTI_RAIL can be considered as "single rail".
738 ret = corsairpsu_get_value(priv, PSU_CMD_OCPMODE, 0, &val);
740 seq_puts(seqf, "N/A\n");
742 seq_printf(seqf, "%s\n", (val == OCP_MULTI_RAIL) ? "multi rail" : "single rail");
746 DEFINE_SHOW_ATTRIBUTE(ocpmode);
748 static void corsairpsu_debugfs_init(struct corsairpsu_data *priv)
752 scnprintf(name, sizeof(name), "%s-%s", DRIVER_NAME, dev_name(&priv->hdev->dev));
754 priv->debugfs = debugfs_create_dir(name, NULL);
755 debugfs_create_file("uptime", 0444, priv->debugfs, priv, &uptime_fops);
756 debugfs_create_file("uptime_total", 0444, priv->debugfs, priv, &uptime_total_fops);
757 debugfs_create_file("vendor", 0444, priv->debugfs, priv, &vendor_fops);
758 debugfs_create_file("product", 0444, priv->debugfs, priv, &product_fops);
759 debugfs_create_file("ocpmode", 0444, priv->debugfs, priv, &ocpmode_fops);
764 static void corsairpsu_debugfs_init(struct corsairpsu_data *priv)
770 static int corsairpsu_probe(struct hid_device *hdev, const struct hid_device_id *id)
772 struct corsairpsu_data *priv;
775 priv = devm_kzalloc(&hdev->dev, sizeof(struct corsairpsu_data), GFP_KERNEL);
779 priv->cmd_buffer = devm_kmalloc(&hdev->dev, CMD_BUFFER_SIZE, GFP_KERNEL);
780 if (!priv->cmd_buffer)
783 ret = hid_parse(hdev);
787 ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
791 ret = hid_hw_open(hdev);
796 hid_set_drvdata(hdev, priv);
797 mutex_init(&priv->lock);
798 init_completion(&priv->wait_completion);
800 hid_device_io_start(hdev);
802 ret = corsairpsu_init(priv);
804 dev_err(&hdev->dev, "unable to initialize device (%d)\n", ret);
808 ret = corsairpsu_fwinfo(priv);
810 dev_err(&hdev->dev, "unable to query firmware (%d)\n", ret);
814 corsairpsu_get_criticals(priv);
815 corsairpsu_check_cmd_support(priv);
817 priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "corsairpsu", priv,
818 &corsairpsu_chip_info, NULL);
820 if (IS_ERR(priv->hwmon_dev)) {
821 ret = PTR_ERR(priv->hwmon_dev);
825 corsairpsu_debugfs_init(priv);
836 static void corsairpsu_remove(struct hid_device *hdev)
838 struct corsairpsu_data *priv = hid_get_drvdata(hdev);
840 debugfs_remove_recursive(priv->debugfs);
841 hwmon_device_unregister(priv->hwmon_dev);
846 static int corsairpsu_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data,
849 struct corsairpsu_data *priv = hid_get_drvdata(hdev);
851 if (completion_done(&priv->wait_completion))
854 memcpy(priv->cmd_buffer, data, min(CMD_BUFFER_SIZE, size));
855 complete(&priv->wait_completion);
861 static int corsairpsu_resume(struct hid_device *hdev)
863 struct corsairpsu_data *priv = hid_get_drvdata(hdev);
865 /* some PSUs turn off the microcontroller during standby, so a reinit is required */
866 return corsairpsu_init(priv);
870 static const struct hid_device_id corsairpsu_idtable[] = {
871 { HID_USB_DEVICE(0x1b1c, 0x1c03) }, /* Corsair HX550i */
872 { HID_USB_DEVICE(0x1b1c, 0x1c04) }, /* Corsair HX650i */
873 { HID_USB_DEVICE(0x1b1c, 0x1c05) }, /* Corsair HX750i */
874 { HID_USB_DEVICE(0x1b1c, 0x1c06) }, /* Corsair HX850i */
875 { HID_USB_DEVICE(0x1b1c, 0x1c07) }, /* Corsair HX1000i Series 2022 */
876 { HID_USB_DEVICE(0x1b1c, 0x1c08) }, /* Corsair HX1200i */
877 { HID_USB_DEVICE(0x1b1c, 0x1c09) }, /* Corsair RM550i */
878 { HID_USB_DEVICE(0x1b1c, 0x1c0a) }, /* Corsair RM650i */
879 { HID_USB_DEVICE(0x1b1c, 0x1c0b) }, /* Corsair RM750i */
880 { HID_USB_DEVICE(0x1b1c, 0x1c0c) }, /* Corsair RM850i */
881 { HID_USB_DEVICE(0x1b1c, 0x1c0d) }, /* Corsair RM1000i */
882 { HID_USB_DEVICE(0x1b1c, 0x1c1e) }, /* Corsair HX1000i Series 2023 */
883 { HID_USB_DEVICE(0x1b1c, 0x1c1f) }, /* Corsair HX1500i Series 2022 */
886 MODULE_DEVICE_TABLE(hid, corsairpsu_idtable);
888 static struct hid_driver corsairpsu_driver = {
890 .id_table = corsairpsu_idtable,
891 .probe = corsairpsu_probe,
892 .remove = corsairpsu_remove,
893 .raw_event = corsairpsu_raw_event,
895 .resume = corsairpsu_resume,
896 .reset_resume = corsairpsu_resume,
899 module_hid_driver(corsairpsu_driver);
901 MODULE_LICENSE("GPL");
902 MODULE_AUTHOR("Wilken Gottwalt <wilken.gottwalt@posteo.net>");
903 MODULE_DESCRIPTION("Linux driver for Corsair power supplies with HID sensors interface");