From efde723fdac02111872bff606ef362074fc1efa8 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 20 Jul 2005 23:03:50 +0200 Subject: [PATCH] I2C: Separate non-i2c hwmon drivers from i2c-core (1/9) Temporarily export a few structures and functions from i2c-core, because we will soon need them in i2c-isa. Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'drivers/i2c/i2c-core.c') diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 4a9ead277596..7a7837ae3114 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -61,7 +61,7 @@ static int i2c_bus_resume(struct device * dev) return rc; } -static struct bus_type i2c_bus_type = { +struct bus_type i2c_bus_type = { .name = "i2c", .match = i2c_device_match, .suspend = i2c_bus_suspend, @@ -78,13 +78,13 @@ static int i2c_device_remove(struct device *dev) return 0; } -static void i2c_adapter_dev_release(struct device *dev) +void i2c_adapter_dev_release(struct device *dev) { struct i2c_adapter *adap = dev_to_i2c_adapter(dev); complete(&adap->dev_released); } -static struct device_driver i2c_adapter_driver = { +struct device_driver i2c_adapter_driver = { .name = "i2c_adapter", .bus = &i2c_bus_type, .probe = i2c_device_probe, @@ -97,7 +97,7 @@ static void i2c_adapter_class_dev_release(struct class_device *dev) complete(&adap->class_dev_released); } -static struct class i2c_adapter_class = { +struct class i2c_adapter_class = { .name = "i2c-adapter", .release = &i2c_adapter_class_dev_release, }; @@ -1171,6 +1171,12 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, } +/* Next four are needed by i2c-isa */ +EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); +EXPORT_SYMBOL_GPL(i2c_adapter_driver); +EXPORT_SYMBOL_GPL(i2c_adapter_class); +EXPORT_SYMBOL_GPL(i2c_bus_type); + EXPORT_SYMBOL(i2c_add_adapter); EXPORT_SYMBOL(i2c_del_adapter); EXPORT_SYMBOL(i2c_add_driver); -- cgit v1.2.1 From 7bef559455fc71f66f8573cc1aafe1dd33966c1c Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 27 Jul 2005 22:14:49 +0200 Subject: [PATCH] I2C: refactor message in i2c_detach_client We could refactor the error message 34 different i2c drivers print if i2c_detach_client() fails in this function itself. Saves quite a few lines of code. Documentation is updated to reflect that change. Note that this patch should be applied after Rudolf Marek's w83792d patches. Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers/i2c/i2c-core.c') diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 7a7837ae3114..b0bceb2fb8b1 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -449,8 +449,12 @@ int i2c_detach_client(struct i2c_client *client) struct i2c_adapter *adapter = client->adapter; int res = 0; - if ((client->flags & I2C_CLIENT_ALLOW_USE) && (client->usage_count > 0)) + if ((client->flags & I2C_CLIENT_ALLOW_USE) + && (client->usage_count > 0)) { + dev_warn(&client->dev, "Client [%s] still busy, " + "can't detach\n", client->name); return -EBUSY; + } if (adapter->client_unregister) { res = adapter->client_unregister(client); -- cgit v1.2.1 From cdcb19219714c796ddef1202e952566c5f86354d Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Thu, 28 Jul 2005 23:09:40 +0200 Subject: [PATCH] I2C: inline i2c_adapter_id We could inline i2c_adapter_id, as it is really, really short. Doing so saves a few bytes both in i2c-core and in the drivers using this function. before after diff drivers/hwmon/adm1026.ko 41344 41305 -39 drivers/hwmon/asb100.ko 27325 27246 -79 drivers/hwmon/gl518sm.ko 20824 20785 -39 drivers/hwmon/it87.ko 26419 26380 -39 drivers/hwmon/lm78.ko 21424 21385 -39 drivers/hwmon/lm85.ko 41034 40939 -95 drivers/hwmon/w83781d.ko 39561 39514 -47 drivers/hwmon/w83792d.ko 32979 32932 -47 drivers/i2c/i2c-core.ko 24708 24531 -177 Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'drivers/i2c/i2c-core.c') diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index b0bceb2fb8b1..20f92e355f56 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -759,14 +759,6 @@ int i2c_probe(struct i2c_adapter *adapter, return 0; } -/* - * return id number for a specific adapter - */ -int i2c_adapter_id(struct i2c_adapter *adap) -{ - return adap->nr; -} - struct i2c_adapter* i2c_get_adapter(int id) { struct i2c_adapter *adapter; @@ -1196,7 +1188,6 @@ EXPORT_SYMBOL(i2c_master_send); EXPORT_SYMBOL(i2c_master_recv); EXPORT_SYMBOL(i2c_control); EXPORT_SYMBOL(i2c_transfer); -EXPORT_SYMBOL(i2c_adapter_id); EXPORT_SYMBOL(i2c_get_adapter); EXPORT_SYMBOL(i2c_put_adapter); EXPORT_SYMBOL(i2c_probe); -- cgit v1.2.1 From b6d7b3d1b5a388b7e9af2629a9ecccedee064078 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 31 Jul 2005 19:02:53 +0200 Subject: [PATCH] I2C: Improve core debugging messages The debugging messages in i2c-core are more confusing than helpful. Some lack their trailing newline, some lack a prefix, some are redundant, some lack precious information. Here is my attempt to introduce some standardization in there. I also changed two messages in i2c-dev to make it clear they come from i2c-dev. Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core.c | 63 +++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) (limited to 'drivers/i2c/i2c-core.c') diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 20f92e355f56..19d8a994b3b7 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -188,6 +188,8 @@ int i2c_add_adapter(struct i2c_adapter *adap) strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); class_device_register(&adap->class_dev); + dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); + /* inform drivers of new adapters */ list_for_each(item,&drivers) { driver = list_entry(item, struct i2c_driver, list); @@ -196,8 +198,6 @@ int i2c_add_adapter(struct i2c_adapter *adap) driver->attach_adapter(adap); } - dev_dbg(&adap->dev, "registered as adapter #%d\n", adap->nr); - out_unlock: up(&core_lists); return res; @@ -220,8 +220,8 @@ int i2c_del_adapter(struct i2c_adapter *adap) break; } if (adap_from_list != adap) { - pr_debug("I2C: Attempting to delete an unregistered " - "adapter\n"); + pr_debug("i2c-core: attempting to delete unregistered " + "adapter [%s]\n", adap->name); res = -EINVAL; goto out_unlock; } @@ -230,9 +230,8 @@ int i2c_del_adapter(struct i2c_adapter *adap) driver = list_entry(item, struct i2c_driver, list); if (driver->detach_adapter) if ((res = driver->detach_adapter(adap))) { - dev_warn(&adap->dev, "can't detach adapter " - "while detaching driver %s: driver " - "not detached!\n", driver->name); + dev_err(&adap->dev, "detach_adapter failed " + "for driver [%s]\n", driver->name); goto out_unlock; } } @@ -247,9 +246,8 @@ int i2c_del_adapter(struct i2c_adapter *adap) * must be deleted, as this would cause invalid states. */ if ((res=client->driver->detach_client(client))) { - dev_err(&adap->dev, "adapter not " - "unregistered, because client at " - "address %02x can't be detached. ", + dev_err(&adap->dev, "detach_client failed for client " + "[%s] at address 0x%02x\n", client->name, client->addr); goto out_unlock; } @@ -270,7 +268,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) /* free dynamically allocated bus id */ idr_remove(&i2c_adapter_idr, adap->nr); - dev_dbg(&adap->dev, "adapter unregistered\n"); + dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); out_unlock: up(&core_lists); @@ -303,7 +301,7 @@ int i2c_add_driver(struct i2c_driver *driver) goto out_unlock; list_add_tail(&driver->list,&drivers); - pr_debug("i2c-core: driver %s registered.\n", driver->name); + pr_debug("i2c-core: driver [%s] registered\n", driver->name); /* now look for instances of driver on our adapters */ if (driver->flags & I2C_DF_NOTIFY) { @@ -331,21 +329,17 @@ int i2c_del_driver(struct i2c_driver *driver) /* Have a look at each adapter, if clients of this driver are still * attached. If so, detach them to be able to kill the driver * afterwards. - */ - pr_debug("i2c-core: unregister_driver - looking for clients.\n"); - /* removing clients does not depend on the notify flag, else + * + * Removing clients does not depend on the notify flag, else * invalid operation might (will!) result, when using stale client * pointers. */ list_for_each(item1,&adapters) { adap = list_entry(item1, struct i2c_adapter, list); - dev_dbg(&adap->dev, "examining adapter\n"); if (driver->detach_adapter) { if ((res = driver->detach_adapter(adap))) { - dev_warn(&adap->dev, "while unregistering " - "dummy driver %s, adapter could " - "not be detached properly; driver " - "not unloaded!",driver->name); + dev_err(&adap->dev, "detach_adapter failed " + "for driver [%s]\n", driver->name); goto out_unlock; } } else { @@ -353,16 +347,13 @@ int i2c_del_driver(struct i2c_driver *driver) client = list_entry(item2, struct i2c_client, list); if (client->driver != driver) continue; - pr_debug("i2c-core.o: detaching client %s:\n", client->name); + dev_dbg(&adap->dev, "detaching client [%s] " + "at 0x%02x\n", client->name, + client->addr); if ((res = driver->detach_client(client))) { - dev_err(&adap->dev, "while " - "unregistering driver " - "`%s', the client at " - "address %02x of " - "adapter could not " - "be detached; driver " - "not unloaded!", - driver->name, + dev_err(&adap->dev, "detach_client " + "failed for client [%s] at " + "0x%02x\n", client->name, client->addr); goto out_unlock; } @@ -372,7 +363,7 @@ int i2c_del_driver(struct i2c_driver *driver) driver_unregister(&driver->driver); list_del(&driver->list); - pr_debug("i2c-core: driver unregistered: %s\n", driver->name); + pr_debug("i2c-core: driver [%s] unregistered\n", driver->name); out_unlock: up(&core_lists); @@ -417,15 +408,12 @@ int i2c_attach_client(struct i2c_client *client) if (adapter->client_register) { if (adapter->client_register(client)) { - dev_warn(&adapter->dev, "warning: client_register " - "seems to have failed for client %02x\n", - client->addr); + dev_dbg(&adapter->dev, "client_register " + "failed for client [%s] at 0x%02x\n", + client->name, client->addr); } } - dev_dbg(&adapter->dev, "client [%s] registered to adapter\n", - client->name); - if (client->flags & I2C_CLIENT_ALLOW_USE) client->usage_count = 0; @@ -436,7 +424,8 @@ int i2c_attach_client(struct i2c_client *client) snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), "%d-%04x", i2c_adapter_id(adapter), client->addr); - pr_debug("registering %s\n", client->dev.bus_id); + dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", + client->name, client->dev.bus_id); device_register(&client->dev); device_create_file(&client->dev, &dev_attr_client_name); -- cgit v1.2.1 From 9fc6adfa9adf2be84119a3c2592287f33bd1dff2 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 31 Jul 2005 21:20:43 +0200 Subject: [PATCH] hwmon: hwmon vs i2c, second round (01/11) Add support for kind-forced addresses to i2c_probe, like i2c_detect has for (essentially) hardware monitoring drivers. Note that this change will slightly increase the size of the drivers using I2C_CLIENT_INSMOD, with no immediate benefit. This is a requirement if we want to merge i2c_probe and i2c_detect though, and seems a reasonable price to pay in comparison with the previous cleanups which saved much more than that (such as the i2c-isa cleanup or the i2c address ranges removal.) Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'drivers/i2c/i2c-core.c') diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 19d8a994b3b7..372b5996d045 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -662,6 +662,28 @@ int i2c_control(struct i2c_client *client, * Will not work for 10-bit addresses! * ---------------------------------------------------- */ +/* Return: kind (>= 0) if force found, -1 if not found */ +static inline int i2c_probe_forces(struct i2c_adapter *adapter, int addr, + unsigned short **forces) +{ + unsigned short kind; + int j, adap_id = i2c_adapter_id(adapter); + + for (kind = 0; forces[kind]; kind++) { + for (j = 0; forces[kind][j] != I2C_CLIENT_END; j += 2) { + if ((forces[kind][j] == adap_id || + forces[kind][j] == ANY_I2C_BUS) + && forces[kind][j + 1] == addr) { + dev_dbg(&adapter->dev, "found force parameter, " + "addr 0x%02x, kind %u\n", addr, kind); + return kind; + } + } + } + + return -1; +} + int i2c_probe(struct i2c_adapter *adapter, struct i2c_client_address_data *address_data, int (*found_proc) (struct i2c_adapter *, int, int)) @@ -683,19 +705,15 @@ int i2c_probe(struct i2c_adapter *adapter, at all */ found = 0; - for (i = 0; !found && (address_data->force[i] != I2C_CLIENT_END); i += 2) { - if (((adap_id == address_data->force[i]) || - (address_data->force[i] == ANY_I2C_BUS)) && - (addr == address_data->force[i+1])) { - dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", - adap_id, addr); - if ((err = found_proc(adapter,addr,0))) + if (address_data->forces) { + int kind = i2c_probe_forces(adapter, addr, + address_data->forces); + if (kind >= 0) { /* force found */ + if ((err = found_proc(adapter, addr, kind))) return err; - found = 1; + continue; } } - if (found) - continue; /* If this address is in one of the ignores, we can forget about it right now */ -- cgit v1.2.1 From a89ba0bc02e82920a0f4137aa5d655ac0366cc28 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Tue, 9 Aug 2005 20:17:55 +0200 Subject: [PATCH] I2C: Rewrite i2c_probe i2c_probe was quite complex and slow, so I rewrote it in a more efficient and hopefully clearer way. Note that this slightly changes the way the module parameters are handled. This shouldn't change anything for the most common cases though. For one thing, the function now respects the order of the parameters for address probing. It used to always do lower addresses first. The new approach gives the user more control. For another, ignore addresses don't overrule probe addresses anymore. This could have been restored the way it was at the cost of a few more lines of code, but I don't think it's worth it. Both lists are given as module parameters, so a user would be quite silly to specify the same addresses in both lists. The normal addresses list is the only one that isn't controlled by a module parameter, thus is the only one the user may reasonably want to remove an address from. Another significant change is the fact that i2c_probe() will no more stop when a detection function returns -ENODEV. Just because a driver found a chip it doesn't support isn't a valid reason to stop all probings for this one driver. This closes the long standing lm_sensors ticket #1807. http://www2.lm-sensors.nu/~lm78/readticket.cgi?ticket=1807 I updated the documentation accordingly. In terms of algorithmic complexity, the new code is way better. If I is the ignore address count, P the probe address count, N the normal address count and F the force address count, the old code was doing 128 * (F + I + P + N) iterations max, while the new code does F + P + ((I+1) * N) iterations max. For the most common case where F, I and P are empty, this is down from 128 * N to N. Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core.c | 165 ++++++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 76 deletions(-) (limited to 'drivers/i2c/i2c-core.c') diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 372b5996d045..bee0148dfab8 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -662,107 +662,120 @@ int i2c_control(struct i2c_client *client, * Will not work for 10-bit addresses! * ---------------------------------------------------- */ -/* Return: kind (>= 0) if force found, -1 if not found */ -static inline int i2c_probe_forces(struct i2c_adapter *adapter, int addr, - unsigned short **forces) +static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind, + int (*found_proc) (struct i2c_adapter *, int, int)) { - unsigned short kind; - int j, adap_id = i2c_adapter_id(adapter); - - for (kind = 0; forces[kind]; kind++) { - for (j = 0; forces[kind][j] != I2C_CLIENT_END; j += 2) { - if ((forces[kind][j] == adap_id || - forces[kind][j] == ANY_I2C_BUS) - && forces[kind][j + 1] == addr) { - dev_dbg(&adapter->dev, "found force parameter, " - "addr 0x%02x, kind %u\n", addr, kind); - return kind; - } - } + int err; + + /* Make sure the address is valid */ + if (addr < 0x03 || addr > 0x77) { + dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", + addr); + return -EINVAL; } - return -1; + /* Skip if already in use */ + if (i2c_check_addr(adapter, addr)) + return 0; + + /* Make sure there is something at this address, unless forced */ + if (kind < 0 + && i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) < 0) + return 0; + + /* Finally call the custom detection function */ + err = found_proc(adapter, addr, kind); + + /* -ENODEV can be returned if there is a chip at the given address + but it isn't supported by this chip driver. We catch it here as + this isn't an error. */ + return (err == -ENODEV) ? 0 : err; } int i2c_probe(struct i2c_adapter *adapter, struct i2c_client_address_data *address_data, int (*found_proc) (struct i2c_adapter *, int, int)) { - int addr,i,found,err; + int i, err; int adap_id = i2c_adapter_id(adapter); /* Forget it if we can't probe using SMBUS_QUICK */ if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK)) return -1; - for (addr = 0x00; addr <= 0x7f; addr++) { - - /* Skip if already in use */ - if (i2c_check_addr(adapter,addr)) - continue; - - /* If it is in one of the force entries, we don't do any detection - at all */ - found = 0; - - if (address_data->forces) { - int kind = i2c_probe_forces(adapter, addr, - address_data->forces); - if (kind >= 0) { /* force found */ - if ((err = found_proc(adapter, addr, kind))) - return err; - continue; - } - } - - /* If this address is in one of the ignores, we can forget about - it right now */ - for (i = 0; - !found && (address_data->ignore[i] != I2C_CLIENT_END); - i += 2) { - if (((adap_id == address_data->ignore[i]) || - ((address_data->ignore[i] == ANY_I2C_BUS))) && - (addr == address_data->ignore[i+1])) { - dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, " - "addr %04x\n", adap_id ,addr); - found = 1; + /* Force entries are done first, and are not affected by ignore + entries */ + if (address_data->forces) { + unsigned short **forces = address_data->forces; + int kind; + + for (kind = 0; forces[kind]; kind++) { + for (i = 0; forces[kind][i] != I2C_CLIENT_END; + i += 2) { + if (forces[kind][i] == adap_id + || forces[kind][i] == ANY_I2C_BUS) { + dev_dbg(&adapter->dev, "found force " + "parameter for adapter %d, " + "addr 0x%02x, kind %d\n", + adap_id, forces[kind][i + 1], + kind); + err = i2c_probe_address(adapter, + forces[kind][i + 1], + kind, found_proc); + if (err) + return err; + } } } - if (found) - continue; + } - /* Now, we will do a detection, but only if it is in the normal or - probe entries */ - for (i = 0; - !found && (address_data->normal_i2c[i] != I2C_CLIENT_END); - i += 1) { - if (addr == address_data->normal_i2c[i]) { - found = 1; - dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, " - "addr %02x\n", adap_id, addr); - } + /* Probe entries are done second, and are not affected by ignore + entries either */ + for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) { + if (address_data->probe[i] == adap_id + || address_data->probe[i] == ANY_I2C_BUS) { + dev_dbg(&adapter->dev, "found probe parameter for " + "adapter %d, addr 0x%02x\n", adap_id, + address_data->probe[i + 1]); + err = i2c_probe_address(adapter, + address_data->probe[i + 1], + -1, found_proc); + if (err) + return err; } + } - for (i = 0; - !found && (address_data->probe[i] != I2C_CLIENT_END); - i += 2) { - if (((adap_id == address_data->probe[i]) || - ((address_data->probe[i] == ANY_I2C_BUS))) && - (addr == address_data->probe[i+1])) { - found = 1; - dev_dbg(&adapter->dev, "found probe parameter for adapter %d, " - "addr %04x\n", adap_id,addr); + /* Normal entries are done last, unless shadowed by an ignore entry */ + for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) { + int j, ignore; + + ignore = 0; + for (j = 0; address_data->ignore[j] != I2C_CLIENT_END; + j += 2) { + if ((address_data->ignore[j] == adap_id || + address_data->ignore[j] == ANY_I2C_BUS) + && address_data->ignore[j + 1] + == address_data->normal_i2c[i]) { + dev_dbg(&adapter->dev, "found ignore " + "parameter for adapter %d, " + "addr 0x%02x\n", adap_id, + address_data->ignore[j + 1]); } + ignore = 1; + break; } - if (!found) + if (ignore) continue; - /* OK, so we really should examine this address. First check - whether there is some client here at all! */ - if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0) - if ((err = found_proc(adapter,addr,-1))) - return err; + dev_dbg(&adapter->dev, "found normal entry for adapter %d, " + "addr 0x%02x\n", adap_id, + address_data->normal_i2c[i]); + err = i2c_probe_address(adapter, address_data->normal_i2c[i], + -1, found_proc); + if (err) + return err; } + return 0; } -- cgit v1.2.1 From 4c9337da37c877e53a64696fc8524f642d446cba Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Tue, 9 Aug 2005 20:28:10 +0200 Subject: [PATCH] I2C: Centralize 24RF08 corruption prevention The 24RF08 corruption would better be prevented at i2c-core level than at chip driver level, for several reasons: * The second quick write should happen as soon as possible after the first one, so as to limit the risk that another command is issued on the bus inbetween, causing the corruption. * As a matter of fact, the protection code at driver level was reworked at least three times already, which proves how hard it is to get it right there, while it's straightforward at i2c-core level. * It's easy to add a new driver that would need the protection, and forget to add it. This did happen already. * As additional probing addresses can be passed to most i2c chip drivers as module parameters, virtually every i2c chip driver would need the protection if we want to be really safe. * Why duplicate code when we can easily avoid it? Signed-off-by: Jean Delvare Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'drivers/i2c/i2c-core.c') diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index bee0148dfab8..dda472e5e8be 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -679,9 +679,16 @@ static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind, return 0; /* Make sure there is something at this address, unless forced */ - if (kind < 0 - && i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) < 0) - return 0; + if (kind < 0) { + if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, + I2C_SMBUS_QUICK, NULL) < 0) + return 0; + + /* prevent 24RF08 corruption */ + if ((addr & ~0x0f) == 0x50) + i2c_smbus_xfer(adapter, addr, 0, 0, 0, + I2C_SMBUS_QUICK, NULL); + } /* Finally call the custom detection function */ err = found_proc(adapter, addr, kind); -- cgit v1.2.1