From patchwork Sat Feb 11 16:59:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Anderweit X-Patchwork-Id: 13137182 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B613C636CC for ; Sat, 11 Feb 2023 16:59:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229585AbjBKQ7Q (ORCPT ); Sat, 11 Feb 2023 11:59:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjBKQ7P (ORCPT ); Sat, 11 Feb 2023 11:59:15 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA91226BD; Sat, 11 Feb 2023 08:59:09 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id a2so8157518wrd.6; Sat, 11 Feb 2023 08:59:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z8H+7AINgI/jSeO6Q1IIPfehvvwLhaBeqo0zrK6WmkI=; b=I7gLmbz/f4+259Xiaw35bd0ebOFt3voVdnioFgdpDAZ7pZgk4zdIpXKx8RpcTpwP2y 9HH62/MDUaPdFcH6dxx67BRfanX8HUe0QvPQfaQnyatx1oD+y0HeysQP4znOV9VL0aKl An9+Gbhe7CQeEH3/8J6dMyxQ+dbF5qEo5e/4+hOMwi9m4S16ZPm52NeJ0tx2iDrLXEsQ rR27LRODx3uxfDrgXRWiHnVyxr4hNamLwWYPESK0f2WzHe9ELNztBCLx2Vlif//LEC5N Pe7B0tugTjH004HLn0Y2OgIRohkwHG67tJteDovibkMDPT71j/yJ3Vm37QnJ77bLE2yf 5DdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z8H+7AINgI/jSeO6Q1IIPfehvvwLhaBeqo0zrK6WmkI=; b=OdhzFVgkljf6EEUGXxDZ0byPGQontH3GMqeZAqUxUyQDePRKbjl7+Ti0lMCHq9vmEv SL+wRtMyf6mZT7OJaV9sqjmW6yiuSyLBjzwc6Bskpc3QbcjimQLi+LG5/DCe1T+Y2hBe untcCMxglKYl1+ErutcfEXTOLOzl37BHNDCcvujxxZ2YO5nWZ/2AgeXrhfuLGC3wwJOH vQFO3F+31MZT7wukyukTUVsc9Qh0Q8PvwVMYbxhqPjtZf55V5nFeC7GvI+FsoyNY4foW EYdrXazqHJ5Gv67gs3y0gQzLUO87lG7I3gmbHp+TH45IuQm+67JZHn0EY1EsGpXBsYpq HPKw== X-Gm-Message-State: AO0yUKUmNIzF4oyForoTJ65Jp9hd8W3k7WJUYhRbdmfoFIfHqpf89y+9 NhLqRtZCmfhlXrCUKtcz26RVfCGdp8VT3w== X-Google-Smtp-Source: AK7set+khXAQrtDghP+lf5bYXrAmWEDEoKrgaAv2fsmj1iAsb7w8JzNx3Cj5mIoe20THBOhrRVwwFQ== X-Received: by 2002:a5d:5583:0:b0:2bf:bc75:1730 with SMTP id i3-20020a5d5583000000b002bfbc751730mr16555726wrv.70.1676134749152; Sat, 11 Feb 2023 08:59:09 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20d3:ac00:30d6:d4a1:e6f6:5876]) by smtp.gmail.com with ESMTPSA id k16-20020adfe8d0000000b002c54536c662sm5097893wrn.34.2023.02.11.08.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 08:59:08 -0800 (PST) From: Leonard Anderweit To: linux-hwmon@vger.kernel.org Cc: Aleksa Savic , Jack Doan , Jean Delvare , Guenter Roeck , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Leonard Anderweit Subject: [PATCH 1/5] hwmon: (aquacomputer_d5next) Support one byte control values Date: Sat, 11 Feb 2023 17:59:19 +0100 Message-Id: <20230211165923.17807-2-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230211165923.17807-1-leonard.anderweit@gmail.com> References: <20230211165923.17807-1-leonard.anderweit@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add support for one byte control values. This extends aqc_set_ctrl_val() and aqc_get_ctrl_val() with a type. Currently supported types are AQC_8 (one byte) and AQC_BE16 (two bytes big endian). More types will be added in the future. Signed-off-by: Leonard Anderweit --- drivers/hwmon/aquacomputer_d5next.c | 47 +++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index 12682a610ce7..d69c2396854c 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -70,6 +70,10 @@ static u8 secondary_ctrl_report[] = { /* Report IDs for legacy devices */ #define POWERADJUST3_STATUS_REPORT_ID 0x03 +/* Data types for reading and writing control reports */ +#define AQC_8 0 +#define AQC_BE16 1 + /* Info, sensor sizes and offsets for most Aquacomputer devices */ #define AQC_SERIAL_START 0x3 #define AQC_FIRMWARE_VERSION 0xD @@ -544,7 +548,7 @@ 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) +static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val, int type) { int ret; @@ -554,14 +558,23 @@ static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val) if (ret < 0) goto unlock_and_return; - *val = (s16)get_unaligned_be16(priv->buffer + offset); + switch (type) { + case AQC_BE16: + *val = (s16)get_unaligned_be16(priv->buffer + offset); + break; + case AQC_8: + *val = priv->buffer[offset]; + break; + default: + ret = -EINVAL; + } unlock_and_return: mutex_unlock(&priv->mutex); return ret; } -static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val) +static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int type) { int ret; @@ -571,7 +584,18 @@ static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val) if (ret < 0) goto unlock_and_return; - put_unaligned_be16((s16)val, priv->buffer + offset); + switch (type) { + case AQC_BE16: + put_unaligned_be16((s16)val, priv->buffer + offset); + break; + case AQC_8: + priv->buffer[offset] = (u8)val; + break; + default: + ret = -EINVAL; + } + if (ret < 0) + goto unlock_and_return; ret = aqc_send_ctrl_data(priv); @@ -775,7 +799,7 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, case hwmon_temp_offset: ret = aqc_get_ctrl_val(priv, priv->temp_ctrl_offset + - channel * AQC_SENSOR_SIZE, val); + channel * AQC_SENSOR_SIZE, val, AQC_BE16); if (ret < 0) return ret; @@ -791,7 +815,8 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, *val = priv->speed_input[channel]; break; case hwmon_fan_pulses: - ret = aqc_get_ctrl_val(priv, priv->flow_pulses_ctrl_offset, val); + ret = aqc_get_ctrl_val(priv, priv->flow_pulses_ctrl_offset, + val, AQC_BE16); if (ret < 0) return ret; break; @@ -804,7 +829,8 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, break; case hwmon_pwm: if (priv->fan_ctrl_offsets) { - ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel], val); + ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel], + val, AQC_BE16); if (ret < 0) return ret; @@ -877,7 +903,7 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, val = clamp_val(val, -15000, 15000) / 10; ret = aqc_set_ctrl_val(priv, priv->temp_ctrl_offset + - channel * AQC_SENSOR_SIZE, val); + channel * AQC_SENSOR_SIZE, val, AQC_BE16); if (ret < 0) return ret; break; @@ -889,7 +915,8 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, switch (attr) { case hwmon_fan_pulses: val = clamp_val(val, 10, 1000); - ret = aqc_set_ctrl_val(priv, priv->flow_pulses_ctrl_offset, val); + ret = aqc_set_ctrl_val(priv, priv->flow_pulses_ctrl_offset, + val, AQC_BE16); if (ret < 0) return ret; break; @@ -906,7 +933,7 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, return pwm_value; ret = aqc_set_ctrl_val(priv, priv->fan_ctrl_offsets[channel], - pwm_value); + pwm_value, AQC_BE16); if (ret < 0) return ret; } From patchwork Sat Feb 11 16:59:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Anderweit X-Patchwork-Id: 13137183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D502C64EC7 for ; Sat, 11 Feb 2023 16:59:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbjBKQ7Q (ORCPT ); Sat, 11 Feb 2023 11:59:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjBKQ7P (ORCPT ); Sat, 11 Feb 2023 11:59:15 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D81F468C; Sat, 11 Feb 2023 08:59:11 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id h16so8126300wrz.12; Sat, 11 Feb 2023 08:59:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2taWdDgLTpL4HSFhwsK1VBZDkJon+2YscjEWs17ebXk=; b=WLkqV+YDbnq9w/tude0NZVCQkdkwtDVmHXXwbN5QzjcBWFm/vinCEPjNvkbU4AtnLx 9O7IKWkAToeZjaSBKsSv7tVVkPHGuhJNQWPzksh3fynie3zrJ34unhGhb1bsdzMkue/M 6GvEx+00Xh3aM6gU1T8hgtU8B3ngqxfdNJ4LidXHPHfP0ctswyFycii4XslrqrODGkDr l47hUAZNjUZgXVjt4ZN16Zgb3PJZcYlVYhQwD0YcT8tO0vXJLxTCho36jCCWqtmUVBF6 r4dEn27wcca4NZXlFeFztbh5HF2hy9ohav/Tgw8eCooHZ8CsfrHslUXkkZsWLWPHd+Uj esPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2taWdDgLTpL4HSFhwsK1VBZDkJon+2YscjEWs17ebXk=; b=d0iUxVeBfyKeJXG59RatBrAH9uuoYQnEbrmL3dAWyMp98wiz0COD0aRSIntsXftqxH f4zv6LuZdPy0ztoyQxuXdP7/jnNp9vxFr3dHOHcP5P+4ZT5nMbK8ybftTBLaLXs04Ri7 bMjAxE6Uf/DUwVYXiSp0jODDnjP/nsBnH6P8ov/4zG3OwzEGcCEErVlwH3rzvSjHhSik zMg9JrGBEPjdcgxpvJSj42pWlU1lo9slA+2tdqzLC0X5O8d57AlzoMnhefUYbpJj2OS0 hVLLgtO59eGOOoqZ32vcvDVaX9jQn6u3szVAskBLsf9Tzm7YTTE4X7DxWhghs48VsAjC UW1Q== X-Gm-Message-State: AO0yUKXCI4HKZn9vSSKzmrsaQJzJ9m8teLRBsMpEpD51zEfr0SNVgkdB 6AQb6nxYPZIdUZoO0W4b81APn/LPWXIdKQ== X-Google-Smtp-Source: AK7set+pzYsN5wGDHt64WllBkjh8BdjpkINHGflTiOkzaQa5dRpmQ4uG36xoe5H9U8nPH6elZFcOHg== X-Received: by 2002:adf:e80d:0:b0:2c5:51a7:efd4 with SMTP id o13-20020adfe80d000000b002c551a7efd4mr1216289wrm.54.1676134749999; Sat, 11 Feb 2023 08:59:09 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20d3:ac00:30d6:d4a1:e6f6:5876]) by smtp.gmail.com with ESMTPSA id k16-20020adfe8d0000000b002c54536c662sm5097893wrn.34.2023.02.11.08.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 08:59:09 -0800 (PST) From: Leonard Anderweit To: linux-hwmon@vger.kernel.org Cc: Aleksa Savic , Jack Doan , Jean Delvare , Guenter Roeck , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Leonard Anderweit Subject: [PATCH 2/5] hwmon: (aquacomputer_d5next) Support writing multiple control values at once Date: Sat, 11 Feb 2023 17:59:20 +0100 Message-Id: <20230211165923.17807-3-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230211165923.17807-1-leonard.anderweit@gmail.com> References: <20230211165923.17807-1-leonard.anderweit@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add new function aqc_set_ctrl_vals() to support changing multiple control values at once while sending only one control report. Signed-off-by: Leonard Anderweit --- drivers/hwmon/aquacomputer_d5next.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index d69c2396854c..03ef9e0258d2 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -574,9 +574,9 @@ static int aqc_get_ctrl_val(struct aqc_data *priv, int offset, long *val, int ty return ret; } -static int aqc_set_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) { - int ret; + int ret, i; mutex_lock(&priv->mutex); @@ -584,15 +584,17 @@ static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int typ if (ret < 0) goto unlock_and_return; - switch (type) { - case AQC_BE16: - put_unaligned_be16((s16)val, priv->buffer + offset); - break; - case AQC_8: - priv->buffer[offset] = (u8)val; - break; - default: - ret = -EINVAL; + for (i = 0; i < len; i++) { + switch (types[i]) { + case AQC_BE16: + put_unaligned_be16((s16)vals[i], priv->buffer + offsets[i]); + break; + case AQC_8: + priv->buffer[offsets[i]] = (u8)vals[i]; + break; + default: + ret = -EINVAL; + } } if (ret < 0) goto unlock_and_return; @@ -604,6 +606,11 @@ static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int typ return ret; } +static int aqc_set_ctrl_val(struct aqc_data *priv, int offset, long val, int type) +{ + return aqc_set_ctrl_vals(priv, &offset, &val, &type, 1); +} + static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel) { const struct aqc_data *priv = data; From patchwork Sat Feb 11 16:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Anderweit X-Patchwork-Id: 13137187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93533C678D4 for ; Sat, 11 Feb 2023 16:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229553AbjBKQ7T (ORCPT ); Sat, 11 Feb 2023 11:59:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbjBKQ7Q (ORCPT ); Sat, 11 Feb 2023 11:59:16 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AD014C14; Sat, 11 Feb 2023 08:59:12 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id bu23so8144349wrb.8; Sat, 11 Feb 2023 08:59:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k4hKRpZ+hEFQcyNwS5GOyvO7MtSq27VTxXLUqx+BqEE=; b=gf9WGAXomfqvl9gBc576Y0OAlru1UJ0z2cbJ4vtU/Bvi6+POa/Was0k7sL6kBDsz3K +ingw4XCeJG/t6APudjgh5/iApG/Hdpu+Y+QZIatoSlex5fOWkp/CsWcQzc93/AzDhWv XQrW0a/fy023nQy1rwJoQbU0+peGwvcT8cbYTq3e29z7ThNwqTUDQjG3Iu/LRBMTmR2p Vk6XNqYeRx+E4B7Gu/cYoDG9xfCA8UdqhzTjDYChS+AqATFLQ0lIve3AflwGM21YHfcd O8wu8AKcF5UHmmwowknfP5pHL28cQx3d7iaz2XTuLM5a04Qs1eMHUIXX7IfIEZnwi5a7 9VCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k4hKRpZ+hEFQcyNwS5GOyvO7MtSq27VTxXLUqx+BqEE=; b=zX0acVWn061iG9Slgw2dZ6jIfN7M9i2cY4ar/rI76frTEn3Cik1ZqvgL7pCsN/lTHI N6YryNnWNc+xMo0ooXKGuVRGSlRcW+QW0+XLDV6NIcdCKcglYnZpB2Sh4GrsZ6XHq5xw N3xr7pOrWNC4I/Vcz4SN3RHrX4vXH2DhLZNY36BKuyQgpqrcjXqah9rUovHgrss6F8ld Xkn+ZdhNS8mPsIacb2RVJwhHOfb/44Pan22VFuYVFP3CX1JD86gTUlm2fGcOw+VPGiN+ bse08boueWv2JJuzdOs8obST1/AlLp0LZEM58V8RO0B8yZFpz9OPkSE9qa/2qBA3wFhF qksg== X-Gm-Message-State: AO0yUKUYKDyqbKUW+4PB85ueeINhETzeWQgAxNhl9++QkvuLMDWdiJfd ZVbDimUAOuADbA4Vs3dZ7mhsb9/lgZpomw== X-Google-Smtp-Source: AK7set/8WPwPTjxbE+2w323WC9PdsMzpDrO8rtQlbmJfcsHMlA+47RWZoiieotQIChIIAybX7ZJGqQ== X-Received: by 2002:a05:6000:12cb:b0:2bf:cb91:a40a with SMTP id l11-20020a05600012cb00b002bfcb91a40amr15759490wrx.46.1676134750780; Sat, 11 Feb 2023 08:59:10 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20d3:ac00:30d6:d4a1:e6f6:5876]) by smtp.gmail.com with ESMTPSA id k16-20020adfe8d0000000b002c54536c662sm5097893wrn.34.2023.02.11.08.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 08:59:10 -0800 (PST) From: Leonard Anderweit To: linux-hwmon@vger.kernel.org Cc: Aleksa Savic , Jack Doan , Jean Delvare , Guenter Roeck , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Leonard Anderweit Subject: [PATCH 3/5] hwmon: (aquacomputer_d5next) Add temperature offset control for Aquaero Date: Sat, 11 Feb 2023 17:59:21 +0100 Message-Id: <20230211165923.17807-4-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230211165923.17807-1-leonard.anderweit@gmail.com> References: <20230211165923.17807-1-leonard.anderweit@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Support sending control reports to Aquacomputer Aquaero. This commit only enables control of the temperature offset as this works in the same manner as with already supported devices. Also, mention temperature offset control for Aquaero in docs. Signed-off-by: Leonard Anderweit --- Documentation/hwmon/aquacomputer_d5next.rst | 4 +- drivers/hwmon/aquacomputer_d5next.c | 62 ++++++++++++++++----- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Documentation/hwmon/aquacomputer_d5next.rst b/Documentation/hwmon/aquacomputer_d5next.rst index 7d0d015b1a52..de43374940b8 100644 --- a/Documentation/hwmon/aquacomputer_d5next.rst +++ b/Documentation/hwmon/aquacomputer_d5next.rst @@ -25,7 +25,7 @@ communicate through proprietary USB HID protocols. The Aquaero devices expose eight physical, eight virtual and four calculated virtual temperature sensors, as well as two flow sensors. The fans expose their -speed (in RPM), power, voltage and current. +speed (in RPM), power, voltage and current. The temperature offset can be controlled. For the D5 Next pump, available sensors are pump and fan speed, power, voltage and current, as well as coolant temperature and eight virtual temp sensors. Also @@ -75,7 +75,7 @@ Sysfs entries ================ ============================================================== temp[1-20]_input Physical/virtual temperature sensors (in millidegrees Celsius) -temp[1-4]_offset Temperature sensor correction offset (in millidegrees Celsius) +temp[1-8]_offset Temperature sensor correction offset (in millidegrees Celsius) fan[1-8]_input Pump/fan speed (in RPM) / Flow speed (in dL/h) fan5_pulses Quadro flow sensor pulses power[1-8]_input Pump/fan power (in micro Watts) diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index 03ef9e0258d2..95461e2907e1 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -56,6 +56,7 @@ static const char *const aqc_device_names[] = { #define SERIAL_PART_OFFSET 2 #define CTRL_REPORT_ID 0x03 +#define AQUAERO_CTRL_REPORT_ID 0x0b /* The HID report that the official software always sends * after writing values, currently same for all devices @@ -67,6 +68,14 @@ static u8 secondary_ctrl_report[] = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x34, 0xC6 }; +/* Secondary HID report values for Aquaero */ +#define AQUAERO_SECONDARY_CTRL_REPORT_ID 0x06 +#define AQUAERO_SECONDARY_CTRL_REPORT_SIZE 0x07 + +static u8 aquaero_secondary_ctrl_report[] = { + 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 +}; + /* Report IDs for legacy devices */ #define POWERADJUST3_STATUS_REPORT_ID 0x03 @@ -94,6 +103,7 @@ static u8 secondary_ctrl_report[] = { #define AQUAERO_NUM_VIRTUAL_SENSORS 8 #define AQUAERO_NUM_CALC_VIRTUAL_SENSORS 4 #define AQUAERO_NUM_FLOW_SENSORS 2 +#define AQUAERO_CTRL_REPORT_SIZE 0xa93 /* Sensor report offsets for Aquaero fan controllers */ #define AQUAERO_SENSOR_START 0x65 @@ -106,6 +116,9 @@ static u8 secondary_ctrl_report[] = { #define AQUAERO_FAN_SPEED_OFFSET 0x00 static u16 aquaero_sensor_fan_offsets[] = { 0x167, 0x173, 0x17f, 0x18B }; +/* Control report offsets for the Aquaero fan controllers */ +#define AQUAERO_TEMP_CTRL_OFFSET 0xdb + /* Specs of the D5 Next pump */ #define D5NEXT_NUM_FANS 2 #define D5NEXT_NUM_SENSORS 1 @@ -441,6 +454,10 @@ struct aqc_data { const char *name; int status_report_id; /* Used for legacy devices, report is stored in buffer */ + int ctrl_report_id; + int secondary_ctrl_report_id; + int secondary_ctrl_report_size; + u8 *secondary_ctrl_report; int buffer_size; u8 *buffer; @@ -513,7 +530,7 @@ static int aqc_get_ctrl_data(struct aqc_data *priv) int ret; memset(priv->buffer, 0x00, priv->buffer_size); - ret = hid_hw_raw_request(priv->hdev, CTRL_REPORT_ID, priv->buffer, priv->buffer_size, + ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size, HID_FEATURE_REPORT, HID_REQ_GET_REPORT); if (ret < 0) ret = -ENODATA; @@ -527,23 +544,27 @@ static int aqc_send_ctrl_data(struct aqc_data *priv) int ret; u16 checksum; - /* Init and xorout value for CRC-16/USB is 0xffff */ - checksum = crc16(0xffff, priv->buffer + priv->checksum_start, priv->checksum_length); - checksum ^= 0xffff; + /* Checksum is not needed for Aquaero */ + if (priv->kind != aquaero) { + /* Init and xorout value for CRC-16/USB is 0xffff */ + checksum = crc16(0xffff, priv->buffer + priv->checksum_start, + priv->checksum_length); + checksum ^= 0xffff; - /* Place the new checksum at the end of the report */ - put_unaligned_be16(checksum, priv->buffer + priv->checksum_offset); + /* Place the new checksum at the end of the report */ + put_unaligned_be16(checksum, priv->buffer + priv->checksum_offset); + } /* Send the patched up report back to the device */ - ret = hid_hw_raw_request(priv->hdev, CTRL_REPORT_ID, priv->buffer, priv->buffer_size, + ret = hid_hw_raw_request(priv->hdev, priv->ctrl_report_id, priv->buffer, priv->buffer_size, HID_FEATURE_REPORT, HID_REQ_SET_REPORT); if (ret < 0) return ret; /* The official software sends this report after every change, so do it here as well */ - ret = hid_hw_raw_request(priv->hdev, SECONDARY_CTRL_REPORT_ID, secondary_ctrl_report, - SECONDARY_CTRL_REPORT_SIZE, HID_FEATURE_REPORT, - HID_REQ_SET_REPORT); + ret = hid_hw_raw_request(priv->hdev, priv->secondary_ctrl_report_id, + priv->secondary_ctrl_report, priv->secondary_ctrl_report_size, + HID_FEATURE_REPORT, HID_REQ_SET_REPORT); return ret; } @@ -969,10 +990,10 @@ static const struct hwmon_channel_info *aqc_info[] = { HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET, HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET, HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET, - 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_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET, + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET, + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET, + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_OFFSET, HWMON_T_INPUT | HWMON_T_LABEL, HWMON_T_INPUT | HWMON_T_LABEL, HWMON_T_INPUT | HWMON_T_LABEL, @@ -1275,6 +1296,9 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->num_flow_sensors = AQUAERO_NUM_FLOW_SENSORS; priv->flow_sensors_start_offset = AQUAERO_FLOW_SENSORS_START; + priv->buffer_size = AQUAERO_CTRL_REPORT_SIZE; + priv->temp_ctrl_offset = AQUAERO_TEMP_CTRL_OFFSET; + priv->temp_label = label_temp_sensors; priv->virtual_temp_label = label_virtual_temp_sensors; priv->calc_virt_temp_label = label_aquaero_calc_temp_sensors; @@ -1438,6 +1462,11 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->firmware_version_offset = AQUAERO_FIRMWARE_VERSION; priv->fan_structure = &aqc_aquaero_fan_structure; + + priv->ctrl_report_id = AQUAERO_CTRL_REPORT_ID; + priv->secondary_ctrl_report_id = AQUAERO_SECONDARY_CTRL_REPORT_ID; + priv->secondary_ctrl_report_size = AQUAERO_SECONDARY_CTRL_REPORT_SIZE; + priv->secondary_ctrl_report = aquaero_secondary_ctrl_report; break; case poweradjust3: priv->status_report_id = POWERADJUST3_STATUS_REPORT_ID; @@ -1446,6 +1475,11 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->serial_number_start_offset = AQC_SERIAL_START; priv->firmware_version_offset = AQC_FIRMWARE_VERSION; + priv->ctrl_report_id = CTRL_REPORT_ID; + priv->secondary_ctrl_report_id = SECONDARY_CTRL_REPORT_ID; + priv->secondary_ctrl_report_size = SECONDARY_CTRL_REPORT_SIZE; + priv->secondary_ctrl_report = secondary_ctrl_report; + if (priv->kind == aquastreamult) priv->fan_structure = &aqc_aquastreamult_fan_structure; else From patchwork Sat Feb 11 16:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Anderweit X-Patchwork-Id: 13137185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42938C64ED6 for ; Sat, 11 Feb 2023 16:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229645AbjBKQ7S (ORCPT ); Sat, 11 Feb 2023 11:59:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbjBKQ7Q (ORCPT ); Sat, 11 Feb 2023 11:59:16 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B274ED1; Sat, 11 Feb 2023 08:59:13 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id by3so6846077wrb.10; Sat, 11 Feb 2023 08:59:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4gc+Ey24cOtq0YnlGdaIZXPrHIGUrqi/dcY9GMPsZDs=; b=FKvBRRYMeuMDfNLZ+rDGVhAr45x5g9VQOoIs3OLOLLW3b/j3YuCT4IQ2zcV16hm1yv Wf0FHt5p852QMgqYpIy+AP7djw3RAUROWobD1SbcYkQbvE4uJi5mlCrRmeh1IWMY/7FB RpgbFdmF51WCUOTA3TPVDxitCpbEhdIny+rSRnIOOz6hrb4JfCeNXnbxaTKDlChFdPwF t6rla2jehaRTKGQOkEh5HKORoWprT0HNv37FxWnZdfdHxn/rSFfVxs0GXEUEU8ZoA1B5 Rsp/VEtNXfQWMJ8lJf9lQdUydEuqkczaJgVxUWDYmNe9oPhKLFDl7OrnXN/2gaaoB4hM xBUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4gc+Ey24cOtq0YnlGdaIZXPrHIGUrqi/dcY9GMPsZDs=; b=aAP14OtZ3dJ3RCk+QagHnGncWUy/VP3TAUINgYp0Eyxxue5ADgThmA22yztOLqcMlR jGlG1K6vFeKw/7GIvHPomXc4t5o35atYG91a+wKT+qoSUiBZUoy+OL+OOQ1sFqKpuJPz mcLocVi3TOApOmVGYBabZ5gFcmeDkMNJkUxH4my0+z77GcVna8J/84vXWznrWj11hxzR 1lGkURW7eJnCnSUN+fCYZTGpGmqDp1KG1sLdphn2YAkyUAK+0CZfgZRrOxF9pnNE/Gca j+7rGZHLefTPYK8JznErl3ZeRpaEwLPNAC6PEDSL8+twk3lz5wy7qt2RA2GcqQnSmXtk 6qRQ== X-Gm-Message-State: AO0yUKV9mguFP3biANbgEsoirxrLguT2FD5LrcL8az3ddp+luZ5tpfh1 3t3zIzjz1ZtZLxrrHqbQrM7GcsIVXN/OJA== X-Google-Smtp-Source: AK7set//e+3EAbp5kraTmogWd5f/aqWKEDBDB0STJJ1nNxE4Tb4iYKcKqaQg9ehaTtSlo2VmFoe4yQ== X-Received: by 2002:adf:ff82:0:b0:2c5:499e:df69 with SMTP id j2-20020adfff82000000b002c5499edf69mr4473428wrr.68.1676134751592; Sat, 11 Feb 2023 08:59:11 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20d3:ac00:30d6:d4a1:e6f6:5876]) by smtp.gmail.com with ESMTPSA id k16-20020adfe8d0000000b002c54536c662sm5097893wrn.34.2023.02.11.08.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 08:59:11 -0800 (PST) From: Leonard Anderweit To: linux-hwmon@vger.kernel.org Cc: Aleksa Savic , Jack Doan , Jean Delvare , Guenter Roeck , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Leonard Anderweit Subject: [PATCH 4/5] hwmon: (aquacomputer_d5next) Add fan PWM control for Aquaero Date: Sat, 11 Feb 2023 17:59:22 +0100 Message-Id: <20230211165923.17807-5-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230211165923.17807-1-leonard.anderweit@gmail.com> References: <20230211165923.17807-1-leonard.anderweit@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add the option to control fan PWM on Aquacomputer Aquaero. The Aquaero is the most complex Aquacomputer device, control is therefore more complicated then on already supported devices. Setting PWM requires multiple steps. First, an internal static PWM controller is set to the desired PWM value. Second, the fan is set to use that cwPWMpwm controller. Last, the minimum and maximum accepted PWM values of the fan are set to allow all possible PWM values. Signed-off-by: Leonard Anderweit --- Documentation/hwmon/aquacomputer_d5next.rst | 3 +- drivers/hwmon/aquacomputer_d5next.c | 63 +++++++++++++++++++-- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Documentation/hwmon/aquacomputer_d5next.rst b/Documentation/hwmon/aquacomputer_d5next.rst index de43374940b8..2dbb3bd37878 100644 --- a/Documentation/hwmon/aquacomputer_d5next.rst +++ b/Documentation/hwmon/aquacomputer_d5next.rst @@ -25,7 +25,8 @@ communicate through proprietary USB HID protocols. The Aquaero devices expose eight physical, eight virtual and four calculated virtual temperature sensors, as well as two flow sensors. The fans expose their -speed (in RPM), power, voltage and current. The temperature offset can be controlled. +speed (in RPM), power, voltage and current. The temperature offset and the fan speed +can be controlled. For the D5 Next pump, available sensors are pump and fan speed, power, voltage and current, as well as coolant temperature and eight virtual temp sensors. Also diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index 95461e2907e1..02551c26918a 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -104,6 +104,9 @@ static u8 aquaero_secondary_ctrl_report[] = { #define AQUAERO_NUM_CALC_VIRTUAL_SENSORS 4 #define AQUAERO_NUM_FLOW_SENSORS 2 #define AQUAERO_CTRL_REPORT_SIZE 0xa93 +#define AQUAERO_CTRL_PRESET_ID 0x5c +#define AQUAERO_CTRL_PRESET_SIZE 0x02 +#define AQUAERO_CTRL_PRESET_START 0x55c /* Sensor report offsets for Aquaero fan controllers */ #define AQUAERO_SENSOR_START 0x65 @@ -118,6 +121,10 @@ static u16 aquaero_sensor_fan_offsets[] = { 0x167, 0x173, 0x17f, 0x18B }; /* Control report offsets for the Aquaero fan controllers */ #define AQUAERO_TEMP_CTRL_OFFSET 0xdb +#define AQUAERO_FAN_CTRL_MIN_PWR_OFFSET 0x04 +#define AQUAERO_FAN_CTRL_MAX_PWR_OFFSET 0x06 +#define AQUAERO_FAN_CTRL_SRC_OFFSET 0x10 +static u16 aquaero_ctrl_fan_offsets[] = { 0x20c, 0x220, 0x234, 0x248 }; /* Specs of the D5 Next pump */ #define D5NEXT_NUM_FANS 2 @@ -856,13 +863,22 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, *val = priv->power_input[channel]; break; case hwmon_pwm: - if (priv->fan_ctrl_offsets) { + switch (priv->kind) { + case aquaero: + ret = aqc_get_ctrl_val(priv, AQUAERO_CTRL_PRESET_START + channel * AQUAERO_CTRL_PRESET_SIZE, + val, AQC_BE16); + if (ret < 0) + return ret; + *val = aqc_percent_to_pwm(*val); + break; + default: ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel], val, AQC_BE16); if (ret < 0) return ret; *val = aqc_percent_to_pwm(ret); + break; } break; case hwmon_in: @@ -921,6 +937,10 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, long val) { int ret, pwm_value; + /* Arrays for setting multiple values at once in the control report */ + int ctrl_values_offsets[4]; + long ctrl_values[4]; + int ctrl_values_types[4]; struct aqc_data *priv = dev_get_drvdata(dev); switch (type) { @@ -955,15 +975,47 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, case hwmon_pwm: switch (attr) { case hwmon_pwm_input: - if (priv->fan_ctrl_offsets) { - pwm_value = aqc_pwm_to_percent(val); - if (pwm_value < 0) - return pwm_value; + pwm_value = aqc_pwm_to_percent(val); + if (pwm_value < 0) + return pwm_value; + switch (priv->kind) { + case aquaero: + /* Write pwm value to preset corresponding to the channel */ + ctrl_values_offsets[0] = AQUAERO_CTRL_PRESET_START + + channel * AQUAERO_CTRL_PRESET_SIZE; + ctrl_values[0] = pwm_value; + ctrl_values_types[0] = AQC_BE16; + + /* Write preset number in fan control source */ + ctrl_values_offsets[1] = priv->fan_ctrl_offsets[channel] + + AQUAERO_FAN_CTRL_SRC_OFFSET; + ctrl_values[1] = AQUAERO_CTRL_PRESET_ID + channel; + ctrl_values_types[1] = AQC_BE16; + + /* Set minimum power to 0 to allow the fan to turn off */ + ctrl_values_offsets[2] = priv->fan_ctrl_offsets[channel] + + AQUAERO_FAN_CTRL_MIN_PWR_OFFSET; + ctrl_values[2] = 0; + ctrl_values_types[2] = AQC_BE16; + + /* Set maximum power to 255 to allow the fan to reach max speed */ + ctrl_values_offsets[3] = priv->fan_ctrl_offsets[channel] + + AQUAERO_FAN_CTRL_MAX_PWR_OFFSET; + ctrl_values[3] = aqc_pwm_to_percent(255); + ctrl_values_types[3] = AQC_BE16; + + ret = aqc_set_ctrl_vals(priv, ctrl_values_offsets, ctrl_values, + ctrl_values_types, 4); + if (ret < 0) + return ret; + break; + default: ret = aqc_set_ctrl_val(priv, priv->fan_ctrl_offsets[channel], pwm_value, AQC_BE16); if (ret < 0) return ret; + break; } break; default: @@ -1286,6 +1338,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) priv->num_fans = AQUAERO_NUM_FANS; priv->fan_sensor_offsets = aquaero_sensor_fan_offsets; + priv->fan_ctrl_offsets = aquaero_ctrl_fan_offsets; priv->num_temp_sensors = AQUAERO_NUM_SENSORS; priv->temp_sensor_start_offset = AQUAERO_SENSOR_START; From patchwork Sat Feb 11 16:59:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Anderweit X-Patchwork-Id: 13137186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03F75C636CC for ; Sat, 11 Feb 2023 16:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229589AbjBKQ7S (ORCPT ); Sat, 11 Feb 2023 11:59:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjBKQ7Q (ORCPT ); Sat, 11 Feb 2023 11:59:16 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C552A4EE8; Sat, 11 Feb 2023 08:59:13 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id by3so6846100wrb.10; Sat, 11 Feb 2023 08:59:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4ljPvl7RI6IskznJgFi6iQwmZKfNOsC/TK50tjYkT9I=; b=ouTcX3hZj7mUUVxxjL/QfVbZpAl4KGRI8XMHD0X90W1gUQBMPuQx2koh8i6UHSZgGc 76/M2hAvT9pakBCmXJPk91wqYWByMvYM5N9TXs9h1FkVcRTVCQgZCgrsxn5tP9D0qSEU C7WQ5pAg2VtNervXJ0n51WRYjTlgvIJLUQxl1H9wxe9nA0ljK/BxkqgjQE376PKl8YSZ FagmRgb04gLmT7GG3RALib6DEJAfEMINeAT1wJ7ALzUEslhfjsMn471d+QYA5BpWDOmc xVRwheW27MAouFFSaFUa7472g+ncZGdnWC2PIHFvTNiXTWsIFkQGpRYTavdq+ohpDi1c XD7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4ljPvl7RI6IskznJgFi6iQwmZKfNOsC/TK50tjYkT9I=; b=gbtB2V/sS3zUufdKDujYt6h+Zwhll6aGHRTAp/Jgx9Vsj7bNr1BiK3XckKApj+MJg8 C+m2zyBjumriFty9HZNoCl9cWvX3WH4q8NJMmwJvRKW3gHazg6xTg2gidtU2hUHvEaY8 QA1U70SzeSw/4TRt8x9OhJNrh1GUWoQcGCJQB1c+Kmeup7G2AjvU5J3uC+JDo/LtGm65 7bzPPjv50ot/LB5dyJJ4rzjuxvht/ysU+wjMkm7u//AX7ZKcDW6RT7uyb2W4F6V96dQT E0E0pyyKKUnplw+zXFMfBlJsgdDtSlIroHq7uKBojIUFqG/+9AFv+fewmKVDPvHNIaJh +ZLw== X-Gm-Message-State: AO0yUKW/A7dZEXwV8zahESG/nb1Nkcq5bKPk9Uw7uhj+JuseGP1RlFwZ Y+a3V3hhE+urg8QxVwZ7J2tr2jap6dyLaw== X-Google-Smtp-Source: AK7set9SoJihj4CsphsWv1veXk6foJ34RavO3fVT2l/sU4PffJzgL0j5iEMb46TwGngaYhGiOc6XvQ== X-Received: by 2002:adf:f9ca:0:b0:2c5:4d68:5512 with SMTP id w10-20020adff9ca000000b002c54d685512mr2202091wrr.19.1676134752386; Sat, 11 Feb 2023 08:59:12 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20d3:ac00:30d6:d4a1:e6f6:5876]) by smtp.gmail.com with ESMTPSA id k16-20020adfe8d0000000b002c54536c662sm5097893wrn.34.2023.02.11.08.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 08:59:12 -0800 (PST) From: Leonard Anderweit To: linux-hwmon@vger.kernel.org Cc: Aleksa Savic , Jack Doan , Jean Delvare , Guenter Roeck , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Leonard Anderweit Subject: [PATCH 5/5] hwmon: (aquacomputer_d5next) Add PWM mode control for Aquaero Date: Sat, 11 Feb 2023 17:59:23 +0100 Message-Id: <20230211165923.17807-6-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230211165923.17807-1-leonard.anderweit@gmail.com> References: <20230211165923.17807-1-leonard.anderweit@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add PWM mode control for the Aquacomputer Aquaero. On the Aquaero 6 all four ports can switch between DC and PWM control. On the Aquaero 5 this is only supported for the fourth port, but changing the setting for the other ports has no consequences. Signed-off-by: Leonard Anderweit --- Documentation/hwmon/aquacomputer_d5next.rst | 4 +- drivers/hwmon/aquacomputer_d5next.c | 86 ++++++++++++++++----- 2 files changed, 70 insertions(+), 20 deletions(-) diff --git a/Documentation/hwmon/aquacomputer_d5next.rst b/Documentation/hwmon/aquacomputer_d5next.rst index 2dbb3bd37878..002cb9eecdf5 100644 --- a/Documentation/hwmon/aquacomputer_d5next.rst +++ b/Documentation/hwmon/aquacomputer_d5next.rst @@ -26,7 +26,8 @@ communicate through proprietary USB HID protocols. The Aquaero devices expose eight physical, eight virtual and four calculated virtual temperature sensors, as well as two flow sensors. The fans expose their speed (in RPM), power, voltage and current. The temperature offset and the fan speed -can be controlled. +can be controlled. The fan PWM mode (DC/PWM) can be controlled. The Aquaero 6 supports +this on all four fan connectors and the Aquaero 5 only on the fourth connector. For the D5 Next pump, available sensors are pump and fan speed, power, voltage and current, as well as coolant temperature and eight virtual temp sensors. Also @@ -83,6 +84,7 @@ power[1-8]_input Pump/fan power (in micro Watts) in[0-7]_input Pump/fan voltage (in milli Volts) curr[1-8]_input Pump/fan current (in milli Amperes) pwm[1-8] Fan PWM (0 - 255) +pwm[1-4]_mode Fan control mode (0: DC mode; 1: PWM mode) ================ ============================================================== Debugfs entries diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index 02551c26918a..2ec00124785f 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -123,6 +123,7 @@ static u16 aquaero_sensor_fan_offsets[] = { 0x167, 0x173, 0x17f, 0x18B }; #define AQUAERO_TEMP_CTRL_OFFSET 0xdb #define AQUAERO_FAN_CTRL_MIN_PWR_OFFSET 0x04 #define AQUAERO_FAN_CTRL_MAX_PWR_OFFSET 0x06 +#define AQUAERO_FAN_CTRL_MODE_OFFSET 0x0f #define AQUAERO_FAN_CTRL_SRC_OFFSET 0x10 static u16 aquaero_ctrl_fan_offsets[] = { 0x20c, 0x220, 0x234, 0x248 }; @@ -672,10 +673,23 @@ static umode_t aqc_is_visible(const void *data, enum hwmon_sensor_types type, u3 break; case hwmon_pwm: if (priv->fan_ctrl_offsets && channel < priv->num_fans) { - switch (attr) { - case hwmon_pwm_input: - return 0644; + switch (priv->kind) { + case aquaero: + switch (attr) { + case hwmon_pwm_input: + case hwmon_pwm_mode: + return 0644; + default: + break; + } + break; default: + switch (attr) { + case hwmon_pwm_input: + return 0644; + default: + break; + } break; } } @@ -863,22 +877,46 @@ static int aqc_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, *val = priv->power_input[channel]; break; case hwmon_pwm: - switch (priv->kind) { - case aquaero: - ret = aqc_get_ctrl_val(priv, AQUAERO_CTRL_PRESET_START + channel * AQUAERO_CTRL_PRESET_SIZE, - val, AQC_BE16); - if (ret < 0) - return ret; - *val = aqc_percent_to_pwm(*val); + switch (attr) { + case hwmon_pwm_input: + switch (priv->kind) { + case aquaero: + ret = aqc_get_ctrl_val(priv, AQUAERO_CTRL_PRESET_START + + channel * AQUAERO_CTRL_PRESET_SIZE, + val, AQC_BE16); + if (ret < 0) + return ret; + *val = aqc_percent_to_pwm(*val); + break; + default: + ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel], + val, AQC_BE16); + if (ret < 0) + return ret; + + *val = aqc_percent_to_pwm(ret); + break; + } break; - default: - ret = aqc_get_ctrl_val(priv, priv->fan_ctrl_offsets[channel], - val, AQC_BE16); + case hwmon_pwm_mode: + ret = aqc_get_ctrl_val(priv, + priv->fan_ctrl_offsets[channel] + + AQUAERO_FAN_CTRL_MODE_OFFSET, val, AQC_8); if (ret < 0) return ret; - *val = aqc_percent_to_pwm(ret); + switch (*val) { + case 0: /* DC mode */ + break; + case 2: /* PWM mode */ + *val = 1; + break; + default: + break; + } break; + default: + return -EOPNOTSUPP; } break; case hwmon_in: @@ -936,7 +974,7 @@ static int aqc_read_string(struct device *dev, enum hwmon_sensor_types type, u32 static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { - int ret, pwm_value; + int ret, pwm_value, ctrl_mode; /* Arrays for setting multiple values at once in the control report */ int ctrl_values_offsets[4]; long ctrl_values[4]; @@ -1018,6 +1056,16 @@ static int aqc_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, break; } break; + case hwmon_pwm_mode: + if (val > 1 || val < 0) + return -EINVAL; + ctrl_mode = 2 * val; + ret = aqc_set_ctrl_val(priv, + priv->fan_ctrl_offsets[channel] + + AQUAERO_FAN_CTRL_MODE_OFFSET, ctrl_mode, AQC_8); + if (ret < 0) + return ret; + break; default: break; } @@ -1077,10 +1125,10 @@ static const struct hwmon_channel_info *aqc_info[] = { HWMON_P_INPUT | HWMON_P_LABEL, HWMON_P_INPUT | HWMON_P_LABEL), HWMON_CHANNEL_INFO(pwm, - HWMON_PWM_INPUT, - HWMON_PWM_INPUT, - HWMON_PWM_INPUT, - HWMON_PWM_INPUT, + HWMON_PWM_INPUT | HWMON_PWM_MODE, + HWMON_PWM_INPUT | HWMON_PWM_MODE, + HWMON_PWM_INPUT | HWMON_PWM_MODE, + HWMON_PWM_INPUT | HWMON_PWM_MODE, HWMON_PWM_INPUT, HWMON_PWM_INPUT, HWMON_PWM_INPUT,