hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/hwmon/lm92.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * lm92 - Hardware monitoring driver
34 * Copyright (C) 2005-2008 Jean Delvare <jdelvare@suse.de>
....@@ -24,16 +25,6 @@
2425 * Support could easily be added for the National Semiconductor LM76
2526 * and Maxim MAX6633 and MAX6634 chips, which are mostly compatible
2627 * 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.
3728 */
3829
3930 #include <linux/module.h>
....@@ -127,8 +118,8 @@
127118
128119 mutex_lock(&data->update_lock);
129120
130
- if (time_after(jiffies, data->last_updated + HZ)
131
- || !data->valid) {
121
+ if (time_after(jiffies, data->last_updated + HZ) ||
122
+ !data->valid) {
132123 dev_dbg(&client->dev, "Updating lm92 data\n");
133124 for (i = 0; i < t_num_regs; i++) {
134125 data->temp[i] =
....@@ -143,7 +134,7 @@
143134 return data;
144135 }
145136
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,
147138 char *buf)
148139 {
149140 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
....@@ -152,8 +143,9 @@
152143 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
153144 }
154145
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)
157149 {
158150 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
159151 struct lm92_data *data = dev_get_drvdata(dev);
....@@ -161,7 +153,7 @@
161153 int nr = attr->index;
162154 long val;
163155 int err;
164
-
156
+
165157 err = kstrtol(buf, 10, &val);
166158 if (err)
167159 return err;
....@@ -173,11 +165,12 @@
173165 return count;
174166 }
175167
176
-static ssize_t show_temp_hyst(struct device *dev,
168
+static ssize_t temp_hyst_show(struct device *dev,
177169 struct device_attribute *devattr, char *buf)
178170 {
179171 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
180172 struct lm92_data *data = lm92_update_device(dev);
173
+
181174 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])
182175 - TEMP_FROM_REG(data->temp[t_hyst]));
183176 }
....@@ -186,13 +179,14 @@
186179 struct device_attribute *attr, char *buf)
187180 {
188181 struct lm92_data *data = lm92_update_device(dev);
182
+
189183 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[t_min])
190184 + TEMP_FROM_REG(data->temp[t_hyst]));
191185 }
192186
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)
196190 {
197191 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
198192 struct lm92_data *data = dev_get_drvdata(dev);
....@@ -206,7 +200,7 @@
206200
207201 val = clamp_val(val, -120000, 220000);
208202 mutex_lock(&data->update_lock);
209
- data->temp[t_hyst] =
203
+ data->temp[t_hyst] =
210204 TEMP_TO_REG(TEMP_FROM_REG(data->temp[attr->index]) - val);
211205 i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST,
212206 data->temp[t_hyst]);
....@@ -218,10 +212,11 @@
218212 char *buf)
219213 {
220214 struct lm92_data *data = lm92_update_device(dev);
215
+
221216 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp[t_input]));
222217 }
223218
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,
225220 char *buf)
226221 {
227222 int bitnr = to_sensor_dev_attr(attr)->index;
....@@ -229,21 +224,17 @@
229224 return sprintf(buf, "%d\n", (data->temp[t_input] >> bitnr) & 1);
230225 }
231226
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);
239231 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);
243234 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);
247238
248239 /*
249240 * Detection and registration
....@@ -301,8 +292,7 @@
301292 return 0;
302293 }
303294
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)
306296 {
307297 struct device *hwmon_dev;
308298 struct lm92_data *data;
....@@ -324,7 +314,6 @@
324314 return PTR_ERR_OR_ZERO(hwmon_dev);
325315 }
326316
327
-
328317 /*
329318 * Module and driver stuff
330319 */
....@@ -341,7 +330,7 @@
341330 .driver = {
342331 .name = "lm92",
343332 },
344
- .probe = lm92_probe,
333
+ .probe_new = lm92_probe,
345334 .id_table = lm92_id,
346335 .detect = lm92_detect,
347336 .address_list = normal_i2c,