From patchwork Wed Mar 1 13:20:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 9598371 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 7CCBB60453 for ; Wed, 1 Mar 2017 13:12:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67B7C28542 for ; Wed, 1 Mar 2017 13:12:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 589D928544; Wed, 1 Mar 2017 13:12:47 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9B65D28542 for ; Wed, 1 Mar 2017 13:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=TKM6SBrzb+VZi+AwXqQ4vIuOkI0zqy9JyECaYFG59CU=; b=h80 Gm0T0DxQpTJF3sjxTE8R/gy7aOO/YaH1NylXcnwwZbY3ELXh8PD0aKwViDi33zqTleUC1R8wGA4sn fOFeTpXXt13E7F4+0GVv5Hwtj+ZlJRNv3+aMEo22ovXbkO4jz7MGa1TlREQXOxiEpdBg4MpzcfbF7 nqjAlVMI2SkOx1Agrj+Z0WaCu4J1JPbJCwDuggBGzU0jbaW+vCjFRCMTtGtaVPpsu5/9i4Xt6Ef9W 4VZwGSVk28M9odEpUCVIRIrnMjXIe6A94sOKRv6JGDm9RrVRCe2QbEJ8kqMiryNPxL+3honHX1eLt hVFd1EYHe/dm+KOjNDhssgJlBjRbE7A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cj43i-0001Fx-8T; Wed, 01 Mar 2017 13:12:46 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cj42B-0008Jz-Mn; Wed, 01 Mar 2017 13:11:14 +0000 Received: by mail-wr0-x241.google.com with SMTP id l37so5451329wrc.3; Wed, 01 Mar 2017 05:10:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=560//HvFlM1WY6OcW265YfnP+jjce8p/vPi+iSmQEg8=; b=qOpeasHDzKuCQLfEkChXFJDejKvHLKidTn3VtNLbAp+ekn7gR8n1mNDLtDNnzmRcxK aJIyrP70TGMjw+ANnBbi+DnSiGasFHopb9Es+3sDads2vIY3wcJajTAnqLE1Vxt53bh2 55ARimLu9QCx1yr/j1OI+Y0mI9LHVtw3sNqRekjBHvWMUvFkVA8D3NEZWB8Ed55red3a jvfyIrP1ZJrGEVpMxbRPf1c0IzyWCGx0i2iOE6SIsm7Gh8tHysLwQtuvUc4rqyzRQ2Lf PDPGejgVTSYvkGIJWmhzFeqZL8TsFK0TC6Q6kdTC3c86aLbOMFqFMM3rHYtSfg0JtMFp VBNQ== 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; bh=560//HvFlM1WY6OcW265YfnP+jjce8p/vPi+iSmQEg8=; b=pdux0qNpUXbN1UVaL+L3xVCol91L2wew670ovjMKm3xTY4S4MY770zNQBQOmjkZMMU MWKEO7kmVw73LieUrwZIBqeboa1sbxbbiYnwBsBl9uNwEaeGc1qkU6uBnXIs/Gc/0hX7 UoTpjPl7yNLq5itdN0iSRPEoqrYm3Q04DC+zT8veAs8R+Q3vaSlPQpGzKlsIswq1AAAq TI43mymEQuy9iO+oO3nh7buA6VVPYXKiUEmRTdfj//d+cpWuvJd6RsHI1RR8AXj1F92Y k6nKHoSvHTTFx8odNdWuBaodRD60F4F9pwFpQr0v4PGLiY+m2tdeI4NOq4J/EUwNEMYn aFBw== X-Gm-Message-State: AMke39mphjsfMBAiEWpNRtUT2+uoB3bn+g0PGIuD1HIc58HR+vg7uBtXPDTvINCbUcdNqg== X-Received: by 10.223.156.2 with SMTP id f2mr8062923wrc.4.1488373849463; Wed, 01 Mar 2017 05:10:49 -0800 (PST) Received: from satan.homestation.setup ([151.45.79.45]) by smtp.gmail.com with ESMTPSA id y43sm2191368wrd.0.2017.03.01.05.10.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Mar 2017 05:10:48 -0800 (PST) From: Carlo Caione To: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux@endlessm.com, punit.agrawal@arm.com, sudeep.holla@arm.com Subject: [PATCH] hwmon: (scpi) Add slope and offset to SCP sensor readings Date: Wed, 1 Mar 2017 14:20:28 +0100 Message-Id: <20170301132028.25309-1-carlo@caione.org> X-Mailer: git-send-email 2.12.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170301_051112_020343_AE1AA1F5 X-CRM114-Status: GOOD ( 14.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Carlo Caione MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Carlo Caione The temperature provided by the SCP sensors not always is expressed in millicelsius, whereas this is required by the thermal framework. This is for example the case for the Amlogic devices, where the SCP sensor readings are expressed in degree (and not milli degree) Celsius. To convert the sensor readings, the thermal framework provides the "coefficients" property, used by the thermal sensor device to adjust their reading. This adjustment in currently not considered by the SCPI hwmon driver. Fix this introducing slope and offset for the SCP sensor readings. Signed-off-by: Carlo Caione --- drivers/hwmon/scpi-hwmon.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c index 094f948f99ff..cdc05c60ba67 100644 --- a/drivers/hwmon/scpi-hwmon.c +++ b/drivers/hwmon/scpi-hwmon.c @@ -33,6 +33,7 @@ struct sensor_data { struct scpi_thermal_zone { int sensor_id; struct scpi_sensors *scpi_sensors; + struct thermal_zone_device *z; }; struct scpi_sensors { @@ -51,13 +52,17 @@ static int scpi_read_temp(void *dev, int *temp) struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops; struct sensor_data *sensor = &scpi_sensors->data[zone->sensor_id]; u64 value; + int slope, offset; int ret; ret = scpi_ops->sensor_get_value(sensor->info.sensor_id, &value); if (ret) return ret; - *temp = value; + slope = thermal_zone_get_slope(zone->z); + offset = thermal_zone_get_offset(zone->z); + + *temp = value * slope + offset; return 0; } @@ -216,7 +221,6 @@ static int scpi_hwmon_probe(struct platform_device *pdev) INIT_LIST_HEAD(&scpi_sensors->thermal_zones); for (i = 0; i < nr_sensors; i++) { struct sensor_data *sensor = &scpi_sensors->data[i]; - struct thermal_zone_device *z; struct scpi_thermal_zone *zone; if (sensor->info.class != TEMPERATURE) @@ -228,17 +232,17 @@ static int scpi_hwmon_probe(struct platform_device *pdev) zone->sensor_id = i; zone->scpi_sensors = scpi_sensors; - z = devm_thermal_zone_of_sensor_register(dev, - sensor->info.sensor_id, - zone, - &scpi_sensor_ops); + zone->z = devm_thermal_zone_of_sensor_register(dev, + sensor->info.sensor_id, + zone, + &scpi_sensor_ops); /* * The call to thermal_zone_of_sensor_register returns * an error for sensors that are not associated with * any thermal zones or if the thermal subsystem is * not configured. */ - if (IS_ERR(z)) { + if (IS_ERR(zone->z)) { devm_kfree(dev, zone); continue; }