提交 c81406d6 编写于 作者: L Linus Torvalds

Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging

* 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
  i2c-core: Use per-adapter userspace device lists
  i2c: Fix probing of FSC hardware monitoring chips
  i2c-core: Erase pointer to clientdata on removal
...@@ -74,6 +74,11 @@ structure at all. You should use this to keep device-specific data. ...@@ -74,6 +74,11 @@ structure at all. You should use this to keep device-specific data.
/* retrieve the value */ /* retrieve the value */
void *i2c_get_clientdata(const struct i2c_client *client); void *i2c_get_clientdata(const struct i2c_client *client);
Note that starting with kernel 2.6.34, you don't have to set the `data' field
to NULL in remove() or if probe() failed anymore. The i2c-core does this
automatically on these occasions. Those are also the only times the core will
touch this field.
Accessing the client Accessing the client
==================== ====================
......
...@@ -40,12 +40,11 @@ ...@@ -40,12 +40,11 @@
#include "i2c-core.h" #include "i2c-core.h"
/* core_lock protects i2c_adapter_idr, userspace_devices, and guarantees /* core_lock protects i2c_adapter_idr, and guarantees
that device detection, deletion of detected devices, and attach_adapter that device detection, deletion of detected devices, and attach_adapter
and detach_adapter calls are serialized */ and detach_adapter calls are serialized */
static DEFINE_MUTEX(core_lock); static DEFINE_MUTEX(core_lock);
static DEFINE_IDR(i2c_adapter_idr); static DEFINE_IDR(i2c_adapter_idr);
static LIST_HEAD(userspace_devices);
static struct device_type i2c_client_type; static struct device_type i2c_client_type;
static int i2c_check_addr(struct i2c_adapter *adapter, int addr); static int i2c_check_addr(struct i2c_adapter *adapter, int addr);
...@@ -117,8 +116,10 @@ static int i2c_device_probe(struct device *dev) ...@@ -117,8 +116,10 @@ static int i2c_device_probe(struct device *dev)
dev_dbg(dev, "probe\n"); dev_dbg(dev, "probe\n");
status = driver->probe(client, i2c_match_id(driver->id_table, client)); status = driver->probe(client, i2c_match_id(driver->id_table, client));
if (status) if (status) {
client->driver = NULL; client->driver = NULL;
i2c_set_clientdata(client, NULL);
}
return status; return status;
} }
...@@ -139,8 +140,10 @@ static int i2c_device_remove(struct device *dev) ...@@ -139,8 +140,10 @@ static int i2c_device_remove(struct device *dev)
dev->driver = NULL; dev->driver = NULL;
status = 0; status = 0;
} }
if (status == 0) if (status == 0) {
client->driver = NULL; client->driver = NULL;
i2c_set_clientdata(client, NULL);
}
return status; return status;
} }
...@@ -538,9 +541,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, ...@@ -538,9 +541,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
return -EEXIST; return -EEXIST;
/* Keep track of the added device */ /* Keep track of the added device */
mutex_lock(&core_lock); i2c_lock_adapter(adap);
list_add_tail(&client->detected, &userspace_devices); list_add_tail(&client->detected, &adap->userspace_clients);
mutex_unlock(&core_lock); i2c_unlock_adapter(adap);
dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",
info.type, info.addr); info.type, info.addr);
...@@ -579,9 +582,10 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, ...@@ -579,9 +582,10 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
/* Make sure the device was added through sysfs */ /* Make sure the device was added through sysfs */
res = -ENOENT; res = -ENOENT;
mutex_lock(&core_lock); i2c_lock_adapter(adap);
list_for_each_entry_safe(client, next, &userspace_devices, detected) { list_for_each_entry_safe(client, next, &adap->userspace_clients,
if (client->addr == addr && client->adapter == adap) { detected) {
if (client->addr == addr) {
dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", dev_info(dev, "%s: Deleting device %s at 0x%02hx\n",
"delete_device", client->name, client->addr); "delete_device", client->name, client->addr);
...@@ -591,7 +595,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, ...@@ -591,7 +595,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
break; break;
} }
} }
mutex_unlock(&core_lock); i2c_unlock_adapter(adap);
if (res < 0) if (res < 0)
dev_err(dev, "%s: Can't find device in list\n", dev_err(dev, "%s: Can't find device in list\n",
...@@ -673,6 +677,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) ...@@ -673,6 +677,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
} }
rt_mutex_init(&adap->bus_lock); rt_mutex_init(&adap->bus_lock);
INIT_LIST_HEAD(&adap->userspace_clients);
/* Set default timeout to 1 second if not already set */ /* Set default timeout to 1 second if not already set */
if (adap->timeout == 0) if (adap->timeout == 0)
...@@ -875,14 +880,15 @@ int i2c_del_adapter(struct i2c_adapter *adap) ...@@ -875,14 +880,15 @@ int i2c_del_adapter(struct i2c_adapter *adap)
return res; return res;
/* Remove devices instantiated from sysfs */ /* Remove devices instantiated from sysfs */
list_for_each_entry_safe(client, next, &userspace_devices, detected) { i2c_lock_adapter(adap);
if (client->adapter == adap) { list_for_each_entry_safe(client, next, &adap->userspace_clients,
dev_dbg(&adap->dev, "Removing %s at 0x%x\n", detected) {
client->name, client->addr); dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
list_del(&client->detected); client->addr);
i2c_unregister_device(client); list_del(&client->detected);
} i2c_unregister_device(client);
} }
i2c_unlock_adapter(adap);
/* Detach any active clients. This can't fail, thus we do not /* Detach any active clients. This can't fail, thus we do not
checking the returned value. */ checking the returned value. */
...@@ -1260,12 +1266,23 @@ static int i2c_detect_address(struct i2c_client *temp_client, ...@@ -1260,12 +1266,23 @@ static int i2c_detect_address(struct i2c_client *temp_client,
return 0; return 0;
/* Make sure there is something at this address */ /* Make sure there is something at this address */
if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) < 0) if (addr == 0x73 && (adapter->class & I2C_CLASS_HWMON)) {
return 0; /* Special probe for FSC hwmon chips */
union i2c_smbus_data dummy;
/* Prevent 24RF08 corruption */ if (i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_READ, 0,
if ((addr & ~0x0f) == 0x50) I2C_SMBUS_BYTE_DATA, &dummy) < 0)
i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL); return 0;
} else {
if (i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_WRITE, 0,
I2C_SMBUS_QUICK, NULL) < 0)
return 0;
/* Prevent 24RF08 corruption */
if ((addr & ~0x0f) == 0x50)
i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_WRITE, 0,
I2C_SMBUS_QUICK, NULL);
}
/* Finally call the custom detection function */ /* Finally call the custom detection function */
memset(&info, 0, sizeof(struct i2c_board_info)); memset(&info, 0, sizeof(struct i2c_board_info));
......
...@@ -355,6 +355,8 @@ struct i2c_adapter { ...@@ -355,6 +355,8 @@ struct i2c_adapter {
int nr; int nr;
char name[48]; char name[48];
struct completion dev_released; struct completion dev_released;
struct list_head userspace_clients;
}; };
#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册