Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752048AbbF0VlM (ORCPT ); Sat, 27 Jun 2015 17:41:12 -0400 Received: from gproxy1-pub.mail.unifiedlayer.com ([69.89.25.95]:47549 "HELO gproxy1-pub.mail.unifiedlayer.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751498AbbF0VlH (ORCPT ); Sat, 27 Jun 2015 17:41:07 -0400 X-Greylist: delayed 397 seconds by postgrey-1.27 at vger.kernel.org; Sat, 27 Jun 2015 17:41:07 EDT X-Authority-Analysis: v=2.1 cv=ALgDonD0 c=1 sm=1 tr=0 a=J7Q474dc+DFtUK1fo70nSg==:117 a=J7Q474dc+DFtUK1fo70nSg==:17 a=cNaOj0WVAAAA:8 a=f5113yIGAAAA:8 a=dSbym95GAAAA:8 a=ZhRHZX3j7ZUA:10 a=ZL9j6v-TU1MA:10 a=XAFQembCKUMA:10 a=hkrvFma3eQO7vfzSHHYA:9 From: Constantine Shulyupin To: jdelvare@suse.de, linux@roeck-us.net, lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org Cc: const Subject: [PATCH] hwmon: (nct7802) add temperature sensor type attribute Date: Sun, 28 Jun 2015 00:34:10 +0300 Message-Id: <1435440850-18246-1-git-send-email-const@MakeLinux.com> X-Mailer: git-send-email 1.9.1 X-Identified-User: {1470:box668.bluehost.com:makelinu:makelinux.net} {sentby:smtp auth 84.228.195.160 authed with poster@makelinux.net} Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2964 Lines: 96 From: const 0, 3 - Temperature attributes are hidden 1 - Current mode 2 - Thermistor mode Reference: Nuvoton Hardware Monitoring IC NCT7802Y 7.2.32 Mode Selection Register Location : Index 22h Signed-off-by: Constantine Shulyupin --- drivers/hwmon/nct7802.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c index 60cf5d1..444eedf 100644 --- a/drivers/hwmon/nct7802.c +++ b/drivers/hwmon/nct7802.c @@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = { #define REG_VOLTAGE_LOW 0x0f #define REG_FANCOUNT_LOW 0x13 #define REG_START 0x21 -#define REG_MODE 0x22 +#define REG_MODE 0x22 /* 7.2.32 Mode Selection Register */ #define REG_PECI_ENABLE 0x23 #define REG_FAN_ENABLE 0x24 #define REG_VMON_ENABLE 0x25 @@ -725,7 +725,58 @@ static struct attribute_group nct7802_fan_group = { .is_visible = nct7802_fan_is_visible, }; +static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct nct7802_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); + unsigned int val; + int ret; + + ret = regmap_read(data->regmap, REG_MODE, &val); + if (ret < 0) + return ret; + + return sprintf(buf, "%u\n", val >> (2 * sattr->index) & 3); +} + +static ssize_t store_temp_type(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct nct7802_data *data = dev_get_drvdata(dev); + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); + unsigned int val; + int err; + + err = kstrtouint(buf, 0, &val); + if (err < 0) + return err; + if (val > 0xF) + return -EINVAL; + + err = regmap_update_bits(data->regmap, REG_MODE, + 3 << 2 * sattr->index, val << 2 * sattr->index); + sysfs_update_group(&dev->kobj, &nct7802_temp_group); + return err ? : count; +} + +/* 7.2.32 Mode Selection Register */ +static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, + show_temp_type, store_temp_type, 0); +static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, + show_temp_type, store_temp_type, 1); +static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, + show_temp_type, store_temp_type, 2); + +static struct attribute *general_attributes[] = { + &sensor_dev_attr_temp1_type.dev_attr.attr, + &sensor_dev_attr_temp2_type.dev_attr.attr, + &sensor_dev_attr_temp3_type.dev_attr.attr, + NULL +}; + static const struct attribute_group *nct7802_groups[] = { + &(const struct attribute_group){ .attrs = general_attributes }, &nct7802_temp_group, &nct7802_in_group, &nct7802_fan_group, -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/