* [PATCH] hwmon: (nct7802) add temperature sensor type attribute
@ 2015-06-27 21:23 Constantine Shulyupin
2015-06-27 21:44 ` Guenter Roeck
0 siblings, 1 reply; 4+ messages in thread
From: Constantine Shulyupin @ 2015-06-27 21:23 UTC (permalink / raw)
To: jdelvare, linux, lm-sensors, linux-kernel; +Cc: const
From: const <const@MakeLinux.com>
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 <const@MakeLinux.com>
---
drivers/hwmon/nct7802.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-
scripts/checkpatch.pl | 2 +-
2 files changed, 53 insertions(+), 2 deletions(-)
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,
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4f484ac..bf9a680 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -14,7 +14,7 @@ my $V = '0.32';
use Getopt::Long qw(:config no_auto_abbrev);
-my $LINELENGTH=120;
+my $LINELENGTH=80;
my $quiet = 0;
my $tree = 1;
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] hwmon: (nct7802) add temperature sensor type attribute
2015-06-27 21:23 [PATCH] hwmon: (nct7802) add temperature sensor type attribute Constantine Shulyupin
@ 2015-06-27 21:44 ` Guenter Roeck
0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2015-06-27 21:44 UTC (permalink / raw)
To: Constantine Shulyupin, jdelvare, lm-sensors, linux-kernel
Hi Constantine,
On 06/27/2015 02:23 PM, Constantine Shulyupin wrote:
> From: const <const@MakeLinux.com>
>
> 0, 3 - Temperature attributes are hidden
Not really per your code (though they should be hidden).
> 1 - Current mode
> 2 - Thermistor mode
>
Wrong - that should be 3 for current (diode) mode and 4 for thermistor mode.
The values are part of the ABI and must not be changed
(look at the output of the sensors command and you'll understand why).
> Reference:
> Nuvoton Hardware Monitoring IC NCT7802Y
> 7.2.32 Mode Selection Register
> Location : Index 22h
>
> Signed-off-by: Constantine Shulyupin <const@MakeLinux.com>
> ---
> drivers/hwmon/nct7802.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-
> scripts/checkpatch.pl | 2 +-
> 2 files changed, 53 insertions(+), 2 deletions(-)
>
> 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);
Please convert to correct ABI values.
> +}
> +
> +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;
> +
Please only accept 3 and 4 for the first two sensors,
and only 4 for the third sensor, and convert to register
values as needed.
> + 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);
Please align continuation lines with '('.
> +
> +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 },
Please merge the new attributes into temp_group to get correct visibility.
> &nct7802_temp_group,
> &nct7802_in_group,
> &nct7802_fan_group,
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 4f484ac..bf9a680 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -14,7 +14,7 @@ my $V = '0.32';
>
> use Getopt::Long qw(:config no_auto_abbrev);
>
> -my $LINELENGTH=120;
> +my $LINELENGTH=80;
>
That doesn't belong here.
> my $quiet = 0;
> my $tree = 1;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] hwmon: (nct7802) add temperature sensor type attribute
@ 2015-06-27 21:34 Constantine Shulyupin
2015-06-27 21:46 ` Guenter Roeck
0 siblings, 1 reply; 4+ messages in thread
From: Constantine Shulyupin @ 2015-06-27 21:34 UTC (permalink / raw)
To: jdelvare, linux, lm-sensors, linux-kernel; +Cc: const
From: const <const@MakeLinux.com>
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 <const@MakeLinux.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] hwmon: (nct7802) add temperature sensor type attribute
2015-06-27 21:34 Constantine Shulyupin
@ 2015-06-27 21:46 ` Guenter Roeck
0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2015-06-27 21:46 UTC (permalink / raw)
To: Constantine Shulyupin, jdelvare, lm-sensors, linux-kernel
On 06/27/2015 02:34 PM, Constantine Shulyupin wrote:
> From: const <const@MakeLinux.com>
>
> 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 <const@MakeLinux.com>
Hi Constantine,
when resending a patch, please mark its version and provide a change log.
Remember that the patches are visible online forever, and without an
indication what changed no one will know the difference a year from now
with out version and change log.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-27 21:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-27 21:23 [PATCH] hwmon: (nct7802) add temperature sensor type attribute Constantine Shulyupin
2015-06-27 21:44 ` Guenter Roeck
-- strict thread matches above, loose matches on Subject: below --
2015-06-27 21:34 Constantine Shulyupin
2015-06-27 21:46 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox