From patchwork Tue Oct 4 21:40:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 9362323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0FE1E608A6 for ; Tue, 4 Oct 2016 21:41:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3244285AD for ; Tue, 4 Oct 2016 21:41:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7A23287DC; Tue, 4 Oct 2016 21:41:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D91A8285AD for ; Tue, 4 Oct 2016 21:41:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750934AbcJDVlJ (ORCPT ); Tue, 4 Oct 2016 17:41:09 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:43145 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750873AbcJDVlJ (ORCPT ); Tue, 4 Oct 2016 17:41:09 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 8B6F9806A8; Wed, 5 Oct 2016 10:41:05 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1475617265; bh=6+ofCldz5jAxqxO6h2Ys4swZhnysfK7Un82Y71cY4o8=; h=From:To:Cc:Subject:Date; b=y/dxOcB0N0mmI5dpoarBtjFYURl07nerAAWArlNrq71Eyh7Rcsz8ES5HsPPe/UsMP LGM4vqlE3mgsRX6NrECVVz7jl6e354miZh4tS0lbfKlk3b9gBmloP2/Jw3F8HHGseT Vje7bBPhoAgLDGF4tHHndLG5Who57snYOEgMQ27o= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 6, 8438) id ; Wed, 05 Oct 2016 10:41:05 +1300 Received: from monster-build1.atlnz.lc (monster-build1.atlnz.lc [10.32.18.140]) by smtp (Postfix) with ESMTP id 13E4913EC4C; Wed, 5 Oct 2016 10:40:59 +1300 (NZDT) Received: by monster-build1.atlnz.lc (Postfix, from userid 1030) id E8D43500549; Wed, 5 Oct 2016 10:40:59 +1300 (NZDT) From: Chris Packham To: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michael.Wang@alliedtelesis.co.nz, Chris Packham Subject: [PATCHv2] hwmon: adm9240: handle temperature readings below 0 Date: Wed, 5 Oct 2016 10:40:54 +1300 Message-Id: <20161004214054.18501-1-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.10.1 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Unlike the temperature thresholds the temperature data is a 9-bit signed value. This allows and additional 0.5 degrees of precision on the reading but makes handling negative values slightly harder. In order to have sign-extension applied correctly the 9-bit value is stored in the upper bits of a signed 16-bit value. When presenting this in sysfs the value is shifted and scaled appropriately. Signed-off-by: Chris Packham --- Changes in v2: - Simplify as per feedback from Guenter. - Re-word commit message. drivers/hwmon/adm9240.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index 98114ce..8d8ede8 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c @@ -197,7 +197,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev) data->temp = ((i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP) << 8) | i2c_smbus_read_byte_data(client, - ADM9240_REG_TEMP_CONF)) / 128; + ADM9240_REG_TEMP_CONF)); for (i = 0; i < 2; i++) { /* read fans */ data->fan[i] = i2c_smbus_read_byte_data(client, @@ -263,7 +263,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *dummy, char *buf) { struct adm9240_data *data = adm9240_update_device(dev); - return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */ + return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */ } static ssize_t show_max(struct device *dev, struct device_attribute *devattr,