Skip to contentSkip to conversation

hwmon: (ds1621) Add ds1721 update interval sysfs attribute

PATCH Applied Robert Coulson 3 participants 6 messages May 9, 2013 – Jun 6, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 hwmon: (ds1621) Add ds1721 update interval sysfs attribute

The ds1721 device can be configured for 9..12 bit resolutions; add a sysfs attribute for userspace to configure this attribute. The definition, description, details, and usage are shown in the documentation and were crafted from an LM73 driver patch done by Chris Verges & Guenter Roeck).

---
 Documentation/hwmon/ds1621 |   65 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/hwmon/ds1621.c     |   58 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 123 insertions(+)
Documentation/hwmon/ds1621 +65 -0
index ee7bc01..ae29036 100644
@@ -75,3 +75,68 @@ The DS1721 is pin compatible with the DS1621, has an accuracy of +/- 1.0
 degree Celius over a -10 to +85 degree range, a minimum/maximum alarm
 default setting of 75 and 80 degrees respectifully, and a maximum conversion
 time of 750ms.
+
+In addition, the DS1721 supports four resolution settings from 9 to 12 bits
+(defined in degrees C per LSB: 0.5, 0.25, 0.125, and 0.0625, respectifully),
+that are set at device power on to the highest resolution: 12-bits (0.0625 degree C).
+
+Changing the DS1721 resolution mode affects the conversion time and can be
+done from userspace, via the device 'update_interval' sysfs attribute. This
+attribute will normalize range of input values to the device maximum resolution
+values defined in the datasheet as such:
+
+Resolution    Conversion Time    Input Range
+ (C/LSB)       (msec)             (msec)
+--------------------------------------------
+0.5             93.75              0....94
+0.25            187.5              95...187
+0.125           375                188..375
+0.0625          750                376..infinity
+--------------------------------------
+
+The following examples show how the 'update_interval' attribute can be
+used to change the conversion time:
+
+$ cat update_interval
+750
+$ cat temp1_input
+22062
+$
+$ echo 300 > update_interval
+$ cat update_interval
+375
+$ cat temp1_input
+22125
+$
+$ echo 150 > update_interval
+$ cat update_interval
+188
+$ cat temp1_input
+22250
+$
+$ echo 1 > update_interval
+$ cat update_interval
+94
+$ cat temp1_input
+22000
+$
+$ echo 1000 > update_interval
+$ cat update_interval
+750
+$ cat temp1_input
+22062
+$
+
+As shown, the ds1621 driver automatically adjusts the 'update_interval'
+user input, via a step function. Reading back the 'update_interval' value
+after a write operation provides the conversion time used by the device.
+
+Mathematically, the resolution can be derived from the conversion time
+via the following function:
+
+   g(x) = 0.5 * [minimum_conversion_time/x]
+
+where:
+ -> 'x' = the output from 'update_interval'
+ -> 'g(x)' = the resolution in degrees C per LSB.
+ -> 93.75ms = minimum conversion time
drivers/hwmon/ds1621.c +58 -0

76 lines not on this page · raw message

Signature · 7 lines
1.7.9.5


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
maintainer Applied
#1 lore raw
Quoted 7 lines · Robert Coulson

The ds1721 device can be configured for 9..12 bit resolutions; add a sysfs attribute for userspace to configure this attribute. The definition, description, details, and usage are shown in the documentation and were crafted from an LM73 driver patch done by Chris Verges & Guenter Roeck).

Applied to hwmon-next.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw
In reply to Robert Coulson

Hi Robert, hi Guenter,

Sorry for joining the game a little late...

Quoted 5 lines · Robert Coulson
drivers/hwmon/ds1621.c +5 -0
+static umode_t ds1621_attribute_visible(struct kobject *kobj,
+					struct attribute *attr, int index)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct i2c_client *client = to_i2c_client(dev);

drivers/hwmon/ds1621.c static struct attribute *ds1621_attributes[] = { · line 351

Quoted 10 lines
drivers/hwmon/ds1621.c +10 -0
+	struct ds1621_data *data = i2c_get_clientdata(client);
+	struct device_attribute *devattr;
+
+	devattr = container_of(attr, struct device_attribute, attr);
+	if (attr = &dev_attr_update_interval.attr)
+		if (data->kind != ds1721)
+			/* shhh, we're hiding update_interval */
+			return 0;
+	return attr->mode;
+}

