Source
126
126
{
127
127
struct ads1015_data *data = i2c_get_clientdata(client);
128
128
unsigned int pga = data->channel_data[channel].pga;
129
129
int fullscale = fullscale_table[pga];
130
130
const int mask = data->id == ads1115 ? 0x7fff : 0x7ff0;
131
131
132
132
return DIV_ROUND_CLOSEST(reg * fullscale, mask);
133
133
}
134
134
135
135
/* sysfs callback function */
136
-
static ssize_t show_in(struct device *dev, struct device_attribute *da,
137
-
char *buf)
136
+
static ssize_t in_show(struct device *dev, struct device_attribute *da,
137
+
char *buf)
138
138
{
139
139
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
140
140
struct i2c_client *client = to_i2c_client(dev);
141
141
int res;
142
142
int index = attr->index;
143
143
144
144
res = ads1015_read_adc(client, index);
145
145
if (res < 0)
146
146
return res;
147
147
148
148
return sprintf(buf, "%d\n", ads1015_reg_to_mv(client, index, res));
149
149
}
150
150
151
151
static const struct sensor_device_attribute ads1015_in[] = {
152
-
SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
153
-
SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
154
-
SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
155
-
SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
156
-
SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
157
-
SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
158
-
SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
159
-
SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
152
+
SENSOR_ATTR_RO(in0_input, in, 0),
153
+
SENSOR_ATTR_RO(in1_input, in, 1),
154
+
SENSOR_ATTR_RO(in2_input, in, 2),
155
+
SENSOR_ATTR_RO(in3_input, in, 3),
156
+
SENSOR_ATTR_RO(in4_input, in, 4),
157
+
SENSOR_ATTR_RO(in5_input, in, 5),
158
+
SENSOR_ATTR_RO(in6_input, in, 6),
159
+
SENSOR_ATTR_RO(in7_input, in, 7),
160
160
};
161
161
162
162
/*
163
163
* Driver interface
164
164
*/
165
165
166
166
static int ads1015_remove(struct i2c_client *client)
167
167
{
168
168
struct ads1015_data *data = i2c_get_clientdata(client);
169
169
int k;