forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/hwmon/w83793.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * w83793.c - Linux kernel driver for hardware monitoring
34 * Copyright (C) 2006 Winbond Electronics Corp.
....@@ -7,20 +8,6 @@
78 * Watchdog driver part
89 * (Based partially on fschmd driver,
910 * Copyright 2007-2008 by Hans de Goede)
10
- *
11
- * This program is free software; you can redistribute it and/or modify
12
- * it under the terms of the GNU General Public License as published by
13
- * the Free Software Foundation - version 2.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
- * 02110-1301 USA.
2411 */
2512
2613 /*
....@@ -215,7 +202,6 @@
215202 }
216203
217204 struct w83793_data {
218
- struct i2c_client *lm75[2];
219205 struct device *hwmon_dev;
220206 struct mutex update_lock;
221207 char valid; /* !=0 if following fields are valid */
....@@ -296,8 +282,7 @@
296282
297283 static u8 w83793_read_value(struct i2c_client *client, u16 reg);
298284 static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value);
299
-static int w83793_probe(struct i2c_client *client,
300
- const struct i2c_device_id *id);
285
+static int w83793_probe(struct i2c_client *client);
301286 static int w83793_detect(struct i2c_client *client,
302287 struct i2c_board_info *info);
303288 static int w83793_remove(struct i2c_client *client);
....@@ -316,7 +301,7 @@
316301 .driver = {
317302 .name = "w83793",
318303 },
319
- .probe = w83793_probe,
304
+ .probe_new = w83793_probe,
320305 .remove = w83793_remove,
321306 .id_table = w83793_id,
322307 .detect = w83793_detect,
....@@ -1341,7 +1326,7 @@
13411326 /* Store pointer to data into filp's private data */
13421327 filp->private_data = data;
13431328
1344
- return nonseekable_open(inode, filp);
1329
+ return stream_open(inode, filp);
13451330 }
13461331
13471332 static int watchdog_close(struct inode *inode, struct file *filp)
....@@ -1471,6 +1456,7 @@
14711456 .release = watchdog_close,
14721457 .write = watchdog_write,
14731458 .unlocked_ioctl = watchdog_ioctl,
1459
+ .compat_ioctl = compat_ptr_ioctl,
14741460 };
14751461
14761462 /*
....@@ -1564,9 +1550,6 @@
15641550 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
15651551 device_remove_file(dev, &w83793_temp[i].dev_attr);
15661552
1567
- i2c_unregister_device(data->lm75[0]);
1568
- i2c_unregister_device(data->lm75[1]);
1569
-
15701553 /* Decrease data reference counter */
15711554 mutex_lock(&watchdog_data_mutex);
15721555 kref_put(&data->kref, w83793_release_resources);
....@@ -1578,11 +1561,10 @@
15781561 static int
15791562 w83793_detect_subclients(struct i2c_client *client)
15801563 {
1581
- int i, id, err;
1564
+ int i, id;
15821565 int address = client->addr;
15831566 u8 tmp;
15841567 struct i2c_adapter *adapter = client->adapter;
1585
- struct w83793_data *data = i2c_get_clientdata(client);
15861568
15871569 id = i2c_adapter_id(adapter);
15881570 if (force_subclients[0] == id && force_subclients[1] == address) {
....@@ -1593,8 +1575,7 @@
15931575 "invalid subclient "
15941576 "address %d; must be 0x48-0x4f\n",
15951577 force_subclients[i]);
1596
- err = -EINVAL;
1597
- goto ERROR_SC_0;
1578
+ return -EINVAL;
15981579 }
15991580 }
16001581 w83793_write_value(client, W83793_REG_I2C_SUBADDR,
....@@ -1603,29 +1584,20 @@
16031584 }
16041585
16051586 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
1606
- if (!(tmp & 0x08))
1607
- data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7));
1608
- if (!(tmp & 0x80)) {
1609
- if ((data->lm75[0] != NULL)
1610
- && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
1611
- dev_err(&client->dev,
1612
- "duplicate addresses 0x%x, "
1613
- "use force_subclients\n", data->lm75[0]->addr);
1614
- err = -ENODEV;
1615
- goto ERROR_SC_1;
1616
- }
1617
- data->lm75[1] = i2c_new_dummy(adapter,
1618
- 0x48 + ((tmp >> 4) & 0x7));
1587
+
1588
+ if (!(tmp & 0x88) && (tmp & 0x7) == ((tmp >> 4) & 0x7)) {
1589
+ dev_err(&client->dev,
1590
+ "duplicate addresses 0x%x, use force_subclient\n", 0x48 + (tmp & 0x7));
1591
+ return -ENODEV;
16191592 }
16201593
1594
+ if (!(tmp & 0x08))
1595
+ devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (tmp & 0x7));
1596
+
1597
+ if (!(tmp & 0x80))
1598
+ devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((tmp >> 4) & 0x7));
1599
+
16211600 return 0;
1622
-
1623
- /* Undo inits in case of errors */
1624
-
1625
-ERROR_SC_1:
1626
- i2c_unregister_device(data->lm75[0]);
1627
-ERROR_SC_0:
1628
- return err;
16291601 }
16301602
16311603 /* Return 0 if detection is successful, -ENODEV otherwise */
....@@ -1669,8 +1641,7 @@
16691641 return 0;
16701642 }
16711643
1672
-static int w83793_probe(struct i2c_client *client,
1673
- const struct i2c_device_id *id)
1644
+static int w83793_probe(struct i2c_client *client)
16741645 {
16751646 struct device *dev = &client->dev;
16761647 static const int watchdog_minors[] = {
....@@ -1958,9 +1929,6 @@
19581929
19591930 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
19601931 device_remove_file(dev, &w83793_temp[i].dev_attr);
1961
-
1962
- i2c_unregister_device(data->lm75[0]);
1963
- i2c_unregister_device(data->lm75[1]);
19641932 free_mem:
19651933 kfree(data);
19661934 exit:
....@@ -2123,7 +2091,7 @@
21232091 static u8 w83793_read_value(struct i2c_client *client, u16 reg)
21242092 {
21252093 struct w83793_data *data = i2c_get_clientdata(client);
2126
- u8 res = 0xff;
2094
+ u8 res;
21272095 u8 new_bank = reg >> 8;
21282096
21292097 new_bank |= data->bank & 0xfc;