linux/drivers/hwmon/aquacomputer_d5next.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * hwmon driver for Aquacomputer devices (D5 Next, Farbwerk, Farbwerk 360, Octo,
 * Quadro, High Flow Next, Aquaero, Aquastream Ultimate, Leakshield,
 * High Flow USB/MPS Flow family)
 *
 * Aquacomputer devices send HID reports (with ID 0x01) every second to report
 * sensor values, except for devices that communicate through the
 * legacy way (currently, Poweradjust 3 and High Flow USB/MPS Flow family).
 *
 * Copyright 2021 Aleksa Savic <[email protected]>
 * Copyright 2022 Jack Doan <[email protected]>
 */

#include <linux/crc16.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/hid.h>
#include <linux/hwmon.h>
#include <linux/jiffies.h>
#include <linux/ktime.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/seq_file.h>
#include <asm/unaligned.h>

#define USB_VENDOR_ID_AQUACOMPUTER
#define USB_PRODUCT_ID_AQUAERO
#define USB_PRODUCT_ID_FARBWERK
#define USB_PRODUCT_ID_QUADRO
#define USB_PRODUCT_ID_D5NEXT
#define USB_PRODUCT_ID_FARBWERK360
#define USB_PRODUCT_ID_OCTO
#define USB_PRODUCT_ID_HIGHFLOWNEXT
#define USB_PRODUCT_ID_LEAKSHIELD
#define USB_PRODUCT_ID_AQUASTREAMXT
#define USB_PRODUCT_ID_AQUASTREAMULT
#define USB_PRODUCT_ID_POWERADJUST3
#define USB_PRODUCT_ID_HIGHFLOW

enum kinds {};

static const char *const aqc_device_names[] =;

#define DRIVER_NAME

#define STATUS_REPORT_ID
#define STATUS_UPDATE_INTERVAL
#define SERIAL_PART_OFFSET

#define CTRL_REPORT_ID
#define AQUAERO_CTRL_REPORT_ID

#define CTRL_REPORT_DELAY

/* The HID report that the official software always sends
 * after writing values, currently same for all devices
 */
#define SECONDARY_CTRL_REPORT_ID
#define SECONDARY_CTRL_REPORT_SIZE

static u8 secondary_ctrl_report[] =;

/* Secondary HID report values for Aquaero */
#define AQUAERO_SECONDARY_CTRL_REPORT_ID
#define AQUAERO_SECONDARY_CTRL_REPORT_SIZE

static u8 aquaero_secondary_ctrl_report[] =;

/* Report IDs for legacy devices */
#define AQUASTREAMXT_STATUS_REPORT_ID

#define POWERADJUST3_STATUS_REPORT_ID

#define HIGHFLOW_STATUS_REPORT_ID

/* Data types for reading and writing control reports */
#define AQC_8
#define AQC_BE16

/* Info, sensor sizes and offsets for most Aquacomputer devices */
#define AQC_SERIAL_START
#define AQC_FIRMWARE_VERSION

#define AQC_SENSOR_SIZE
#define AQC_SENSOR_NA
#define AQC_FAN_PERCENT_OFFSET
#define AQC_FAN_VOLTAGE_OFFSET
#define AQC_FAN_CURRENT_OFFSET
#define AQC_FAN_POWER_OFFSET
#define AQC_FAN_SPEED_OFFSET

/* Specs of the Aquaero fan controllers */
#define AQUAERO_SERIAL_START
#define AQUAERO_FIRMWARE_VERSION
#define AQUAERO_NUM_FANS
#define AQUAERO_NUM_SENSORS
#define AQUAERO_NUM_VIRTUAL_SENSORS
#define AQUAERO_NUM_CALC_VIRTUAL_SENSORS
#define AQUAERO_NUM_FLOW_SENSORS
#define AQUAERO_CTRL_REPORT_SIZE
#define AQUAERO_CTRL_PRESET_ID
#define AQUAERO_CTRL_PRESET_SIZE
#define AQUAERO_CTRL_PRESET_START

/* Sensor report offsets for Aquaero fan controllers */
#define AQUAERO_SENSOR_START
#define AQUAERO_VIRTUAL_SENSOR_START
#define AQUAERO_CALC_VIRTUAL_SENSOR_START
#define AQUAERO_FLOW_SENSORS_START
#define AQUAERO_FAN_VOLTAGE_OFFSET
#define AQUAERO_FAN_CURRENT_OFFSET
#define AQUAERO_FAN_POWER_OFFSET
#define AQUAERO_FAN_SPEED_OFFSET
static u16 aquaero_sensor_fan_offsets[] =;

