From patchwork Sun Nov 27 23:00:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9448927 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 1D4036071A for ; Sun, 27 Nov 2016 23:00:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14FD1204BF for ; Sun, 27 Nov 2016 23:00:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0919520747; Sun, 27 Nov 2016 23:00:41 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 29900204BF for ; Sun, 27 Nov 2016 23:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753387AbcK0XAj (ORCPT ); Sun, 27 Nov 2016 18:00:39 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:51187 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751532AbcK0XAi (ORCPT ); Sun, 27 Nov 2016 18:00:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=In-Reply-To:Content-Type:MIME-Version:References :Message-ID:Subject:Cc:To:From:Date; bh=BArYyHWLt6+72qT1egDu9eiWu9vv8kEgCbxqO0+3N3Y=; b=VsX5nIGLQN0YStlEPVriN5fqEb 3OsRsU5cZ3NvNT9o48knk/+dnn9CA2JOf3AIZJgEBDnv4wABtiWI/mfHOuoXS0D5APjak6/r8n02I QraW4rutsqC8SQKGL5S3hboU2jWMNu+eMSJX3PUh4C+oQpLDsU2TMJabz/vubOE1yItHOH3HYCbF4 gJ7zfBJX1rMbUojKU7MSkxlfyZEvebsa2VlOC5rqwNWcK+1Nq+nCuidFFH4xnH++MDDjBOUSpCWHG WiaSCszUZxgizi6OmDE5P5C6k4cKqBzydLVYt2LuAYGKrCg4JFOT/Hk4qp06gs7oPGjhgUzKxv8DN whSNW43g==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:60086 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1cB8R0-00043O-4g; Sun, 27 Nov 2016 23:00:34 +0000 Date: Sun, 27 Nov 2016 15:00:35 -0800 From: Guenter Roeck To: John Muir Cc: Jean Delvare , Jonathan Corbet , Mark Rutland , Rob Herring , linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH 3/3] hwmon: tmp108: Update driver to use hwmon_chip_info. Message-ID: <20161127230035.GA19132@roeck-us.net> References: <1480223737-82080-2-git-send-email-john@jmuir.com> <1480223737-82080-4-git-send-email-john@jmuir.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1480223737-82080-4-git-send-email-john@jmuir.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: 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 On Sat, Nov 26, 2016 at 09:15:37PM -0800, John Muir wrote: > Move the tmp108 driver from hwmon attribute groups to > hwmon_chip_info. > > Signed-off-by: John Muir > --- Hi John, please have a look at the following patch. Something else: Symbolic permissions are out of favor nowadays. You might instead just use 0644 / 0444. Not that I really care, but it prevents the inevitable follow-up patches. Thanks, Guenter --- From: Guenter Roeck Date: Sun, 27 Nov 2016 14:54:19 -0800 Subject: [PATCH] hwmon: (tmp108) Add support for various attributes Add support for temp1_{min,max}_hyst, temp1_{min,max}_alarm, and update_interval. Signed-off-by: Guenter Roeck --- drivers/hwmon/tmp108.c | 144 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 124 insertions(+), 20 deletions(-) diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c index 29ddc2e124c6..4cc2adee069a 100644 --- a/drivers/hwmon/tmp108.c +++ b/drivers/hwmon/tmp108.c @@ -103,7 +103,33 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type, { struct tmp108 *tmp108 = dev_get_drvdata(dev); unsigned int regval; - int err, reg; + int err, hyst; + + if (type == hwmon_chip) { + if (attr == hwmon_chip_update_interval) { + err = regmap_read(tmp108->regmap, TMP108_REG_CONF, + ®val); + if (err < 0) + return err; + switch (regval & TMP108_CONF_CONVRATE_MASK) { + case TMP108_CONVRATE_0P25HZ: + default: + *temp = 4000; + break; + case TMP108_CONVRATE_1HZ: + *temp = 1000; + break; + case TMP108_CONVRATE_4HZ: + *temp = 250; + break; + case TMP108_CONVRATE_16HZ: + *temp = 63; + break; + } + return 0; + } + return -EOPNOTSUPP; + } switch (attr) { case hwmon_temp_input: @@ -113,23 +139,57 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type, __func__); return -EAGAIN; } - reg = TMP108_REG_TEMP; + err = regmap_read(tmp108->regmap, TMP108_REG_TEMP, ®val); + if (err < 0) + return err; + *temp = tmp108_temp_reg_to_mC(regval); break; case hwmon_temp_min: - reg = TMP108_REG_TLOW; - break; case hwmon_temp_max: - reg = TMP108_REG_THIGH; + err = regmap_read(tmp108->regmap, attr == hwmon_temp_min ? + TMP108_REG_TLOW : TMP108_REG_THIGH, ®val); + if (err < 0) + return err; + *temp = tmp108_temp_reg_to_mC(regval); + break; + case hwmon_temp_min_alarm: + case hwmon_temp_max_alarm: + err = regmap_read(tmp108->regmap, TMP108_REG_CONF, ®val); + if (err < 0) + return err; + *temp = !!(regval & (attr == hwmon_temp_min_alarm ? + TMP108_CONF_FL : TMP108_CONF_FH)); + break; + case hwmon_temp_min_hyst: + case hwmon_temp_max_hyst: + err = regmap_read(tmp108->regmap, TMP108_REG_CONF, ®val); + if (err < 0) + return err; + switch (regval & TMP108_CONF_HYSTERESIS_MASK) { + case TMP108_HYSTERESIS_0C: + default: + hyst = 0; + break; + case TMP108_HYSTERESIS_1C: + hyst = 1000; + break; + case TMP108_HYSTERESIS_2C: + hyst = 2000; + break; + case TMP108_HYSTERESIS_4C: + hyst = 4000; + break; + } + err = regmap_read(tmp108->regmap, attr == hwmon_temp_min_hyst ? + TMP108_REG_TLOW : TMP108_REG_THIGH, ®val); + if (err < 0) + return err; + *temp = tmp108_temp_reg_to_mC(regval) - hyst; break; default: return -EOPNOTSUPP; } - err = regmap_read(tmp108->regmap, reg, ®val); - if (err < 0) - return err; - *temp = tmp108_temp_reg_to_mC(regval); - return 0; } @@ -137,33 +197,76 @@ static int tmp108_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long temp) { struct tmp108 *tmp108 = dev_get_drvdata(dev); - int reg; + u32 regval, mask; + int err; + + if (type == hwmon_chip) { + if (attr == hwmon_chip_update_interval) { + if (temp < 156) + mask = TMP108_CONVRATE_16HZ; + else if (temp < 625) + mask = TMP108_CONVRATE_4HZ; + else if (temp < 2500) + mask = TMP108_CONVRATE_1HZ; + else + mask = TMP108_CONVRATE_0P25HZ; + + return regmap_update_bits(tmp108->regmap, + TMP108_REG_CONF, + TMP108_CONF_CONVRATE_MASK, + mask); + } + return -EOPNOTSUPP; + } switch (attr) { case hwmon_temp_min: - reg = TMP108_REG_TLOW; - break; case hwmon_temp_max: - reg = TMP108_REG_THIGH; - break; + temp = clamp_val(temp, TMP108_TEMP_MIN_MC, TMP108_TEMP_MAX_MC); + return regmap_write(tmp108->regmap, + attr == hwmon_temp_min ? + TMP108_REG_TLOW : TMP108_REG_THIGH, + tmp108_mC_to_temp_reg(temp)); + case hwmon_temp_min_hyst: + /* limit value range to prevent overflow */ + temp = clamp_val(temp, -300000, 300000); + err = regmap_read(tmp108->regmap, TMP108_REG_TLOW, ®val); + if (err < 0) + return err; + temp = tmp108_temp_reg_to_mC(regval) - temp; + if (temp < 500) + mask = TMP108_HYSTERESIS_0C; + else if (temp < 1500) + mask = TMP108_HYSTERESIS_1C; + else if (temp < 3000) + mask = TMP108_HYSTERESIS_2C; + else + mask = TMP108_HYSTERESIS_4C; + return regmap_update_bits(tmp108->regmap, TMP108_REG_CONF, + TMP108_CONF_HYSTERESIS_MASK, + mask); default: return -EOPNOTSUPP; } - - temp = clamp_val(temp, TMP108_TEMP_MIN_MC, TMP108_TEMP_MAX_MC); - return regmap_write(tmp108->regmap, reg, tmp108_mC_to_temp_reg(temp)); } static umode_t tmp108_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel) { + if (type == hwmon_chip && attr == hwmon_chip_update_interval) + return S_IRUGO | S_IWUSR; + if (type != hwmon_temp) return 0; switch (attr) { case hwmon_temp_input: + case hwmon_temp_max_hyst: + case hwmon_temp_min_alarm: + case hwmon_temp_max_alarm: return S_IRUGO; case hwmon_temp_min: + case hwmon_temp_min_hyst: case hwmon_temp_max: return S_IRUGO | S_IWUSR; default: @@ -172,7 +275,7 @@ static umode_t tmp108_is_visible(const void *data, enum hwmon_sensor_types type, } static u32 tmp108_chip_config[] = { - HWMON_C_REGISTER_TZ, + HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL, 0 }; @@ -182,7 +285,8 @@ static const struct hwmon_channel_info tmp108_chip = { }; static u32 tmp108_temp_config[] = { - HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MIN, + HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MIN | HWMON_T_MIN_HYST + | HWMON_T_MAX_HYST | HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM, 0 };