From patchwork Fri Dec 10 20:01:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12670909 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 18ED9C433F5 for ; Fri, 10 Dec 2021 20:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240478AbhLJUFS (ORCPT ); Fri, 10 Dec 2021 15:05:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240266AbhLJUFR (ORCPT ); Fri, 10 Dec 2021 15:05:17 -0500 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65FFFC061746 for ; Fri, 10 Dec 2021 12:01:42 -0800 (PST) Received: by mail-oi1-x22d.google.com with SMTP id o4so14680598oia.10 for ; Fri, 10 Dec 2021 12:01:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=324RA3Gg2dJx1zBs0E3znK4Ivd7vMuSkoiZtjRKOIuU=; b=PSCzCHVyAFhTWoDjWd9ApM1TnFkLO/6G4PQwW81eOq3T1MR4/W1kvVSbcQmVLRUAMx 70Yem1YIeGtmFVg6X/a2MHB1JWJGFffB81qR7SC9CdGvxM3RWQzVJL77UN4vFJCnCnFD xVnhtL0DV6e0ir1zE+2bj/peJzSJEk2ykVMmtXKRivjMTUM6tfhQYGnw2zg8/WHye6/F Cinl10bUe5OoZjedpJ8HuM9Z+jdivziXMSAf+xqs8h3gPMIPZS95Q+Xh5KSzQbWBXdwa ODpRN6jQiMgaTWPGaKO1JOxgmUeBymGd3Y+nWfnRb12z1PCRdT+FfwzhgHK+94IjMLP1 NZyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=324RA3Gg2dJx1zBs0E3znK4Ivd7vMuSkoiZtjRKOIuU=; b=NQ1PdPgNEa0zoVRZjqTyRT7fE6INaVYi5TdOCVv/OPKs5DOxV0S6YXY/BCIMBLObSL BsXodpspCPgBke2h5hxOKEnDkc+F7NWnYsvsFcX1gO//OYUHWVZLJPLJ/J4eaIEcg1qc Eea2yBkhv4XxG7UeXOsSiXJLTjj8MAh3xKqn+Rmvp+0phCDROerOKFQ34ILjnL3fXz/h oVdZRB1EuUEWghDeZQmdN2k4Fy8OzWfZBCpOdsWolgGINW5Glq8x1NffJZ8deDNFokC8 D0jyGVJbQV9s2VpfbnkX0QxeBFVw1ZfFhNzYutzQxwChncS43PMWLvMEFlhSRD9uY/im UFYw== X-Gm-Message-State: AOAM532LFPKuuuDWY8ACqbzZpPVwg7T+BYbWmFU8nR1SOCul8jJXgAvP kkKOK7E5O1uer0ry2O9iefRePHXeN9o= X-Google-Smtp-Source: ABdhPJwcplvaR8xgXs+KBQOn2srNo8Ia4yFn8yPCudUCfX7ZabmTexgUaPyGtso/7FUkyMf5LTbyDA== X-Received: by 2002:a05:6808:2181:: with SMTP id be1mr13775671oib.147.1639166501512; Fri, 10 Dec 2021 12:01:41 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id g17sm873433oiy.14.2021.12.10.12.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 12:01:41 -0800 (PST) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck Subject: [PATCH 1/5] hwmon: (lm90) Fix usage of CONFIG2 register in detect function Date: Fri, 10 Dec 2021 12:01:32 -0800 Message-Id: <20211210200136.1662127-2-linux@roeck-us.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211210200136.1662127-1-linux@roeck-us.net> References: <20211210200136.1662127-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The detect function had a comment "Make compiler happy" when id did not read the second configuration register. As it turns out, the code was checking the contents of this register for manufacturer ID 0xA1 (NXP Semiconductor/Philips), but never actually read the register. So it wasn't surprising that the compiler complained, and it indeed had a point. Fix the code to read the register contents for manufacturer ID 0xa1. At the same time, the code was reading the register for manufacturer ID 0x41 (Analog Devices), but it was not using the results. In effect it was just checking if reading the register returned an error. That doesn't really add much if any value, so stop doing that. Fixes: f90be42fb383 ("hwmon: (lm90) Refactor reading of config2 register") Signed-off-by: Guenter Roeck --- drivers/hwmon/lm90.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 618052c6cdb6..b05d73c4fbe2 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -1465,12 +1465,11 @@ static int lm90_detect(struct i2c_client *client, if (man_id < 0 || chip_id < 0 || config1 < 0 || convrate < 0) return -ENODEV; - if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) { + if (man_id == 0x01 || man_id == 0x5C || man_id == 0xA1) { config2 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG2); if (config2 < 0) return -ENODEV; - } else - config2 = 0; /* Make compiler happy */ + } if ((address == 0x4C || address == 0x4D) && man_id == 0x01) { /* National Semiconductor */ From patchwork Fri Dec 10 20:01:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12670911 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 3F040C433FE for ; Fri, 10 Dec 2021 20:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242314AbhLJUFU (ORCPT ); Fri, 10 Dec 2021 15:05:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240266AbhLJUFT (ORCPT ); Fri, 10 Dec 2021 15:05:19 -0500 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 64196C061746 for ; Fri, 10 Dec 2021 12:01:44 -0800 (PST) Received: by mail-ot1-x329.google.com with SMTP id r10-20020a056830080a00b0055c8fd2cebdso10704839ots.6 for ; Fri, 10 Dec 2021 12:01:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aQroFgpoqsZDK7VslPHctf2JgED3OthtRhCfFPKi1C8=; b=eOJquqTgZyXZwN+WGugyiKqNP5S3YUPUUhEWZmwBY6JEttnBulKJvqPX+wS8z7cyag JrRa7y7nDVS+8ORr6fVadqJJuHcD6OlVm7FknFa6bGt5tXevjVMCYZVb6vK5QQcD9T7O 5ZEyzZzdV3JHpLwSCbpqAkcX9ZcGN5KGGylmuChUnGi3vL2pIYSYkl3LVbiQDNrhucdB jZ+9Taly1PJeU2d+cuNcckyi3Z4WinQIibDXv4uEAMWND+VA329p1iQB5bCHMI9xSkEd 85647oxxHNH20kfLQzzcOvuZuChcKaKI6cs4I+AZhyCdvPf30V2aV/+upGwUOFK6FK7a t8RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=aQroFgpoqsZDK7VslPHctf2JgED3OthtRhCfFPKi1C8=; b=0H7rlNeuoQJfsfUw7JJ2CF+cjGuo8K53OhLHO/fXirtfDjDT3CYFdw04+UV2gEdagp ulW/z0aLLsdfuVVYKIW9syXdRlOTyxi/XwNRi4kAbEF+qc5kjvMrkaYHEVZ2UPFHrY5W vRJMO7+e3839/TBfOjh4Jg64E7TC+wt1C2JRmHa9yeY47sgzaXnzjBI4GWDr7uHj3Pv5 9bJOwOMzgTMQ7/u441et7aToORLoq0aOKMS2hRc2Jv/xYd+dHIAz8BFe/WTlQwppSiqj J1utSQS4xQgaUMJ0A+W+pcHImn6lRN7K/e0EPFT7c5oUv0nNfSCK2gBxH/UHmcsZan2P Hk/w== X-Gm-Message-State: AOAM532oE152hTp+CsiHe5XnRrAGsOhY9318u6SzCEiauB1VXhPOYs8t 0fDuXFiOrqlQQKfL/mLcBcUgs4s6buQ= X-Google-Smtp-Source: ABdhPJzarB+3eCti7OCkBefBFEPa7NkPl33a1Fj5tb0VkcRyGxWSm/WHaOX6IKkPO9LctEeXWzzlGg== X-Received: by 2002:a05:6830:1154:: with SMTP id x20mr12907596otq.205.1639166503379; Fri, 10 Dec 2021 12:01:43 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id v12sm660577ote.9.2021.12.10.12.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 12:01:42 -0800 (PST) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Dmitry Osipenko Subject: [PATCH 2/5] hwmon: (lm90) Prevent integer overflow/underflow in hysteresis calculations Date: Fri, 10 Dec 2021 12:01:33 -0800 Message-Id: <20211210200136.1662127-3-linux@roeck-us.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211210200136.1662127-1-linux@roeck-us.net> References: <20211210200136.1662127-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Commit b50aa49638c7 ("hwmon: (lm90) Prevent integer underflows of temperature calculations") addressed a number of underflow situations when writing temperature limits. However, it missed one situation, seen when an attempt is made to set the hysteresis value to MAX_LONG and the critical temperature limit is negative. Use clamp_val() when setting the hysteresis temperature to ensure that the provided value can never overflow or underflow. Fixes: b50aa49638c7 ("hwmon: (lm90) Prevent integer underflows of temperature calculations") Cc: Dmitry Osipenko Signed-off-by: Guenter Roeck Reviewed-by: Dmitry Osipenko --- drivers/hwmon/lm90.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index b05d73c4fbe2..72969ea83d82 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -1160,8 +1160,8 @@ static int lm90_set_temphyst(struct lm90_data *data, long val) else temp = temp_from_s8(data->temp8[LOCAL_CRIT]); - /* prevent integer underflow */ - val = max(val, -128000l); + /* prevent integer overflow/underflow */ + val = clamp_val(val, -128000l, 255000l); data->temp_hyst = hyst_to_reg(temp - val); err = i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, From patchwork Fri Dec 10 20:01:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12670913 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 2AE14C433EF for ; Fri, 10 Dec 2021 20:01:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243101AbhLJUFW (ORCPT ); Fri, 10 Dec 2021 15:05:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240266AbhLJUFV (ORCPT ); Fri, 10 Dec 2021 15:05:21 -0500 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 102DEC061746 for ; Fri, 10 Dec 2021 12:01:46 -0800 (PST) Received: by mail-oi1-x229.google.com with SMTP id bj13so14725177oib.4 for ; Fri, 10 Dec 2021 12:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kA+VDgLXqZ1omHVz2/EDZQ5F4N/5S0G6z3LKduTvXUE=; b=ZMNKtEnPu40dUg7DHFpTYrgw3+UlPpUY/tYWfxcWhHsHtwTDft7yanwHghtQ87lHSI rKmlAWRZ3lJuGWUp2+6SkCNyDvEFR5r4mb6qbNedkH/6RzHUkpLdR91aPeFEqYpzR+L/ 4Ii7bBfJkG/AmPoyEGQkUd4hi1km6fjYQUEAwEtbAXcKwczPcTUo+biuwT1dZ3YBkuf1 g8upnyFp7Wn3EmKvX9mYA8u2LIL44vEhL9XQyYI+PyH3KyWMBeNmwp03pZM25l03jEmB BxzY8lWLOlAZ7RbZOvZaj8Lr9u3UqCPVxhCbQWlXKbpj4zUHEJ2ZOH2gEtXBXTHexw8D vp+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kA+VDgLXqZ1omHVz2/EDZQ5F4N/5S0G6z3LKduTvXUE=; b=eFYigJsMxpk0eRMyt6McYzmISqQY3Iyu87OvLG1WFCQFQ021KKQMZVxx11RDDU4dh7 CKMJpPy8zvOlgiQhJyAxH0aJYe3WCs73ZGp80KerI3KnVF7wpDHwMlF3PjlqC/i6lRfQ Gu7vbamzzvK8n/p3nK50v8c+dTd1WjEwYIt+znFCwhVjoyZhLL8FYFwOBohACUgMPK0r j4JJVvbdwE1qjcvs8YnraQidgQbaVcwMqLOqWAty76RKl3Gr1Kv8edazDwXEPoP/XL+x boz5DCJmvYF7bi5P3zhchGhiNzZx2fGAqcCKunuqYsrOkQGuPcL995pKnOZrYUMQhx0e uZSQ== X-Gm-Message-State: AOAM532MykSFOUnfv5NVqMxL7Tm11PuYHZhSfh49Z3v6rL+ks+dC0VzK EOpp1iWbcMLoSahnZpMggmbTvxsHsVA= X-Google-Smtp-Source: ABdhPJzuZzS0Wz+AQ9CGRfYYxNAFTq4mSx2asVnQVxNPB5ZPGbdpTr2AcbfTHd12Hi43TFcYvHVBpQ== X-Received: by 2002:a05:6808:1a83:: with SMTP id bm3mr14689095oib.173.1639166505179; Fri, 10 Dec 2021 12:01:45 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id g4sm700351oof.40.2021.12.10.12.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 12:01:44 -0800 (PST) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck , Josh Lehan Subject: [PATCH 3/5] hwmon: (lm90) Drop critical attribute support for MAX6654 Date: Fri, 10 Dec 2021 12:01:34 -0800 Message-Id: <20211210200136.1662127-4-linux@roeck-us.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211210200136.1662127-1-linux@roeck-us.net> References: <20211210200136.1662127-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Tests with a real chip and a closer look into the datasheet show that MAX6654 does not support CRIT/THERM/OVERTEMP limits, so drop support of the respective attributes for this chip. Introduce LM90_HAVE_CRIT flag and use it to instantiate critical limit attributes to solve the problem. Cc: Josh Lehan Fixes: 229d495d8189 ("hwmon: (lm90) Add max6654 support to lm90 driver") Signed-off-by: Guenter Roeck --- drivers/hwmon/lm90.c | 86 +++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 72969ea83d82..6597d055e09d 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -35,13 +35,14 @@ * explicitly as max6659, or if its address is not 0x4c. * These chips lack the remote temperature offset feature. * - * This driver also supports the MAX6654 chip made by Maxim. This chip can - * be at 9 different addresses, similar to MAX6680/MAX6681. The MAX6654 is - * otherwise similar to MAX6657/MAX6658/MAX6659. Extended range is available - * by setting the configuration register accordingly, and is done during - * initialization. Extended precision is only available at conversion rates - * of 1 Hz and slower. Note that extended precision is not enabled by - * default, as this driver initializes all chips to 2 Hz by design. + * This driver also supports the MAX6654 chip made by Maxim. This chip can be + * at 9 different addresses, similar to MAX6680/MAX6681. The MAX6654 is similar + * to MAX6657/MAX6658/MAX6659, but does not support critical temperature + * limits. Extended range is available by setting the configuration register + * accordingly, and is done during initialization. Extended precision is only + * available at conversion rates of 1 Hz and slower. Note that extended + * precision is not enabled by default, as this driver initializes all chips + * to 2 Hz by design. * * This driver also supports the MAX6646, MAX6647, MAX6648, MAX6649 and * MAX6692 chips made by Maxim. These are again similar to the LM86, @@ -188,6 +189,7 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */ #define LM90_HAVE_EXTENDED_TEMP (1 << 8) /* extended temperature support*/ #define LM90_PAUSE_FOR_CONFIG (1 << 9) /* Pause conversion for config */ +#define LM90_HAVE_CRIT (1 << 10)/* Chip supports CRIT/OVERT register */ /* LM90 status */ #define LM90_STATUS_LTHRM (1 << 0) /* local THERM limit tripped */ @@ -354,38 +356,43 @@ struct lm90_params { static const struct lm90_params lm90_params[] = { [adm1032] = { .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT - | LM90_HAVE_BROKEN_ALERT, + | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 10, }, [adt7461] = { .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT - | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP, + | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP + | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 10, }, [g781] = { .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT - | LM90_HAVE_BROKEN_ALERT, + | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 8, }, [lm86] = { - .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, + .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT + | LM90_HAVE_CRIT, .alert_alarms = 0x7b, .max_convrate = 9, }, [lm90] = { - .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, + .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT + | LM90_HAVE_CRIT, .alert_alarms = 0x7b, .max_convrate = 9, }, [lm99] = { - .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, + .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT + | LM90_HAVE_CRIT, .alert_alarms = 0x7b, .max_convrate = 9, }, [max6646] = { + .flags = LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 6, .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, @@ -396,50 +403,50 @@ static const struct lm90_params lm90_params[] = { .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, }, [max6657] = { - .flags = LM90_PAUSE_FOR_CONFIG, + .flags = LM90_PAUSE_FOR_CONFIG | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 8, .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, }, [max6659] = { - .flags = LM90_HAVE_EMERGENCY, + .flags = LM90_HAVE_EMERGENCY | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 8, .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, }, [max6680] = { - .flags = LM90_HAVE_OFFSET, + .flags = LM90_HAVE_OFFSET | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 7, }, [max6696] = { .flags = LM90_HAVE_EMERGENCY - | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3, + | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3 | LM90_HAVE_CRIT, .alert_alarms = 0x1c7c, .max_convrate = 6, .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, }, [w83l771] = { - .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, + .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 8, }, [sa56004] = { - .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT, + .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT | LM90_HAVE_CRIT, .alert_alarms = 0x7b, .max_convrate = 9, .reg_local_ext = SA56004_REG_R_LOCAL_TEMPL, }, [tmp451] = { .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT - | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP, + | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 9, .reg_local_ext = TMP451_REG_R_LOCAL_TEMPL, }, [tmp461] = { .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT - | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP, + | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP | LM90_HAVE_CRIT, .alert_alarms = 0x7c, .max_convrate = 9, .reg_local_ext = TMP451_REG_R_LOCAL_TEMPL, @@ -668,20 +675,22 @@ static int lm90_update_limits(struct device *dev) struct i2c_client *client = data->client; int val; - val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT); - if (val < 0) - return val; - data->temp8[LOCAL_CRIT] = val; + if (data->flags & LM90_HAVE_CRIT) { + val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT); + if (val < 0) + return val; + data->temp8[LOCAL_CRIT] = val; - val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT); - if (val < 0) - return val; - data->temp8[REMOTE_CRIT] = val; + val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT); + if (val < 0) + return val; + data->temp8[REMOTE_CRIT] = val; - val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST); - if (val < 0) - return val; - data->temp_hyst = val; + val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST); + if (val < 0) + return val; + data->temp_hyst = val; + } val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); if (val < 0) @@ -1902,11 +1911,14 @@ static int lm90_probe(struct i2c_client *client) info->config = data->channel_config; data->channel_config[0] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | - HWMON_T_CRIT | HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | - HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM; + HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM; data->channel_config[1] = HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | - HWMON_T_CRIT | HWMON_T_CRIT_HYST | HWMON_T_MIN_ALARM | - HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_FAULT; + HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | HWMON_T_FAULT; + + if (data->flags & LM90_HAVE_CRIT) { + data->channel_config[0] |= HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_CRIT_HYST; + data->channel_config[1] |= HWMON_T_CRIT | HWMON_T_CRIT_ALARM | HWMON_T_CRIT_HYST; + } if (data->flags & LM90_HAVE_OFFSET) data->channel_config[1] |= HWMON_T_OFFSET; From patchwork Fri Dec 10 20:01:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12670915 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 B4BC2C433F5 for ; Fri, 10 Dec 2021 20:01:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243110AbhLJUFX (ORCPT ); Fri, 10 Dec 2021 15:05:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240266AbhLJUFX (ORCPT ); Fri, 10 Dec 2021 15:05:23 -0500 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD1FC061746 for ; Fri, 10 Dec 2021 12:01:47 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id t19so14735764oij.1 for ; Fri, 10 Dec 2021 12:01:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ffwWNqDP2HZVSmFNMnkPXbuxKunkVFyJ7rjF1atSMSU=; b=Y+tepQTm62LmlGDhvTWUaOvTexeCVOOXZawJX4I+ZFwOjz5LF/AwpqtLessZeQmZU3 El0Z4M7uCWj4WGIOiM0HUSqb1RwwWnHLaJlWeJfbD55Rd6QJaudvFv9cFWz97T7KHSss yG9x0JjyUF2rWKaPU1vdfXb/2x+DzUAJXdRWTEWr31Xi4nqKVhSBJqkuAtTq3eojvN3K QHNFpPwlAMDyQR9TIFJ2Wkz5Q9stIprY1Qd01lfMZFs58tEZLTb9+p+HmjeGTvT84WCL zPTpeueS2gYEeFoLvEqh+C/HU1UJ50xDXA3o8w9PtpxB4rFXV8PMYnssG5lzry39tHZ4 FFuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ffwWNqDP2HZVSmFNMnkPXbuxKunkVFyJ7rjF1atSMSU=; b=wFAwvNCYOImD6Ym3JR4PJpSLAIV64PDIIulV4CYBQxwOPNnLjxD+Vkn7bRkyONoBvf YtmeaeYaTX9LZS/Rm90tsOjDnrRG7CiJPHEVpNewQpBRlLQh4rI2zaS4JS3hEXsx52Ug QT/kZa2th6Kx2//oGMmHP3ubGNnkrD/G1vIX9i2XXWByP8fHSnbkB48vcO7bK5/DaXAl 0f7zWGX97YxH9rIhd3WGoHYKVze1jdOncVlEFHJst7+A2JLPnHD7K31RsEzZYk4oeWIs 46oJzIEZFE89HS9JCptQlc5VW+0iwRkqRAHOAIUbxoZl01s+Io5ROhU+/iDkYS0uG1J4 9eIQ== X-Gm-Message-State: AOAM531digVRaXNJZcEepxNqy/uqX1Te1lIjCBl0w99BlNoyPeHcM5ze 9D8xyRE15+RQfe/VS8UxomvyPaTJNp8= X-Google-Smtp-Source: ABdhPJzsd9k7GB7kHLZVOvMt8aMNubVpll8/wgXL316WB2TEmBnVcBmNIu9A5xY4CEbVpjoxIGvpnA== X-Received: by 2002:a05:6808:f01:: with SMTP id m1mr14995645oiw.166.1639166507052; Fri, 10 Dec 2021 12:01:47 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id e26sm674971oog.46.2021.12.10.12.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 12:01:46 -0800 (PST) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck Subject: [PATCH 4/5] hwmom: (lm90) Fix citical alarm status for MAX6680/MAX6681 Date: Fri, 10 Dec 2021 12:01:35 -0800 Message-Id: <20211210200136.1662127-5-linux@roeck-us.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211210200136.1662127-1-linux@roeck-us.net> References: <20211210200136.1662127-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Tests with a real chip and a closer look into the datasheet reveals that the local and remote critical alarm status bits are swapped for MAX6680/MAX6681. Signed-off-by: Guenter Roeck --- drivers/hwmon/lm90.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 6597d055e09d..dd8612a9d536 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -190,6 +190,7 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, #define LM90_HAVE_EXTENDED_TEMP (1 << 8) /* extended temperature support*/ #define LM90_PAUSE_FOR_CONFIG (1 << 9) /* Pause conversion for config */ #define LM90_HAVE_CRIT (1 << 10)/* Chip supports CRIT/OVERT register */ +#define LM90_HAVE_CRIT_ALRM_SWP (1 << 11)/* critical alarm bits swapped */ /* LM90 status */ #define LM90_STATUS_LTHRM (1 << 0) /* local THERM limit tripped */ @@ -415,7 +416,8 @@ static const struct lm90_params lm90_params[] = { .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, }, [max6680] = { - .flags = LM90_HAVE_OFFSET | LM90_HAVE_CRIT, + .flags = LM90_HAVE_OFFSET | LM90_HAVE_CRIT + | LM90_HAVE_CRIT_ALRM_SWP, .alert_alarms = 0x7c, .max_convrate = 7, }, @@ -1201,6 +1203,7 @@ static const u8 lm90_temp_emerg_index[3] = { static const u8 lm90_min_alarm_bits[3] = { 5, 3, 11 }; static const u8 lm90_max_alarm_bits[3] = { 6, 4, 12 }; static const u8 lm90_crit_alarm_bits[3] = { 0, 1, 9 }; +static const u8 lm90_crit_alarm_bits_swapped[3] = { 1, 0, 9 }; static const u8 lm90_emergency_alarm_bits[3] = { 15, 13, 14 }; static const u8 lm90_fault_bits[3] = { 0, 2, 10 }; @@ -1226,7 +1229,10 @@ static int lm90_temp_read(struct device *dev, u32 attr, int channel, long *val) *val = (data->alarms >> lm90_max_alarm_bits[channel]) & 1; break; case hwmon_temp_crit_alarm: - *val = (data->alarms >> lm90_crit_alarm_bits[channel]) & 1; + if (data->flags & LM90_HAVE_CRIT_ALRM_SWP) + *val = (data->alarms >> lm90_crit_alarm_bits_swapped[channel]) & 1; + else + *val = (data->alarms >> lm90_crit_alarm_bits[channel]) & 1; break; case hwmon_temp_emergency_alarm: *val = (data->alarms >> lm90_emergency_alarm_bits[channel]) & 1; From patchwork Fri Dec 10 20:01:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12670917 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 84F99C433FE for ; Fri, 10 Dec 2021 20:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243134AbhLJUFZ (ORCPT ); Fri, 10 Dec 2021 15:05:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240266AbhLJUFZ (ORCPT ); Fri, 10 Dec 2021 15:05:25 -0500 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1286C061746 for ; Fri, 10 Dec 2021 12:01:49 -0800 (PST) Received: by mail-ot1-x32b.google.com with SMTP id x3-20020a05683000c300b0057a5318c517so10647331oto.13 for ; Fri, 10 Dec 2021 12:01:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oilA2TBjRF3Di23uPtnJJY9cvZw18ecRGUkDSA8T+KI=; b=HMKpr4vM1UAhsuGKg0Na0AW3j94xvmGhoo1p8IBsKct1fPSJyCc2lstrokCiY/n8cU I6XLv46/rGRT7qYyUwIC/h5ho5BuUXMa7WfcKIXXiLFAVPux6yR1IL8RveCTdQN7keDI wpzzSjGZzgC/Ot++3ww9Ze88nwOMDtuw2PkDnDeedbE5SsKrNIhrORIMAzZ5KXFatdPG NCB+NmovzfuAClj3EpQP+1mvAaWfWPJoG+01qYXFmbf14JUn9/G2Sy5O9H0M33hLBh/v dfoQBHZtMjPoCUTY98mnVXJ964n29+ppYicOd3/YfLtFh4845VUjEcBxCdZXwaJOggif 5dnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=oilA2TBjRF3Di23uPtnJJY9cvZw18ecRGUkDSA8T+KI=; b=HhkFaqW/R2Entw4Z9xDNdCIjFBtxF059cVVNgwoHKxiy4wDDKKDyOpzVeIvEy2HiLR oW5pR9lvd500iNwQa6d4K+wEkNSNGm7P0q3GXpsKiXM3r/A41HuCBznQewSMbvjSM1eK ULKG1AusVNFqg20NP4W0eS588R80GnFWd7ieq9V5G6msEwQTdAFECOiMfndebysD2BHx NcJgJvUsmYF8uDeeNMKBzvjEeGOmiiIylnGecpqBvrgJBfODcVgVHwAoNQ5fo8orOIqJ NjGVdcSGuW050TgHQiNiDgK+TluF4Uzo7d6kJk6muy6a3hr/vL8ftRW18E9mZlX1OhaL exYA== X-Gm-Message-State: AOAM5306WTv0lUSa0BvqTjxTMNgNKfKAMkEc8eAytxQy1DA1Gm6e1Bsj yGJiBfo49IH78qbDBt4cRb/gBDGN+4I= X-Google-Smtp-Source: ABdhPJwdKgOr9HGjp494STi8jUJv2XBrOXDgBVREUhDz3rJE47+dyjSMCjqdiZR9+k0t2ZrL2IMsEA== X-Received: by 2002:a9d:7454:: with SMTP id p20mr12267750otk.307.1639166508712; Fri, 10 Dec 2021 12:01:48 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d8sm972619oiw.24.2021.12.10.12.01.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 12:01:48 -0800 (PST) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck Subject: [PATCH 5/5] hwmon: (lm90) Do not report 'busy' status bit as alarm Date: Fri, 10 Dec 2021 12:01:36 -0800 Message-Id: <20211210200136.1662127-6-linux@roeck-us.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211210200136.1662127-1-linux@roeck-us.net> References: <20211210200136.1662127-1-linux@roeck-us.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Bit 7 of the status register indicates that the chip is busy doing a conversion. It does not indicate an alarm status. Stop reporting it as alarm status bit. Signed-off-by: Guenter Roeck --- drivers/hwmon/lm90.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index dd8612a9d536..74019dff2550 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -200,6 +200,7 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, #define LM90_STATUS_RHIGH (1 << 4) /* remote high temp limit tripped */ #define LM90_STATUS_LLOW (1 << 5) /* local low temp limit tripped */ #define LM90_STATUS_LHIGH (1 << 6) /* local high temp limit tripped */ +#define LM90_STATUS_BUSY (1 << 7) /* conversion is ongoing */ #define MAX6696_STATUS2_R2THRM (1 << 1) /* remote2 THERM limit tripped */ #define MAX6696_STATUS2_R2OPEN (1 << 2) /* remote2 is an open circuit */ @@ -820,7 +821,7 @@ static int lm90_update_device(struct device *dev) val = lm90_read_reg(client, LM90_REG_R_STATUS); if (val < 0) return val; - data->alarms = val; /* lower 8 bit of alarms */ + data->alarms = val & ~LM90_STATUS_BUSY; if (data->kind == max6696) { val = lm90_select_remote_channel(data, 1);