From 276281b8e89863f78cd21922a333fc319c0cc28d Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Tue, 27 Jul 2021 16:20:54 -0700 Subject: hwmon: sht4x: update Documentation for Malformed table Make top and bottom border lines match. Documentation/hwmon/sht4x.rst:42: WARNING: Malformed table. Text in column margin in table line 4. Fixes: 505c2549373f ("hwmon: Add sht4x Temperature and Humidity Sensor Driver") Signed-off-by: Randy Dunlap Cc: Navin Sankar Velliangiri Cc: Guenter Roeck Cc: Jean Delvare Cc: linux-hwmon@vger.kernel.org Link: https://lore.kernel.org/r/20210727232054.7426-1-rdunlap@infradead.org Signed-off-by: Guenter Roeck --- Documentation/hwmon/sht4x.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Documentation') diff --git a/Documentation/hwmon/sht4x.rst b/Documentation/hwmon/sht4x.rst index 3b37abcd4a46..c318e5582ead 100644 --- a/Documentation/hwmon/sht4x.rst +++ b/Documentation/hwmon/sht4x.rst @@ -42,4 +42,4 @@ humidity1_input Measured humidity in %H update_interval The minimum interval for polling the sensor, in milliseconds. Writable. Must be at least 2000. -============== ============================================= +=============== ============================================ -- cgit v1.2.3 From 04fecf0c6155f73ed446b5b67726ff882b8078a9 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 22 Jul 2021 11:59:59 +0200 Subject: dt-bindings: firmware: update arm,scpi.yaml reference Changeset 1496be719468 ("dt-bindings: firmware: arm,scpi: Convert to json schema") renamed: Documentation/devicetree/bindings/arm/arm,scpi.txt to: Documentation/devicetree/bindings/firmware/arm,scpi.yaml. Update its cross-reference accordingly. Fixes: 1496be719468 ("dt-bindings: firmware: arm,scpi: Convert to json schema") Signed-off-by: Mauro Carvalho Chehab Acked-by: Sudeep Holla Link: https://lore.kernel.org/r/b5a2b0cb83e7f8193b4be4cef9250dd4c42877ab.1626947923.git.mchehab+huawei@kernel.org Signed-off-by: Guenter Roeck --- Documentation/hwmon/scpi-hwmon.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Documentation') diff --git a/Documentation/hwmon/scpi-hwmon.rst b/Documentation/hwmon/scpi-hwmon.rst index eee7022b44db..1e3f83ec0658 100644 --- a/Documentation/hwmon/scpi-hwmon.rst +++ b/Documentation/hwmon/scpi-hwmon.rst @@ -32,5 +32,5 @@ Usage Notes The driver relies on device tree node to indicate the presence of SCPI support in the kernel. See -Documentation/devicetree/bindings/arm/arm,scpi.txt for details of the +Documentation/devicetree/bindings/firmware/arm,scpi.yaml for details of the devicetree node. -- cgit v1.2.3 From 04165fb73f9b8ea9e5cc2f3c21ca2a777516fc7b Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Mon, 26 Jul 2021 19:06:14 +0530 Subject: hwmon: (sbrmi) Add Documentation - Add documentation for SB-RMI module Reviewed-by: Guenter Roeck Signed-off-by: Akshay Gupta Signed-off-by: Naveen Krishna Chatradhi Link: https://lore.kernel.org/r/20210726133615.9709-2-nchatrad@amd.com Signed-off-by: Guenter Roeck --- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/sbrmi.rst | 79 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 Documentation/hwmon/sbrmi.rst (limited to 'Documentation') diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index bc01601ea81a..470f2c50ecc2 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -160,6 +160,7 @@ Hardware Monitoring Kernel Drivers pwm-fan q54sj108a2 raspberrypi-hwmon + sbrmi sbtsi_temp sch5627 sch5636 diff --git a/Documentation/hwmon/sbrmi.rst b/Documentation/hwmon/sbrmi.rst new file mode 100644 index 000000000000..296049e13ac9 --- /dev/null +++ b/Documentation/hwmon/sbrmi.rst @@ -0,0 +1,79 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver sbrmi +=================== + +Supported hardware: + + * Sideband Remote Management Interface (SB-RMI) compliant AMD SoC + device connected to the BMC via the APML. + + Prefix: 'sbrmi' + + Addresses scanned: This driver doesn't support address scanning. + + To instantiate this driver on an AMD CPU with SB-RMI + support, the i2c bus number would be the bus connected from the board + management controller (BMC) to the CPU. + The SMBus address is really 7 bits. Some vendors and the SMBus + specification show the address as 8 bits, left justified with the R/W + bit as a write (0) making bit 0. Some vendors use only the 7 bits + to describe the address. + As mentioned in AMD's APML specification, The SB-RMI address is + normally 78h(0111 100W) or 3Ch(011 1100) for socket 0 and 70h(0111 000W) + or 38h(011 1000) for socket 1, but it could vary based on hardware + address select pins. + + Datasheet: The SB-RMI interface and protocol along with the Advanced + Platform Management Link (APML) Specification is available + as part of the open source SoC register reference at: + + https://www.amd.com/en/support/tech-docs?keyword=55898 + +Author: Akshay Gupta + +Description +----------- + +The APML provides a way to communicate with the SB Remote Management interface +(SB-RMI) module from the external SMBus master that can be used to report socket +power on AMD platforms using mailbox command and resembles a typical 8-pin remote +power sensor's I2C interface to BMC. + +This driver implements current power with power cap and power cap max. + +sysfs-Interface +--------------- +Power sensors can be queried and set via the standard ``hwmon`` interface +on ``sysfs``, under the directory ``/sys/class/hwmon/hwmonX`` for some value +of ``X`` (search for the ``X`` such that ``/sys/class/hwmon/hwmonX/name`` has +content ``sbrmi``) + +================ ===== ======================================================== +Name Perm Description +================ ===== ======================================================== +power1_input RO Current Power consumed +power1_cap RW Power limit can be set between 0 and power1_cap_max +power1_cap_max RO Maximum powerlimit calculated and reported by the SMU FW +================ ===== ======================================================== + +The following example show how the 'Power' attribute from the i2c-addresses +can be monitored using the userspace utilities like ``sensors`` binary:: + + # sensors + sbrmi-i2c-1-38 + Adapter: bcm2835 I2C adapter + power1: 61.00 W (cap = 225.00 W) + + sbrmi-i2c-1-3c + Adapter: bcm2835 I2C adapter + power1: 28.39 W (cap = 224.77 W) + # + +Also, Below shows how get and set the values from sysfs entries individually:: + # cat /sys/class/hwmon/hwmon1/power1_cap_max + 225000000 + + # echo 180000000 > /sys/class/hwmon/hwmon1/power1_cap + # cat /sys/class/hwmon/hwmon1/power1_cap + 180000000 -- cgit v1.2.3 From 60b76c3a117ce076f60f58de17bae1122849746a Mon Sep 17 00:00:00 2001 From: Akshay Gupta Date: Mon, 26 Jul 2021 19:06:15 +0530 Subject: dt-bindings: sbrmi: Add SB-RMI hwmon driver bindings - Document device tree bindings for AMD SB-RMI emulated service. Signed-off-by: Akshay Gupta Signed-off-by: Naveen Krishna Chatradhi Reviewed-by: Rob Herring Link: https://lore.kernel.org/r/20210726133615.9709-3-nchatrad@amd.com Signed-off-by: Guenter Roeck --- .../devicetree/bindings/hwmon/amd,sbrmi.yaml | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml b/Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml new file mode 100644 index 000000000000..7598b083979c --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/amd,sbrmi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: > + Sideband Remote Management Interface (SB-RMI) compliant + AMD SoC power device. + +maintainers: + - Akshay Gupta + +description: | + SB Remote Management Interface (SB-RMI) is an SMBus compatible + interface that reports AMD SoC's Power (normalized Power) using, + Mailbox Service Request and resembles a typical 8-pin remote power + sensor's I2C interface to BMC. The power attributes in hwmon + reports power in microwatts. + +properties: + compatible: + enum: + - amd,sbrmi + + reg: + maxItems: 1 + description: | + I2C bus address of the device as specified in Section SBI SMBus Address + of the SoC register reference. The SB-RMI address is normally 78h for + socket 0 and 70h for socket 1, but it could vary based on hardware + address select pins. + \[open source SoC register reference\] + https://www.amd.com/en/support/tech-docs?keyword=55898 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c0 { + #address-cells = <1>; + #size-cells = <0>; + + sbrmi@3c { + compatible = "amd,sbrmi"; + reg = <0x3c>; + }; + }; +... -- cgit v1.2.3 From 542613a25eff333488c331dd92066388a6bf95bb Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 30 Jul 2021 01:05:42 +0200 Subject: dt-bindings: hwmon: Add bindings for Winbond W83781D This adds a device tree binding for the Winbond W83781D and its sibling HW monitoring ICs. This is used in for example the Freecom FSG-3 router/NAS. Cc: devicetree@vger.kernel.org Signed-off-by: Linus Walleij Reviewed-by: Rob Herring Link: https://lore.kernel.org/r/20210729230543.2853485-1-linus.walleij@linaro.org Signed-off-by: Guenter Roeck --- .../devicetree/bindings/hwmon/winbond,w83781d.yaml | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/winbond,w83781d.yaml (limited to 'Documentation') diff --git a/Documentation/devicetree/bindings/hwmon/winbond,w83781d.yaml b/Documentation/devicetree/bindings/hwmon/winbond,w83781d.yaml new file mode 100644 index 000000000000..31ce77a4b087 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/winbond,w83781d.yaml @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/hwmon/winbond,w83781d.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Winbond W83781 and compatible hardware monitor IC + +maintainers: + - Linus Walleij + +properties: + compatible: + enum: + - winbond,w83781d + - winbond,w83781g + - winbond,w83782d + - winbond,w83783s + - asus,as99127f + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + temperature-sensor@28 { + compatible = "winbond,w83781d"; + reg = <0x28>; + }; + }; -- cgit v1.2.3 From 0e35f63f7f4eebd268ec236fd1bbf4e561ce8de5 Mon Sep 17 00:00:00 2001 From: Aleksa Savic Date: Sat, 28 Aug 2021 07:26:28 +0200 Subject: hwmon: add driver for Aquacomputer D5 Next This driver exposes hardware sensors of the Aquacomputer D5 Next watercooling pump, which communicates through a proprietary USB HID protocol. Available sensors are pump and fan speed, power, voltage and current, as well as coolant temperature. Also available through debugfs are the serial number, firmware version and power-on count. Attaching a fan is optional and allows it to be controlled using temperature curves directly from the pump. If it's not connected, the fan-related sensors will report zeroes. The pump can be configured either through software or via its physical interface. Configuring the pump through this driver is not implemented, as it seems to require sending it a complete configuration. That includes addressable RGB LEDs, for which there is no standard sysfs interface. Thus, that task is better suited for userspace tools. This driver has been tested on x86_64, both in-kernel and as a module. Signed-off-by: Aleksa Savic Signed-off-by: Guenter Roeck --- Documentation/hwmon/aquacomputer_d5next.rst | 61 +++++ Documentation/hwmon/index.rst | 1 + MAINTAINERS | 7 + drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/aquacomputer_d5next.c | 363 ++++++++++++++++++++++++++++ 6 files changed, 443 insertions(+) create mode 100644 Documentation/hwmon/aquacomputer_d5next.rst create mode 100644 drivers/hwmon/aquacomputer_d5next.c (limited to 'Documentation') diff --git a/Documentation/hwmon/aquacomputer_d5next.rst b/Documentation/hwmon/aquacomputer_d5next.rst new file mode 100644 index 000000000000..1f4bb4ba2e4b --- /dev/null +++ b/Documentation/hwmon/aquacomputer_d5next.rst @@ -0,0 +1,61 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver aquacomputer-d5next +================================= + +Supported devices: + +* Aquacomputer D5 Next watercooling pump + +Author: Aleksa Savic + +Description +----------- + +This driver exposes hardware sensors of the Aquacomputer D5 Next watercooling +pump, which communicates through a proprietary USB HID protocol. + +Available sensors are pump and fan speed, power, voltage and current, as +well as coolant temperature. Also available through debugfs are the serial +number, firmware version and power-on count. + +Attaching a fan is optional and allows it to be controlled using temperature +curves directly from the pump. If it's not connected, the fan-related sensors +will report zeroes. + +The pump can be configured either through software or via its physical +interface. Configuring the pump through this driver is not implemented, as it +seems to require sending it a complete configuration. That includes addressable +RGB LEDs, for which there is no standard sysfs interface. Thus, that task is +better suited for userspace tools. + +Usage notes +----------- + +The pump communicates via HID reports. The driver is loaded automatically by +the kernel and supports hotswapping. + +Sysfs entries +------------- + +============ ============================================= +temp1_input Coolant temperature (in millidegrees Celsius) +fan1_input Pump speed (in RPM) +fan2_input Fan speed (in RPM) +power1_input Pump power (in micro Watts) +power2_input Fan power (in micro Watts) +in0_input Pump voltage (in milli Volts) +in1_input Fan voltage (in milli Volts) +in2_input +5V rail voltage (in milli Volts) +curr1_input Pump current (in milli Amperes) +curr2_input Fan current (in milli Amperes) +============ ============================================= + +Debugfs entries +--------------- + +================ =============================================== +serial_number Serial number of the pump +firmware_version Version of installed firmware +power_cycles Count of how many times the pump was powered on +================ =============================================== diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index 470f2c50ecc2..f790f1260c33 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -39,6 +39,7 @@ Hardware Monitoring Kernel Drivers adt7475 aht10 amc6821 + aquacomputer_d5next asb100 asc7621 aspeed-pwm-tacho diff --git a/MAINTAINERS b/MAINTAINERS index c9467d2839f5..4ce7512e8972 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1316,6 +1316,13 @@ L: linux-media@vger.kernel.org S: Maintained F: drivers/media/i2c/aptina-pll.* +AQUACOMPUTER D5 NEXT PUMP SENSOR DRIVER +M: Aleksa Savic +L: linux-hwmon@vger.kernel.org +S: Maintained +F: Documentation/hwmon/aquacomputer_d5next.rst +F: drivers/hwmon/aquacomputer_d5next.c + AQUANTIA ETHERNET DRIVER (atlantic) M: Igor Russkikh L: netdev@vger.kernel.org diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 64533141ea4a..c4578e8f34bb 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -254,6 +254,16 @@ config SENSORS_AHT10 This driver can also be built as a module. If so, the module will be called aht10. +config SENSORS_AQUACOMPUTER_D5NEXT + tristate "Aquacomputer D5 Next watercooling pump" + depends on USB_HID + help + If you say yes here you get support for the Aquacomputer D5 Next + watercooling pump sensors. + + This driver can also be built as a module. If so, the module + will be called aquacomputer_d5next. + config SENSORS_AS370 tristate "Synaptics AS370 SoC hardware monitoring driver" help diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 4b33421746c0..162940270661 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -46,6 +46,7 @@ obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o obj-$(CONFIG_SENSORS_AHT10) += aht10.o obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o +obj-$(CONFIG_SENSORS_AQUACOMPUTER_D5NEXT) += aquacomputer_d5next.o obj-$(CONFIG_SENSORS_ARM_SCMI) += scmi-hwmon.o obj-$(CONFIG_SENSORS_ARM_SCPI) += scpi-hwmon.o obj-$(CONFIG_SENSORS_AS370) += as370-hwmon.o diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c new file mode 100644 index 000000000000..fb9341a53051 --- /dev/null +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -0,0 +1,363 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * hwmon driver for Aquacomputer D5 Next watercooling pump + * + * The D5 Next sends HID reports (with ID 0x01) every second to report sensor values + * (coolant temperature, pump and fan speed, voltage, current and power). It responds to + * Get_Report requests, but returns a dummy value of no use. + * + * Copyright 2021 Aleksa Savic + */ + +#include +#include +#include +#include +#include +#include +#include + +#define DRIVER_NAME "aquacomputer-d5next" + +#define D5NEXT_STATUS_REPORT_ID 0x01 +#define D5NEXT_STATUS_UPDATE_INTERVAL (2 * HZ) /* In seconds */ + +/* Register offsets for the D5 Next pump */ + +#define D5NEXT_SERIAL_FIRST_PART 3 +#define D5NEXT_SERIAL_SECOND_PART 5 +#define D5NEXT_FIRMWARE_VERSION 13 +#define D5NEXT_POWER_CYCLES 24 + +#define D5NEXT_COOLANT_TEMP 87 + +#define D5NEXT_PUMP_SPEED 116 +#define D5NEXT_FAN_SPEED 103 + +#define D5NEXT_PUMP_POWER 114 +#define D5NEXT_FAN_POWER 101 + +#define D5NEXT_PUMP_VOLTAGE 110 +#define D5NEXT_FAN_VOLTAGE 97 +#define D5NEXT_5V_VOLTAGE 57 + +#define D5NEXT_PUMP_CURRENT 112 +#define D5NEXT_FAN_CURRENT 99 + +/* Labels for provided values */ + +#define L_COOLANT_TEMP "Coolant temp" + +#define L_PUMP_SPEED "Pump speed" +#define L_FAN_SPEED "Fan speed" + +#define L_PUMP_POWER "Pump power" +#define L_FAN_POWER "Fan power" + +#define L_PUMP_VOLTAGE "Pump voltage" +#define L_FAN_VOLTAGE "Fan voltage" +#define L_5V_VOLTAGE "+5V voltage" + +#define L_PUMP_CURRENT "Pump current" +#define L_FAN_CURRENT "Fan current" + +static const char *const label_speeds[] = { + L_PUMP_SPEED, + L_FAN_SPEED, +}; + +static const char *const label_power[] = { + L_PUMP_POWER, + L_FAN_POWER, +}; + +static const char *const label_voltages[] = { + L_PUMP_VOLTAGE, + L_FAN_VOLTAGE, + L_5V_VOLTAGE, +}; + +static const char *const label_current[] = { + L_PUMP_CURRENT, + L_FAN_CURRENT, +}; + +struct d5next_data { + struct hid_device *hdev; + struct device *hwmon_dev; + struct dentry *debugfs; + s32 temp_input; + u16 speed_input[2]; + u32 power_input[2]; + u16 voltage_input[3]; + u16 current_input[2]; + u32 serial_number[2]; + u16 firmware_version; + u32 power_cycles; /* How many times the device was powered on */ + unsigned long updated; +}; + +static umode_t d5next_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, + int channel) +{ + return 0444; +} + +static int d5next_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, + long *val) +{ + struct d5next_data *priv = dev_get_drvdata(dev); + + if (time_after(jiffies, priv->updated + D5NEXT_STATUS_UPDATE_INTERVAL)) + return -ENODATA; + + switch (type) { + case hwmon_temp: + *val = priv->temp_input; + break; + case hwmon_fan: + *val = priv->speed_input[channel]; + break; + case hwmon_power: + *val = priv->power_input[channel]; + break; + case hwmon_in: + *val = priv->voltage_input[channel]; + break; + case hwmon_curr: + *val = priv->current_input[channel]; + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static int d5next_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr, + int channel, const char **str) +{ + switch (type) { + case hwmon_temp: + *str = L_COOLANT_TEMP; + break; + case hwmon_fan: + *str = label_speeds[channel]; + break; + case hwmon_power: + *str = label_power[channel]; + break; + case hwmon_in: + *str = label_voltages[channel]; + break; + case hwmon_curr: + *str = label_current[channel]; + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static const struct hwmon_ops d5next_hwmon_ops = { + .is_visible = d5next_is_visible, + .read = d5next_read, + .read_string = d5next_read_string, +}; + +static const struct hwmon_channel_info *d5next_info[] = { + HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_LABEL), + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_LABEL, HWMON_F_INPUT | HWMON_F_LABEL), + HWMON_CHANNEL_INFO(power, HWMON_P_INPUT | HWMON_P_LABEL, HWMON_P_INPUT | HWMON_P_LABEL), + HWMON_CHANNEL_INFO(in, HWMON_I_INPUT | HWMON_I_LABEL, HWMON_I_INPUT | HWMON_I_LABEL, + HWMON_I_INPUT | HWMON_I_LABEL), + HWMON_CHANNEL_INFO(curr, HWMON_C_INPUT | HWMON_C_LABEL, HWMON_C_INPUT | HWMON_C_LABEL), + NULL +}; + +static const struct hwmon_chip_info d5next_chip_info = { + .ops = &d5next_hwmon_ops, + .info = d5next_info, +}; + +static int d5next_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size) +{ + struct d5next_data *priv; + + if (report->id != D5NEXT_STATUS_REPORT_ID) + return 0; + + priv = hid_get_drvdata(hdev); + + /* Info provided with every report */ + + priv->serial_number[0] = get_unaligned_be16(data + D5NEXT_SERIAL_FIRST_PART); + priv->serial_number[1] = get_unaligned_be16(data + D5NEXT_SERIAL_SECOND_PART); + + priv->firmware_version = get_unaligned_be16(data + D5NEXT_FIRMWARE_VERSION); + priv->power_cycles = get_unaligned_be32(data + D5NEXT_POWER_CYCLES); + + /* Sensor readings */ + + priv->temp_input = get_unaligned_be16(data + D5NEXT_COOLANT_TEMP) * 10; + + priv->speed_input[0] = get_unaligned_be16(data + D5NEXT_PUMP_SPEED); + priv->speed_input[1] = get_unaligned_be16(data + D5NEXT_FAN_SPEED); + + priv->power_input[0] = get_unaligned_be16(data + D5NEXT_PUMP_POWER) * 10000; + priv->power_input[1] = get_unaligned_be16(data + D5NEXT_FAN_POWER) * 10000; + + priv->voltage_input[0] = get_unaligned_be16(data + D5NEXT_PUMP_VOLTAGE) * 10; + priv->voltage_input[1] = get_unaligned_be16(data + D5NEXT_FAN_VOLTAGE) * 10; + priv->voltage_input[2] = get_unaligned_be16(data + D5NEXT_5V_VOLTAGE) * 10; + + priv->current_input[0] = get_unaligned_be16(data + D5NEXT_PUMP_CURRENT); + priv->current_input[1] = get_unaligned_be16(data + D5NEXT_FAN_CURRENT); + + priv->updated = jiffies; + + return 0; +} + +#ifdef CONFIG_DEBUG_FS + +static int serial_number_show(struct seq_file *seqf, void *unused) +{ + struct d5next_data *priv = seqf->private; + + seq_printf(seqf, "%05u-%05u\n", priv->serial_number[0], priv->serial_number[1]); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(serial_number); + +static int firmware_version_show(struct seq_file *seqf, void *unused) +{ + struct d5next_data *priv = seqf->private; + + seq_printf(seqf, "%u\n", priv->firmware_version); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(firmware_version); + +static int power_cycles_show(struct seq_file *seqf, void *unused) +{ + struct d5next_data *priv = seqf->private; + + seq_printf(seqf, "%u\n", priv->power_cycles); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(power_cycles); + +static void d5next_debugfs_init(struct d5next_data *priv) +{ + char name[32]; + + scnprintf(name, sizeof(name), "%s-%s", DRIVER_NAME, dev_name(&priv->hdev->dev)); + + priv->debugfs = debugfs_create_dir(name, NULL); + debugfs_create_file("serial_number", 0444, priv->debugfs, priv, &serial_number_fops); + debugfs_create_file("firmware_version", 0444, priv->debugfs, priv, &firmware_version_fops); + debugfs_create_file("power_cycles", 0444, priv->debugfs, priv, &power_cycles_fops); +} + +#else + +static void d5next_debugfs_init(struct d5next_data *priv) +{ +} + +#endif + +static int d5next_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ + struct d5next_data *priv; + int ret; + + priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->hdev = hdev; + hid_set_drvdata(hdev, priv); + + priv->updated = jiffies - D5NEXT_STATUS_UPDATE_INTERVAL; + + ret = hid_parse(hdev); + if (ret) + return ret; + + ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); + if (ret) + return ret; + + ret = hid_hw_open(hdev); + if (ret) + goto fail_and_stop; + + priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "d5next", priv, + &d5next_chip_info, NULL); + + if (IS_ERR(priv->hwmon_dev)) { + ret = PTR_ERR(priv->hwmon_dev); + goto fail_and_close; + } + + d5next_debugfs_init(priv); + + return 0; + +fail_and_close: + hid_hw_close(hdev); +fail_and_stop: + hid_hw_stop(hdev); + return ret; +} + +static void d5next_remove(struct hid_device *hdev) +{ + struct d5next_data *priv = hid_get_drvdata(hdev); + + debugfs_remove_recursive(priv->debugfs); + hwmon_device_unregister(priv->hwmon_dev); + + hid_hw_close(hdev); + hid_hw_stop(hdev); +} + +static const struct hid_device_id d5next_table[] = { + { HID_USB_DEVICE(0x0c70, 0xf00e) }, /* Aquacomputer D5 Next */ + {}, +}; + +MODULE_DEVICE_TABLE(hid, d5next_table); + +static struct hid_driver d5next_driver = { + .name = DRIVER_NAME, + .id_table = d5next_table, + .probe = d5next_probe, + .remove = d5next_remove, + .raw_event = d5next_raw_event, +}; + +static int __init d5next_init(void) +{ + return hid_register_driver(&d5next_driver); +} + +static void __exit d5next_exit(void) +{ + hid_unregister_driver(&d5next_driver); +} + +/* Request to initialize after the HID bus to ensure it's not being loaded before */ + +late_initcall(d5next_init); +module_exit(d5next_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Aleksa Savic "); +MODULE_DESCRIPTION("Hwmon driver for Aquacomputer D5 Next pump"); -- cgit v1.2.3