From patchwork Tue Feb 14 22:02:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Anderweit X-Patchwork-Id: 13140937 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 17E51C64EC7 for ; Tue, 14 Feb 2023 22:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233243AbjBNWCD (ORCPT ); Tue, 14 Feb 2023 17:02:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233165AbjBNWB5 (ORCPT ); Tue, 14 Feb 2023 17:01:57 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B271716A; Tue, 14 Feb 2023 14:01:52 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id k3so9604447wrv.5; Tue, 14 Feb 2023 14:01:52 -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=lhUd31tbYc8/GAz1s1GxERvfWBKhM44LCwYftwbthSU=; b=VZUZk0Py67Lk9352uvTnZl5bLCzZmEQzsZPsEDa584Ci1dwNOeFhYj4CQLOGTHXlNb v7Ya6kxHvttpMM3EHxn5bTsfVEM2EH3sP5khKoOetjB2HWubOg1hP5VgIeEIOx3Jpuyg N/ycHCWg1+CZpsY6eQWwPY7ihLn2e5hf0we7blMsC/xZqR+uGrujphlkFbvidHjLAhcz nJ0vf1/qd8Rum3G8ONoBUx/4tO6pQuvfbUsnXLKk+Ud6VbDfK+GB9JJdwMehmsUi1/mR PhKzsSCr7X0U1XHrwAl36mazFd1AHLOEVCxhOWeJJ8UuY5mIE0QA1jGm819v1FAQIji+ qBsw== 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=lhUd31tbYc8/GAz1s1GxERvfWBKhM44LCwYftwbthSU=; b=I2ZkByvTyrANVxgDucpPPZ1mz2EeSc1MLnfZs9v1ZAVVO/jrU02C74rGsWnYYyMu4x ANZMsFOsxtvGnIc/TSUplqy1GgKL5e3AFK3CWZpwyWWcK/3SJxPrAQllDcqzTq+ssmow ouD1wAcSToy4AF2JalHgKJ8Jeyw3JIeEvBLCLwfdLm/cp64npRyu5IhGTgzlQTLzNVPx dq+NQ2NiS4iAOO8RvAHFJROFLb/MbhIZnwfJI76jYM1BRuhuJYO9HgfFyYQqyjT/VQiB tUCkXR1V3wjbkeaqGvb1Zjt25x1BOlQMvTJmU8BBnaOYkfQB3CtPPRf7lQWzKmhHCxvk E1cA== X-Gm-Message-State: AO0yUKU0QKk/k6AoZEm7yn8sjWPynVH0O2BgmOuPEq8vIAv9LziEbg5h 46zE3JzmH56u98k7KPvf43503f5Nl9ooHQ== X-Google-Smtp-Source: AK7set/KmaTI3DeaRfBvkZuIuhTtDhnSI4giJXvtnuT9yOQlX/Uz/NIVlWMsyML3jjYcLd9ECIl2tw== X-Received: by 2002:adf:f746:0:b0:2c5:5a65:799f with SMTP id z6-20020adff746000000b002c55a65799fmr3356810wrp.34.1676412111368; Tue, 14 Feb 2023 14:01:51 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20f2:3300:c2d2:a008:b022:b1e0]) by smtp.gmail.com with ESMTPSA id u14-20020adff88e000000b002c56046a3b5sm4033704wrp.53.2023.02.14.14.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 14:01:50 -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 v2 1/6] hwmon: (aquacomputer_d5next) Support one byte control values Date: Tue, 14 Feb 2023 23:02:16 +0100 Message-Id: <20230214220221.15003-2-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214220221.15003-1-leonard.anderweit@gmail.com> References: <20230214220221.15003-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 | 48 +++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index 12682a610ce7..babfd998e70c 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,19 @@ 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 +800,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 +816,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 +830,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 +904,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 +916,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 +934,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 Tue Feb 14 22:02:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Anderweit X-Patchwork-Id: 13140935 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 C9F57C6379F for ; Tue, 14 Feb 2023 22:01:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232846AbjBNWB6 (ORCPT ); Tue, 14 Feb 2023 17:01:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233141AbjBNWB5 (ORCPT ); Tue, 14 Feb 2023 17:01:57 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD43030B24; Tue, 14 Feb 2023 14:01:53 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id bg5-20020a05600c3c8500b003e00c739ce4so144697wmb.5; Tue, 14 Feb 2023 14:01:53 -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=xM8rk8AOAbfRjfXoKyQDHMPFgTmFtxGgcgSbiV7qN7Y=; b=oSMZ6mfOvLg0dWdh5AfewbBS1pXTj0PyCri7L8C7dbsDJ2Z6fqb4guvjWT3q7CZsG3 px/rZI1Hagkn1SvHPt4NVwUFjhdoSUI6qHRjehbfCAZF9NZBHDVHFxBRhM35G4cMTzte jE46pbns7UdJaVLrdJUbUTXRIUf5ZiRbtm4M+f7NZkNvVGCWMmWbEryz4W1zBMF/4slX ciR3P4ZU8v4kIHgDTq8Xh1bdv8PjJqMElF5PxVudiaTPSUP70b34F2+eHQAmbv4PWQF5 1K6fXqmSdor1wU3kKwMf2XF/MKetuT7CJLr8bL+W+C7HdVjysk+eUiBGwrEEH/+779fr lgvQ== 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=xM8rk8AOAbfRjfXoKyQDHMPFgTmFtxGgcgSbiV7qN7Y=; b=gxe2p49OIw+LhoXqq1yQ0RUk6AEKj94c4ry0ViVzRW6rXiwVnCKnO5++5AMu1/WR11 Clf676azJd4AH0100GaSC2TlxJGzV8BQtgWcd95GNZecrgIdQlolw1kcqIreMqT+IoyL PbDmjrHgPX11XYfUsKGHOMa/ApLxi9Tnz8pktww3RhxE/cyckv1SiMg/hqsogHtBtFBz qTAmcm2lTD+JVYCfF2/4yu5I0lHNimh3u6Mh6tmuvL8z9enVxxGXS3D9rbN8xVhfNJEa UTNMDOTz/e0e6XV3JJA+XdC9sR7AstZC2xfvwq3yfO1hreSy0PQeINoe0YxtUHFHLPdo OiqQ== X-Gm-Message-State: AO0yUKXR8OnLvfmwN4F1LFG/YK1FJ8N8avLU6k+mWBI4DScNHsru2zVc OvE7XVDN0ECyhOIPT3NWcu7OZM7Epw6/9g== X-Google-Smtp-Source: AK7set8ndCtMX8GsrLwXKjy5YXLy5mGCx5n+AUH1mEcLQfe28zp3Oz4LQCUB2G2GoyE0gBXqLjatyg== X-Received: by 2002:a05:600c:2b46:b0:3dc:932f:f7cb with SMTP id e6-20020a05600c2b4600b003dc932ff7cbmr255079wmf.37.1676412112169; Tue, 14 Feb 2023 14:01:52 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20f2:3300:c2d2:a008:b022:b1e0]) by smtp.gmail.com with ESMTPSA id u14-20020adff88e000000b002c56046a3b5sm4033704wrp.53.2023.02.14.14.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 14:01:51 -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 v2 2/6] hwmon: (aquacomputer_d5next) Support writing multiple control values at once Date: Tue, 14 Feb 2023 23:02:17 +0100 Message-Id: <20230214220221.15003-3-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214220221.15003-1-leonard.anderweit@gmail.com> References: <20230214220221.15003-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 babfd998e70c..f0c036d38e91 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) @@ -605,6 +607,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 Tue Feb 14 22:02:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Anderweit X-Patchwork-Id: 13140934 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 E399CC64ED9 for ; Tue, 14 Feb 2023 22:02:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233218AbjBNWB7 (ORCPT ); Tue, 14 Feb 2023 17:01:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233140AbjBNWB5 (ORCPT ); Tue, 14 Feb 2023 17:01:57 -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 8933830B2E; Tue, 14 Feb 2023 14:01:54 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id a2so17243159wrd.6; Tue, 14 Feb 2023 14:01:54 -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=fa51H3f4eapSWiBabLmEx5vtaOrCOecKwtW5XZydamw=; b=TGC1OtiGHfVN5n4B9ebL14p5ELUTAPaQDqPR7LAkkGfm6Gjxe6+OIVaUMVBCfiRuAZ txO/voM/BY+W1Q0VhXKq0YdsIdt3lr6kpIZE2B7SbhcOMjC9QRLlBnzN5La8GxTV5JJO MZIm7hTJyeRu8EFYBdTbTvdKwW48FrA8QogNPFq3yZb2ef79FLekKR06XNAH/1dRnNV+ 4Ee9uQRCL3VdmDGIWQ726UZWfL5TVgl+QV51jzbtIqctJP3xRHW/7EiXz1HGnOtH1Qrb xomSJlUyinYeusQ01Idyjx/s1Ws2qoVvyyWIan9hUlYUAmq0h4jK8D2fWzPZu1S4bzQ/ 3vWg== 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=fa51H3f4eapSWiBabLmEx5vtaOrCOecKwtW5XZydamw=; b=WxEBeDgAR/YgbYBKXtJ8595hMupFzJRC1kOpmNGtexk9vtUV/qqteyzUXipPIFrZC6 OdMsJQBV7f54vz8EIKMscy7mckMuqnGes4eDIB//PKasJQUjQGs0V6EQWf7S2mE+F0+Y 6OUtbHiZi9zsRi2MOXwXDETF0KOcW0H+nPcQWX0ZNi051qB8a8cgozB299gwgZqsdUWp 1JbXoUpsA/IypTp9vNGiwUXmb2Zj5rSVXoKQbIGMg9/DDSeTVhM0rIIOO+AW8xuQ4368 0OgDTHVruqBlLSu+18G982kMmVMVgr0FddhAT/8z9lHzwBgj3yPH9Wish10nr4n2EeEz zR+Q== X-Gm-Message-State: AO0yUKXm1SuDSsZe7/Y8lzPPgNIT3Sevq762WrhghvhNSu4ZGYKivlQA gumATih83w3+bB5jpwkORu2iou6tNezYIA== X-Google-Smtp-Source: AK7set+hzVw8XX9Hzz6FT1XbLaH91lQbIJJEwutR3UKx/ebEWryobUwQpgZZclJH1g6Jjn2ZCTdVeg== X-Received: by 2002:adf:e78b:0:b0:2c5:53a1:eeb with SMTP id n11-20020adfe78b000000b002c553a10eebmr3685304wrm.54.1676412113006; Tue, 14 Feb 2023 14:01:53 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20f2:3300:c2d2:a008:b022:b1e0]) by smtp.gmail.com with ESMTPSA id u14-20020adff88e000000b002c56046a3b5sm4033704wrp.53.2023.02.14.14.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 14:01:52 -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 v2 3/6] hwmon: (aquacomputer_d5next) Device dependent control report settings Date: Tue, 14 Feb 2023 23:02:18 +0100 Message-Id: <20230214220221.15003-4-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214220221.15003-1-leonard.anderweit@gmail.com> References: <20230214220221.15003-1-leonard.anderweit@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add device dependent control report id, secondary control report id, secondary control report size and secondary control report for devices which need different control report settings. All currently supported devices use the same values. Signed-off-by: Leonard Anderweit --- drivers/hwmon/aquacomputer_d5next.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index f0c036d38e91..535d2fc0e55c 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -441,6 +441,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 +517,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; @@ -535,15 +539,15 @@ static int aqc_send_ctrl_data(struct aqc_data *priv) 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; } @@ -1447,6 +1451,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 Tue Feb 14 22:02: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: 13140936 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 0E79EC678D4 for ; Tue, 14 Feb 2023 22:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233231AbjBNWCA (ORCPT ); Tue, 14 Feb 2023 17:02:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233142AbjBNWB5 (ORCPT ); Tue, 14 Feb 2023 17:01:57 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41C4E2B0B3; Tue, 14 Feb 2023 14:01:55 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id l2so608893wry.0; Tue, 14 Feb 2023 14:01:55 -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=QrxmW2KQawIfFzS6qpWZdNTYLIimlBJFQO9rfVDksZ4=; b=RHDcbKAoZwGoa+xK9ukxAmbQJf9gJll9jpnm26D9HXdVSbGP7+OyIgEmkJoSl5kiDG Qnn+Og/4Z9EmirWHWZEyRKMVa9QiRNDvXeUMUcOYph5NYUM7Scj2xfX1M/rRrZAHmzz9 1qeP52fhtEYBZBIE7JanxtqNop6Vnf4gYiwwGgMufMOkr/LwD2tXihFzThWOJH0H0ZY/ m7+pqxISN4uUIANITBuYK3SveKlw9e3bfKxzseGwxHMLUKbF+5JkFC2p0REgErdn9bmo oYC1OxDqwUOEg1l06PzzDBlao+1tpQMWASgjALiLqOKebhHjhVd0hzw/iB4oSMPgGKv+ CJMQ== 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=QrxmW2KQawIfFzS6qpWZdNTYLIimlBJFQO9rfVDksZ4=; b=lLnfsgD1L+6zRZ0MikqGyVUDtvbaAXMy9sDLmyviqQ3PAj3D89USC+/wL2YTaNyqo5 KKpQwEaxoBH34mtIJHZA/NqdlABlrK6sjHwhPIZ3CA6MwHVINamf1XYI+q4SxirUma2a Y/xgsWvhr4SKRrqEu48cAi3rl2FUnyr3dDF3v/KbRmiyy/wph2vLPrBxVOwFRtxk+sX2 Cb1PH0mfMqwQqi+s/Pj+WSKivKy7RvhYQUSrvgN8i0GsN1QBfFUAENuW04tNcxXTd/tv b9AExTclLU1awFr6EdejomZHy6M+VxO9vgt4YzB3UCNB9hq2yMJNkI4r9oqU5Mp5fKUh 61WQ== X-Gm-Message-State: AO0yUKUmueQmWz5/y9xKsm4o98y6N2rd5kbMNMiaXTllc/fip/RXTjEQ rMYTRwM9wknZi8XnOJmwYAirBwy0ycXZUA== X-Google-Smtp-Source: AK7set8z29MXIXlKOWSohYfEM9ibTud9wiQlpJMD3wnSS2vqmcBWLyB5AkGGsWQLFj5fHVQ1iY5eyg== X-Received: by 2002:adf:f64f:0:b0:2bf:bf05:85ac with SMTP id x15-20020adff64f000000b002bfbf0585acmr299715wrp.23.1676412113811; Tue, 14 Feb 2023 14:01:53 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20f2:3300:c2d2:a008:b022:b1e0]) by smtp.gmail.com with ESMTPSA id u14-20020adff88e000000b002c56046a3b5sm4033704wrp.53.2023.02.14.14.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 14:01:53 -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 v2 4/6] hwmon: (aquacomputer_d5next) Add infrastructure for Aquaero control reports Date: Tue, 14 Feb 2023 23:02:19 +0100 Message-Id: <20230214220221.15003-5-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214220221.15003-1-leonard.anderweit@gmail.com> References: <20230214220221.15003-1-leonard.anderweit@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add information on the Aquacomputer Aquaero control report and disable the control report checksum for Aquaero. The Aquaero does not use the checksum so it must be disabled to avoid overwriting the last two bytes of the control report. Signed-off-by: Leonard Anderweit --- drivers/hwmon/aquacomputer_d5next.c | 31 ++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/aquacomputer_d5next.c b/drivers/hwmon/aquacomputer_d5next.c index 535d2fc0e55c..eb185318098a 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 @@ -531,12 +541,16 @@ 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, priv->ctrl_report_id, priv->buffer, priv->buffer_size, @@ -1280,6 +1294,8 @@ 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_label = label_temp_sensors; priv->virtual_temp_label = label_virtual_temp_sensors; priv->calc_virt_temp_label = label_aquaero_calc_temp_sensors; @@ -1443,6 +1459,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; From patchwork Tue Feb 14 22:02: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: 13140939 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 AAB49C64EC7 for ; Tue, 14 Feb 2023 22:02:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233256AbjBNWCB (ORCPT ); Tue, 14 Feb 2023 17:02:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233147AbjBNWB5 (ORCPT ); Tue, 14 Feb 2023 17:01:57 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30523305E6; Tue, 14 Feb 2023 14:01:56 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id co8so13487401wrb.1; Tue, 14 Feb 2023 14:01:56 -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=8wVCVDWqocKGppF+Fpoz1fhnzSpt25qSkQ0ztIc8eqY=; b=bAqRpZ2uGaI2rmZX6Rh5Xfd4vx+eBvYPZhZBYhrPZqajekiuk7fHGbffuQ4zKx4lqv CF82m2Pv0bUINLAIsQMrS4afy8WKjfOVaL6d7pt9ybiv/C71he06JDmOgcyxCauXughQ X5IdNRWoR/oMqu12iDJ7WRZt8XbypWqPHUSsJEg/6ij+5s57+KCLSR9ZOZdTUWw9nVDJ NPmIX2ynayj5BI2G6OblsT23Dwpd3Jaf205Gp+fplfhmhEVBQhVKwQA2ImfnOp6fOogx Pn1BsSOxLPn0R2b/faSxfxKJjfGLTCRWwMvyqPK7hTGePL5hA5i5aO/8T0KPny3Zvu7C 3DbA== 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=8wVCVDWqocKGppF+Fpoz1fhnzSpt25qSkQ0ztIc8eqY=; b=g+NmimfvYu1qIjuDvZoJHxH24deH2zpTs5q8qUdtkBHhzo7rhKS3TGcXwlPvHQndWj YLxTQDvs7LsjM0d8KUXdrvYRCj+M7GFxfYKRw6Wfa4VSrFdBV/ZoKLbJrksZ6pzgP1dQ qFTDaDbNyaAF2Nr2YKZMfXZptC6TIF5hO269R6wDvCEFFi0Me6B2IkBfRGEgJGPd5oLd NQSTeB4HyAjeksWYu98eC5P4KW1cSW0436Gp1ut3HzNETXz6YycRsZuo+XrbeRqNkIGc iEgafmwSg5ebE0Kefi69sfOo5I/ueVaLMpaWuraCLP4m/gUeOhPQCUKVQf3WWjxrQpI3 JN0w== X-Gm-Message-State: AO0yUKWjm8NMPAUwd0MgYvpjXQ/S+jW+UD1UyncepDdMJ0uguPKPF32u ubk3KjIW6QY5LgDFjtuV1j1yM164tuA87A== X-Google-Smtp-Source: AK7set955QGyyiJswyK+H+0qL5XScGA+BWwumtIKVZQ7Vvs3VMQWxLHQCzNTBoNbvLD60WaO3m9Idw== X-Received: by 2002:adf:e984:0:b0:2c5:5455:96a1 with SMTP id h4-20020adfe984000000b002c5545596a1mr4538020wrm.29.1676412114606; Tue, 14 Feb 2023 14:01:54 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20f2:3300:c2d2:a008:b022:b1e0]) by smtp.gmail.com with ESMTPSA id u14-20020adff88e000000b002c56046a3b5sm4033704wrp.53.2023.02.14.14.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 14:01:54 -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 v2 5/6] hwmon: (aquacomputer_d5next) Add temperature offset control for Aquaero Date: Tue, 14 Feb 2023 23:02:20 +0100 Message-Id: <20230214220221.15003-6-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214220221.15003-1-leonard.anderweit@gmail.com> References: <20230214220221.15003-1-leonard.anderweit@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Adds control over the Aquacomputer Aquaero temperature offset for all eight temperature sensors. Signed-off-by: Leonard Anderweit --- Documentation/hwmon/aquacomputer_d5next.rst | 4 ++-- drivers/hwmon/aquacomputer_d5next.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Documentation/hwmon/aquacomputer_d5next.rst b/Documentation/hwmon/aquacomputer_d5next.rst index 7d0d015b1a52..618c826093a2 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. Temperature offsets 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 eb185318098a..61c1ffcd8f3b 100644 --- a/drivers/hwmon/aquacomputer_d5next.c +++ b/drivers/hwmon/aquacomputer_d5next.c @@ -116,6 +116,9 @@ static u8 aquaero_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 @@ -988,10 +991,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, @@ -1295,6 +1298,7 @@ static int aqc_probe(struct hid_device *hdev, const struct hid_device_id *id) 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; From patchwork Tue Feb 14 22:02: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: 13140938 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 48041C6FD18 for ; Tue, 14 Feb 2023 22:02:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233269AbjBNWCD (ORCPT ); Tue, 14 Feb 2023 17:02:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233197AbjBNWB6 (ORCPT ); Tue, 14 Feb 2023 17:01:58 -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 10943305F8; Tue, 14 Feb 2023 14:01:57 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id bu23so17218940wrb.8; Tue, 14 Feb 2023 14:01:56 -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=CRsF8ja+tN5dl8vKAEs9o0Dk+bv83K0UHjvvq2K1ytI=; b=obMn1FX8n+MUzihMA5YMDtgm4JW0ECMx3XUTO5JWDobb0jddOwXK9G2SOvOnlbHc51 g7rQDcCCjKocdlM15aCRjzIX8UNY8KF4tgqyCezyQ01WwPTXDBLaE97WAa67Nojn4IRS 5seAeoSNblaqvVFnX8ugtuVSAlvPKzet5iZMjG+sTCGiFQNCbnkMRh7UIE+7wJpzQ1C8 jyFWH7qKmo8uYdLuYCYD7WVwgD4BgK/8+CMQJYa5t3KbcbC3LOAdf9SgvI1FgzfXewwU MnUxJ85VVXrvDbAp2DoheTbirF+sG/mASbKHlDvJiCJt4ZrKUlrVc1jGZF8Tpm+2uH1c 7r6g== 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=CRsF8ja+tN5dl8vKAEs9o0Dk+bv83K0UHjvvq2K1ytI=; b=KEFaXt8okGELJhw4atfWrHRMzbcfnPF0SF65CQC/lfr4IJ71gCbufLEeKhUZFiZs68 6poGL/lEdWWBdJAb6+mQe54Wk/F8Nl/dwhOZituqOE4jtZ4jJ+xsr84fatcrbzn0Iei1 VGG9VwLgBosnDViczk3NT2hAa7++EZQMB9/I/tpa2oPIvig4bIQ6N80PSrZyv/RxWxsy Wg5p8BjfwX4VukR3oNLNDQcNkrfftifFIoQyyG+aHoc37SUjO9hOZDOv1fJ4mGP1s7z4 6CGI2I3v29s/itafI1aTQWNDLP7SAGP8YKWYBsjb97lT7SY7/BkdBP+b1oKWWWLNcM4j r6yA== X-Gm-Message-State: AO0yUKVhYubxHU/q5d3AWPMsQO5qoZgxKCA5q+A8ZJtK6xNMF2Eia9n6 n37skg90MvS53nAhgLQCL77WJfCbqW6eLw== X-Google-Smtp-Source: AK7set971LW0ys8KLs3D13GvqB1Jwv+kgEKZLz2dcEUGq0n19QHFszxPPNCbhVN6BSVQsgPueiLcKA== X-Received: by 2002:adf:f80b:0:b0:2c5:4c8c:410d with SMTP id s11-20020adff80b000000b002c54c8c410dmr3289871wrp.6.1676412115485; Tue, 14 Feb 2023 14:01:55 -0800 (PST) Received: from localhost.localdomain ([2001:9e8:20f2:3300:c2d2:a008:b022:b1e0]) by smtp.gmail.com with ESMTPSA id u14-20020adff88e000000b002c56046a3b5sm4033704wrp.53.2023.02.14.14.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 14:01:55 -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 v2 6/6] hwmon: (aquacomputer_d5next) Add fan PWM control for Aquaero Date: Tue, 14 Feb 2023 23:02:21 +0100 Message-Id: <20230214220221.15003-7-leonard.anderweit@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230214220221.15003-1-leonard.anderweit@gmail.com> References: <20230214220221.15003-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 PWM 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 618c826093a2..c604d4becb8d 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. Temperature offsets can be controlled. +speed (in RPM), power, voltage and current. Temperature offsets and fan speeds +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 61c1ffcd8f3b..a6cff7f9cac9 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 @@ -857,13 +864,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: @@ -922,6 +938,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) { @@ -956,15 +976,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: @@ -1287,6 +1339,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;