Commit 2fa065fd authored by Aaron Sierra's avatar Aaron Sierra Committed by Greg Kroah-Hartman

misc: ds1682: Show device registers as unsigned

This patch leverages the fact that all DS1682 registers are unsigned to
merge two return paths into one. It also introduces val_le as used in
ds1682_store() to merge two endianness conversions into one.
Signed-off-by: default avatarAaron Sierra <asierra@xes-inc.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1a3771d5
...@@ -59,25 +59,25 @@ static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr, ...@@ -59,25 +59,25 @@ static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
{ {
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
__le32 val = 0; unsigned long long val;
__le32 val_le = 0;
int rc; int rc;
dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name); dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
/* Read the register */ /* Read the register */
rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr, rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
(u8 *) & val); (u8 *)&val_le);
if (rc < 0) if (rc < 0)
return -EIO; return -EIO;
/* Special case: the 32 bit regs are time values with 1/4s val = le32_to_cpu(val_le);
* resolution, scale them up to milliseconds */
if (sattr->nr == 4)
return sprintf(buf, "%llu\n",
((unsigned long long)le32_to_cpu(val)) * 250);
/* Format the output string and return # of bytes */ /* Format the output string and return # of bytes
return sprintf(buf, "%li\n", (long)le32_to_cpu(val)); * Special case: the 32 bit regs are time values with 1/4s
* resolution, scale them up to milliseconds
*/
return sprintf(buf, "%llu\n", (sattr->nr == 4) ? (val * 250) : val);
} }
static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr, static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment