1. 关注unreg_slave接口
1.1 这个接口在哪里被调用呢?
在drivers/i2c/i2c-core-slave.c中
int i2c_slave_unregister(struct i2c_client *client)
{
int ret;
if (!client->adapter->algo->unreg_slave) { dev_err(&client->dev, "%s: not supported by adapter ", __func__); return -EOPNOTSUPP; } i2c_lock_bus(client->adapter, I2C_LOCK_ROOT_ADAPTER); ret = client->adapter->algo->unreg_slave(client); i2c_unlock_bus(client->adapter, I2C_LOCK_ROOT_ADAPTER); if (ret == 0) client->slave_cb = NULL; else dev_err(&client->dev, "%s: adapter returned error %d ", __func__, ret); return ret;
}
1.2 那么i2c_slave_unregister又是在哪里被调用的呢?
在drivers/i2c/i2c-slave-eeprom.c中被调用
static int i2c_slave_eeprom_remove(struct i2c_client *client) { struct eeprom_data *eeprom = i2c_get_clientdata(client); i2c_slave_unregister(client); sysfs_remove_bin_file(&client->dev.kobj, &eeprom->bin); return 0; }