/* Control report offsets for the Aquaero fan controllers */
#define AQUAERO_TEMP_CTRL_OFFSET
#define AQUAERO_FAN_CTRL_MIN_PWR_OFFSET
#define AQUAERO_FAN_CTRL_MAX_PWR_OFFSET
#define AQUAERO_FAN_CTRL_SRC_OFFSET
static u16 aquaero_ctrl_fan_offsets[] =;

/* Specs of the D5 Next pump */
#define D5NEXT_NUM_FANS
#define D5NEXT_NUM_SENSORS
#define D5NEXT_NUM_VIRTUAL_SENSORS
#define D5NEXT_CTRL_REPORT_SIZE

/* Sensor report offsets for the D5 Next pump */
#define D5NEXT_POWER_CYCLES
#define D5NEXT_COOLANT_TEMP
#define D5NEXT_PUMP_OFFSET
#define D5NEXT_FAN_OFFSET
#define D5NEXT_5V_VOLTAGE
#define D5NEXT_12V_VOLTAGE
#define D5NEXT_VIRTUAL_SENSORS_START
static u16 d5next_sensor_fan_offsets[] =;

/* Control report offsets for the D5 Next pump */
#define D5NEXT_TEMP_CTRL_OFFSET
static u16 d5next_ctrl_fan_offsets[] =;	/* Pump and fan speed (from 0-100%) */

/* Specs of the Aquastream Ultimate pump */
/* Pump does not follow the standard structure, so only consider the fan */
#define AQUASTREAMULT_NUM_FANS
#define AQUASTREAMULT_NUM_SENSORS

/* Sensor report offsets for the Aquastream Ultimate pump */
#define AQUASTREAMULT_SENSOR_START
#define AQUASTREAMULT_PUMP_OFFSET
#define AQUASTREAMULT_PUMP_VOLTAGE
#define AQUASTREAMULT_PUMP_CURRENT
#define AQUASTREAMULT_PUMP_POWER
#define AQUASTREAMULT_FAN_OFFSET
#define AQUASTREAMULT_PRESSURE_OFFSET
#define AQUASTREAMULT_FLOW_SENSOR_OFFSET
#define AQUASTREAMULT_FAN_VOLTAGE_OFFSET
#define AQUASTREAMULT_FAN_CURRENT_OFFSET
#define AQUASTREAMULT_FAN_POWER_OFFSET
#define AQUASTREAMULT_FAN_SPEED_OFFSET
static u16 aquastreamult_sensor_fan_offsets[] =;

/* Spec and sensor report offset for the Farbwerk RGB controller */
#define FARBWERK_NUM_SENSORS
#define FARBWERK_SENSOR_START

/* Specs of the Farbwerk 360 RGB controller */
#define FARBWERK360_NUM_SENSORS
#define FARBWERK360_NUM_VIRTUAL_SENSORS
#define FARBWERK360_CTRL_REPORT_SIZE

/* Sensor report offsets for the Farbwerk 360 */
#define FARBWERK360_SENSOR_START
#define FARBWERK360_VIRTUAL_SENSORS_START

/* Control report offsets for the Farbwerk 360 */
#define FARBWERK360_TEMP_CTRL_OFFSET

/* Specs of the Octo fan controller */
#define OCTO_NUM_FANS
#define OCTO_NUM_SENSORS
#define OCTO_NUM_VIRTUAL_SENSORS
#define OCTO_NUM_FLOW_SENSORS
#define OCTO_CTRL_REPORT_SIZE

/* Sensor report offsets for the Octo */
#define OCTO_POWER_CYCLES
#define OCTO_SENSOR_START
#define OCTO_VIRTUAL_SENSORS_START
#define OCTO_FLOW_SENSOR_OFFSET
static u16 octo_sensor_fan_offsets[] =;

/* Control report offsets for the Octo */
#define OCTO_TEMP_CTRL_OFFSET
#define OCTO_FLOW_PULSES_CTRL_OFFSET
/* Fan speed offsets (0-100%) */
static u16 octo_ctrl_fan_offsets[] =;

/* Specs of Quadro fan controller */
#define QUADRO_NUM_FANS
#define QUADRO_NUM_SENSORS
#define QUADRO_NUM_VIRTUAL_SENSORS
#define QUADRO_NUM_FLOW_SENSORS
#define QUADRO_CTRL_REPORT_SIZE

