hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/adm1025.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * adm1025.c
34 *
....@@ -12,7 +13,7 @@
1213 * resolution of about 0.5% of the nominal value). Temperature values are
1314 * reported with a 1 deg resolution and a 3 deg accuracy. Complete
1415 * datasheet can be obtained from Analog's website at:
15
- * http://www.onsemi.com/PowerSolutions/product.do?id=ADM1025
16
+ * https://www.onsemi.com/PowerSolutions/product.do?id=ADM1025
1617 *
1718 * This driver also supports the ADM1025A, which differs from the ADM1025
1819 * only in that it has "open-drain VID inputs while the ADM1025 has
....@@ -29,20 +30,6 @@
2930 * Since the ADM1025 was the first chipset supported by this driver, most
3031 * comments will refer to this chipset, but are actually general and
3132 * concern all supported chipsets, unless mentioned otherwise.
32
- *
33
- * This program is free software; you can redistribute it and/or modify
34
- * it under the terms of the GNU General Public License as published by
35
- * the Free Software Foundation; either version 2 of the License, or
36
- * (at your option) any later version.
37
- *
38
- * This program is distributed in the hope that it will be useful,
39
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
40
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41
- * GNU General Public License for more details.
42
- *
43
- * You should have received a copy of the GNU General Public License
44
- * along with this program; if not, write to the Free Software
45
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4633 */
4734
4835 #include <linux/module.h>
....@@ -174,7 +161,7 @@
174161 */
175162
176163 static ssize_t
177
-show_in(struct device *dev, struct device_attribute *attr, char *buf)
164
+in_show(struct device *dev, struct device_attribute *attr, char *buf)
178165 {
179166 int index = to_sensor_dev_attr(attr)->index;
180167 struct adm1025_data *data = adm1025_update_device(dev);
....@@ -183,7 +170,7 @@
183170 }
184171
185172 static ssize_t
186
-show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
173
+in_min_show(struct device *dev, struct device_attribute *attr, char *buf)
187174 {
188175 int index = to_sensor_dev_attr(attr)->index;
189176 struct adm1025_data *data = adm1025_update_device(dev);
....@@ -192,7 +179,7 @@
192179 }
193180
194181 static ssize_t
195
-show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
182
+in_max_show(struct device *dev, struct device_attribute *attr, char *buf)
196183 {
197184 int index = to_sensor_dev_attr(attr)->index;
198185 struct adm1025_data *data = adm1025_update_device(dev);
....@@ -201,7 +188,7 @@
201188 }
202189
203190 static ssize_t
204
-show_temp(struct device *dev, struct device_attribute *attr, char *buf)
191
+temp_show(struct device *dev, struct device_attribute *attr, char *buf)
205192 {
206193 int index = to_sensor_dev_attr(attr)->index;
207194 struct adm1025_data *data = adm1025_update_device(dev);
....@@ -209,7 +196,7 @@
209196 }
210197
211198 static ssize_t
212
-show_temp_min(struct device *dev, struct device_attribute *attr, char *buf)
199
+temp_min_show(struct device *dev, struct device_attribute *attr, char *buf)
213200 {
214201 int index = to_sensor_dev_attr(attr)->index;
215202 struct adm1025_data *data = adm1025_update_device(dev);
....@@ -217,15 +204,15 @@
217204 }
218205
219206 static ssize_t
220
-show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
207
+temp_max_show(struct device *dev, struct device_attribute *attr, char *buf)
221208 {
222209 int index = to_sensor_dev_attr(attr)->index;
223210 struct adm1025_data *data = adm1025_update_device(dev);
224211 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
225212 }
226213
227
-static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
228
- const char *buf, size_t count)
214
+static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
215
+ const char *buf, size_t count)
229216 {
230217 int index = to_sensor_dev_attr(attr)->index;
231218 struct adm1025_data *data = dev_get_drvdata(dev);
....@@ -245,8 +232,8 @@
245232 return count;
246233 }
247234
248
-static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
249
- const char *buf, size_t count)
235
+static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
236
+ const char *buf, size_t count)
250237 {
251238 int index = to_sensor_dev_attr(attr)->index;
252239 struct adm1025_data *data = dev_get_drvdata(dev);
....@@ -266,22 +253,28 @@
266253 return count;
267254 }
268255
269
-#define set_in(offset) \
270
-static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
271
- show_in, NULL, offset); \
272
-static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
273
- show_in_min, set_in_min, offset); \
274
-static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
275
- show_in_max, set_in_max, offset)
276
-set_in(0);
277
-set_in(1);
278
-set_in(2);
279
-set_in(3);
280
-set_in(4);
281
-set_in(5);
256
+static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
257
+static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
258
+static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
259
+static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
260
+static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
261
+static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
262
+static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
263
+static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
264
+static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
265
+static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
266
+static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
267
+static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
268
+static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
269
+static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
270
+static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
271
+static SENSOR_DEVICE_ATTR_RO(in5_input, in, 5);
272
+static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5);
273
+static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5);
282274
283
-static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
284
- const char *buf, size_t count)
275
+static ssize_t temp_min_store(struct device *dev,
276
+ struct device_attribute *attr, const char *buf,
277
+ size_t count)
285278 {
286279 int index = to_sensor_dev_attr(attr)->index;
287280 struct adm1025_data *data = dev_get_drvdata(dev);
....@@ -301,8 +294,9 @@
301294 return count;
302295 }
303296
304
-static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
305
- const char *buf, size_t count)
297
+static ssize_t temp_max_store(struct device *dev,
298
+ struct device_attribute *attr, const char *buf,
299
+ size_t count)
306300 {
307301 int index = to_sensor_dev_attr(attr)->index;
308302 struct adm1025_data *data = dev_get_drvdata(dev);
....@@ -322,15 +316,12 @@
322316 return count;
323317 }
324318
325
-#define set_temp(offset) \
326
-static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
327
- show_temp, NULL, offset - 1); \
328
-static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
329
- show_temp_min, set_temp_min, offset - 1); \
330
-static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
331
- show_temp_max, set_temp_max, offset - 1)
332
-set_temp(1);
333
-set_temp(2);
319
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
320
+static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
321
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
322
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
323
+static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
324
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
334325
335326 static ssize_t
336327 alarms_show(struct device *dev, struct device_attribute *attr, char *buf)
....@@ -341,21 +332,21 @@
341332 static DEVICE_ATTR_RO(alarms);
342333
343334 static ssize_t
344
-show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
335
+alarm_show(struct device *dev, struct device_attribute *attr, char *buf)
345336 {
346337 int bitnr = to_sensor_dev_attr(attr)->index;
347338 struct adm1025_data *data = adm1025_update_device(dev);
348339 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
349340 }
350
-static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
351
-static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
352
-static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
353
-static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
354
-static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
355
-static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
356
-static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 5);
357
-static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
358
-static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
341
+static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
342
+static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
343
+static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
344
+static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
345
+static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8);
346
+static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 9);
347
+static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 5);
348
+static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 4);
349
+static SENSOR_DEVICE_ATTR_RO(temp1_fault, alarm, 14);
359350
360351 static ssize_t
361352 cpu0_vid_show(struct device *dev, struct device_attribute *attr, char *buf)
....@@ -526,8 +517,7 @@
526517 (reg&0x7E)|0x01);
527518 }
528519
529
-static int adm1025_probe(struct i2c_client *client,
530
- const struct i2c_device_id *id)
520
+static int adm1025_probe(struct i2c_client *client)
531521 {
532522 struct device *dev = &client->dev;
533523 struct device *hwmon_dev;
....@@ -569,7 +559,7 @@
569559 .driver = {
570560 .name = "adm1025",
571561 },
572
- .probe = adm1025_probe,
562
+ .probe_new = adm1025_probe,
573563 .id_table = adm1025_id,
574564 .detect = adm1025_detect,
575565 .address_list = normal_i2c,