Skip to content

Commit 3bfa08f

Browse files
author
Wolfram Sang
committed
Revert "i2c: Replace list-based mechanism for handling auto-detected clients"
This reverts commit 56a5066. Mux handling is not sufficiently implemented. It needs more time. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent c4d3dfd commit 3bfa08f

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,23 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adap)
17041704
}
17051705
EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
17061706

1707+
static void i2c_do_del_adapter(struct i2c_driver *driver,
1708+
struct i2c_adapter *adapter)
1709+
{
1710+
struct i2c_client *client, *_n;
1711+
1712+
/* Remove the devices we created ourselves as the result of hardware
1713+
* probing (using a driver's detect method) */
1714+
list_for_each_entry_safe(client, _n, &driver->clients, detected) {
1715+
if (client->adapter == adapter) {
1716+
dev_dbg(&adapter->dev, "Removing %s at 0x%x\n",
1717+
client->name, client->addr);
1718+
list_del(&client->detected);
1719+
i2c_unregister_device(client);
1720+
}
1721+
}
1722+
}
1723+
17071724
static int __unregister_client(struct device *dev, void *dummy)
17081725
{
17091726
struct i2c_client *client = i2c_verify_client(dev);
@@ -1719,6 +1736,12 @@ static int __unregister_dummy(struct device *dev, void *dummy)
17191736
return 0;
17201737
}
17211738

1739+
static int __process_removed_adapter(struct device_driver *d, void *data)
1740+
{
1741+
i2c_do_del_adapter(to_i2c_driver(d), data);
1742+
return 0;
1743+
}
1744+
17221745
/**
17231746
* i2c_del_adapter - unregister I2C adapter
17241747
* @adap: the adapter being unregistered
@@ -1742,6 +1765,11 @@ void i2c_del_adapter(struct i2c_adapter *adap)
17421765
}
17431766

17441767
i2c_acpi_remove_space_handler(adap);
1768+
/* Tell drivers about this removal */
1769+
mutex_lock(&core_lock);
1770+
bus_for_each_drv(&i2c_bus_type, NULL, adap,
1771+
__process_removed_adapter);
1772+
mutex_unlock(&core_lock);
17451773

17461774
/* Remove devices instantiated from sysfs */
17471775
mutex_lock_nested(&adap->userspace_clients_lock,
@@ -1760,10 +1788,8 @@ void i2c_del_adapter(struct i2c_adapter *adap)
17601788
* we can't remove the dummy devices during the first pass: they
17611789
* could have been instantiated by real devices wishing to clean
17621790
* them up properly, so we give them a chance to do that first. */
1763-
mutex_lock(&core_lock);
17641791
device_for_each_child(&adap->dev, NULL, __unregister_client);
17651792
device_for_each_child(&adap->dev, NULL, __unregister_dummy);
1766-
mutex_unlock(&core_lock);
17671793

17681794
/* device name is gone after device_unregister */
17691795
dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
@@ -1983,6 +2009,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
19832009
/* add the driver to the list of i2c drivers in the driver core */
19842010
driver->driver.owner = owner;
19852011
driver->driver.bus = &i2c_bus_type;
2012+
INIT_LIST_HEAD(&driver->clients);
19862013

19872014
/* When registration returns, the driver core
19882015
* will have called probe() for all matching-but-unbound devices.
@@ -2000,13 +2027,10 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
20002027
}
20012028
EXPORT_SYMBOL(i2c_register_driver);
20022029

2003-
static int __i2c_unregister_detected_client(struct device *dev, void *argp)
2030+
static int __process_removed_driver(struct device *dev, void *data)
20042031
{
2005-
struct i2c_client *client = i2c_verify_client(dev);
2006-
2007-
if (client && client->flags & I2C_CLIENT_AUTO)
2008-
i2c_unregister_device(client);
2009-
2032+
if (dev->type == &i2c_adapter_type)
2033+
i2c_do_del_adapter(data, to_i2c_adapter(dev));
20102034
return 0;
20112035
}
20122036

@@ -2017,12 +2041,7 @@ static int __i2c_unregister_detected_client(struct device *dev, void *argp)
20172041
*/
20182042
void i2c_del_driver(struct i2c_driver *driver)
20192043
{
2020-
mutex_lock(&core_lock);
2021-
/* Satisfy __must_check, function can't fail */
2022-
if (driver_for_each_device(&driver->driver, NULL, NULL,
2023-
__i2c_unregister_detected_client)) {
2024-
}
2025-
mutex_unlock(&core_lock);
2044+
i2c_for_each_dev(driver, __process_removed_driver);
20262045

20272046
driver_unregister(&driver->driver);
20282047
pr_debug("driver [%s] unregistered\n", driver->driver.name);
@@ -2449,7 +2468,6 @@ static int i2c_detect_address(struct i2c_client *temp_client,
24492468
/* Finally call the custom detection function */
24502469
memset(&info, 0, sizeof(struct i2c_board_info));
24512470
info.addr = addr;
2452-
info.flags = I2C_CLIENT_AUTO;
24532471
err = driver->detect(temp_client, &info);
24542472
if (err) {
24552473
/* -ENODEV is returned if the detection fails. We catch it
@@ -2476,7 +2494,9 @@ static int i2c_detect_address(struct i2c_client *temp_client,
24762494
dev_dbg(&adapter->dev, "Creating %s at 0x%02x\n",
24772495
info.type, info.addr);
24782496
client = i2c_new_client_device(adapter, &info);
2479-
if (IS_ERR(client))
2497+
if (!IS_ERR(client))
2498+
list_add_tail(&client->detected, &driver->clients);
2499+
else
24802500
dev_err(&adapter->dev, "Failed creating %s at 0x%02x\n",
24812501
info.type, info.addr);
24822502
}

include/linux/i2c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ enum i2c_driver_flags {
244244
* @id_table: List of I2C devices supported by this driver
245245
* @detect: Callback for device detection
246246
* @address_list: The I2C addresses to probe (for detect)
247+
* @clients: List of detected clients we created (for i2c-core use only)
247248
* @flags: A bitmask of flags defined in &enum i2c_driver_flags
248249
*
249250
* The driver.owner field should be set to the module owner of this driver.
@@ -298,6 +299,7 @@ struct i2c_driver {
298299
/* Device detection callback for automatic device creation */
299300
int (*detect)(struct i2c_client *client, struct i2c_board_info *info);
300301
const unsigned short *address_list;
302+
struct list_head clients;
301303

302304
u32 flags;
303305
};
@@ -334,7 +336,6 @@ struct i2c_client {
334336
#define I2C_CLIENT_SLAVE 0x20 /* we are the slave */
335337
#define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */
336338
#define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */
337-
#define I2C_CLIENT_AUTO 0x100 /* client was auto-detected */
338339
#define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */
339340
/* Must match I2C_M_STOP|IGNORE_NAK */
340341

0 commit comments

Comments
 (0)