From patchwork Tue Mar 25 10:49:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 27034 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6474E20539 for ; Tue, 25 Mar 2014 10:53:17 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id e16sf629541qcx.10 for ; Tue, 25 Mar 2014 03:53:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=xAk+7DiVFaTAcGuM6rXgTSTLI6nnUV7zjIxrD4E4C4w=; b=WVCOyT7Rcw/f4Q7xx/tJOcZFhz6n/J4HYMi4oyt1FD+rvs+hBV/Fp81oM9ks8qd0Nn qeqCKHLV59+HdPR3Laon7j7aJk2U9HNj/QTrmpEs6DKUqJLUDh1U2Ej/Nj8oa3IoDccN enZBrSyCf1nFZAFzDWROMq3/dwTU03KkoARI7ChPlh5PiyX5ROQhHe0gAR1CZSby09W/ BlAq2E8Q2amo8KoRcMUMbM8Yyj16891edWxehYf47RCNOOJKU2PL8Y5n22uWEQ+K+wn7 hBjbORQawy/iCNSp2kd8tiZtyZ/mmTY83Q7vT56NFZvcUipkXL97YOCqxuMnjAfBHtNA sGGQ== X-Gm-Message-State: ALoCoQnJu5k1QfdFgkvLK+TkVzzEoXt3G6H4If36/x6V/G4RMICn+CzWmAr3XeUJ7VksZwJyomaP X-Received: by 10.236.173.42 with SMTP id u30mr11626492yhl.2.1395744797113; Tue, 25 Mar 2014 03:53:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.29.134 with SMTP id b6ls149655qgb.91.gmail; Tue, 25 Mar 2014 03:53:17 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr6982302veb.21.1395744797011; Tue, 25 Mar 2014 03:53:17 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id tm8si3737610vdc.26.2014.03.25.03.53.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 03:53:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id jw12so291012veb.41 for ; Tue, 25 Mar 2014 03:53:16 -0700 (PDT) X-Received: by 10.58.57.67 with SMTP id g3mr54355742veq.3.1395744796922; Tue, 25 Mar 2014 03:53:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp293936vck; Tue, 25 Mar 2014 03:53:16 -0700 (PDT) X-Received: by 10.68.201.67 with SMTP id jy3mr77914405pbc.20.1395744795929; Tue, 25 Mar 2014 03:53:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wm7si11294413pab.315.2014.03.25.03.53.14; Tue, 25 Mar 2014 03:53:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754059AbaCYKxE (ORCPT + 26 others); Tue, 25 Mar 2014 06:53:04 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:35151 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753343AbaCYKuc (ORCPT ); Tue, 25 Mar 2014 06:50:32 -0400 Received: by mail-pa0-f49.google.com with SMTP id lj1so267580pab.36 for ; Tue, 25 Mar 2014 03:50:31 -0700 (PDT) X-Received: by 10.66.27.48 with SMTP id q16mr78609325pag.9.1395744631654; Tue, 25 Mar 2014 03:50:31 -0700 (PDT) Received: from localhost.localdomain ([162.243.130.63]) by mx.google.com with ESMTPSA id db3sm42987987pbb.10.2014.03.25.03.50.24 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 03:50:31 -0700 (PDT) From: Alex Shi To: mark.hambleton@broadcom.com, mark.brown@linaro.org, eduardo.valentin@ti.com, mporter@linaro.org, lsk-interest@linaro.org, linaro-kernel@linaro.org Cc: Jean Delvare , lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org, Alex Shi Subject: [PATCH 07/19] hwmon: lm75: expose to thermal fw via DT nodes Date: Tue, 25 Mar 2014 18:49:20 +0800 Message-Id: <1395744572-20014-8-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1395744572-20014-1-git-send-email-alex.shi@linaro.org> References: <1395744572-20014-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.shi@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Eduardo Valentin This patch adds to lm75 temperature sensor the possibility to expose itself as thermal zone device, registered on the thermal framework. The thermal zone is built only if a device tree node describing a thermal zone for this sensor is present inside the lm75 DT node. Otherwise, the driver behavior will be the same. Note: This patch has also been reviewed by Jean D. He has requested to perform a wider inspection of possible users of thermal and hwmon interaction API. On the other hand, the change on this patch is acceptable on first step of overall code change. Cc: Jean Delvare Cc: lm-sensors@lm-sensors.org Cc: linux-kernel@vger.kernel.org Acked-by: Guenter Roeck Signed-off-by: Eduardo Valentin (cherry picked from commit 22e731838b0e337fed5f16c67aa0b954028dfe93) Signed-off-by: Alex Shi --- drivers/hwmon/lm75.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index c03b490..1d3600a 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "lm75.h" @@ -70,6 +72,7 @@ static const u8 LM75_REG_TEMP[3] = { /* Each client has this additional data */ struct lm75_data { struct device *hwmon_dev; + struct thermal_zone_device *tz; struct mutex update_lock; u8 orig_conf; u8 resolution; /* In bits, between 9 and 12 */ @@ -90,22 +93,36 @@ static struct lm75_data *lm75_update_device(struct device *dev); /*-----------------------------------------------------------------------*/ +static inline long lm75_reg_to_mc(s16 temp, u8 resolution) +{ + return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); +} + /* sysfs attributes for hwmon */ +static int lm75_read_temp(void *dev, long *temp) +{ + struct lm75_data *data = lm75_update_device(dev); + + if (IS_ERR(data)) + return PTR_ERR(data); + + *temp = lm75_reg_to_mc(data->temp[0], data->resolution); + + return 0; +} + static ssize_t show_temp(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); struct lm75_data *data = lm75_update_device(dev); - long temp; if (IS_ERR(data)) return PTR_ERR(data); - temp = ((data->temp[attr->index] >> (16 - data->resolution)) * 1000) - >> (data->resolution - 8); - - return sprintf(buf, "%ld\n", temp); + return sprintf(buf, "%ld\n", lm75_reg_to_mc(data->temp[attr->index], + data->resolution)); } static ssize_t set_temp(struct device *dev, struct device_attribute *da, @@ -271,6 +288,13 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) goto exit_remove; } + data->tz = thermal_zone_of_sensor_register(&client->dev, + 0, + &client->dev, + lm75_read_temp, NULL); + if (IS_ERR(data->tz)) + data->tz = NULL; + dev_info(&client->dev, "%s: sensor '%s'\n", dev_name(data->hwmon_dev), client->name); @@ -285,6 +309,7 @@ static int lm75_remove(struct i2c_client *client) { struct lm75_data *data = i2c_get_clientdata(client); + thermal_zone_of_sensor_unregister(&client->dev, data->tz); hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&client->dev.kobj, &lm75_group); lm75_write_value(client, LM75_REG_CONF, data->orig_conf);