From patchwork Wed Jul 17 15:02:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 2828735 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1F5789F967 for ; Wed, 17 Jul 2013 15:07:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DF64C202B7 for ; Wed, 17 Jul 2013 15:07:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E3EC202CF for ; Wed, 17 Jul 2013 15:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932255Ab3GQPGX (ORCPT ); Wed, 17 Jul 2013 11:06:23 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:39338 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932297Ab3GQPGT (ORCPT ); Wed, 17 Jul 2013 11:06:19 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id r6HF59DV021152; Wed, 17 Jul 2013 10:05:09 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id r6HF5961024641; Wed, 17 Jul 2013 10:05:09 -0500 Received: from dlelxv24.itg.ti.com (172.17.1.199) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.2.342.3; Wed, 17 Jul 2013 10:05:08 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlelxv24.itg.ti.com (8.13.8/8.13.8) with ESMTP id r6HF58NQ003095; Wed, 17 Jul 2013 10:05:08 -0500 Received: from localhost (h68-2.vpn.ti.com [172.24.68.2]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id r6HF54t28213; Wed, 17 Jul 2013 10:05:04 -0500 (CDT) From: Eduardo Valentin To: CC: , , , , , Eduardo Valentin , Jean Delvare , Guenter Roeck Subject: [PATCH 7/8] hwmon: lm75: expose to thermal fw via DT nodes Date: Wed, 17 Jul 2013 11:02:51 -0400 Message-ID: <1374073374-30946-16-git-send-email-eduardo.valentin@ti.com> X-Mailer: git-send-email 1.8.2.1.342.gfa7285d In-Reply-To: <1374073374-30946-1-git-send-email-eduardo.valentin@ti.com> References: <1374073374-30946-1-git-send-email-eduardo.valentin@ti.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Cc: Jean Delvare Cc: Guenter Roeck Cc: lm-sensors@lm-sensors.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/hwmon/lm75.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index c03b490..0aa5e28 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 */ @@ -92,6 +95,19 @@ static struct lm75_data *lm75_update_device(struct device *dev); /* sysfs attributes for hwmon */ +static int lm75_read_temp(void *dev, unsigned long *temp) +{ + struct lm75_data *data = lm75_update_device(dev); + + if (IS_ERR(data)) + return PTR_ERR(data); + + *temp = ((data->temp[0] >> (16 - data->resolution)) * 1000) >> + (data->resolution - 8); + + return 0; +} + static ssize_t show_temp(struct device *dev, struct device_attribute *da, char *buf) { @@ -271,11 +287,23 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) goto exit_remove; } + if (of_find_node_by_name(client->dev.of_node, "thermal_zone")) { + data->tz = thermal_zone_of_device_register(&client->dev, + &client->dev, + lm75_read_temp); + if (IS_ERR(data->tz)) { + status = PTR_ERR(data->tz); + goto exit_hwmon; + } + } + dev_info(&client->dev, "%s: sensor '%s'\n", dev_name(data->hwmon_dev), client->name); return 0; +exit_hwmon: + hwmon_device_unregister(data->hwmon_dev); exit_remove: sysfs_remove_group(&client->dev.kobj, &lm75_group); return status; @@ -285,6 +313,7 @@ static int lm75_remove(struct i2c_client *client) { struct lm75_data *data = i2c_get_clientdata(client); + thermal_zone_device_unregister(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);