From patchwork Sun Feb 5 21:03:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 9556941 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 C103560424 for ; Sun, 5 Feb 2017 21:05:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA87B25D9E for ; Sun, 5 Feb 2017 21:05:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9ED2625EA6; Sun, 5 Feb 2017 21:05:33 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 EE16C25D9E for ; Sun, 5 Feb 2017 21:05:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752329AbdBEVFc (ORCPT ); Sun, 5 Feb 2017 16:05:32 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33229 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752057AbdBEVFa (ORCPT ); Sun, 5 Feb 2017 16:05:30 -0500 Received: by mail-wm0-f68.google.com with SMTP id v77so18040116wmv.0; Sun, 05 Feb 2017 13:05:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=b1HovWxeCHDq5PfHCfOL4EVHD7YhMP6ABdjb9P45GMU=; b=AS/OJAYrgKb6BX7qhJtytlNY5SQw4XEwFL15pTBNTAoqbuI60gncfAydxrCHxp87bD ZZXQZExfnfOizDl6L7a3R1Wh8mnC5N0txGWEyrhm3JCg7W6+5y10rKAzQrWAkxig76df nBj+MrznLJnpkI7ZPo5bIi4q5xIxMQKKB7z4OX5h/+bXTTsLoHvq7uER1gZ33zwrErg8 wITXX71iP0MLKVHlX74hf0GtoYeOwfbCZ5k2a019JmCzW396aOLX7OgzZog95VplrEmx GBy1WB1BJS/SF9TDvijrUnJZl8nWtGa7p6TH0LANTzw7jtlSj71prujeDdjM6LpQGvLi j++Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=b1HovWxeCHDq5PfHCfOL4EVHD7YhMP6ABdjb9P45GMU=; b=WbAcOkairgeEzCYObrFLX8DmoUL73nx6+RJG7BYXbPG/nmvTvCXVn3R75PqRqyVOpg aOyKdMURkqZyL5qBOoNrduOC3MSnEXsAuiGc0l01ddEACXs/p/Wi/FEFpf5K2b1LjplI 9PHAj/her4EbZHIf/ddNLYzmQUl18Irp89Dy6Ekt9SReSdci4sejMnGE4PoQY2UgktiE jwJIwPlR21/Zm+HWjaTAWYeDPSP/R5Nx2xNcILGII+XgxGC9bSKfIKh3iGIBgz1Ti57+ GnZw4MkXA9cocRgkVyqox4Xe/jBU3TJQyiX/meE1h5H1w4Mx5wjHBtSenj/IsA2nOugn zPdA== X-Gm-Message-State: AMke39mk1eK//VuCDSxjKQaJjHVLkbnbu5S/MBy2PBxQzadmCdPekSMXbK3J3TkFGen6Dg== X-Received: by 10.28.188.9 with SMTP id m9mr5727669wmf.79.1486328728970; Sun, 05 Feb 2017 13:05:28 -0800 (PST) Received: from debian64.daheim (p5B0D7CCE.dip0.t-ipconnect.de. [91.13.124.206]) by smtp.gmail.com with ESMTPSA id u47sm56874610wrb.15.2017.02.05.13.05.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Feb 2017 13:05:27 -0800 (PST) Received: from chuck by debian64.daheim with local (Exim 4.89) (envelope-from ) id 1caTxs-0002Dy-BW; Sun, 05 Feb 2017 22:03:16 +0100 From: Christian Lamparter To: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: Christian Lamparter , Mark Rutland , Rob Herring , Jean Delvare , Wei Ni Subject: [RFC 2/2] hwmon: lm90: add thermal_zone temperature sensor support Date: Sun, 5 Feb 2017 22:03:16 +0100 Message-Id: <0e28c2989f021bedaff3c8958ab8c1ef738182b7.1486327509.git.chunkeey@googlemail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: 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 This patch adds thermal_zone temperature sensor support to the lm90 module. The feature has to be enabled separately via the Kconfig option: CONFIG_SENSORS_LM90_THERMAL_DEVICE The LM90 supports two (three for MAX6695 and MAX6696) temperature sensors. The local sensor is integrated into the LM90 chip. The remote sensors are connected to external temperature sensing diodes. Cc: Wei Ni Signed-off-by: Christian Lamparter --- --- drivers/hwmon/Kconfig | 11 +++++++ drivers/hwmon/lm90.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 190d270b20a2..9df70ad21a21 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1085,6 +1085,17 @@ config SENSORS_LM90 This driver can also be built as a module. If so, the module will be called lm90. +config SENSORS_LM90_THERMAL_DEVICE + bool "Support for thermal-zone temperature sensors" + depends on SENSORS_LM90 && THERMAL_OF + help + If you say yes here you get support for thermal-zone temperature + sensors for the lm90 module and all supported chips. + + Refer to Documentation/devicetree/bindings/thermal/thermal.txt + and Documentation/devicetree/bindings/hwmon/lm90.txt on how to + use it for your platform. + config SENSORS_LM92 tristate "National Semiconductor LM92 and compatibles" depends on I2C diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 841f2428e84a..584550c7336d 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -95,6 +95,9 @@ #include #include #include +#include +#include +#include /* * Addresses to scan @@ -1643,6 +1646,90 @@ static const struct hwmon_ops lm90_ops = { .write = lm90_write, }; +#ifdef CONFIG_SENSORS_LM90_THERMAL_DEVICE + +static int lm90_read_local_temp(void *data, int *temp) +{ + *temp = lm90_get_temp11(data, LOCAL_TEMP); + return 0; +} + +static int lm90_read_remote_temp(void *data, int *temp) +{ + *temp = lm90_get_temp11(data, REMOTE_TEMP); + return 0; +} + +static int lm90_read_remote2_temp(void *data, int *temp) +{ + *temp = lm90_get_temp11(data, REMOTE2_TEMP); + return 0; +} + +static const struct thermal_zone_of_device_ops local_temp_sensor = { + .get_temp = lm90_read_local_temp, +}; + +static const struct thermal_zone_of_device_ops remote_temp_sensor = { + .get_temp = lm90_read_remote_temp, +}; + +static const struct thermal_zone_of_device_ops remote2_temp_sensor = { + .get_temp = lm90_read_remote2_temp, +}; + +static const struct thermal_zone_sensors_struct { + int sensor_id; + const char *name; + const struct thermal_zone_of_device_ops *ops; + u32 flag_mask; + u32 flag_required; +} thermal_zone_sensors[] = { + { LM90_REMOTE_TEMPERATURE, "remote", &remote_temp_sensor }, + { LM90_LOCAL_TEMPERATURE, "local", &local_temp_sensor }, + { LM90_REMOTE2_TEMPERATURE, "second remote", &remote2_temp_sensor, + LM90_HAVE_TEMP3, LM90_HAVE_TEMP3 }, +}; + +static int lm90_setup_thermal_device(struct device *dev, + struct lm90_data *data) +{ + const struct thermal_zone_sensors_struct *entry; + struct thermal_zone_device *therm_dev; + int i; + + for (i = 0; i < ARRAY_SIZE(thermal_zone_sensors); i++) { + entry = &thermal_zone_sensors[i]; + + if ((data->flags & entry->flag_mask) != entry->flag_required) + continue; + + therm_dev = devm_thermal_zone_of_sensor_register(dev, + entry->sensor_id, data, entry->ops); + + /* + * if a sensor device isn't requested in a thermal-zone the + * call to devm_thermal_zone_of_sensor_register will fail + * with -ENODEV. In this case we can ignore/skip it. + */ + + if (IS_ERR(therm_dev) && (PTR_ERR(therm_dev) != -ENODEV)) { + dev_err(dev, "Failed to register %s thermal_zone sensor device\n", + entry->name); + return PTR_ERR(therm_dev); + } + } + return 0; +} +#else +static int lm90_setup_thermal_device(struct device __maybe_unused *dev, + struct lm90_data __maybe_unused *data) +{ + return 0; +} +#endif + + static int lm90_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1765,6 +1852,10 @@ static int lm90_probe(struct i2c_client *client, if (IS_ERR(hwmon_dev)) return PTR_ERR(hwmon_dev); + err = lm90_setup_thermal_device(dev, data); + if (err) + return err; + if (client->irq) { dev_dbg(dev, "IRQ: %d\n", client->irq); err = devm_request_threaded_irq(dev, client->irq,