Source
132
132
133
133
data->last_updated = jiffies;
134
134
data->valid = 1;
135
135
}
136
136
abort:
137
137
mutex_unlock(&data->update_lock);
138
138
139
139
return ret;
140
140
}
141
141
142
-
static ssize_t show_temp(struct device *dev, struct device_attribute *da,
142
+
static ssize_t temp_show(struct device *dev, struct device_attribute *da,
143
143
char *buf)
144
144
{
145
145
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
146
146
struct ds620_data *data = ds620_update_client(dev);
147
147
148
148
if (IS_ERR(data))
149
149
return PTR_ERR(data);
150
150
151
151
return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
152
152
}
153
153
154
-
static ssize_t set_temp(struct device *dev, struct device_attribute *da,
155
-
const char *buf, size_t count)
154
+
static ssize_t temp_store(struct device *dev, struct device_attribute *da,
155
+
const char *buf, size_t count)
156
156
{
157
157
int res;
158
158
long val;
159
159
160
160
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
161
161
struct ds620_data *data = dev_get_drvdata(dev);
162
162
struct i2c_client *client = data->client;
163
163
164
164
res = kstrtol(buf, 10, &val);
165
165
169
169
val = (clamp_val(val, -128000, 128000) * 10 / 625) * 8;
170
170
171
171
mutex_lock(&data->update_lock);
172
172
data->temp[attr->index] = val;
173
173
i2c_smbus_write_word_swapped(client, DS620_REG_TEMP[attr->index],
174
174
data->temp[attr->index]);
175
175
mutex_unlock(&data->update_lock);
176
176
return count;
177
177
}
178
178
179
-
static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
179
+
static ssize_t alarm_show(struct device *dev, struct device_attribute *da,
180
180
char *buf)
181
181
{
182
182
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
183
183
struct ds620_data *data = ds620_update_client(dev);
184
184
struct i2c_client *client;
185
185
u16 conf, new_conf;
186
186
int res;
187
187
188
188
if (IS_ERR(data))
189
189
return PTR_ERR(data);
200
200
if (conf != new_conf) {
201
201
res = i2c_smbus_write_word_swapped(client, DS620_REG_CONF,
202
202
new_conf);
203
203
if (res < 0)
204
204
return res;
205
205
}
206
206
207
207
return sprintf(buf, "%d\n", !!(conf & attr->index));
208
208
}
209
209
210
-
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
211
-
static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
212
-
static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
213
-
static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
214
-
DS620_REG_CONFIG_TLF);
215
-
static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
216
-
DS620_REG_CONFIG_THF);
210
+
static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
211
+
static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, 1);
212
+
static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, 2);
213
+
static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, alarm, DS620_REG_CONFIG_TLF);
214
+
static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, DS620_REG_CONFIG_THF);
217
215
218
216
static struct attribute *ds620_attrs[] = {
219
217
&sensor_dev_attr_temp1_input.dev_attr.attr,
220
218
&sensor_dev_attr_temp1_min.dev_attr.attr,
221
219
&sensor_dev_attr_temp1_max.dev_attr.attr,
222
220
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
223
221
&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
224
222
NULL
225
223
};
226
224