forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/hwmon/w83791d.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * w83791d.c - Part of lm_sensors, Linux kernel modules for hardware
34 * monitoring
45 *
56 * Copyright (C) 2006-2007 Charles Spirakis <bezaur@gmail.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
207 */
218
229 /*
....@@ -286,9 +273,6 @@
286273 char valid; /* !=0 if following fields are valid */
287274 unsigned long last_updated; /* In jiffies */
288275
289
- /* array of 2 pointers to subclients */
290
- struct i2c_client *lm75[2];
291
-
292276 /* volts */
293277 u8 in[NUMBER_OF_VIN]; /* Register value */
294278 u8 in_max[NUMBER_OF_VIN]; /* Register value */
....@@ -328,8 +312,7 @@
328312 u8 vrm; /* hwmon-vid */
329313 };
330314
331
-static int w83791d_probe(struct i2c_client *client,
332
- const struct i2c_device_id *id);
315
+static int w83791d_probe(struct i2c_client *client);
333316 static int w83791d_detect(struct i2c_client *client,
334317 struct i2c_board_info *info);
335318 static int w83791d_remove(struct i2c_client *client);
....@@ -355,7 +338,7 @@
355338 .driver = {
356339 .name = "w83791d",
357340 },
358
- .probe = w83791d_probe,
341
+ .probe_new = w83791d_probe,
359342 .remove = w83791d_remove,
360343 .id_table = w83791d_id,
361344 .detect = w83791d_detect,
....@@ -1271,9 +1254,8 @@
12711254 static int w83791d_detect_subclients(struct i2c_client *client)
12721255 {
12731256 struct i2c_adapter *adapter = client->adapter;
1274
- struct w83791d_data *data = i2c_get_clientdata(client);
12751257 int address = client->addr;
1276
- int i, id, err;
1258
+ int i, id;
12771259 u8 val;
12781260
12791261 id = i2c_adapter_id(adapter);
....@@ -1285,8 +1267,7 @@
12851267 "invalid subclient "
12861268 "address %d; must be 0x48-0x4f\n",
12871269 force_subclients[i]);
1288
- err = -ENODEV;
1289
- goto error_sc_0;
1270
+ return -ENODEV;
12901271 }
12911272 }
12921273 w83791d_write(client, W83791D_REG_I2C_SUBADDR,
....@@ -1295,30 +1276,20 @@
12951276 }
12961277
12971278 val = w83791d_read(client, W83791D_REG_I2C_SUBADDR);
1298
- if (!(val & 0x08))
1299
- data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7));
1300
- if (!(val & 0x80)) {
1301
- if ((data->lm75[0] != NULL) &&
1302
- ((val & 0x7) == ((val >> 4) & 0x7))) {
1303
- dev_err(&client->dev,
1304
- "duplicate addresses 0x%x, "
1305
- "use force_subclient\n",
1306
- data->lm75[0]->addr);
1307
- err = -ENODEV;
1308
- goto error_sc_1;
1309
- }
1310
- data->lm75[1] = i2c_new_dummy(adapter,
1311
- 0x48 + ((val >> 4) & 0x7));
1279
+
1280
+ if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) {
1281
+ dev_err(&client->dev,
1282
+ "duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7));
1283
+ return -ENODEV;
13121284 }
13131285
1286
+ if (!(val & 0x08))
1287
+ devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (val & 0x7));
1288
+
1289
+ if (!(val & 0x80))
1290
+ devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((val >> 4) & 0x7));
1291
+
13141292 return 0;
1315
-
1316
-/* Undo inits in case of errors */
1317
-
1318
-error_sc_1:
1319
- i2c_unregister_device(data->lm75[0]);
1320
-error_sc_0:
1321
- return err;
13221293 }
13231294
13241295
....@@ -1367,8 +1338,7 @@
13671338 return 0;
13681339 }
13691340
1370
-static int w83791d_probe(struct i2c_client *client,
1371
- const struct i2c_device_id *id)
1341
+static int w83791d_probe(struct i2c_client *client)
13721342 {
13731343 struct w83791d_data *data;
13741344 struct device *dev = &client->dev;
....@@ -1407,7 +1377,7 @@
14071377 /* Register sysfs hooks */
14081378 err = sysfs_create_group(&client->dev.kobj, &w83791d_group);
14091379 if (err)
1410
- goto error3;
1380
+ return err;
14111381
14121382 /* Check if pins of fan/pwm 4-5 are in use as GPIO */
14131383 has_fanpwm45 = w83791d_read(client, W83791D_REG_GPIO) & 0x10;
....@@ -1432,9 +1402,6 @@
14321402 sysfs_remove_group(&client->dev.kobj, &w83791d_group_fanpwm45);
14331403 error4:
14341404 sysfs_remove_group(&client->dev.kobj, &w83791d_group);
1435
-error3:
1436
- i2c_unregister_device(data->lm75[0]);
1437
- i2c_unregister_device(data->lm75[1]);
14381405 return err;
14391406 }
14401407
....@@ -1444,9 +1411,6 @@
14441411
14451412 hwmon_device_unregister(data->hwmon_dev);
14461413 sysfs_remove_group(&client->dev.kobj, &w83791d_group);
1447
-
1448
- i2c_unregister_device(data->lm75[0]);
1449
- i2c_unregister_device(data->lm75[1]);
14501414
14511415 return 0;
14521416 }