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: 9598657 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 3EE21604DC for ; Wed, 1 Mar 2017 15:43:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E0EE281DB for ; Wed, 1 Mar 2017 15:43:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 223BD284E7; Wed, 1 Mar 2017 15:43:36 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 8DDF6281DB for ; Wed, 1 Mar 2017 15:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751756AbdCAPnf (ORCPT ); Wed, 1 Mar 2017 10:43:35 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35104 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751592AbdCAPnd (ORCPT ); Wed, 1 Mar 2017 10:43:33 -0500 Received: by mail-wr0-f196.google.com with SMTP id u108so2097141wrb.2 for ; Wed, 01 Mar 2017 07:42:59 -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=e1qvfeLz6aBNJQKzDlYfadCbpLfguaPmT44QGbJg50UItdJQJU0hqOzXE0hUBQtVKi Sv14ITLHD+HVXA6pqqwNJnvH3hkyoyqegPSU1DIG75n9mHOeVasGAGclSJ/TfihmZ4am ZsTm1UDjDG0W9WiX7Yk5c+GlRRpyXDWTKiBRkTkn9BbADSw8Sc18D9mRWR1VDGxL2273 OEkNDwwyiplMG9KrNlu7VBh4U210W3iISppp87yR92iN5iBZ7OUYR4l1jiltRmIVovwP eXwjTyo8d4YKShYPOODLIroDHOqvcm7DduGpGcXJsN7zQJ1XAvlqtpsvD6xYQbTqRegn MCMg== X-Gm-Message-State: AMke39ksdn5tWOTytjwEZpDV7RMeYAePQpzCjAF4t42W86wr6PwkUTHztl4nDAXFYS+rYQ== 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 Cc: Carlo Caione 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 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 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; }