Merge tag 'nfs-for-3.10-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
[firefly-linux-kernel-4.4.55.git] / drivers / hwmon / ltc4215.c
index 98b3d04f98b70bee2713914031c4173451f5517a..8a142960d69ef1cbdbf884bf1b382cb78c1d5eb9 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
+#include <linux/jiffies.h>
 
 /* Here are names of the chip's registers (a.k.a. commands) */
 enum ltc4215_cmd {
@@ -171,12 +172,12 @@ static ssize_t ltc4215_show_alarm(struct device *dev,
                                          struct device_attribute *da,
                                          char *buf)
 {
-       struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(da);
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
        struct ltc4215_data *data = ltc4215_update_device(dev);
-       const u8 reg = data->regs[attr->index];
-       const u32 mask = attr->nr;
+       const u8 reg = data->regs[LTC4215_STATUS];
+       const u32 mask = attr->index;
 
-       return snprintf(buf, PAGE_SIZE, "%u\n", (reg & mask) ? 1 : 0);
+       return snprintf(buf, PAGE_SIZE, "%u\n", !!(reg & mask));
 }
 
 /*
@@ -185,39 +186,29 @@ static ssize_t ltc4215_show_alarm(struct device *dev,
  * for each register.
  */
 
-#define LTC4215_VOLTAGE(name, ltc4215_cmd_idx) \
-       static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
-       ltc4215_show_voltage, NULL, ltc4215_cmd_idx)
-
-#define LTC4215_CURRENT(name) \
-       static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
-       ltc4215_show_current, NULL, 0);
-
-#define LTC4215_POWER(name) \
-       static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
-       ltc4215_show_power, NULL, 0);
-
-#define LTC4215_ALARM(name, mask, reg) \
-       static SENSOR_DEVICE_ATTR_2(name, S_IRUGO, \
-       ltc4215_show_alarm, NULL, (mask), reg)
-
 /* Construct a sensor_device_attribute structure for each register */
 
 /* Current */
-LTC4215_CURRENT(curr1_input);
-LTC4215_ALARM(curr1_max_alarm, (1 << 2),       LTC4215_STATUS);
+static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4215_show_current, NULL, 0);
+static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc4215_show_alarm, NULL,
+                         1 << 2);
 
 /* Power (virtual) */
-LTC4215_POWER(power1_input);
+static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ltc4215_show_power, NULL, 0);
 
 /* Input Voltage */
-LTC4215_VOLTAGE(in1_input,                     LTC4215_ADIN);
-LTC4215_ALARM(in1_max_alarm,   (1 << 0),       LTC4215_STATUS);
-LTC4215_ALARM(in1_min_alarm,   (1 << 1),       LTC4215_STATUS);
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4215_show_voltage, NULL,
+                         LTC4215_ADIN);
+static SENSOR_DEVICE_ATTR(in1_max_alarm, S_IRUGO, ltc4215_show_alarm, NULL,
+                         1 << 0);
+static SENSOR_DEVICE_ATTR(in1_min_alarm, S_IRUGO, ltc4215_show_alarm, NULL,
+                         1 << 1);
 
 /* Output Voltage */
-LTC4215_VOLTAGE(in2_input,                     LTC4215_SOURCE);
-LTC4215_ALARM(in2_min_alarm,   (1 << 3),       LTC4215_STATUS);
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4215_show_voltage, NULL,
+                         LTC4215_SOURCE);
+static SENSOR_DEVICE_ATTR(in2_min_alarm, S_IRUGO, ltc4215_show_alarm, NULL,
+                         1 << 3);
 
 /*
  * Finally, construct an array of pointers to members of the above objects,