| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * w83793.c - Linux kernel driver for hardware monitoring |
|---|
| 3 | 4 | * Copyright (C) 2006 Winbond Electronics Corp. |
|---|
| .. | .. |
|---|
| 7 | 8 | * Watchdog driver part |
|---|
| 8 | 9 | * (Based partially on fschmd driver, |
|---|
| 9 | 10 | * 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. |
|---|
| 24 | 11 | */ |
|---|
| 25 | 12 | |
|---|
| 26 | 13 | /* |
|---|
| .. | .. |
|---|
| 215 | 202 | } |
|---|
| 216 | 203 | |
|---|
| 217 | 204 | struct w83793_data { |
|---|
| 218 | | - struct i2c_client *lm75[2]; |
|---|
| 219 | 205 | struct device *hwmon_dev; |
|---|
| 220 | 206 | struct mutex update_lock; |
|---|
| 221 | 207 | char valid; /* !=0 if following fields are valid */ |
|---|
| .. | .. |
|---|
| 296 | 282 | |
|---|
| 297 | 283 | static u8 w83793_read_value(struct i2c_client *client, u16 reg); |
|---|
| 298 | 284 | 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); |
|---|
| 301 | 286 | static int w83793_detect(struct i2c_client *client, |
|---|
| 302 | 287 | struct i2c_board_info *info); |
|---|
| 303 | 288 | static int w83793_remove(struct i2c_client *client); |
|---|
| .. | .. |
|---|
| 316 | 301 | .driver = { |
|---|
| 317 | 302 | .name = "w83793", |
|---|
| 318 | 303 | }, |
|---|
| 319 | | - .probe = w83793_probe, |
|---|
| 304 | + .probe_new = w83793_probe, |
|---|
| 320 | 305 | .remove = w83793_remove, |
|---|
| 321 | 306 | .id_table = w83793_id, |
|---|
| 322 | 307 | .detect = w83793_detect, |
|---|
| .. | .. |
|---|
| 1341 | 1326 | /* Store pointer to data into filp's private data */ |
|---|
| 1342 | 1327 | filp->private_data = data; |
|---|
| 1343 | 1328 | |
|---|
| 1344 | | - return nonseekable_open(inode, filp); |
|---|
| 1329 | + return stream_open(inode, filp); |
|---|
| 1345 | 1330 | } |
|---|
| 1346 | 1331 | |
|---|
| 1347 | 1332 | static int watchdog_close(struct inode *inode, struct file *filp) |
|---|
| .. | .. |
|---|
| 1471 | 1456 | .release = watchdog_close, |
|---|
| 1472 | 1457 | .write = watchdog_write, |
|---|
| 1473 | 1458 | .unlocked_ioctl = watchdog_ioctl, |
|---|
| 1459 | + .compat_ioctl = compat_ptr_ioctl, |
|---|
| 1474 | 1460 | }; |
|---|
| 1475 | 1461 | |
|---|
| 1476 | 1462 | /* |
|---|
| .. | .. |
|---|
| 1564 | 1550 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) |
|---|
| 1565 | 1551 | device_remove_file(dev, &w83793_temp[i].dev_attr); |
|---|
| 1566 | 1552 | |
|---|
| 1567 | | - i2c_unregister_device(data->lm75[0]); |
|---|
| 1568 | | - i2c_unregister_device(data->lm75[1]); |
|---|
| 1569 | | - |
|---|
| 1570 | 1553 | /* Decrease data reference counter */ |
|---|
| 1571 | 1554 | mutex_lock(&watchdog_data_mutex); |
|---|
| 1572 | 1555 | kref_put(&data->kref, w83793_release_resources); |
|---|
| .. | .. |
|---|
| 1578 | 1561 | static int |
|---|
| 1579 | 1562 | w83793_detect_subclients(struct i2c_client *client) |
|---|
| 1580 | 1563 | { |
|---|
| 1581 | | - int i, id, err; |
|---|
| 1564 | + int i, id; |
|---|
| 1582 | 1565 | int address = client->addr; |
|---|
| 1583 | 1566 | u8 tmp; |
|---|
| 1584 | 1567 | struct i2c_adapter *adapter = client->adapter; |
|---|
| 1585 | | - struct w83793_data *data = i2c_get_clientdata(client); |
|---|
| 1586 | 1568 | |
|---|
| 1587 | 1569 | id = i2c_adapter_id(adapter); |
|---|
| 1588 | 1570 | if (force_subclients[0] == id && force_subclients[1] == address) { |
|---|
| .. | .. |
|---|
| 1593 | 1575 | "invalid subclient " |
|---|
| 1594 | 1576 | "address %d; must be 0x48-0x4f\n", |
|---|
| 1595 | 1577 | force_subclients[i]); |
|---|
| 1596 | | - err = -EINVAL; |
|---|
| 1597 | | - goto ERROR_SC_0; |
|---|
| 1578 | + return -EINVAL; |
|---|
| 1598 | 1579 | } |
|---|
| 1599 | 1580 | } |
|---|
| 1600 | 1581 | w83793_write_value(client, W83793_REG_I2C_SUBADDR, |
|---|
| .. | .. |
|---|
| 1603 | 1584 | } |
|---|
| 1604 | 1585 | |
|---|
| 1605 | 1586 | 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; |
|---|
| 1619 | 1592 | } |
|---|
| 1620 | 1593 | |
|---|
| 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 | + |
|---|
| 1621 | 1600 | 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; |
|---|
| 1629 | 1601 | } |
|---|
| 1630 | 1602 | |
|---|
| 1631 | 1603 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
|---|
| .. | .. |
|---|
| 1669 | 1641 | return 0; |
|---|
| 1670 | 1642 | } |
|---|
| 1671 | 1643 | |
|---|
| 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) |
|---|
| 1674 | 1645 | { |
|---|
| 1675 | 1646 | struct device *dev = &client->dev; |
|---|
| 1676 | 1647 | static const int watchdog_minors[] = { |
|---|
| .. | .. |
|---|
| 1958 | 1929 | |
|---|
| 1959 | 1930 | for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) |
|---|
| 1960 | 1931 | device_remove_file(dev, &w83793_temp[i].dev_attr); |
|---|
| 1961 | | - |
|---|
| 1962 | | - i2c_unregister_device(data->lm75[0]); |
|---|
| 1963 | | - i2c_unregister_device(data->lm75[1]); |
|---|
| 1964 | 1932 | free_mem: |
|---|
| 1965 | 1933 | kfree(data); |
|---|
| 1966 | 1934 | exit: |
|---|
| .. | .. |
|---|
| 2123 | 2091 | static u8 w83793_read_value(struct i2c_client *client, u16 reg) |
|---|
| 2124 | 2092 | { |
|---|
| 2125 | 2093 | struct w83793_data *data = i2c_get_clientdata(client); |
|---|
| 2126 | | - u8 res = 0xff; |
|---|
| 2094 | + u8 res; |
|---|
| 2127 | 2095 | u8 new_bank = reg >> 8; |
|---|
| 2128 | 2096 | |
|---|
| 2129 | 2097 | new_bank |= data->bank & 0xfc; |
|---|