forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/drivers/hwmon/lineage-pem.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for Lineage Compact Power Line series of power entry modules.
34 *
....@@ -5,20 +6,6 @@
56 *
67 * Documentation:
78 * http://www.lineagepower.com/oem/pdf/CPLI2C.pdf
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
229 */
2310
2411 #include <linux/kernel.h>
....@@ -282,8 +269,8 @@
282269 * Show boolean, either a fault or an alarm.
283270 * .nr points to the register, .index is the bit mask to check
284271 */
285
-static ssize_t pem_show_bool(struct device *dev,
286
- struct device_attribute *da, char *buf)
272
+static ssize_t pem_bool_show(struct device *dev, struct device_attribute *da,
273
+ char *buf)
287274 {
288275 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(da);
289276 struct pem_data *data = pem_update_device(dev);
....@@ -296,7 +283,7 @@
296283 return snprintf(buf, PAGE_SIZE, "%d\n", !!status);
297284 }
298285
299
-static ssize_t pem_show_data(struct device *dev, struct device_attribute *da,
286
+static ssize_t pem_data_show(struct device *dev, struct device_attribute *da,
300287 char *buf)
301288 {
302289 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
....@@ -312,7 +299,7 @@
312299 return snprintf(buf, PAGE_SIZE, "%ld\n", value);
313300 }
314301
315
-static ssize_t pem_show_input(struct device *dev, struct device_attribute *da,
302
+static ssize_t pem_input_show(struct device *dev, struct device_attribute *da,
316303 char *buf)
317304 {
318305 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
....@@ -328,7 +315,7 @@
328315 return snprintf(buf, PAGE_SIZE, "%ld\n", value);
329316 }
330317
331
-static ssize_t pem_show_fan(struct device *dev, struct device_attribute *da,
318
+static ssize_t pem_fan_show(struct device *dev, struct device_attribute *da,
332319 char *buf)
333320 {
334321 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
....@@ -345,53 +332,42 @@
345332 }
346333
347334 /* Voltages */
348
-static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, pem_show_data, NULL,
349
- PEM_DATA_VOUT_LSB);
350
-static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, pem_show_bool, NULL,
351
- PEM_DATA_ALARM_1, ALRM1_VOUT_OUT_LIMIT);
352
-static SENSOR_DEVICE_ATTR_2(in1_crit_alarm, S_IRUGO, pem_show_bool, NULL,
353
- PEM_DATA_ALARM_1, ALRM1_OV_VOLT_SHUTDOWN);
354
-static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, pem_show_input, NULL,
355
- PEM_INPUT_VOLTAGE);
356
-static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, pem_show_bool, NULL,
357
- PEM_DATA_ALARM_1,
358
- ALRM1_VIN_OUT_LIMIT | ALRM1_PRIMARY_FAULT);
335
+static SENSOR_DEVICE_ATTR_RO(in1_input, pem_data, PEM_DATA_VOUT_LSB);
336
+static SENSOR_DEVICE_ATTR_2_RO(in1_alarm, pem_bool, PEM_DATA_ALARM_1,
337
+ ALRM1_VOUT_OUT_LIMIT);
338
+static SENSOR_DEVICE_ATTR_2_RO(in1_crit_alarm, pem_bool, PEM_DATA_ALARM_1,
339
+ ALRM1_OV_VOLT_SHUTDOWN);
340
+static SENSOR_DEVICE_ATTR_RO(in2_input, pem_input, PEM_INPUT_VOLTAGE);
341
+static SENSOR_DEVICE_ATTR_2_RO(in2_alarm, pem_bool, PEM_DATA_ALARM_1,
342
+ ALRM1_VIN_OUT_LIMIT | ALRM1_PRIMARY_FAULT);
359343
360344 /* Currents */
361
-static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, pem_show_data, NULL,
362
- PEM_DATA_CURRENT);
363
-static SENSOR_DEVICE_ATTR_2(curr1_alarm, S_IRUGO, pem_show_bool, NULL,
364
- PEM_DATA_ALARM_1, ALRM1_VIN_OVERCURRENT);
345
+static SENSOR_DEVICE_ATTR_RO(curr1_input, pem_data, PEM_DATA_CURRENT);
346
+static SENSOR_DEVICE_ATTR_2_RO(curr1_alarm, pem_bool, PEM_DATA_ALARM_1,
347
+ ALRM1_VIN_OVERCURRENT);
365348
366349 /* Power */
367
-static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, pem_show_input, NULL,
368
- PEM_INPUT_POWER_LSB);
369
-static SENSOR_DEVICE_ATTR_2(power1_alarm, S_IRUGO, pem_show_bool, NULL,
370
- PEM_DATA_ALARM_1, ALRM1_POWER_LIMIT);
350
+static SENSOR_DEVICE_ATTR_RO(power1_input, pem_input, PEM_INPUT_POWER_LSB);
351
+static SENSOR_DEVICE_ATTR_2_RO(power1_alarm, pem_bool, PEM_DATA_ALARM_1,
352
+ ALRM1_POWER_LIMIT);
371353
372354 /* Fans */
373
-static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, pem_show_fan, NULL,
374
- PEM_FAN_FAN1);
375
-static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, pem_show_fan, NULL,
376
- PEM_FAN_FAN2);
377
-static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, pem_show_fan, NULL,
378
- PEM_FAN_FAN3);
379
-static SENSOR_DEVICE_ATTR_2(fan1_alarm, S_IRUGO, pem_show_bool, NULL,
380
- PEM_DATA_ALARM_2, ALRM2_FAN_FAULT);
355
+static SENSOR_DEVICE_ATTR_RO(fan1_input, pem_fan, PEM_FAN_FAN1);
356
+static SENSOR_DEVICE_ATTR_RO(fan2_input, pem_fan, PEM_FAN_FAN2);
357
+static SENSOR_DEVICE_ATTR_RO(fan3_input, pem_fan, PEM_FAN_FAN3);
358
+static SENSOR_DEVICE_ATTR_2_RO(fan1_alarm, pem_bool, PEM_DATA_ALARM_2,
359
+ ALRM2_FAN_FAULT);
381360
382361 /* Temperatures */
383
-static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, pem_show_data, NULL,
384
- PEM_DATA_TEMP);
385
-static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, pem_show_data, NULL,
386
- PEM_DATA_TEMP_MAX);
387
-static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, pem_show_data, NULL,
388
- PEM_DATA_TEMP_CRIT);
389
-static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, pem_show_bool, NULL,
390
- PEM_DATA_ALARM_1, ALRM1_TEMP_WARNING);
391
-static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, pem_show_bool, NULL,
392
- PEM_DATA_ALARM_1, ALRM1_TEMP_SHUTDOWN);
393
-static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, pem_show_bool, NULL,
394
- PEM_DATA_ALARM_2, ALRM2_TEMP_FAULT);
362
+static SENSOR_DEVICE_ATTR_RO(temp1_input, pem_data, PEM_DATA_TEMP);
363
+static SENSOR_DEVICE_ATTR_RO(temp1_max, pem_data, PEM_DATA_TEMP_MAX);
364
+static SENSOR_DEVICE_ATTR_RO(temp1_crit, pem_data, PEM_DATA_TEMP_CRIT);
365
+static SENSOR_DEVICE_ATTR_2_RO(temp1_alarm, pem_bool, PEM_DATA_ALARM_1,
366
+ ALRM1_TEMP_WARNING);
367
+static SENSOR_DEVICE_ATTR_2_RO(temp1_crit_alarm, pem_bool, PEM_DATA_ALARM_1,
368
+ ALRM1_TEMP_SHUTDOWN);
369
+static SENSOR_DEVICE_ATTR_2_RO(temp1_fault, pem_bool, PEM_DATA_ALARM_2,
370
+ ALRM2_TEMP_FAULT);
395371
396372 static struct attribute *pem_attributes[] = {
397373 &sensor_dev_attr_in1_input.dev_attr.attr,
....@@ -441,8 +417,7 @@
441417 .attrs = pem_fan_attributes,
442418 };
443419
444
-static int pem_probe(struct i2c_client *client,
445
- const struct i2c_device_id *id)
420
+static int pem_probe(struct i2c_client *client)
446421 {
447422 struct i2c_adapter *adapter = client->adapter;
448423 struct device *dev = &client->dev;
....@@ -536,7 +511,7 @@
536511 .driver = {
537512 .name = "lineage_pem",
538513 },
539
- .probe = pem_probe,
514
+ .probe_new = pem_probe,
540515 .id_table = pem_id,
541516 };
542517