From patchwork Sun Feb 19 23:29:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony O'Brien X-Patchwork-Id: 13146013 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 D0A8BC05027 for ; Sun, 19 Feb 2023 23:30:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229521AbjBSXaC (ORCPT ); Sun, 19 Feb 2023 18:30:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjBSXaB (ORCPT ); Sun, 19 Feb 2023 18:30:01 -0500 Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [IPv6:2001:df5:b000:5::4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E8611ABC5 for ; Sun, 19 Feb 2023 15:29:59 -0800 (PST) Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 40A6C2C05FA; Mon, 20 Feb 2023 12:29:56 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1676849396; bh=bD34Flb4PZpQOH+aca7SIHb4GcyA+Pc/7slSPHD7C/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zs4StTFrxzmPDAtLrb45oG7NG+/1eRHkCRQzNlhXqZzGJR4zTRI2yRpY6l1Pcrkqi YmwXxiQ2W9zPmjAEHIhZS1vyxTZpZyQlDB3MzTDv1ZIk0Bo9YjQAUprtE39m4puf/q +9YX8JIGg80tww3wW1Ihp+vG6/1bqRtC9rTOK0e1GbHTcb/8INtX2tLifqF/FZ/rFB gOrVBYT2enFYm7bGIMIQ4RchwqGeda9HbP+1WhbHoAPgU3dgNwzSE7uRtX5B8pOfm6 MShDr+hJfDD7Lw4DZM8h4aceoyD8lqzzg1oVIxheEUBeTl7o5gMgJgFe/UYWc4k3TG 2lLLW/+gB1h2Q== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Mon, 20 Feb 2023 12:29:56 +1300 Received: from tonyo-dl.ws.atlnz.lc (tonyo-dl.ws.atlnz.lc [10.33.12.31]) by pat.atlnz.lc (Postfix) with ESMTP id 14A2913EE56; Mon, 20 Feb 2023 12:29:56 +1300 (NZDT) Received: by tonyo-dl.ws.atlnz.lc (Postfix, from userid 1161) id 1252DA008A; Mon, 20 Feb 2023 12:29:56 +1300 (NZDT) From: Tony O'Brien To: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org Cc: chris.packham@alliedtelesis.co.nz, hdegoede@redhat.com, jordan.crouse@amd.com, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] hwmon: (adt7475) Fix setting of hysteresis registers Date: Mon, 20 Feb 2023 12:29:56 +1300 Message-Id: <20230219232956.23784-3-tony.obrien@alliedtelesis.co.nz> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230219232956.23784-1-tony.obrien@alliedtelesis.co.nz> References: <20230219232956.23784-1-tony.obrien@alliedtelesis.co.nz> MIME-Version: 1.0 X-SEG-SpamProfiler-Analysis: v=2.3 cv=GdlpYjfL c=1 sm=1 tr=0 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=m04uMKEZRckA:10 a=528Z5tJWtxPNw0CsBnAA:9 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org In temp_store(), for the hysteresis setting calculation there were two errors. The first tries to clamp the hysteresis value by comparing the required hysteresis value to THERM - 15C. This is incorrect since the hysteresis value is a relative value whereas THERM - 15C is an absolute value. This causes it to always select 15C for hysteresis. Change the first parameter to THERM - val to compare two absolute temperatures. The second error masks the wrong bits in the hysteresis register; indices 0 and 2 should zero bits [7:4] and preserve bits [3:0], and index 1 should zero bits [3:0] and preserve bits [7:4]. Fixes: 1c301fc5394f ("hwmon: Add a driver for the ADT7475 hardware monitoring chip") Signed-off-by: Tony O'Brien --- drivers/hwmon/adt7475.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 77222c35a38e..68233191798e 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -484,14 +484,14 @@ static ssize_t temp_store(struct device *dev, struct device_attribute *attr, adt7475_read_hystersis(client); temp = reg2temp(data, data->temp[THERM][sattr->index]); - val = clamp_val(val, temp - 15000, temp); + val = clamp_val(temp - val, temp - 15000, temp); val = (temp - val) / 1000; if (sattr->index != 1) { - data->temp[HYSTERSIS][sattr->index] &= 0xF0; + data->temp[HYSTERSIS][sattr->index] &= 0x0F; data->temp[HYSTERSIS][sattr->index] |= (val & 0xF) << 4; } else { - data->temp[HYSTERSIS][sattr->index] &= 0x0F; + data->temp[HYSTERSIS][sattr->index] &= 0xF0; data->temp[HYSTERSIS][sattr->index] |= (val & 0xF); }