/* Sensor report offsets for the Quadro */
#define QUADRO_POWER_CYCLES
#define QUADRO_SENSOR_START
#define QUADRO_VIRTUAL_SENSORS_START
#define QUADRO_FLOW_SENSOR_OFFSET
static u16 quadro_sensor_fan_offsets[] =;

/* Control report offsets for the Quadro */
#define QUADRO_TEMP_CTRL_OFFSET
#define QUADRO_FLOW_PULSES_CTRL_OFFSET
static u16 quadro_ctrl_fan_offsets[] =; /* Fan speed offsets (0-100%) */

/* Specs of High Flow Next flow sensor */
#define HIGHFLOWNEXT_NUM_SENSORS
#define HIGHFLOWNEXT_NUM_FLOW_SENSORS

/* Sensor report offsets for the High Flow Next */
#define HIGHFLOWNEXT_SENSOR_START
#define HIGHFLOWNEXT_FLOW
#define HIGHFLOWNEXT_WATER_QUALITY
#define HIGHFLOWNEXT_POWER
#define HIGHFLOWNEXT_CONDUCTIVITY
#define HIGHFLOWNEXT_5V_VOLTAGE
#define HIGHFLOWNEXT_5V_VOLTAGE_USB

/* Specs of the Leakshield */
#define LEAKSHIELD_NUM_SENSORS

/* Sensor report offsets for Leakshield */
#define LEAKSHIELD_PRESSURE_ADJUSTED
#define LEAKSHIELD_TEMPERATURE_1
#define LEAKSHIELD_TEMPERATURE_2
#define LEAKSHIELD_PRESSURE_MIN
#define LEAKSHIELD_PRESSURE_TARGET
#define LEAKSHIELD_PRESSURE_MAX
#define LEAKSHIELD_PUMP_RPM_IN
#define LEAKSHIELD_FLOW_IN
#define LEAKSHIELD_RESERVOIR_VOLUME
#define LEAKSHIELD_RESERVOIR_FILLED

/* Specs of the Aquastream XT pump */
#define AQUASTREAMXT_SERIAL_START
#define AQUASTREAMXT_FIRMWARE_VERSION
#define AQUASTREAMXT_NUM_FANS
#define AQUASTREAMXT_NUM_SENSORS
#define AQUASTREAMXT_FAN_STOPPED
#define AQUASTREAMXT_PUMP_CONVERSION_CONST
#define AQUASTREAMXT_FAN_CONVERSION_CONST
#define AQUASTREAMXT_SENSOR_REPORT_SIZE

/* Sensor report offsets and info for Aquastream XT */
#define AQUASTREAMXT_SENSOR_START
#define AQUASTREAMXT_FAN_VOLTAGE_OFFSET
#define AQUASTREAMXT_FAN_STATUS_OFFSET
#define AQUASTREAMXT_PUMP_VOLTAGE_OFFSET
#define AQUASTREAMXT_PUMP_CURR_OFFSET
static u16 aquastreamxt_sensor_fan_offsets[] =;

/* Specs of the Poweradjust 3 */
#define POWERADJUST3_NUM_SENSORS
#define POWERADJUST3_SENSOR_REPORT_SIZE

/* Sensor report offsets for the Poweradjust 3 */
#define POWERADJUST3_SENSOR_START

/* Specs of the High Flow USB */
#define HIGHFLOW_NUM_SENSORS
#define HIGHFLOW_NUM_FLOW_SENSORS
#define HIGHFLOW_SENSOR_REPORT_SIZE

/* Sensor report offsets for the High Flow USB */
#define HIGHFLOW_FIRMWARE_VERSION
#define HIGHFLOW_SERIAL_START
#define HIGHFLOW_FLOW_SENSOR_OFFSET
#define HIGHFLOW_SENSOR_START

/* Labels for D5 Next */
static const char *const label_d5next_temp[] =;

static const char *const label_d5next_speeds[] =;

static const char *const label_d5next_power[] =;

static const char *const label_d5next_voltages[] =;

static const char *const label_d5next_current[] =;

/* Labels for Aquaero, Farbwerk, Farbwerk 360 and Octo and Quadro temperature sensors */
static const char *const label_temp_sensors[] =;

static const char *const label_virtual_temp_sensors[] =;

static const char *const label_aquaero_calc_temp_sensors[] =;

