From patchwork Wed May 26 15:40:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12282169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06135C47088 for ; Wed, 26 May 2021 15:40:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7882613D2 for ; Wed, 26 May 2021 15:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232537AbhEZPmC (ORCPT ); Wed, 26 May 2021 11:42:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232762AbhEZPmA (ORCPT ); Wed, 26 May 2021 11:42:00 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53507C061574 for ; Wed, 26 May 2021 08:40:29 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id t24so1919839oiw.3 for ; Wed, 26 May 2021 08:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tE7T5ILApC5dfgDC4MmLEMVtvGXvgam3HPuiam11UME=; b=OLVHW15Khi36CykkB4WjRQch4cVZMtHWU0Lfyd0MbxWFo0aXMxxMYTIlovApAxTTsB IfeJBOWPq9JBLLq7eaCZDNErHWWvQdk0FZSL+9qMapwmIXRUTjQNu2OcR+0b2I8/rRHf Sl2TPwEGwkJQ50Jr4648HvryjWbx17JniZCdBRUsj5sGEQPBN+kQLRmRV5zmGacLnYoo L6E+uTEXCqpWIdcPTaXhUIPqLBJq45BBzN4TeZOdUPx0Y8zLMOBJh8WhD/ex7/NKV02z BN3VWStFgBhH2zV3/Z/8If68d8Bc9qLasCMhA4f/MjOeNzUquTm4AIRYhprF5QOkB/9S shHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=tE7T5ILApC5dfgDC4MmLEMVtvGXvgam3HPuiam11UME=; b=sQzfwBPmszRq5fzb9GxLbjdzNiilHKJt6HgadJlWRRZvoel9H6sfJDK5OmZr2vqxJ0 4CksjdllP3JlyAq+Mas2pvsNllFLQEcllp+A0CwmPcwo762DiyuEaI0bdL/Qkd4/2RVw cE6m8EerLonBZWGVa+jJZ2Cpr4vua5kQslrfwiXm4JcokvM9N2IGB66VqT+02sREsp0J uURad4I+/5fGjgC8r1i4hUhhzDSDCXYghyn9OTHFfQUD0jQo5/wAi8cdHyHqrSAxRDUx +Fm6kgZnF/KHk1RFMaWjXVlGgotkMk3glkEpmm7xU12U8hbAE2o+M5wG9WrXfUGMgfhI BIeA== X-Gm-Message-State: AOAM533QicJwfgIXd6B/Lny+hpBitPgeIliFeMGsvSsE96AMxTLph1ac B7ceD8zoMkguDr8XSqZDS/5mSdRctXo= X-Google-Smtp-Source: ABdhPJx1GbdJgdeU4jaeQJjGjij4xDECN2WVq44NKgauJP+OdyDryYNgkxnMVwxqx6q/jYI31Sxeng== X-Received: by 2002:aca:e142:: with SMTP id y63mr2364756oig.57.1622043628326; Wed, 26 May 2021 08:40:28 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id j20sm4065741oot.29.2021.05.26.08.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 08:40:27 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Jean Delvare , jan.kundrat@cesnet.cz, kubernat@cesnet.cz, Guenter Roeck Subject: [PATCH 1/7] hwmon: (max31790) Fix fan speed reporting for fan7..12 Date: Wed, 26 May 2021 08:40:16 -0700 Message-Id: <20210526154022.3223012-2-linux@roeck-us.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210526154022.3223012-1-linux@roeck-us.net> References: <20210526154022.3223012-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Fans 7..12 do not have their own set of configuration registers. So far the code ignored that and read beyond the end of the configuration register range to get the tachometer period. This resulted in more or less random fan speed values for those fans. The datasheet is quite vague when it comes to defining the tachometer period for fans 7..12. Experiments confirm that the period is the same for both fans associated with a given set of configuration registers. Fixes: 54187ff9d766 ("hwmon: (max31790) Convert to use new hwmon registration API") Fixes: 195a4b4298a7 ("hwmon: Driver for Maxim MAX31790") Cc: Jan Kundrát Cc: Václav Kubernát Signed-off-by: Guenter Roeck Reviewed-by: Jan Kundrát --- drivers/hwmon/max31790.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 86e6c71db685..f6d4fc0a2f13 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -170,7 +170,7 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel, switch (attr) { case hwmon_fan_input: - sr = get_tach_period(data->fan_dynamics[channel]); + sr = get_tach_period(data->fan_dynamics[channel % NR_CHANNEL]); rpm = RPM_FROM_REG(data->tach[channel], sr); *val = rpm; return 0; From patchwork Wed May 26 15:40:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12282173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A19F2C47082 for ; Wed, 26 May 2021 15:40:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72080613D3 for ; Wed, 26 May 2021 15:40:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233940AbhEZPmI (ORCPT ); Wed, 26 May 2021 11:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233118AbhEZPmC (ORCPT ); Wed, 26 May 2021 11:42:02 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 480A7C061574 for ; Wed, 26 May 2021 08:40:31 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id i14-20020a9d624e0000b029033683c71999so1401305otk.5 for ; Wed, 26 May 2021 08:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=watCmo8fCeuLjsloSdMLMz/4TONEMVWv4McrOuHPx84=; b=Ss096A0X8DDg3U1oX0KIrCnuVu5FOjcRP58hndthBu/rcxUwuMPdbber12udYUb7l8 fy9+m10g8MHkTLqR1eWEpvGavwkuC9SW6XuXX3lR+weS8R9MR4OXRJWguuLrylzh5aM8 s3hHPLhKtRThIzApQkpUSrhmeuE+GIaet74sQF0Ly1Qoy/kHAsc++sM4PvqXhGPfeVa/ X3L+d9twcxTANPfiSoFBjSzljhrvmLT1YesPaiCnua8JH2l7sqLhr8j1irfUG8fgvd0p 63QKLzndzB8RLXe/s1DFF++L4AhyyblcSmr0qG9pFj+WIpCvHVFF8H9a9Xxj5TR17vdA 1SUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=watCmo8fCeuLjsloSdMLMz/4TONEMVWv4McrOuHPx84=; b=hNJFHB820MQ4YyLwzfklJsy3HiL9rGVQ+qbMnVao/HZWH7QRLQ9CqAKXcvdg7gu0IQ DnC71J7axtukhMdwsWSnXjJVS6Lunju8YPWM/ZoUR7JHB22oAcoPHz5LJrRwtkYhKPq0 n9SSdKxuCWASS05Lewi/J1B1olwIbmz0SI3zjdeDfTqLATiiFkdZAA7//np29hPTGxiy c/qSnG8ZScNohtZx5jh5fXjzDvHrGiduQO2rAmDY2OMCTNYFTcdWSsH6yaE9D/TGzD2L eOKQiVG4kiDVH7DE1/vq0KJsPCCWawXmTQ2a+to52oVly3zzWk/+VAbT2kEoDI0mZXVt Qsfg== X-Gm-Message-State: AOAM532CT8dGyKA1vP9jOlUkqpsWktS74v+NpZcoFPSEnK0Zu07zBSAQ ll+YraDi1GwCGhYtScZizkdey3wOxCg= X-Google-Smtp-Source: ABdhPJwopoN0SJKzMYHPfawmxvT3S9xeHhB5rznN1jKS8a97ICUAjkRBMgYMKN+iECl33pcNCZzSlw== X-Received: by 2002:a9d:7852:: with SMTP id c18mr2787034otm.115.1622043630333; Wed, 26 May 2021 08:40:30 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id x5sm4349019otg.76.2021.05.26.08.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 08:40:29 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Jean Delvare , jan.kundrat@cesnet.cz, kubernat@cesnet.cz, Guenter Roeck Subject: [PATCH 2/7] hwmon: (max31790) Report correct current pwm duty cycles Date: Wed, 26 May 2021 08:40:17 -0700 Message-Id: <20210526154022.3223012-3-linux@roeck-us.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210526154022.3223012-1-linux@roeck-us.net> References: <20210526154022.3223012-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The MAX31790 has two sets of registers for pwm duty cycles, one to request a duty cycle and one to read the actual current duty cycle. Both do not have to be the same. When reporting the pwm duty cycle to the user, the actual pwm duty cycle from pwm duty cycle registers needs to be reported. When setting it, the pwm target duty cycle needs to be written. Since we don't know the actual pwm duty cycle after a target pwm duty cycle has been written, set the valid flag to false to indicate that actual pwm duty cycle should be read from the chip instead of using cached values. Cc: Jan Kundrát Cc: Václav Kubernát Signed-off-by: Guenter Roeck Tested-by: Václav Kubernát Reviewed-by: Jan Kundrát --- Documentation/hwmon/max31790.rst | 3 ++- drivers/hwmon/max31790.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst index f301385d8cef..54ff0f49e28f 100644 --- a/Documentation/hwmon/max31790.rst +++ b/Documentation/hwmon/max31790.rst @@ -39,5 +39,6 @@ fan[1-12]_input RO fan tachometer speed in RPM fan[1-12]_fault RO fan experienced fault fan[1-6]_target RW desired fan speed in RPM pwm[1-6]_enable RW regulator mode, 0=disabled, 1=manual mode, 2=rpm mode -pwm[1-6] RW fan target duty cycle (0-255) +pwm[1-6] RW read: current pwm duty cycle, + write: target pwm duty cycle (0-255) ================== === ======================================================= diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index f6d4fc0a2f13..693497e09ac0 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -104,7 +104,7 @@ static struct max31790_data *max31790_update_device(struct device *dev) data->tach[NR_CHANNEL + i] = rv; } else { rv = i2c_smbus_read_word_swapped(client, - MAX31790_REG_PWMOUT(i)); + MAX31790_REG_PWM_DUTY_CYCLE(i)); if (rv < 0) goto abort; data->pwm[i] = rv; @@ -299,10 +299,10 @@ static int max31790_write_pwm(struct device *dev, u32 attr, int channel, err = -EINVAL; break; } - data->pwm[channel] = val << 8; + data->valid = false; err = i2c_smbus_write_word_swapped(client, MAX31790_REG_PWMOUT(channel), - data->pwm[channel]); + val << 8); break; case hwmon_pwm_enable: fan_config = data->fan_config[channel]; From patchwork Wed May 26 15:40:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12282171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4A29C47089 for ; Wed, 26 May 2021 15:40:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 842DA613D2 for ; Wed, 26 May 2021 15:40:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232762AbhEZPmL (ORCPT ); Wed, 26 May 2021 11:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233822AbhEZPmH (ORCPT ); Wed, 26 May 2021 11:42:07 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD241C061756 for ; Wed, 26 May 2021 08:40:33 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 69-20020a9d0a4b0000b02902ed42f141e1so1408548otg.2 for ; Wed, 26 May 2021 08:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U8hedBk4yeetZrsoFkmz9iu/z3yP6GX2aslPIK8qua0=; b=KL0vu/LokOt2L+MCe8+kKLxRFsZZVZb/usZrnJCWirqMs320ZZCVhfwbG9iynJ9XSp 1QjE5Z80TfjtT98Jf81ymjfRLfdl9XkaK8xWNUzh2DpeIfXEd2ilBqJyCZ0HMLCjVU0l d972lyoT5WM2bzpK7FhaOpRD7KKT3WLj6m1E682ZPwKRvjh1kWsWyQYxUHsTu7jT7EoI KzihCKxFUYf+wr2HMCXSTnDS1057MmoSGNLXWqREcJ95N51PTnIfvA4b8sG4wUDYAVVO aQlp0Wi2Z/rkQtq0Ov3+wRpInqYNtPOsTwBOy/4gJ+4pbSHTnS+Dn5rtcXp23lc6JgEw aJdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=U8hedBk4yeetZrsoFkmz9iu/z3yP6GX2aslPIK8qua0=; b=evIuTuwO0xAsMG779BnpYY00HQASZFnx5eo5iQut2GbeRzmVvJWtm2M6TYge0H3q45 tYtHKCkq8SAhsXMwRPHAWBEHTImngKH6RpHgor0p9EMFNZLQfLZ4dHKNX5ZHq/tTfOaQ aLcwec/hiHzFF1jwMNc/uYsTlp8cMifEpNtX+tZGX0oHoaRKRQ70lFjhJcMEsmD70GFa EjGyhH9+ebm/ZEQH3zvxhuQIsYyjOBTXrJXlLDQ3lWB8i/snwNC3zHcxmMAhKnrum/Kb b7kiTsU68alGONAXo2qzdiJlYA13VquzK0I/2XHOivP5ncdRRYrUflo8cDkkDWzzC+vD 0iuQ== X-Gm-Message-State: AOAM532Vo0OZLU2+/g4HLITCKhdjkjHkoHFUTz1i4bwWiKyjwyzafhfi TLZqmXXTxW3EvAvnS4DOI9Ar3wogFf0= X-Google-Smtp-Source: ABdhPJxcR1gJDnUwXgNEoDdCE/M8Kisugu7NJkqlpR1IrQpKIxn2eNEvX7bTNNc7DM8ubfKfFFkQNg== X-Received: by 2002:a9d:741a:: with SMTP id n26mr1136822otk.223.1622043632732; Wed, 26 May 2021 08:40:32 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id f2sm4440259otp.77.2021.05.26.08.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 08:40:31 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Jean Delvare , jan.kundrat@cesnet.cz, kubernat@cesnet.cz, Guenter Roeck Subject: [PATCH 3/7] hwmon: (max31790) Fix pwmX_enable attributes Date: Wed, 26 May 2021 08:40:18 -0700 Message-Id: <20210526154022.3223012-4-linux@roeck-us.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210526154022.3223012-1-linux@roeck-us.net> References: <20210526154022.3223012-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org pwmX_enable supports three possible values: 0: Fan control disabled. Duty cycle is fixed to 0% 1: Fan control enabled, pwm mode. Duty cycle is determined by values written into Target Duty Cycle registers. 2: Fan control enabled, rpm mode Duty cycle is adjusted such that fan speed matches the values in Target Count registers The current code does not do this; instead, it mixes pwm control configuration with fan speed monitoring configuration. Worse, it reports that pwm control would be disabled (pwmX_enable==0) when it is in fact enabled in pwm mode. Part of the problem may be that the chip sets the "TACH input enable" bit on its own whenever the mode bit is set to RPM mode, but that doesn't mean that "TACH input enable" accurately reflects the pwm mode. Fix it up and only handle pwm control with the pwmX_enable attributes. In the documentation, clarify that disabling pwm control (pwmX_enable=0) sets the pwm duty cycle to 0%. In the code, explain why TACH_INPUT_EN is set together with RPM_MODE. While at it, only update the configuration register if the configuration has changed, and only update the cached configuration if updating the chip configuration was successful. Cc: Jan Kundrát Cc: Václav Kubernát Signed-off-by: Guenter Roeck Tested-by: Václav Kubernát Reviewed-by: Jan Kundrát --- Documentation/hwmon/max31790.rst | 2 +- drivers/hwmon/max31790.c | 41 ++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst index 54ff0f49e28f..7b097c3b9b90 100644 --- a/Documentation/hwmon/max31790.rst +++ b/Documentation/hwmon/max31790.rst @@ -38,7 +38,7 @@ Sysfs entries fan[1-12]_input RO fan tachometer speed in RPM fan[1-12]_fault RO fan experienced fault fan[1-6]_target RW desired fan speed in RPM -pwm[1-6]_enable RW regulator mode, 0=disabled, 1=manual mode, 2=rpm mode +pwm[1-6]_enable RW regulator mode, 0=disabled (duty cycle=0%), 1=manual mode, 2=rpm mode pwm[1-6] RW read: current pwm duty cycle, write: target pwm duty cycle (0-255) ================== === ======================================================= diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 693497e09ac0..67677c437768 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -27,6 +27,7 @@ /* Fan Config register bits */ #define MAX31790_FAN_CFG_RPM_MODE 0x80 +#define MAX31790_FAN_CFG_CTRL_MON 0x10 #define MAX31790_FAN_CFG_TACH_INPUT_EN 0x08 #define MAX31790_FAN_CFG_TACH_INPUT 0x01 @@ -271,12 +272,12 @@ static int max31790_read_pwm(struct device *dev, u32 attr, int channel, *val = data->pwm[channel] >> 8; return 0; case hwmon_pwm_enable: - if (fan_config & MAX31790_FAN_CFG_RPM_MODE) + if (fan_config & MAX31790_FAN_CFG_CTRL_MON) + *val = 0; + else if (fan_config & MAX31790_FAN_CFG_RPM_MODE) *val = 2; - else if (fan_config & MAX31790_FAN_CFG_TACH_INPUT_EN) - *val = 1; else - *val = 0; + *val = 1; return 0; default: return -EOPNOTSUPP; @@ -307,23 +308,33 @@ static int max31790_write_pwm(struct device *dev, u32 attr, int channel, case hwmon_pwm_enable: fan_config = data->fan_config[channel]; if (val == 0) { - fan_config &= ~(MAX31790_FAN_CFG_TACH_INPUT_EN | - MAX31790_FAN_CFG_RPM_MODE); + fan_config |= MAX31790_FAN_CFG_CTRL_MON; + /* + * Disable RPM mode; otherwise disabling fan speed + * monitoring is not possible. + */ + fan_config &= ~MAX31790_FAN_CFG_RPM_MODE; } else if (val == 1) { - fan_config = (fan_config | - MAX31790_FAN_CFG_TACH_INPUT_EN) & - ~MAX31790_FAN_CFG_RPM_MODE; + fan_config &= ~(MAX31790_FAN_CFG_CTRL_MON | MAX31790_FAN_CFG_RPM_MODE); } else if (val == 2) { - fan_config |= MAX31790_FAN_CFG_TACH_INPUT_EN | - MAX31790_FAN_CFG_RPM_MODE; + fan_config &= ~MAX31790_FAN_CFG_CTRL_MON; + /* + * The chip sets MAX31790_FAN_CFG_TACH_INPUT_EN on its + * own if MAX31790_FAN_CFG_RPM_MODE is set. + * Do it here as well to reflect the actual register + * value in the cache. + */ + fan_config |= (MAX31790_FAN_CFG_RPM_MODE | MAX31790_FAN_CFG_TACH_INPUT_EN); } else { err = -EINVAL; break; } - data->fan_config[channel] = fan_config; - err = i2c_smbus_write_byte_data(client, - MAX31790_REG_FAN_CONFIG(channel), - fan_config); + if (fan_config != data->fan_config[channel]) { + err = i2c_smbus_write_byte_data(client, MAX31790_REG_FAN_CONFIG(channel), + fan_config); + if (!err) + data->fan_config[channel] = fan_config; + } break; default: err = -EOPNOTSUPP; From patchwork Wed May 26 15:40:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12282177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A395FC47082 for ; Wed, 26 May 2021 15:40:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EB2F613D3 for ; Wed, 26 May 2021 15:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233118AbhEZPmQ (ORCPT ); Wed, 26 May 2021 11:42:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233869AbhEZPmK (ORCPT ); Wed, 26 May 2021 11:42:10 -0400 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA777C061574 for ; Wed, 26 May 2021 08:40:35 -0700 (PDT) Received: by mail-oi1-x235.google.com with SMTP id z3so1907395oib.5 for ; Wed, 26 May 2021 08:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BBj9NClBcqXHysiSl1PnhElCZCyKHyP2g6naC5gjE64=; b=PAFjoKYFMBVIhkA8/W0yNBv0RapqHTrCz4r8d2kShGkahoQ84EnhiHcYQKS7UBGxf0 Ox1gC9Z0HR+9oGVhmltnZaWltw29ckLtwQFL+x5hDK+yKZzlxjTEKT59lOu7ECCoVSfy 5K7HKsGEgQhupPklWhG8pSU44WIbv/CGF9uFyrNoCMReq9Qx+wptwn3keYRclE02JTMw fzh+3UApS5aoMK0GM7qD6uApCGTQX4JKR864KhoBFV4Zv1i/z/sxpHdrVJN3LLcHnHaR EwTzLc5tchPWe2gLUpfq9IvPqECirWAqaspFMbSI7PqA8wBFo6UQgBMwNXweLLB2jAB8 iyBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BBj9NClBcqXHysiSl1PnhElCZCyKHyP2g6naC5gjE64=; b=cbkN4E0QTqrZCoH0NpVx74zJdWxiTy3kHLA49ncU9ZwFwm+Ryzj6QCGyZ0xcOH43xa g71Gvc/30QA4/ZAjKfFmwDDuBSh/YmFBpLipW7oH2Ayi/xaa/2MtlYFa9Qw3Tvc0FZvu lliYwiWl90V/Huj+h9zohUsh8CRrHQrpWoWNUgHXmXOhoOPMq5Y9sS42F1QVMCj59UO5 KGv5+rcT5xnLpx4zXE5T05nOA7N3Dc/LRRa3Y/2ToJVMK1pD0dGERdOPn9qlHCy2qm/+ NNCq6m2Ye8WWKIKPlIBOT3Sm8i9+icPWkkiTdq4THEnUR0dXyXC+ghgdRBDWQPZgNTox DVCQ== X-Gm-Message-State: AOAM533VqMzTvKZiZvoRkkLJOKTn5cMGQSUWXPUhbhXXA6f7Jip3UPtV cvI4SgW/muk40lRVc6cQi46wJ7HJqKg= X-Google-Smtp-Source: ABdhPJw/VmZiAr+70HfgpskUH6nj3fcOieXHcTO0JQaYF1qwjNGM3Y6V0Vwcm4me555jTf+gXtp0WA== X-Received: by 2002:a05:6808:1404:: with SMTP id w4mr2438415oiv.53.1622043634833; Wed, 26 May 2021 08:40:34 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id f13sm4660002ote.46.2021.05.26.08.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 08:40:34 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Jean Delvare , jan.kundrat@cesnet.cz, kubernat@cesnet.cz, Guenter Roeck Subject: [PATCH 4/7] hwmon: (max31790) Add support for fanX_enable attributes Date: Wed, 26 May 2021 08:40:19 -0700 Message-Id: <20210526154022.3223012-5-linux@roeck-us.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210526154022.3223012-1-linux@roeck-us.net> References: <20210526154022.3223012-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Since pwmX_enable is now fixed and only handles pwm support instead of also enabling/disabling fan tachometers, we need an explicit means to do that. For fan channels 7..12, display the enable status if the channel is configured for fan speed reporting. The displayed status matches the value of the companion channel but is read-only. Cc: Jan Kundrát Cc: Václav Kubernát Signed-off-by: Guenter Roeck Tested-by: Václav Kubernát --- Documentation/hwmon/max31790.rst | 3 ++ drivers/hwmon/max31790.c | 55 ++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst index 7b097c3b9b90..b43aa32813fd 100644 --- a/Documentation/hwmon/max31790.rst +++ b/Documentation/hwmon/max31790.rst @@ -35,6 +35,9 @@ Sysfs entries ------------- ================== === ======================================================= +fan[1-12]_enable RW 0=disable fan speed monitoring, 1=enable fan speed monitoring + The value is RO for companion channels (7-12). For those + channels, the value matches the value of the primary channel. fan[1-12]_input RO fan tachometer speed in RPM fan[1-12]_fault RO fan experienced fault fan[1-6]_target RW desired fan speed in RPM diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 67677c437768..19651feb40fb 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -170,6 +170,9 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel, return PTR_ERR(data); switch (attr) { + case hwmon_fan_enable: + *val = !!(data->fan_config[channel % NR_CHANNEL] & MAX31790_FAN_CFG_TACH_INPUT_EN); + return 0; case hwmon_fan_input: sr = get_tach_period(data->fan_dynamics[channel % NR_CHANNEL]); rpm = RPM_FROM_REG(data->tach[channel], sr); @@ -195,12 +198,32 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel, struct i2c_client *client = data->client; int target_count; int err = 0; - u8 bits; + u8 bits, config; int sr; mutex_lock(&data->update_lock); switch (attr) { + case hwmon_fan_enable: + config = data->fan_config[channel]; + if (val == 0) { + /* Disabling TACH_INPUT_EN has no effect in RPM_MODE */ + if (!(config & MAX31790_FAN_CFG_RPM_MODE)) + config &= ~MAX31790_FAN_CFG_TACH_INPUT_EN; + } else if (val == 1) { + config |= MAX31790_FAN_CFG_TACH_INPUT_EN; + } else { + err = -EINVAL; + break; + } + if (config != data->fan_config[channel]) { + err = i2c_smbus_write_byte_data(client, + MAX31790_REG_FAN_CONFIG(channel), + config); + if (!err) + data->fan_config[channel] = config; + } + break; case hwmon_fan_target: val = clamp_val(val, FAN_RPM_MIN, FAN_RPM_MAX); bits = bits_for_tach_period(val); @@ -240,6 +263,12 @@ static umode_t max31790_fan_is_visible(const void *_data, u32 attr, int channel) u8 fan_config = data->fan_config[channel % NR_CHANNEL]; switch (attr) { + case hwmon_fan_enable: + if (channel < NR_CHANNEL) + return 0644; + if (fan_config & MAX31790_FAN_CFG_TACH_INPUT) + return 0444; + return 0; case hwmon_fan_input: case hwmon_fan_fault: if (channel < NR_CHANNEL || @@ -404,18 +433,18 @@ static umode_t max31790_is_visible(const void *data, static const struct hwmon_channel_info *max31790_info[] = { HWMON_CHANNEL_INFO(fan, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_INPUT | HWMON_F_FAULT), + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, From patchwork Wed May 26 15:40:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12282175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65DFBC47088 for ; Wed, 26 May 2021 15:40:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 498DA613D2 for ; Wed, 26 May 2021 15:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233822AbhEZPmO (ORCPT ); Wed, 26 May 2021 11:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234193AbhEZPmK (ORCPT ); Wed, 26 May 2021 11:42:10 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A057FC06175F for ; Wed, 26 May 2021 08:40:37 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id i23-20020a9d68d70000b02902dc19ed4c15so1432067oto.0 for ; Wed, 26 May 2021 08:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q9EkXnYEQiICfs65xThtnkdPUbxcpwn3kdqK+p3e1YY=; b=KGo865HDyCs0SNFkwpp9+Su8vTBxDPvtOiiZjiZqxaWtnWgEUFXX5XFMkn6cQPGH9R ICLpGo4hVyXPKrenBjStdYzIqoTp9c7FWSN+4Fz6dxN7PY06H/6r8OcG4sWcjAoRjKrc JKUtrA04G/fLUGQNRd5u2tG2SwGaP8LTOcjJOXMzUJR4dPuVbXSiJGVyf5LMQpyn/bVQ XNVKi9WZLSOSUiA1MBddtcrE8jTGkaJPyeb1bWcRH+lDKoGzvzqnyK+HwcY8PxIEKfII t0Gzdn9nMOUUfQ9Ta7uNjtK1AzzhmLOfqgHnsDH1RLIf/1JLgNafbI5M0RJQ1fMj0CWc 6oCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=q9EkXnYEQiICfs65xThtnkdPUbxcpwn3kdqK+p3e1YY=; b=sZl64Dq3MR4h6xElp86IVkZ5t1y/4AMZXc1l8WcdSpv2rxJ7lSDmoI2JX+G7tDcU8a RYdtbGaxtjYd9UVPcmbtRC9D5Gmqp3OvE3ARHu8k6VovyqG1VaSMfIWg9WXUnrOcDqp5 XWaG18pWEiPsRwet6Xkc23vxGGQOveN/psGUG8j94q/zQFXu2aMO8rYVEc0KMZ8hUi58 uZphpPgdhHdPNkAj3o+tpDaR3POytB9+tGKMsq7kfLND6jiUMuzXWvSUMwf2S84bpbZb wZUoDp2mKD/ek39d2puL0F8ZGstNzPEueehOs6Ux67FYKoJh0UdJco9wqluABf5ANh5J B1zQ== X-Gm-Message-State: AOAM531ApYthFn32E6M5MrDVk5bHfHsCL/DDpwPnC1HXUWj3m2ajsGaw Ybkr55UZl5YRnePLJqwEJWz8cERP8JI= X-Google-Smtp-Source: ABdhPJxC8jSkhE9B5z9QJ9BElGDlsLsnfzdbPVleYHXQC8knXt12WJWNTICbB7v5xBrUg0s8Frcoag== X-Received: by 2002:a05:6830:1155:: with SMTP id x21mr2820773otq.303.1622043636704; Wed, 26 May 2021 08:40:36 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id q14sm4210617ota.31.2021.05.26.08.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 08:40:36 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Jean Delvare , jan.kundrat@cesnet.cz, kubernat@cesnet.cz, Guenter Roeck Subject: [PATCH 5/7] hwmon: (max31790) Clear fan fault after reporting it Date: Wed, 26 May 2021 08:40:20 -0700 Message-Id: <20210526154022.3223012-6-linux@roeck-us.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210526154022.3223012-1-linux@roeck-us.net> References: <20210526154022.3223012-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Fault bits in MAX31790 are sticky and have to be cleared explicitly. A write operation into either the 'Target Duty Cycle' register or the 'Target Count' register is necessary to clear a fault. At the same time, we can never clear cached fault status values before reading them because the companion fault status for any given fan is cleared as well when clearing a fault. Cc: Jan Kundrát Cc: Václav Kubernát Signed-off-by: Guenter Roeck Tested-by: Václav Kubernát --- drivers/hwmon/max31790.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 19651feb40fb..8e4fd9b7c889 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -80,7 +80,7 @@ static struct max31790_data *max31790_update_device(struct device *dev) MAX31790_REG_FAN_FAULT_STATUS1); if (rv < 0) goto abort; - data->fault_status = rv & 0x3F; + data->fault_status |= rv & 0x3F; rv = i2c_smbus_read_byte_data(client, MAX31790_REG_FAN_FAULT_STATUS2); @@ -184,7 +184,21 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel, *val = rpm; return 0; case hwmon_fan_fault: + mutex_lock(&data->update_lock); *val = !!(data->fault_status & (1 << channel)); + data->fault_status &= ~(1 << channel); + /* + * If a fault bit is set, we need to write into one of the fan + * configuration registers to clear it. Note that this also + * clears the fault for the companion channel if enabled. + */ + if (*val) { + int reg = MAX31790_REG_TARGET_COUNT(channel % NR_CHANNEL); + + i2c_smbus_write_byte_data(data->client, reg, + data->target_count[channel % NR_CHANNEL] >> 8); + } + mutex_unlock(&data->update_lock); return 0; default: return -EOPNOTSUPP; From patchwork Wed May 26 15:40:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12282179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49800C47088 for ; Wed, 26 May 2021 15:40:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AA12613D3 for ; Wed, 26 May 2021 15:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233675AbhEZPmR (ORCPT ); Wed, 26 May 2021 11:42:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233819AbhEZPmM (ORCPT ); Wed, 26 May 2021 11:42:12 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DB5EC061756 for ; Wed, 26 May 2021 08:40:39 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id 69-20020a9d0a4b0000b02902ed42f141e1so1408861otg.2 for ; Wed, 26 May 2021 08:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pPQLkKkMQ3uWimuyAs10pPH0N/fVipRIkvuWmS5PZNU=; b=vWm1J/OQzHg0y2KCs2geYQ+ZLnvjbuqWr1HXg0wGpH7l2eY4ro6VTluvYGdr2iBmQR QHTriiBejbfpHTuzFquuCuOPc6yQnmykc7DgjQ41/i+Z9+cptyp+aIeNu1B18yaJmnzd 7FG0IoSovzTMo6SgkAd+XVPFs/NoveHPqL0cCoHTD1J2e2k2/S8EJ2hYlL8msFK8b0R8 InBpsmSwulQNPUMCW+4W+03QUTKwr29ERvXonrnvFPhSxWYzJUHt2HB/00ZOEVZr0G9g 8UCpmfR62WMMwE1G5njRssTeDxVxraMS6H0m1PLVg/4UTjqUo8FGn1KTMYwXlHyK9KOi zJqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pPQLkKkMQ3uWimuyAs10pPH0N/fVipRIkvuWmS5PZNU=; b=LllWcxBx5wbTUYPOWzWunEVB9Q+VJLQChHQ7w+AWFDscc0YjuuGRKGOyl9LLGiwqkn PbPIJz6V2IDsFBGqtauN99zR7BQ3lNmrhAD7uBksNDCR6WnLsFwO3uWktzc0OS/stB1v RsatMYRMiamcK4f+j6yCREY5TWOr7QA1Ksi0oiG/xjXfZpCnO2bV0siw75vQgHuBuRGb 0vrlUM7Ag9h0I1Anw+4XafWyG2dqtI5S9rzs6XHSADTw6aHttjsX4aKaN4X/sBh22NVk g7fCl4cIPHioDlJhkcqVMvzKTLcB01dHIUoGd9/9jCEIZt9NZnxQYGJTJEuhIRMIOFPQ c8bg== X-Gm-Message-State: AOAM533io4VOg1u7tgwu2XbxU/tJ6X4a1tiHS1swsseoiFVOZSEzcEDU jbzH8u+xZ3TdQNAG997JwT+idWCzU0s= X-Google-Smtp-Source: ABdhPJwqYOpi7cR7vCz+gj7gSqbUvhmUojpu/TcXhg+Y8PgzPmXeLmX8vRvGfulRskDkq5DKW3Js6A== X-Received: by 2002:a05:6830:4da:: with SMTP id s26mr2857587otd.77.1622043638533; Wed, 26 May 2021 08:40:38 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id x11sm4488944otr.36.2021.05.26.08.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 08:40:38 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Jean Delvare , jan.kundrat@cesnet.cz, kubernat@cesnet.cz, Guenter Roeck Subject: [PATCH 6/7] hwmon: (max31790) Detect and report zero fan speed Date: Wed, 26 May 2021 08:40:21 -0700 Message-Id: <20210526154022.3223012-7-linux@roeck-us.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210526154022.3223012-1-linux@roeck-us.net> References: <20210526154022.3223012-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org If a fan is not running or not connected, of if fan monitoring is disabled, the fan count register returns a fixed value of 0xffe0. So far this is then translated to a RPM value larger than 0. Since this is misleading and does not really make much sense, report a fan RPM of 0 in this situation. Cc: Jan Kundrát Cc: Václav Kubernát Signed-off-by: Guenter Roeck Tested-by: Václav Kubernát --- drivers/hwmon/max31790.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 8e4fd9b7c889..91fe419b596c 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -40,6 +40,8 @@ #define FAN_RPM_MIN 120 #define FAN_RPM_MAX 7864320 +#define FAN_COUNT_REG_MAX 0xffe0 + #define RPM_FROM_REG(reg, sr) (((reg) >> 4) ? \ ((60 * (sr) * 8192) / ((reg) >> 4)) : \ FAN_RPM_MAX) @@ -175,7 +177,10 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel, return 0; case hwmon_fan_input: sr = get_tach_period(data->fan_dynamics[channel % NR_CHANNEL]); - rpm = RPM_FROM_REG(data->tach[channel], sr); + if (data->tach[channel] == FAN_COUNT_REG_MAX) + rpm = 0; + else + rpm = RPM_FROM_REG(data->tach[channel], sr); *val = rpm; return 0; case hwmon_fan_target: From patchwork Wed May 26 15:40:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12282181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 052DEC47089 for ; Wed, 26 May 2021 15:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1109613D3 for ; Wed, 26 May 2021 15:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232913AbhEZPmS (ORCPT ); Wed, 26 May 2021 11:42:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234282AbhEZPmN (ORCPT ); Wed, 26 May 2021 11:42:13 -0400 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6063BC061574 for ; Wed, 26 May 2021 08:40:41 -0700 (PDT) Received: by mail-ot1-x32d.google.com with SMTP id i23-20020a9d68d70000b02902dc19ed4c15so1432266oto.0 for ; Wed, 26 May 2021 08:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mf7rp2yxur4tzrYtSCdYs49YjVU5xM01obCPMruWP6c=; b=CoGeqg+QVY1bATKgfxXaoBeDhlb/QzOKcSUWn5lu6xdszLIS+9SeMnVeYm8EXnbTD6 /efdoYMYbGtCD8Fm+kc35rX+TKCpLd1KQt/i4MOPui7iYlcSDo+F5VaW3aprDF+PhgQJ 94rAhJO4azUxgg6ZRdW9Bcnkg4UYKW4lfl3hJnXEABJG6tEqWZYnWUTCM4V0nEnwB10+ jL8YZFawSkjn0+x4G5AXMuUOBBpxrUC0C4myjYC0niytztXGBYKX7zgOqxr2xyljLA7u CEk3KCR7YmCRL7vgNd/H25MOuEamqTRPC18bwK22Bcu+S3Mu4em/qu1cC4kYENLaaPOH 52yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mf7rp2yxur4tzrYtSCdYs49YjVU5xM01obCPMruWP6c=; b=HGoHAj+UzSuWqQj79rQVix33W1PLBI0N1gtHE60LlIqN36LLcTAW6iK2p20Ms8V5JU Pksr4CuBrob+FM8YxJBb57MJZ8Zb+6haDy2Gb6GUnvkb2xFaBUUYzydOvBTuiufQkCPT DreZbELdQAvfroJNa3GkQMQW7Npy/0wN/pvzEFVR3bkPpQ21+jq3/9gw5q/9OXMQ23x5 YeCPzcxr4fNBZLT611NDFwWZgB1wsl4AwRLZp/p9Xb0buSwH0+WSdWi4BkEP1k7hTL++ bXJ1dpr79o4Fa8iM2gFfX8pxxQIcp8WezvJQgLpvMe+hY8EC09poBn0MszpIJBZV2X6V NfrQ== X-Gm-Message-State: AOAM530WiNT6uIimnx9vx1hPM7ol0WW6ORTi19AqO8wd2gOIJFLaYfDD m3Ls19yvqxehVTIO2ShhgzOFGEK7BU4= X-Google-Smtp-Source: ABdhPJxnq5HWi9sE7ZwaMtEn4LlDPiF3EozaReooZPhlLiHQe8o+oe94vQ1RpT65Fbn9HmdVjwOKaw== X-Received: by 2002:a9d:4b9c:: with SMTP id k28mr2942839otf.183.1622043640420; Wed, 26 May 2021 08:40:40 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id v8sm3833955oiv.5.2021.05.26.08.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 08:40:39 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Jean Delvare , jan.kundrat@cesnet.cz, kubernat@cesnet.cz, Guenter Roeck Subject: [PATCH 7/7] hwmon: (max31790) Add support for fanX_min attributes Date: Wed, 26 May 2021 08:40:22 -0700 Message-Id: <20210526154022.3223012-8-linux@roeck-us.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210526154022.3223012-1-linux@roeck-us.net> References: <20210526154022.3223012-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The minimum fan speed is closely correlated to the target fan speed. The correlation depends on the pwm mode. It is essential to be able to read and to set it to be able to control when a channel will report a fan fault. Since the minimum fan speed also applies to channels 7..12, make it visible but read-only for those channels as well. Cc: Jan Kundrát Cc: Václav Kubernát Signed-off-by: Guenter Roeck Tested-by: Václav Kubernát --- Documentation/hwmon/max31790.rst | 9 ++++ drivers/hwmon/max31790.c | 70 ++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst index b43aa32813fd..9225c2a78b68 100644 --- a/Documentation/hwmon/max31790.rst +++ b/Documentation/hwmon/max31790.rst @@ -40,6 +40,15 @@ fan[1-12]_enable RW 0=disable fan speed monitoring, 1=enable fan speed monito channels, the value matches the value of the primary channel. fan[1-12]_input RO fan tachometer speed in RPM fan[1-12]_fault RO fan experienced fault +fan[1-12]_min RW minimum fan speed in RPM. Equivalent to target fan speed + in PWM mode and if PWM support is disabled for a channel. + Equivalent to half the target fan speed in RPM mode. + The value is RO for companion channels (7-12). For those + channels, the value matches the value of the primary channel. + Note: In RPM mode, if the pwm duty cycle is 100%, the + minimum fan speed is equivalent to the target fan speed, + and the chip will report a fault condition if the fan + speed is below the target fan speed. fan[1-6]_target RW desired fan speed in RPM pwm[1-6]_enable RW regulator mode, 0=disabled (duty cycle=0%), 1=manual mode, 2=rpm mode pwm[1-6] RW read: current pwm duty cycle, diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c index 91fe419b596c..db97ee99515a 100644 --- a/drivers/hwmon/max31790.c +++ b/drivers/hwmon/max31790.c @@ -111,13 +111,11 @@ static struct max31790_data *max31790_update_device(struct device *dev) if (rv < 0) goto abort; data->pwm[i] = rv; - - rv = i2c_smbus_read_word_swapped(client, - MAX31790_REG_TARGET_COUNT(i)); - if (rv < 0) - goto abort; - data->target_count[i] = rv; } + rv = i2c_smbus_read_word_swapped(client, MAX31790_REG_TARGET_COUNT(i)); + if (rv < 0) + goto abort; + data->target_count[i] = rv; } data->last_updated = jiffies; @@ -183,6 +181,21 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel, rpm = RPM_FROM_REG(data->tach[channel], sr); *val = rpm; return 0; + case hwmon_fan_min: + channel %= NR_CHANNEL; + sr = get_tach_period(data->fan_dynamics[channel]); + if (!(data->fan_config[channel] & MAX31790_FAN_CFG_RPM_MODE) || + (data->fan_config[channel] & MAX31790_FAN_CFG_TACH_INPUT)) { + /* pwm mode: target == min */ + rpm = RPM_FROM_REG(data->target_count[channel], sr); + } else { + /* rpm mode: min tach count is twice target count */ + u16 tach = min(data->target_count[channel] * 2, FAN_COUNT_REG_MAX); + + rpm = RPM_FROM_REG(tach, sr); + } + *val = rpm; + return 0; case hwmon_fan_target: sr = get_tach_period(data->fan_dynamics[channel]); rpm = RPM_FROM_REG(data->target_count[channel], sr); @@ -243,6 +256,20 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel, data->fan_config[channel] = config; } break; + case hwmon_fan_min: + /* + * The minimum fan speed is the same as the target fan speed in + * PWM mode and if a PWM channel is disabled, or it is half the + * target fan speed in RPM mode. + */ + if (!(data->fan_config[channel] & MAX31790_FAN_CFG_TACH_INPUT) && + (data->fan_config[channel] & MAX31790_FAN_CFG_RPM_MODE)) { + /* partial clamp to avoid overflow */ + if (val > FAN_RPM_MAX / 2) + val = FAN_RPM_MAX / 2; + val *= 2; + } + fallthrough; case hwmon_fan_target: val = clamp_val(val, FAN_RPM_MIN, FAN_RPM_MAX); bits = bits_for_tach_period(val); @@ -282,6 +309,7 @@ static umode_t max31790_fan_is_visible(const void *_data, u32 attr, int channel) u8 fan_config = data->fan_config[channel % NR_CHANNEL]; switch (attr) { + case hwmon_fan_min: case hwmon_fan_enable: if (channel < NR_CHANNEL) return 0644; @@ -452,18 +480,24 @@ static umode_t max31790_is_visible(const void *data, static const struct hwmon_channel_info *max31790_info[] = { HWMON_CHANNEL_INFO(fan, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT, - HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_FAULT), + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_TARGET | + HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_TARGET | + HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_TARGET | + HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_TARGET | + HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_TARGET | + HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_TARGET | + HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_FAULT, + HWMON_F_ENABLE | HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_FAULT), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,