.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * lm92 - Hardware monitoring driver |
---|
3 | 4 | * Copyright (C) 2005-2008 Jean Delvare <jdelvare@suse.de> |
---|
.. | .. |
---|
24 | 25 | * Support could easily be added for the National Semiconductor LM76 |
---|
25 | 26 | * and Maxim MAX6633 and MAX6634 chips, which are mostly compatible |
---|
26 | 27 | * with the LM92. |
---|
27 | | - * |
---|
28 | | - * This program is free software; you can redistribute it and/or modify |
---|
29 | | - * it under the terms of the GNU General Public License as published by |
---|
30 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
31 | | - * (at your option) any later version. |
---|
32 | | - * |
---|
33 | | - * This program is distributed in the hope that it will be useful, |
---|
34 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
35 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
36 | | - * GNU General Public License for more details. |
---|
37 | 28 | */ |
---|
38 | 29 | |
---|
39 | 30 | #include <linux/module.h> |
---|
.. | .. |
---|
127 | 118 | |
---|
128 | 119 | mutex_lock(&data->update_lock); |
---|
129 | 120 | |
---|
130 | | - if (time_after(jiffies, data->last_updated + HZ) |
---|
131 | | - || !data->valid) { |
---|
| 121 | + if (time_after(jiffies, data->last_updated + HZ) || |
---|
| 122 | + !data->valid) { |
---|
132 | 123 | dev_dbg(&client->dev, "Updating lm92 data\n"); |
---|
133 | 124 | for (i = 0; i < t_num_regs; i++) { |
---|
134 | 125 | data->temp[i] = |
---|
.. | .. |
---|
143 | 134 | return data; |
---|
144 | 135 | } |
---|
145 | 136 | |
---|
146 | | -static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
---|
| 137 | +static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, |
---|
147 | 138 | char *buf) |
---|
148 | 139 | { |
---|
149 | 140 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
---|
.. | .. |
---|
152 | 143 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); |
---|
153 | 144 | } |
---|
154 | 145 | |
---|
155 | | -static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, |
---|
156 | | - const char *buf, size_t count) |
---|
| 146 | +static ssize_t temp_store(struct device *dev, |
---|
| 147 | + struct device_attribute *devattr, const char *buf, |
---|
| 148 | + size_t count) |
---|
157 | 149 | { |
---|
158 | 150 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
---|
159 | 151 | struct lm92_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
161 | 153 | int nr = attr->index; |
---|
162 | 154 | long val; |
---|
163 | 155 | int err; |
---|
164 | | - |
---|
| 156 | + |
---|
165 | 157 | err = kstrtol(buf, 10, &val); |
---|
166 | 158 | if (err) |
---|
167 | 159 | return err; |
---|
.. | .. |
---|
173 | 165 | return count; |
---|
174 | 166 | } |
---|
175 | 167 | |
---|
176 | | -static ssize_t show_temp_hyst(struct device *dev, |
---|
| 168 | +static ssize_t temp_hyst_show(struct device *dev, |
---|
177 | 169 | struct device_attribute *devattr, char *buf) |
---|
178 | 170 | { |
---|
179 | 171 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
---|
180 | 172 | struct lm92_data *data = lm92_update_device(dev); |
---|
| 173 | + |
---|
181 | 174 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]) |
---|
182 | 175 | - TEMP_FROM_REG(data->temp[t_hyst])); |
---|
183 | 176 | } |
---|
.. | .. |
---|
186 | 179 | struct device_attribute *attr, char *buf) |
---|
187 | 180 | { |
---|
188 | 181 | struct lm92_data *data = lm92_update_device(dev); |
---|
| 182 | + |
---|
189 | 183 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[t_min]) |
---|
190 | 184 | + TEMP_FROM_REG(data->temp[t_hyst])); |
---|
191 | 185 | } |
---|
192 | 186 | |
---|
193 | | -static ssize_t set_temp_hyst(struct device *dev, |
---|
194 | | - struct device_attribute *devattr, |
---|
195 | | - const char *buf, size_t count) |
---|
| 187 | +static ssize_t temp_hyst_store(struct device *dev, |
---|
| 188 | + struct device_attribute *devattr, |
---|
| 189 | + const char *buf, size_t count) |
---|
196 | 190 | { |
---|
197 | 191 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
---|
198 | 192 | struct lm92_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
206 | 200 | |
---|
207 | 201 | val = clamp_val(val, -120000, 220000); |
---|
208 | 202 | mutex_lock(&data->update_lock); |
---|
209 | | - data->temp[t_hyst] = |
---|
| 203 | + data->temp[t_hyst] = |
---|
210 | 204 | TEMP_TO_REG(TEMP_FROM_REG(data->temp[attr->index]) - val); |
---|
211 | 205 | i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST, |
---|
212 | 206 | data->temp[t_hyst]); |
---|
.. | .. |
---|
218 | 212 | char *buf) |
---|
219 | 213 | { |
---|
220 | 214 | struct lm92_data *data = lm92_update_device(dev); |
---|
| 215 | + |
---|
221 | 216 | return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp[t_input])); |
---|
222 | 217 | } |
---|
223 | 218 | |
---|
224 | | -static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
---|
| 219 | +static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
---|
225 | 220 | char *buf) |
---|
226 | 221 | { |
---|
227 | 222 | int bitnr = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
229 | 224 | return sprintf(buf, "%d\n", (data->temp[t_input] >> bitnr) & 1); |
---|
230 | 225 | } |
---|
231 | 226 | |
---|
232 | | -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, t_input); |
---|
233 | | -static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp, set_temp, |
---|
234 | | - t_crit); |
---|
235 | | -static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst, |
---|
236 | | - set_temp_hyst, t_crit); |
---|
237 | | -static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, |
---|
238 | | - t_min); |
---|
| 227 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, t_input); |
---|
| 228 | +static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp, t_crit); |
---|
| 229 | +static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst, temp_hyst, t_crit); |
---|
| 230 | +static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, t_min); |
---|
239 | 231 | static DEVICE_ATTR_RO(temp1_min_hyst); |
---|
240 | | -static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, |
---|
241 | | - t_max); |
---|
242 | | -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp_hyst, NULL, t_max); |
---|
| 232 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, t_max); |
---|
| 233 | +static SENSOR_DEVICE_ATTR_RO(temp1_max_hyst, temp_hyst, t_max); |
---|
243 | 234 | static DEVICE_ATTR_RO(alarms); |
---|
244 | | -static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2); |
---|
245 | | -static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
---|
246 | | -static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); |
---|
| 235 | +static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 2); |
---|
| 236 | +static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, alarm, 0); |
---|
| 237 | +static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 1); |
---|
247 | 238 | |
---|
248 | 239 | /* |
---|
249 | 240 | * Detection and registration |
---|
.. | .. |
---|
301 | 292 | return 0; |
---|
302 | 293 | } |
---|
303 | 294 | |
---|
304 | | -static int lm92_probe(struct i2c_client *new_client, |
---|
305 | | - const struct i2c_device_id *id) |
---|
| 295 | +static int lm92_probe(struct i2c_client *new_client) |
---|
306 | 296 | { |
---|
307 | 297 | struct device *hwmon_dev; |
---|
308 | 298 | struct lm92_data *data; |
---|
.. | .. |
---|
324 | 314 | return PTR_ERR_OR_ZERO(hwmon_dev); |
---|
325 | 315 | } |
---|
326 | 316 | |
---|
327 | | - |
---|
328 | 317 | /* |
---|
329 | 318 | * Module and driver stuff |
---|
330 | 319 | */ |
---|
.. | .. |
---|
341 | 330 | .driver = { |
---|
342 | 331 | .name = "lm92", |
---|
343 | 332 | }, |
---|
344 | | - .probe = lm92_probe, |
---|
| 333 | + .probe_new = lm92_probe, |
---|
345 | 334 | .id_table = lm92_id, |
---|
346 | 335 | .detect = lm92_detect, |
---|
347 | 336 | .address_list = normal_i2c, |
---|