Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754086AbbGBWsg (ORCPT ); Thu, 2 Jul 2015 18:48:36 -0400 Received: from gproxy10-pub.mail.unifiedlayer.com ([69.89.20.226]:49544 "HELO gproxy10-pub.mail.unifiedlayer.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752981AbbGBWs3 (ORCPT ); Thu, 2 Jul 2015 18:48:29 -0400 X-Greylist: delayed 399 seconds by postgrey-1.27 at vger.kernel.org; Thu, 02 Jul 2015 18:48:29 EDT X-Authority-Analysis: v=2.1 cv=UNFOQkvy 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=tvnXkgGHczcA:10 a=zOBTXjUuO1YA:10 a=mDV3o1hIAAAA:8 a=V7lLzJ-jLsDHX_k1bMYA:9 a=CBHFne3RxqcA:10 From: Constantine Shulyupin To: jdelvare@suse.de, linux@roeck-us.net, lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org Cc: Constantine Shulyupin Subject: [PATCH] hwmon: (nct7802) Add fan output control Date: Fri, 3 Jul 2015 01:40:43 +0300 Message-Id: <1435876843-1216-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.198.137 authed with poster@makelinux.net} Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3535 Lines: 114 Notes: Some lines intentionally more than 80 characters because wrapping this lines decreases readability. The patch was checked with scripts/checkpatch.pl --max-line-length=88 Following code is not typecasting. It is inline struct attribute_group definition using compound literal. (See https://gcc.gnu.org/onlinedocs/gcc-3.2.2/gcc/Compound-Literals.html) static const struct attribute_group *nct7802_groups[] = { ... &(const struct attribute_group){ .attrs = fan_output_attributes }, ... Reference: Nuvoton Hardware Monitoring IC NCT7802Y 7.2.91 Fan Control 1 Output Value Location : Index 60h 7.2.92 Fan Control 2 Output Value Location : Index 61h 7.2.93 Fan Control 3 Output Value Location : Index 62h Signed-off-by: Constantine Shulyupin --- drivers/hwmon/nct7802.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c index afa242d..56d3547 100644 --- a/drivers/hwmon/nct7802.c +++ b/drivers/hwmon/nct7802.c @@ -102,6 +102,38 @@ static ssize_t store_temp_type(struct device *dev, return err ? : count; } +static ssize_t show_dec(struct device *dev, struct device_attribute *devattr, char *buf) +{ + int ret = -1; + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct nct7802_data *data = dev_get_drvdata(dev); + unsigned int val = 0; + + ret = regmap_read(data->regmap, attr->index, &val); + if (ret < 0) + return ret; + + ret = sprintf(buf, "%d\n", val); + return ret; +} + +static ssize_t store_u8(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); + struct nct7802_data *data = dev_get_drvdata(dev); + int err; + unsigned int val; + + err = kstrtouint(buf, 0, &val); + if (err < 0) + return err; + if (val > 0xFF) + return -EINVAL; + + err = regmap_write(data->regmap, attr->index, val); + return err ? : count; +} static int nct7802_read_temp(struct nct7802_data *data, u8 reg_temp, u8 reg_temp_low, int *temp) @@ -735,6 +767,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 2); static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep, 0x5b, 2); +/* 7.2.91... Fan Control Output Value */ +static SENSOR_DEVICE_ATTR(fan1_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 0x60); +static SENSOR_DEVICE_ATTR(fan2_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 0x61); +static SENSOR_DEVICE_ATTR(fan3_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 0x62); + static struct attribute *nct7802_fan_attrs[] = { &sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_fan1_min.dev_attr.attr, @@ -773,10 +810,18 @@ static struct attribute_group nct7802_fan_group = { .is_visible = nct7802_fan_is_visible, }; +static struct attribute *fan_output_attributes[] = { + &sensor_dev_attr_fan1_output.dev_attr.attr, + &sensor_dev_attr_fan2_output.dev_attr.attr, + &sensor_dev_attr_fan3_output.dev_attr.attr, + NULL +}; + static const struct attribute_group *nct7802_groups[] = { &nct7802_temp_group, &nct7802_in_group, &nct7802_fan_group, + &(const struct attribute_group){ .attrs = fan_output_attributes }, NULL }; -- 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/