"make W=1" complains that devattr is defined but never used. And this is true, and should be fixed.

Thanks,

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
maintainer
#3 lore raw
In reply to Robert Coulson
Quoted 15 lines · Jean Delvare

Hi Robert, hi Guenter,

Sorry for joining the game a little late...

Quoted 10 lines · Robert Coulson
drivers/hwmon/ds1621.c +10 -0
+static umode_t ds1621_attribute_visible(struct kobject *kobj,
+					struct attribute *attr, int index)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds1621_data *data = i2c_get_clientdata(client);
+	struct device_attribute *devattr;
+
+	devattr = container_of(attr, struct device_attribute, attr);
+	if (attr = &dev_attr_update_interval.attr)
Quoted 9 lines

drivers/hwmon/ds1621.c static struct attribute *ds1621_attributes[] = { · line 351

Quoted 5 lines
drivers/hwmon/ds1621.c +5 -0
+		if (data->kind != ds1721)
+			/* shhh, we're hiding update_interval */
+			return 0;
+	return attr->mode;
+}

"make W=1" complains that devattr is defined but never used. And this is true, and should be fixed.

I'll take care of it.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw
In reply to Robert Coulson
Quoted 25 lines · Guenter Roeck
Quoted 15 lines · Jean Delvare

Hi Robert, hi Guenter,

Sorry for joining the game a little late...

Quoted 10 lines · Robert Coulson
drivers/hwmon/ds1621.c +10 -0
+static umode_t ds1621_attribute_visible(struct kobject *kobj,
+                                   struct attribute *attr, int index)
+{
+   struct device *dev = container_of(kobj, struct device, kobj);
+   struct i2c_client *client = to_i2c_client(dev);
+   struct ds1621_data *data = i2c_get_clientdata(client);
+   struct device_attribute *devattr;
+
+   devattr = container_of(attr, struct device_attribute, attr);
+   if (attr == &dev_attr_update_interval.attr)
Quoted 9 lines

drivers/hwmon/ds1621.c static struct attribute *ds1621_attributes[] = { · line 351

Quoted 5 lines
drivers/hwmon/ds1621.c +5 -0
+           if (data->kind != ds1721)
+                   /* shhh, we're hiding update_interval */
+                   return 0;
+   return attr->mode;
+}

"make W=1" complains that devattr is defined but never used. And this is true, and should be fixed.

Quoted 4 lines

I'll take care of it.

Guenter

Thank you for catching it Jean, I appreciate it.

My apologies for missing it Guenter; Now that I am back, I can take care of it this morning.

Rob

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

maintainer
#5 lore raw
In reply to Robert Coulson
Quoted 29 lines · Robert Coulson
Quoted 27 lines · Guenter Roeck
Quoted 15 lines · Jean Delvare

Hi Robert, hi Guenter,

Sorry for joining the game a little late...

Quoted 10 lines · Robert Coulson
drivers/hwmon/ds1621.c +10 -0
+static umode_t ds1621_attribute_visible(struct kobject *kobj,
+                                   struct attribute *attr, int index)
+{
+   struct device *dev = container_of(kobj, struct device, kobj);
+   struct i2c_client *client = to_i2c_client(dev);
+   struct ds1621_data *data = i2c_get_clientdata(client);
+   struct device_attribute *devattr;
+
+   devattr = container_of(attr, struct device_attribute, attr);
+   if (attr = &dev_attr_update_interval.attr)
Quoted 9 lines

drivers/hwmon/ds1621.c static struct attribute *ds1621_attributes[] = { · line 351

Quoted 5 lines
drivers/hwmon/ds1621.c +5 -0
+           if (data->kind != ds1721)
+                   /* shhh, we're hiding update_interval */
+                   return 0;
+   return attr->mode;
+}

"make W=1" complains that devattr is defined but never used. And this is true, and should be fixed.

I'll take care of it.

Quoted 8 lines
Quoted 2 lines

Guenter

Thank you for catching it Jean, I appreciate it.

My apologies for missing it Guenter; Now that I am back, I can take care of it this morning.

Ok, I'll wait for your updated patch.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors