.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * w83791d.c - Part of lm_sensors, Linux kernel modules for hardware |
---|
3 | 4 | * monitoring |
---|
4 | 5 | * |
---|
5 | 6 | * 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. |
---|
20 | 7 | */ |
---|
21 | 8 | |
---|
22 | 9 | /* |
---|
.. | .. |
---|
286 | 273 | char valid; /* !=0 if following fields are valid */ |
---|
287 | 274 | unsigned long last_updated; /* In jiffies */ |
---|
288 | 275 | |
---|
289 | | - /* array of 2 pointers to subclients */ |
---|
290 | | - struct i2c_client *lm75[2]; |
---|
291 | | - |
---|
292 | 276 | /* volts */ |
---|
293 | 277 | u8 in[NUMBER_OF_VIN]; /* Register value */ |
---|
294 | 278 | u8 in_max[NUMBER_OF_VIN]; /* Register value */ |
---|
.. | .. |
---|
328 | 312 | u8 vrm; /* hwmon-vid */ |
---|
329 | 313 | }; |
---|
330 | 314 | |
---|
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); |
---|
333 | 316 | static int w83791d_detect(struct i2c_client *client, |
---|
334 | 317 | struct i2c_board_info *info); |
---|
335 | 318 | static int w83791d_remove(struct i2c_client *client); |
---|
.. | .. |
---|
355 | 338 | .driver = { |
---|
356 | 339 | .name = "w83791d", |
---|
357 | 340 | }, |
---|
358 | | - .probe = w83791d_probe, |
---|
| 341 | + .probe_new = w83791d_probe, |
---|
359 | 342 | .remove = w83791d_remove, |
---|
360 | 343 | .id_table = w83791d_id, |
---|
361 | 344 | .detect = w83791d_detect, |
---|
.. | .. |
---|
1271 | 1254 | static int w83791d_detect_subclients(struct i2c_client *client) |
---|
1272 | 1255 | { |
---|
1273 | 1256 | struct i2c_adapter *adapter = client->adapter; |
---|
1274 | | - struct w83791d_data *data = i2c_get_clientdata(client); |
---|
1275 | 1257 | int address = client->addr; |
---|
1276 | | - int i, id, err; |
---|
| 1258 | + int i, id; |
---|
1277 | 1259 | u8 val; |
---|
1278 | 1260 | |
---|
1279 | 1261 | id = i2c_adapter_id(adapter); |
---|
.. | .. |
---|
1285 | 1267 | "invalid subclient " |
---|
1286 | 1268 | "address %d; must be 0x48-0x4f\n", |
---|
1287 | 1269 | force_subclients[i]); |
---|
1288 | | - err = -ENODEV; |
---|
1289 | | - goto error_sc_0; |
---|
| 1270 | + return -ENODEV; |
---|
1290 | 1271 | } |
---|
1291 | 1272 | } |
---|
1292 | 1273 | w83791d_write(client, W83791D_REG_I2C_SUBADDR, |
---|
.. | .. |
---|
1295 | 1276 | } |
---|
1296 | 1277 | |
---|
1297 | 1278 | 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; |
---|
1312 | 1284 | } |
---|
1313 | 1285 | |
---|
| 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 | + |
---|
1314 | 1292 | 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; |
---|
1322 | 1293 | } |
---|
1323 | 1294 | |
---|
1324 | 1295 | |
---|
.. | .. |
---|
1367 | 1338 | return 0; |
---|
1368 | 1339 | } |
---|
1369 | 1340 | |
---|
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) |
---|
1372 | 1342 | { |
---|
1373 | 1343 | struct w83791d_data *data; |
---|
1374 | 1344 | struct device *dev = &client->dev; |
---|
.. | .. |
---|
1407 | 1377 | /* Register sysfs hooks */ |
---|
1408 | 1378 | err = sysfs_create_group(&client->dev.kobj, &w83791d_group); |
---|
1409 | 1379 | if (err) |
---|
1410 | | - goto error3; |
---|
| 1380 | + return err; |
---|
1411 | 1381 | |
---|
1412 | 1382 | /* Check if pins of fan/pwm 4-5 are in use as GPIO */ |
---|
1413 | 1383 | has_fanpwm45 = w83791d_read(client, W83791D_REG_GPIO) & 0x10; |
---|
.. | .. |
---|
1432 | 1402 | sysfs_remove_group(&client->dev.kobj, &w83791d_group_fanpwm45); |
---|
1433 | 1403 | error4: |
---|
1434 | 1404 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); |
---|
1435 | | -error3: |
---|
1436 | | - i2c_unregister_device(data->lm75[0]); |
---|
1437 | | - i2c_unregister_device(data->lm75[1]); |
---|
1438 | 1405 | return err; |
---|
1439 | 1406 | } |
---|
1440 | 1407 | |
---|
.. | .. |
---|
1444 | 1411 | |
---|
1445 | 1412 | hwmon_device_unregister(data->hwmon_dev); |
---|
1446 | 1413 | sysfs_remove_group(&client->dev.kobj, &w83791d_group); |
---|
1447 | | - |
---|
1448 | | - i2c_unregister_device(data->lm75[0]); |
---|
1449 | | - i2c_unregister_device(data->lm75[1]); |
---|
1450 | 1414 | |
---|
1451 | 1415 | return 0; |
---|
1452 | 1416 | } |
---|