Source
87
87
* in mOhm.
88
88
*/
89
89
val = DIV_ROUND_CLOSEST(val * 125, 2);
90
90
break;
91
91
default:
92
92
return -EINVAL;
93
93
}
94
94
return val;
95
95
}
96
96
97
-
static ssize_t ltc4222_show_value(struct device *dev,
97
+
static ssize_t ltc4222_value_show(struct device *dev,
98
98
struct device_attribute *da, char *buf)
99
99
{
100
100
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
101
101
int value;
102
102
103
103
value = ltc4222_get_value(dev, attr->index);
104
104
if (value < 0)
105
105
return value;
106
106
return snprintf(buf, PAGE_SIZE, "%d\n", value);
107
107
}
108
108
109
-
static ssize_t ltc4222_show_bool(struct device *dev,
109
+
static ssize_t ltc4222_bool_show(struct device *dev,
110
110
struct device_attribute *da, char *buf)
111
111
{
112
112
struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(da);
113
113
struct regmap *regmap = dev_get_drvdata(dev);
114
114
unsigned int fault;
115
115
int ret;
116
116
117
117
ret = regmap_read(regmap, attr->nr, &fault);
118
118
if (ret < 0)
119
119
return ret;
120
120
fault &= attr->index;
121
121
if (fault) /* Clear reported faults in chip register */
122
122
regmap_update_bits(regmap, attr->nr, attr->index, 0);
123
123
124
124
return snprintf(buf, PAGE_SIZE, "%d\n", !!fault);
125
125
}
126
126
127
127
/* Voltages */
128
-
static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4222_show_value, NULL,
129
-
LTC4222_SOURCE1);
130
-
static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4222_show_value, NULL,
131
-
LTC4222_ADIN1);
132
-
static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, ltc4222_show_value, NULL,
133
-
LTC4222_SOURCE2);
134
-
static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, ltc4222_show_value, NULL,
135
-
LTC4222_ADIN2);
128
+
static SENSOR_DEVICE_ATTR_RO(in1_input, ltc4222_value, LTC4222_SOURCE1);
129
+
static SENSOR_DEVICE_ATTR_RO(in2_input, ltc4222_value, LTC4222_ADIN1);
130
+
static SENSOR_DEVICE_ATTR_RO(in3_input, ltc4222_value, LTC4222_SOURCE2);
131
+
static SENSOR_DEVICE_ATTR_RO(in4_input, ltc4222_value, LTC4222_ADIN2);
136
132
137
133
/*
138
134
* Voltage alarms
139
135
* UV/OV faults are associated with the input voltage, and power bad and fet
140
136
* faults are associated with the output voltage.
141
137
*/
142
-
static SENSOR_DEVICE_ATTR_2(in1_min_alarm, S_IRUGO, ltc4222_show_bool, NULL,
143
-
LTC4222_FAULT1, FAULT_UV);
144
-
static SENSOR_DEVICE_ATTR_2(in1_max_alarm, S_IRUGO, ltc4222_show_bool, NULL,
145
-
LTC4222_FAULT1, FAULT_OV);
146
-
static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, ltc4222_show_bool, NULL,
147
-
LTC4222_FAULT1, FAULT_POWER_BAD | FAULT_FET_BAD);
148
-
149
-
static SENSOR_DEVICE_ATTR_2(in3_min_alarm, S_IRUGO, ltc4222_show_bool, NULL,
150
-
LTC4222_FAULT2, FAULT_UV);
151
-
static SENSOR_DEVICE_ATTR_2(in3_max_alarm, S_IRUGO, ltc4222_show_bool, NULL,
152
-
LTC4222_FAULT2, FAULT_OV);
153
-
static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, ltc4222_show_bool, NULL,
154
-
LTC4222_FAULT2, FAULT_POWER_BAD | FAULT_FET_BAD);
138
+
static SENSOR_DEVICE_ATTR_2_RO(in1_min_alarm, ltc4222_bool, LTC4222_FAULT1,
139
+
FAULT_UV);
140
+
static SENSOR_DEVICE_ATTR_2_RO(in1_max_alarm, ltc4222_bool, LTC4222_FAULT1,
141
+
FAULT_OV);
142
+
static SENSOR_DEVICE_ATTR_2_RO(in2_alarm, ltc4222_bool, LTC4222_FAULT1,
143
+
FAULT_POWER_BAD | FAULT_FET_BAD);
144
+
145
+
static SENSOR_DEVICE_ATTR_2_RO(in3_min_alarm, ltc4222_bool, LTC4222_FAULT2,
146
+
FAULT_UV);
147
+
static SENSOR_DEVICE_ATTR_2_RO(in3_max_alarm, ltc4222_bool, LTC4222_FAULT2,
148
+
FAULT_OV);
149
+
static SENSOR_DEVICE_ATTR_2_RO(in4_alarm, ltc4222_bool, LTC4222_FAULT2,
150
+
FAULT_POWER_BAD | FAULT_FET_BAD);
155
151
156
152
/* Current (via sense resistor) */
157
-
static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4222_show_value, NULL,
158
-
LTC4222_SENSE1);
159
-
static SENSOR_DEVICE_ATTR(curr2_input, S_IRUGO, ltc4222_show_value, NULL,
160
-
LTC4222_SENSE2);
153
+
static SENSOR_DEVICE_ATTR_RO(curr1_input, ltc4222_value, LTC4222_SENSE1);
154
+
static SENSOR_DEVICE_ATTR_RO(curr2_input, ltc4222_value, LTC4222_SENSE2);
161
155
162
156
/* Overcurrent alarm */
163
-
static SENSOR_DEVICE_ATTR_2(curr1_max_alarm, S_IRUGO, ltc4222_show_bool, NULL,
164
-
LTC4222_FAULT1, FAULT_OC);
165
-
static SENSOR_DEVICE_ATTR_2(curr2_max_alarm, S_IRUGO, ltc4222_show_bool, NULL,
166
-
LTC4222_FAULT2, FAULT_OC);
157
+
static SENSOR_DEVICE_ATTR_2_RO(curr1_max_alarm, ltc4222_bool, LTC4222_FAULT1,
158
+
FAULT_OC);
159
+
static SENSOR_DEVICE_ATTR_2_RO(curr2_max_alarm, ltc4222_bool, LTC4222_FAULT2,
160
+
FAULT_OC);
167
161
168
162
static struct attribute *ltc4222_attrs[] = {
169
163
&sensor_dev_attr_in1_input.dev_attr.attr,
170
164
&sensor_dev_attr_in1_min_alarm.dev_attr.attr,
171
165
&sensor_dev_attr_in1_max_alarm.dev_attr.attr,
172
166
&sensor_dev_attr_in2_input.dev_attr.attr,
173
167
&sensor_dev_attr_in2_alarm.dev_attr.attr,
174
168
&sensor_dev_attr_in3_input.dev_attr.attr,
175
169
&sensor_dev_attr_in3_min_alarm.dev_attr.attr,
176
170
&sensor_dev_attr_in3_max_alarm.dev_attr.attr,