hwmon: add Corsair Commander Pro driver
Marius Zachmann
maintainerPATCH v5 1/1 hwmon: add Corsair Commander Pro driver
As requested I have squashed the 3 commits into one. Sorry for the confusion.
This is v5 of a driver for the Corsair Commander Pro. It provides sysfs attributes for:
- Reading fan speed
- Reading temp sensors
- Reading voltage values
- Writing pwm and reading last written pwm
- Reading fan and temp connection status
It is an usb driver, so it needs to be ignored by usbhid. The Corsair Commander Pro is a fan controller and provides no means for user interaction.
The two device numbers are because there is a slightly different version of the same device. (Only difference seem to be in some presets.)
This is based on the staging/hwmon tree.
---
Changes from v4
- squashed 3 commits into one.
Changes from v3
- add device ids to hid_ignore_list in hid-quirks.h
- removed unused update_interval
- ccp_disconnect is static
Changes from v2
- add corsair-cpro to Documentation/hwmon/index.rst
- add SPDX license identifier to corsair-cpro.rst
- remove fanX_enable from Documentation and driver
- changed comment style
- clarified protocol in comments
- add get_temp_cnct for reading temperature sensor connection status
- added temp_cnct and temp_label in ccp_device
- added tempX_label, showing connection status
- renamed get_fan_mode_label to get_fan_cnct
- get_temp_cnct and get_fan_cnct only called in probe
- send_usb_cmd checks errors in the device response
- send_usb_cmd clears the buffer and sets the command
- inlined get_fan_rpm and get_voltage and removed functions
- more reverse christmas tree
--- Documentation/hwmon/corsair-cpro.rst | 40 +++ Documentation/hwmon/index.rst | 1 + MAINTAINERS | 6 + drivers/hid/hid-quirks.c | 2 + drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/corsair-cpro.c | 489 +++++++++++++++++++++++++++ 7 files changed, 549 insertions(+) create mode 100644 Documentation/hwmon/corsair-cpro.rst create mode 100644 drivers/hwmon/corsair-cpro.c
Documentation/hwmon/corsair-cpro.rst new file +40 -0
@@ -0,0 +1,40 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver corsair-cpro +========================== + +Supported devices: + + * Corsair Commander Pro + * Corsair Commander Pro (1000D) + +Author: Marius Zachmann + +Description +----------- + +This driver implements the sysfs interface for the Corsair Commander Pro. +The Corsair Commander Pro is a USB device with 6 fan connectors, +4 temperature sensor connectors and 2 Corsair LED connectors. +It can read the voltage levels on the SATA power connector. + +Usage Notes +----------- + +Since it is a USB device, hotswapping is possible. The device is autodetected. + +Sysfs entries +------------- + +======================= ===================================================================== +in0_input Voltage on SATA 12v +in1_input Voltage on SATA 5v +in2_input Voltage on SATA 3.3v +temp[1-4]_input Temperature on connected temperature sensors +temp[1-4] label Shows "nc" after name, when not connected +fan[1-6]_input Connected fan rpm. +fan[1-6]_label Shows connection status of the fan as detected by the device. +pwm[1-6] Sets the fan speed. Values from 0-255. + When reading, it reports the last value if it was set by the driver. + Otherwise returns 0. +======================= =====================================================================
Documentation/hwmon/index.rst +1 -0
@@ -47,6 +47,7 @@ Hardware Monitoring Kernel Drivers bel-pfe bt1-pvt coretemp + corsair-cpro da9052 da9055 dell-smm-hwmon
MAINTAINERS +6 -0
@@ -4400,6 +4400,12 @@ S: Maintained F: Documentation/hwmon/coretemp.rst F: drivers/hwmon/coretemp.c +CORSAIR-CPRO HARDWARE MONITOR DRIVER +M: Marius <[email protected]> +L: [email protected] +S: Maintained +F: drivers/hwmon/corsair-cpro.c + COSA/SRP SYNC SERIAL DRIVER M: Jan "Yenya" Kasprzak <[email protected]> S: Maintained
drivers/hid/hid-quirks.c +2 -0
@@ -699,6 +699,8 @@ static const struct hid_device_id hid_ignore_list[] = { { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) }, { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, 0x0c10) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, 0x1d00) }, { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) }, { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI4713) }, { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
drivers/hwmon/Kconfig +10 -0
@@ -439,6 +439,16 @@ config SENSORS_BT1_PVT_ALARMS the data conversion will be periodically performed and the data will be saved in the internal driver cache. +config SENSORS_CORSAIR_CPRO + tristate "Corsair Commander Pro controller" + depends on USB + help + If you say yes here you get support for the Corsair Commander Pro + controller. + + This driver can also be built as a module. If so, the module + will be called corsair-cpro. + config SENSORS_DRIVETEMP tristate "Hard disk drives with temperature sensors" depends on SCSI && ATA
drivers/hwmon/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o obj-$(CONFIG_SENSORS_AXI_FAN_CONTROL) += axi-fan-control.o obj-$(CONFIG_SENSORS_BT1_PVT) += bt1-pvt.o obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o +obj-$(CONFIG_SENSORS_CORSAIR_CPRO) += corsair-cpro.o obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o obj-$(CONFIG_SENSORS_DA9055)+= da9055-hwmon.o obj-$(CONFIG_SENSORS_DELL_SMM) += dell-smm-hwmon.o
drivers/hwmon/corsair-cpro.c new file +489 -0
489 lines not on this page · raw message
Signature · 1 line
2.27.0
Guenter Roeck
maintainerQuoted 205 lines · Marius Zachmann
As requested I have squashed the 3 commits into one. Sorry for the confusion.
This is v5 of a driver for the Corsair Commander Pro. It provides sysfs attributes for:
- Reading fan speed
- Reading temp sensors
- Reading voltage values
- Writing pwm and reading last written pwm
- Reading fan and temp connection statusIt is an usb driver, so it needs to be ignored by usbhid. The Corsair Commander Pro is a fan controller and provides no means for user interaction.
The two device numbers are because there is a slightly different version of the same device. (Only difference seem to be in some presets.)This is based on the staging/hwmon tree.
Signed-off-by Marius Zachmann <[email protected]>---
Changes from v4
- squashed 3 commits into one.Changes from v3
- add device ids tohid_ignore_listinhid-quirks.h
- removed unusedupdate_interval
-ccp_disconnectis staticChanges from v2
- add corsair-cpro toDocumentation/hwmon/index.rst
- add SPDX license identifier tocorsair-cpro.rst
- removefanX_enablefrom Documentation and driver
- changed comment style
- clarified protocol in comments
- addget_temp_cnctfor reading temperature sensor connection status
- addedtemp_cnctandtemp_labelinccp_device
- addedtempX_label, showing connection status
- renamedget_fan_mode_labeltoget_fan_cnct
-get_temp_cnctandget_fan_cnctonly called in probe
-send_usb_cmdchecks errors in the device response
-send_usb_cmdclears the buffer and sets the command
- inlinedget_fan_rpmandget_voltageand removed functions
- more reverse christmas tree--- Documentation/hwmon/corsair-cpro.rst | 40 +++ Documentation/hwmon/index.rst | 1 + MAINTAINERS | 6 + drivers/hid/hid-quirks.c | 2 + drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/corsair-cpro.c | 489 +++++++++++++++++++++++++++ 7 files changed, 549 insertions(+) create mode 100644 Documentation/hwmon/corsair-cpro.rst create mode 100644 drivers/hwmon/corsair-cpro.cDocumentation/hwmon/corsair-cpro.rst new file +40
-0@@ -0,0 +1,40 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver corsair-cpro +========================== + +Supported devices: + + * Corsair Commander Pro + * Corsair Commander Pro (1000D) + +Author: Marius Zachmann + +Description +----------- + +This driver implements the sysfs interface for the Corsair Commander Pro. +The Corsair Commander Pro is a USB device with 6 fan connectors, +4 temperature sensor connectors and 2 Corsair LED connectors. +It can read the voltage levels on the SATA power connector. + +Usage Notes +----------- + +Since it is a USB device, hotswapping is possible. The device is autodetected. + +Sysfs entries +------------- + +======================= ===================================================================== +in0_input Voltage on SATA 12v +in1_input Voltage on SATA 5v +in2_input Voltage on SATA 3.3v +temp[1-4]_input Temperature on connected temperature sensors +temp[1-4] label Shows "nc" after name, when not connected +fan[1-6]_input Connected fan rpm. +fan[1-6]_label Shows connection status of the fan as detected by the device. +pwm[1-6] Sets the fan speed. Values from 0-255. + When reading, it reports the last value if it was set by the driver. + Otherwise returns 0. +======================= =====================================================================Documentation/hwmon/index.rst +1
-0@@ -47,6 +47,7 @@ Hardware Monitoring Kernel Drivers bel-pfe bt1-pvt coretemp + corsair-cpro da9052 da9055 dell-smm-hwmonMAINTAINERS +6
-0@@ -4400,6 +4400,12 @@ S: Maintained F: Documentation/hwmon/coretemp.rst F: drivers/hwmon/coretemp.c +CORSAIR-CPRO HARDWARE MONITOR DRIVER +M: Marius <[email protected]> +L: [email protected] +S: Maintained +F: drivers/hwmon/corsair-cpro.c + COSA/SRP SYNC SERIAL DRIVER M: Jan "Yenya" Kasprzak <[email protected]> S: Maintaineddrivers/hid/hid-quirks.c +2
-0@@ -699,6 +699,8 @@ static const struct hid_device_id hid_ignore_list[] = { { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) }, { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, 0x0c10) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, 0x1d00) }, { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) }, { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI4713) }, { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },drivers/hwmon/Kconfig +10
-0@@ -439,6 +439,16 @@ config SENSORS_BT1_PVT_ALARMS the data conversion will be periodically performed and the data will be saved in the internal driver cache. +config SENSORS_CORSAIR_CPRO + tristate "Corsair Commander Pro controller" + depends on USB + help + If you say yes here you get support for the Corsair Commander Pro + controller. + + This driver can also be built as a module. If so, the module + will be called corsair-cpro. + config SENSORS_DRIVETEMP tristate "Hard disk drives with temperature sensors" depends on SCSI && ATAdrivers/hwmon/Makefile +1
-0@@ -56,6 +56,7 @@ obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o obj-$(CONFIG_SENSORS_AXI_FAN_CONTROL) += axi-fan-control.o obj-$(CONFIG_SENSORS_BT1_PVT) += bt1-pvt.o obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o +obj-$(CONFIG_SENSORS_CORSAIR_CPRO) += corsair-cpro.o obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o obj-$(CONFIG_SENSORS_DA9055)+= da9055-hwmon.o obj-$(CONFIG_SENSORS_DELL_SMM) += dell-smm-hwmon.odrivers/hwmon/corsair-cpro.c new file +16
-0@@ -0,0 +1,489 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* corsair-cpro.c - Linux driver for Corsair Commander Pro +* Copyright (C) 2020 Marius Zachmann <[email protected]> +*/ + +#include <linux/kernel.h> +#include <linux/hwmon.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/slab.h> +#include <linux/usb.h> + +#define USB_VENDOR_ID_CORSAIR 0x1b1c +#define USB_PRODUCT_ID_CORSAIR_COMMANDERPRO 0x0c10 +#define USB_PRODUCT_ID_CORSAIR_1000D 0x1d00
drivers/hwmon/corsair-cpro.c line 26
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+ +#define OUT_BUFFER_SIZE 63 +#define IN_BUFFER_SIZE 16 +#define LABEL_LENGTH 12 + +#define CTL_GET_TMP_CNCT 0x10/* +* returns in bytes 1-4 for each temp sensor: +* 0 not connected +* 1 connected +*/
Alignments are odd. Please use tabs. Maximum number of columns is now 100, so there should be enough space to avoid odd line breaks. Example:
#define CTL_GET_TMP_CNCT 0x10 /*
* returns in bytes 1-4 for each temp sensor:
* 0 not connected
* 1 connected
*/
drivers/hwmon/corsair-cpro.c line 29
Quoted 3 lines
drivers/hwmon/corsair-cpro.c new file +3
-0+#define CTL_GET_TMP 0x11/* +* send: byte 1 is channel, rest zero +* rcv: returns temp for channel in bytes 1 and 2
Add units (centi-degrees C ?)
drivers/hwmon/corsair-cpro.c line 34
Quoted 5 lines
drivers/hwmon/corsair-cpro.c new file +5
-0+* returns 17 in byte 0 if no sensor is connected +*/ +#define CTL_GET_VOLT 0x12/* +* send: byte 1 is rail number: 0 = 12v, 1 = 5v, 2 = 3.3v +* rcv: returns volt in bytes 1,2
Add units (mV ?)
Quoted 46 lines
drivers/hwmon/corsair-cpro.c new file +46
-0+*/ +#define CTL_GET_FAN_CNCT 0x20/* +* returns in bytes 1-6 for each fan: +* 0 not connected +* 1 3pin +* 2 4pin +*/ +#define CTL_GET_FAN_RPM 0x21/* +* send: byte 1 is channel, rest zero +* rcv: returns rpm in bytes 1,2 +*/ +#define CTL_SET_FAN_FPWM 0x23/* +* set fixed pwm +* send: byte 1 is fan number +* send: byte 2 is percentage from 0 - 100 +*/ + +struct ccp_device { +struct usb_device *udev; +struct mutex mutex;/* whenever buffer is used, lock before send_usb_cmd */ +u8 *buffer; +int pwm[6 ]; +char fan_label[6 ][LABEL_LENGTH ]; +int temp_cnct[4 ]; +char temp_label[4 ][LABEL_LENGTH ]; +}; + +/* send command, check for error in response, response in ccp->buffer */ +static int send_usb_cmd (struct ccp_device *ccp,u8 command,u8 byte1,u8 byte2) +{ +int actual_length; +int ret; + +memset (ccp->buffer,0x00 ,OUT_BUFFER_SIZE ); + ccp->buffer[0 ] = command; + ccp->buffer[1 ] = byte1; + ccp->buffer[2 ] = byte2; + + ret =usb_bulk_msg (ccp->udev,usb_sndintpipe (ccp->udev,2 ), ccp->buffer,OUT_BUFFER_SIZE , + &actual_length,1000 ); +if (ret) { +dev_err (&ccp->udev->dev,"usb_bulk_msg send failed: %d" , ret); +return ret; + } + +/* response needs to be received every time */
drivers/hwmon/corsair-cpro.c line 90
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+ ret =usb_bulk_msg (ccp->udev,usb_rcvintpipe (ccp->udev,1 ), ccp->buffer,IN_BUFFER_SIZE , + &actual_length,1000 ); +if (ret) { +dev_err (&ccp->udev->dev,"usb_bulk_msg receive failed: %d" , ret); +return ret; + } + +/* first byte of response is error code */ +if (ccp->buffer[0 ] !=0x00 ) { +dev_err (&ccp->udev->dev,"device response error: %d" , ccp->buffer[0 ]);
I'd prefer if you drop those error messages. I am concerned about clogging the log if the device is prone to return errors.
drivers/hwmon/corsair-cpro.c line 97
Quoted 7 lines
drivers/hwmon/corsair-cpro.c new file +7
-0+return -EIO ; + } + +return 0 ; +} + +/* for commands, which return just a number depending on a channel: */
s/,//
s/://
Also, it would be better to actually describe the function, not its callers
drivers/hwmon/corsair-cpro.c line 109
Quoted 12 lines
drivers/hwmon/corsair-cpro.c new file +12
-0+static int get_data (struct ccp_device *ccp,int command,int channel,long *val) +{ +int ret; + +mutex_lock (&ccp->mutex); + + ret =send_usb_cmd (ccp, command, channel,0 ); +if (ret) + goto exit; + + *val = (ccp->buffer[1 ] <<8 ) + ccp->buffer[2 ]; +
Since the data returned from the device is always >= 0, it is unnecessary to have long *val as parameter. Instead, the return value can be used to return both error and the value itself.
ret = (ccp->buffer[1] << 8) + ccp->buffer[2];
Then the calling code can use this value as needed (see below).
Quoted 51 lines
drivers/hwmon/corsair-cpro.c new file +51
-0+exit: +mutex_unlock (&ccp->mutex); + return ret;> +} + +static int set_pwm (struct ccp_device *ccp,int channel,long val) +{ +int ret; + +if (val <0 || val >255 ) +return -EINVAL ; + + ccp->pwm[channel] = val; + +/* The Corsair Commander Pro uses values from 0-100 */ + val =DIV_ROUND_CLOSEST (val *100 ,255 ); + +mutex_lock (&ccp->mutex); + + ret =send_usb_cmd (ccp,CTL_SET_FAN_FPWM , channel, val); + +mutex_unlock (&ccp->mutex); +return ret; +} + +/* read fan connection status and set labels */ +static int get_fan_cnct (struct ccp_device *ccp) +{ +int channel; +int mode; +int ret; + +mutex_lock (&ccp->mutex); + + ret =send_usb_cmd (ccp,CTL_GET_FAN_CNCT ,0 ,0 ); +if (ret) + goto exit; + +for (channel =0 ; channel <6 ; channel++) { + mode = ccp->buffer[channel +1 ]; + +switch (mode) { +case 0 : +scnprintf (ccp->fan_label[channel],LABEL_LENGTH , +"fan%d nc" , channel +1 ); +break ; +case 1 : +scnprintf (ccp->fan_label[channel],LABEL_LENGTH , +"fan%d 3pin" , channel +1 ); +break ; +case 2 : + scnprintf(ccp->fan_label[channel], LABEL_LENGTH,
drivers/hwmon/corsair-cpro.c line 171
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+ "fan%d 4pin", channel + 1); +break ; +default : +scnprintf (ccp->fan_label[channel],LABEL_LENGTH , +"fan%d other" , channel +1 ); +break ; + } + } + +exit:
Nit: Coding style says:
"Choose label names which say what the goto does or why the goto exists"
So a label such as "unlock" would be more appropriate. See Documentation/process/coding-style.rst (Centralized exiting of functions) for details.
drivers/hwmon/corsair-cpro.c line 184
Quoted 13 lines
drivers/hwmon/corsair-cpro.c new file +13
-0+mutex_unlock (&ccp->mutex); +return ret; +} + +/* read temp sensor connection status and set labels */ +static int get_temp_cnct (struct ccp_device *ccp) +{ +int channel; +int mode; +int ret; + +mutex_lock (&ccp->mutex); +
Actually, since the function is only called from probe, the mutex is not needed here. Same for get_fan_cnct().
drivers/hwmon/corsair-cpro.c line 197
Quoted 13 lines
drivers/hwmon/corsair-cpro.c new file +13
-0+ ret =send_usb_cmd (ccp,CTL_GET_TMP_CNCT ,0 ,0 ); +if (ret) + goto exit; + +for (channel =0 ; channel <4 ; channel++) { + mode = ccp->buffer[channel +1 ]; + ccp->temp_cnct[channel] = mode; + +switch (mode) { +case 0 : +scnprintf (ccp->temp_label[channel],LABEL_LENGTH , +"temp%d nc" , channel +1 ); +break ;
Sorry I didn't realize this earlier: Since you know that the temperature sensor is not connected, it would be better to mark it as such and have the is_visible function return 0. The same applied to fans. The easiest way to do that is to add bitmaps to struct ccp_device, one for fans and one for temperature sensors, and set BIT(channel) if the fan/sensor is installed.
Quoted 13 lines
drivers/hwmon/corsair-cpro.c new file +13
-0+case 1 : +scnprintf (ccp->temp_label[channel],LABEL_LENGTH , +"temp%d" , channel +1 ); +break ; +default : +scnprintf (ccp->temp_label[channel],LABEL_LENGTH , +"temp%d other" , channel +1 ); +break ; + } + } + +exit: +mutex_unlock (&ccp->mutex);
drivers/hwmon/corsair-cpro.c line 220
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+return ret; +} + +static int get_temp (struct ccp_device *ccp,int channel,long *val) +{ +int ret; + +if (ccp->temp_cnct[channel] !=1 ) +return -ENODATA ; +
When you do as suggested the above (use is_visible), this won't be needed, and the code does not depend on the magic '1'. Actually, you could then drop this function entirely; mor eon that see below.
drivers/hwmon/corsair-cpro.c line 232
Quoted 12 lines
drivers/hwmon/corsair-cpro.c new file +12
-0+ ret =get_data (ccp,CTL_GET_TMP , channel, val); + *val = *val *10 ; + +return ret; +} + +static int ccp_read_string (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,const char **str) +{ +struct ccp_device *ccp =dev_get_drvdata (dev); +int ret =0 ; +
See below on pre-assignment.
Quoted 25 lines
drivers/hwmon/corsair-cpro.c new file +25
-0+switch (type) { +case hwmon_fan: +switch (attr) { +case hwmon_fan_label: + *str = ccp->fan_label[channel]; +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +case hwmon_temp: +switch (attr) { +case hwmon_temp_label: + *str = ccp->temp_label[channel]; +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +default : + ret = -EOPNOTSUPP ; +break ; + }
drivers/hwmon/corsair-cpro.c line 267
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+ +return ret; +} + +static int ccp_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct ccp_device *ccp =dev_get_drvdata (dev); +int ret =0 ; +
Every code path sets ret, so pre-initializing it is not necessary. If you want to pre-initialize, initialize it with -EOPNOTSUPP and drop all the respective assignments below. Same goes for other similar functions.
drivers/hwmon/corsair-cpro.c line 272
Quoted 5 lines
drivers/hwmon/corsair-cpro.c new file +5
-0+switch (type) { +case hwmon_temp: +switch (attr) { +case hwmon_temp_input: + ret =get_temp (ccp, channel, val);
Better:
ret = get_data(ccp, CTL_GET_TMP, channel); if (ret < 0) break; *val = ret * 10;
drivers/hwmon/corsair-cpro.c line 282
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +case hwmon_fan: +switch (attr) { +case hwmon_fan_input: + ret =get_data (ccp,CTL_GET_FAN_RPM , channel, val);
or:
ret = get_data(ccp, CTL_GET_FAN_RPM, channel); if (ret < 0) break; *val = ret;
Quoted 12 lines
drivers/hwmon/corsair-cpro.c new file +12
-0+break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +case hwmon_pwm: +switch (attr) { +case hwmon_pwm_input: +/* how to read pwm values from the device is currently unknown */ +/* driver returns last set value or 0 */ + *val = ccp->pwm[channel];
drivers/hwmon/corsair-cpro.c line 304
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +case hwmon_in: +switch (attr) { +case hwmon_in_input: + ret =get_data (ccp,CTL_GET_VOLT , channel, val);
or:
ret = get_data(ccp, CTL_GET_VOLT, channel); if (ret < 0) break; *val = ret;
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +default : + ret = -EOPNOTSUPP ; +break ; + }
drivers/hwmon/corsair-cpro.c line 324
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+ +return ret; +}; + +static int ccp_write (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long val) +{ +struct ccp_device *ccp =dev_get_drvdata (dev); +int ret =0 ; +
Every code path sets ret, so pre-initializing it is not necessary.
Quoted 120 lines
drivers/hwmon/corsair-cpro.c new file +120
-0+switch (type) { +case hwmon_pwm: +switch (attr) { +case hwmon_pwm_input: + ret =set_pwm (ccp, channel, val); +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } + +return ret; +}; + +static umode_t ccp_is_visible (const void *data,enum hwmon_sensor_types type, +u32 attr,int channel) +{ +switch (type) { +case hwmon_temp: +switch (attr) { +case hwmon_temp_input: +return 0444 ; +case hwmon_temp_label: +return 0444 ; +default : +break ; + } +break ; +case hwmon_fan: +switch (attr) { +case hwmon_fan_input: +return 0444 ; +case hwmon_fan_label: +return 0444 ; +default : +break ; + } +break ; +case hwmon_pwm: +switch (attr) { +case hwmon_pwm_input: +return 0644 ; +default : +break ; + } +break ; +case hwmon_in: +switch (attr) { +case hwmon_in_input: +return 0444 ; +default : +break ; + } +break ; +default : +break ; + } + +return 0 ; +}; + +static const struct hwmon_ops ccp_hwmon_ops = { + .is_visible = ccp_is_visible, + .read = ccp_read, + .read_string = ccp_read_string, + .write = ccp_write, +}; + +static const struct hwmon_channel_info *ccp_info[] = { +HWMON_CHANNEL_INFO (chip, +HWMON_C_REGISTER_TZ ), +HWMON_CHANNEL_INFO (temp, +HWMON_T_INPUT |HWMON_T_LABEL , +HWMON_T_INPUT |HWMON_T_LABEL , +HWMON_T_INPUT |HWMON_T_LABEL , +HWMON_T_INPUT |HWMON_T_LABEL + ), +HWMON_CHANNEL_INFO (fan, +HWMON_F_INPUT |HWMON_F_LABEL , +HWMON_F_INPUT |HWMON_F_LABEL , +HWMON_F_INPUT |HWMON_F_LABEL , +HWMON_F_INPUT |HWMON_F_LABEL , +HWMON_F_INPUT |HWMON_F_LABEL , +HWMON_F_INPUT |HWMON_F_LABEL + ), +HWMON_CHANNEL_INFO (pwm, +HWMON_PWM_INPUT , +HWMON_PWM_INPUT , +HWMON_PWM_INPUT , +HWMON_PWM_INPUT , +HWMON_PWM_INPUT , +HWMON_PWM_INPUT + ), +HWMON_CHANNEL_INFO (in, +HWMON_I_INPUT , +HWMON_I_INPUT , +HWMON_I_INPUT + ), +NULL +}; + +static const struct hwmon_chip_info ccp_chip_info = { + .ops = &ccp_hwmon_ops, + .info = ccp_info, +}; + +static int ccp_probe (struct usb_interface *intf,const struct usb_device_id *id) +{ +struct device *hwmon_dev; +struct ccp_device *ccp; +int ret; + + ccp =devm_kzalloc (&intf->dev,sizeof (struct ccp_device ),GFP_KERNEL ); +if (!ccp) +return -ENOMEM ;
drivers/hwmon/corsair-cpro.c line 454
Quoted 10 lines
drivers/hwmon/corsair-cpro.c new file +10
-0+ + ccp->buffer =devm_kmalloc (&intf->dev,OUT_BUFFER_SIZE ,GFP_KERNEL ); +if (!ccp->buffer) +return -ENOMEM ; + +mutex_init (&ccp->mutex); + + ccp->udev =interface_to_usbdev (intf); + +/* temp and fan connection status only updates, when device is powered on */
s/,//
Quoted 36 lines
drivers/hwmon/corsair-cpro.c new file +35
-0+ ret =get_temp_cnct (ccp); +if (ret) +return ret; + + ret =get_fan_cnct (ccp); +if (ret) +return ret; + + hwmon_dev =devm_hwmon_device_register_with_info (&intf->dev,"corsaircpro" , ccp, + &ccp_chip_info,0 ); + +return PTR_ERR_OR_ZERO (hwmon_dev); +} + +static void ccp_disconnect (struct usb_interface *intf) +{ +} + +static const struct usb_device_id ccp_devices[] = { + {USB_DEVICE (USB_VENDOR_ID_CORSAIR ,USB_PRODUCT_ID_CORSAIR_COMMANDERPRO ) }, + {USB_DEVICE (USB_VENDOR_ID_CORSAIR ,USB_PRODUCT_ID_CORSAIR_1000D ) }, + { } +}; + +static struct usb_driver ccp_driver = { + .name ="corsair-cpro" , + .probe = ccp_probe, + .disconnect = ccp_disconnect, + .id_table = ccp_devices +}; + +MODULE_DEVICE_TABLE (usb, ccp_devices); +MODULE_LICENSE ("GPL" ); + +module_usb_driver (ccp_driver);