static const char *const label_fan_power[] =;

static const char *const label_fan_voltage[] =;

static const char *const label_fan_current[] =;

/* Labels for Octo fan speeds */
static const char *const label_octo_speeds[] =;

/* Labels for Quadro fan speeds */
static const char *const label_quadro_speeds[] =;

/* Labels for Aquaero fan speeds */
static const char *const label_aquaero_speeds[] =;

/* Labels for High Flow Next */
static const char *const label_highflownext_temp_sensors[] =;

static const char *const label_highflownext_fan_speed[] =;

static const char *const label_highflownext_power[] =;

static const char *const label_highflownext_voltage[] =;

/* Labels for Leakshield */
static const char *const label_leakshield_temp_sensors[] =;

static const char *const label_leakshield_fan_speed[] =;

/* Labels for Aquastream XT */
static const char *const label_aquastreamxt_temp_sensors[] =;

/* Labels for Aquastream Ultimate */
static const char *const label_aquastreamult_temp[] =;

static const char *const label_aquastreamult_speeds[] =;

static const char *const label_aquastreamult_power[] =;

static const char *const label_aquastreamult_voltages[] =;

static const char *const label_aquastreamult_current[] =;

/* Labels for Poweradjust 3 */
static const char *const label_poweradjust3_temp_sensors[] =;

/* Labels for Highflow */
static const char *const label_highflow_temp[] =;

static const char *const label_highflow_speeds[] =;

struct aqc_fan_structure_offsets {};

/* Fan structure offsets for Aquaero */
static struct aqc_fan_structure_offsets aqc_aquaero_fan_structure =;

/* Fan structure offsets for Aquastream Ultimate */
static struct aqc_fan_structure_offsets aqc_aquastreamult_fan_structure =;

/* Fan structure offsets for all devices except those above */
static struct aqc_fan_structure_offsets aqc_general_fan_structure =;

struct aqc_data {};

/* Converts from centi-percent */
static int aqc_percent_to_pwm(u16 val)
{}

/* Converts to centi-percent */
static int aqc_pwm_to_percent(long val)
{}

/* Converts raw value for Aquastream XT pump speed to RPM */
static int aqc_aquastreamxt_convert_pump_rpm(u16 val)
{}

/* Converts raw value for Aquastream XT fan speed to RPM */
static int aqc_aquastreamxt_convert_fan_rpm(u16 val)
{}

static void aqc_delay_ctrl_report(struct aqc_data *priv)
{}

/* Expects the mutex to be locked */
static int aqc_get_ctrl_data(struct aqc_data *priv)
{}

/* Expects the mutex to be locked */
static int aqc_send_ctrl_data(struct aqc_data *priv)
{}

/* Refreshes the control buffer and stores value at offset in val */
static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val, int type)
{}

static int aqc_set_ctrl_vals(struct aqc_data *priv, int *offsets, long *vals, int *types, int len)
{}

static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int type)
{}

static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel)
{}

/* Read device sensors by manually requesting the sensor report (legacy way) */
static int aqc_legacy_read(struct aqc_data *priv)
{}

static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
		    int channel, long *val)
{}

static int aqc_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
			   int channel, const char **str)
{}

static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
		     long val)
{}

static const struct hwmon_ops aqc_hwmon_ops =;

static const struct hwmon_channel_info * const aqc_info[] =;

static const struct hwmon_chip_info aqc_chip_info =;

static int aqc_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size)
{}

static int serial_number_show(struct seq_file *seqf, void *unused)
{}
DEFINE_SHOW_ATTRIBUTE();

static int firmware_version_show(struct seq_file *seqf, void *unused)
{}
DEFINE_SHOW_ATTRIBUTE();

static int power_cycles_show(struct seq_file *seqf, void *unused)
{}
DEFINE_SHOW_ATTRIBUTE();

static void aqc_debugfs_init(struct aqc_data *priv)
{}

static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id)
{}

static void aqc_remove(struct hid_device *hdev)
{}

static const struct hid_device_id aqc_table[] =;

MODULE_DEVICE_TABLE(hid, aqc_table);

static struct hid_driver aqc_driver =;

static int __init aqc_init(void)
{}

static void __exit aqc_exit(void)
{}

/* Request to initialize after the HID bus to ensure it's not being loaded before */
late_initcall(aqc_init);
module_exit(aqc_exit);

MODULE_LICENSE();
MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_DESCRIPTION();