aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-amd756-s4882.c27
-rw-r--r--drivers/i2c/busses/i2c-mpc.c104
-rw-r--r--drivers/i2c/busses/i2c-nforce2-s4985.c31
-rw-r--r--drivers/i2c/chips/eeprom.c92
-rw-r--r--drivers/i2c/chips/max6875.c120
-rw-r--r--drivers/i2c/chips/pca9539.c109
-rw-r--r--drivers/i2c/chips/pcf8574.c108
-rw-r--r--drivers/i2c/chips/pcf8575.c96
-rw-r--r--drivers/i2c/chips/pcf8591.c94
-rw-r--r--drivers/i2c/i2c-core.c4
10 files changed, 340 insertions, 445 deletions
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
index 2f150e33c74c..72872d1e63ef 100644
--- a/drivers/i2c/busses/i2c-amd756-s4882.c
+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
@@ -155,6 +155,16 @@ static int __init amd756_s4882_init(void)
155 int i, error; 155 int i, error;
156 union i2c_smbus_data ioconfig; 156 union i2c_smbus_data ioconfig;
157 157
158 /* Configure the PCA9556 multiplexer */
159 ioconfig.byte = 0x00; /* All I/O to output mode */
160 error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
161 I2C_SMBUS_BYTE_DATA, &ioconfig);
162 if (error) {
163 dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n");
164 error = -EIO;
165 goto ERROR0;
166 }
167
158 /* Unregister physical bus */ 168 /* Unregister physical bus */
159 error = i2c_del_adapter(&amd756_smbus); 169 error = i2c_del_adapter(&amd756_smbus);
160 if (error) { 170 if (error) {
@@ -198,22 +208,11 @@ static int __init amd756_s4882_init(void)
198 s4882_algo[3].smbus_xfer = amd756_access_virt3; 208 s4882_algo[3].smbus_xfer = amd756_access_virt3;
199 s4882_algo[4].smbus_xfer = amd756_access_virt4; 209 s4882_algo[4].smbus_xfer = amd756_access_virt4;
200 210
201 /* Configure the PCA9556 multiplexer */
202 ioconfig.byte = 0x00; /* All I/O to output mode */
203 error = amd756_smbus.algo->smbus_xfer(&amd756_smbus, 0x18, 0,
204 I2C_SMBUS_WRITE, 0x03,
205 I2C_SMBUS_BYTE_DATA, &ioconfig);
206 if (error) {
207 dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n");
208 error = -EIO;
209 goto ERROR3;
210 }
211
212 /* Register virtual adapters */ 211 /* Register virtual adapters */
213 for (i = 0; i < 5; i++) { 212 for (i = 0; i < 5; i++) {
214 error = i2c_add_adapter(s4882_adapter+i); 213 error = i2c_add_adapter(s4882_adapter+i);
215 if (error) { 214 if (error) {
216 dev_err(&amd756_smbus.dev, 215 printk(KERN_ERR "i2c-amd756-s4882: "
217 "Virtual adapter %d registration " 216 "Virtual adapter %d registration "
218 "failed, module not inserted\n", i); 217 "failed, module not inserted\n", i);
219 for (i--; i >= 0; i--) 218 for (i--; i >= 0; i--)
@@ -252,8 +251,8 @@ static void __exit amd756_s4882_exit(void)
252 251
253 /* Restore physical bus */ 252 /* Restore physical bus */
254 if (i2c_add_adapter(&amd756_smbus)) 253 if (i2c_add_adapter(&amd756_smbus))
255 dev_err(&amd756_smbus.dev, "Physical bus restoration " 254 printk(KERN_ERR "i2c-amd756-s4882: "
256 "failed\n"); 255 "Physical bus restoration failed\n");
257} 256}
258 257
259MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 258MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 10b9342a36c2..27443f073bc9 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -17,7 +17,8 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/platform_device.h> 20#include <linux/of_platform.h>
21#include <linux/of_i2c.h>
21 22
22#include <asm/io.h> 23#include <asm/io.h>
23#include <linux/fsl_devices.h> 24#include <linux/fsl_devices.h>
@@ -25,13 +26,13 @@
25#include <linux/interrupt.h> 26#include <linux/interrupt.h>
26#include <linux/delay.h> 27#include <linux/delay.h>
27 28
28#define MPC_I2C_ADDR 0x00 29#define DRV_NAME "mpc-i2c"
30
29#define MPC_I2C_FDR 0x04 31#define MPC_I2C_FDR 0x04
30#define MPC_I2C_CR 0x08 32#define MPC_I2C_CR 0x08
31#define MPC_I2C_SR 0x0c 33#define MPC_I2C_SR 0x0c
32#define MPC_I2C_DR 0x10 34#define MPC_I2C_DR 0x10
33#define MPC_I2C_DFSRR 0x14 35#define MPC_I2C_DFSRR 0x14
34#define MPC_I2C_REGION 0x20
35 36
36#define CCR_MEN 0x80 37#define CCR_MEN 0x80
37#define CCR_MIEN 0x40 38#define CCR_MIEN 0x40
@@ -315,102 +316,117 @@ static struct i2c_adapter mpc_ops = {
315 .timeout = 1, 316 .timeout = 1,
316}; 317};
317 318
318static int fsl_i2c_probe(struct platform_device *pdev) 319static int __devinit fsl_i2c_probe(struct of_device *op, const struct of_device_id *match)
319{ 320{
320 int result = 0; 321 int result = 0;
321 struct mpc_i2c *i2c; 322 struct mpc_i2c *i2c;
322 struct fsl_i2c_platform_data *pdata;
323 struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
324
325 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
326 323
327 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 324 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
328 if (!i2c) 325 if (!i2c)
329 return -ENOMEM; 326 return -ENOMEM;
330 327
331 i2c->irq = platform_get_irq(pdev, 0); 328 if (of_get_property(op->node, "dfsrr", NULL))
332 if (i2c->irq < 0) 329 i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
333 i2c->irq = NO_IRQ; /* Use polling */
334 330
335 i2c->flags = pdata->device_flags; 331 if (of_device_is_compatible(op->node, "fsl,mpc5200-i2c") ||
336 init_waitqueue_head(&i2c->queue); 332 of_device_is_compatible(op->node, "mpc5200-i2c"))
333 i2c->flags |= FSL_I2C_DEV_CLOCK_5200;
337 334
338 i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION); 335 init_waitqueue_head(&i2c->queue);
339 336
337 i2c->base = of_iomap(op->node, 0);
340 if (!i2c->base) { 338 if (!i2c->base) {
341 printk(KERN_ERR "i2c-mpc - failed to map controller\n"); 339 printk(KERN_ERR "i2c-mpc - failed to map controller\n");
342 result = -ENOMEM; 340 result = -ENOMEM;
343 goto fail_map; 341 goto fail_map;
344 } 342 }
345 343
346 if (i2c->irq != NO_IRQ) 344 i2c->irq = irq_of_parse_and_map(op->node, 0);
347 if ((result = request_irq(i2c->irq, mpc_i2c_isr, 345 if (i2c->irq != NO_IRQ) { /* i2c->irq = NO_IRQ implies polling */
348 IRQF_SHARED, "i2c-mpc", i2c)) < 0) { 346 result = request_irq(i2c->irq, mpc_i2c_isr,
349 printk(KERN_ERR 347 IRQF_SHARED, "i2c-mpc", i2c);
350 "i2c-mpc - failed to attach interrupt\n"); 348 if (result < 0) {
351 goto fail_irq; 349 printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
350 goto fail_request;
352 } 351 }
353 352 }
353
354 mpc_i2c_setclock(i2c); 354 mpc_i2c_setclock(i2c);
355 platform_set_drvdata(pdev, i2c); 355
356 dev_set_drvdata(&op->dev, i2c);
356 357
357 i2c->adap = mpc_ops; 358 i2c->adap = mpc_ops;
358 i2c->adap.nr = pdev->id;
359 i2c_set_adapdata(&i2c->adap, i2c); 359 i2c_set_adapdata(&i2c->adap, i2c);
360 i2c->adap.dev.parent = &pdev->dev; 360 i2c->adap.dev.parent = &op->dev;
361 if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) { 361
362 result = i2c_add_adapter(&i2c->adap);
363 if (result < 0) {
362 printk(KERN_ERR "i2c-mpc - failed to add adapter\n"); 364 printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
363 goto fail_add; 365 goto fail_add;
364 } 366 }
367 of_register_i2c_devices(&i2c->adap, op->node);
365 368
366 return result; 369 return result;
367 370
368 fail_add: 371 fail_add:
369 if (i2c->irq != NO_IRQ) 372 dev_set_drvdata(&op->dev, NULL);
370 free_irq(i2c->irq, i2c); 373 free_irq(i2c->irq, i2c);
371 fail_irq: 374 fail_request:
372 iounmap(i2c->base); 375 irq_dispose_mapping(i2c->irq);
373 fail_map: 376 iounmap(i2c->base);
377 fail_map:
374 kfree(i2c); 378 kfree(i2c);
375 return result; 379 return result;
376}; 380};
377 381
378static int fsl_i2c_remove(struct platform_device *pdev) 382static int __devexit fsl_i2c_remove(struct of_device *op)
379{ 383{
380 struct mpc_i2c *i2c = platform_get_drvdata(pdev); 384 struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
381 385
382 i2c_del_adapter(&i2c->adap); 386 i2c_del_adapter(&i2c->adap);
383 platform_set_drvdata(pdev, NULL); 387 dev_set_drvdata(&op->dev, NULL);
384 388
385 if (i2c->irq != NO_IRQ) 389 if (i2c->irq != NO_IRQ)
386 free_irq(i2c->irq, i2c); 390 free_irq(i2c->irq, i2c);
387 391
392 irq_dispose_mapping(i2c->irq);
388 iounmap(i2c->base); 393 iounmap(i2c->base);
389 kfree(i2c); 394 kfree(i2c);
390 return 0; 395 return 0;
391}; 396};
392 397
393/* work with hotplug and coldplug */ 398static const struct of_device_id mpc_i2c_of_match[] = {
394MODULE_ALIAS("platform:fsl-i2c"); 399 {.compatible = "fsl-i2c",},
400 {},
401};
402MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
403
395 404
396/* Structure for a device driver */ 405/* Structure for a device driver */
397static struct platform_driver fsl_i2c_driver = { 406static struct of_platform_driver mpc_i2c_driver = {
398 .probe = fsl_i2c_probe, 407 .match_table = mpc_i2c_of_match,
399 .remove = fsl_i2c_remove, 408 .probe = fsl_i2c_probe,
400 .driver = { 409 .remove = __devexit_p(fsl_i2c_remove),
401 .owner = THIS_MODULE, 410 .driver = {
402 .name = "fsl-i2c", 411 .owner = THIS_MODULE,
412 .name = DRV_NAME,
403 }, 413 },
404}; 414};
405 415
406static int __init fsl_i2c_init(void) 416static int __init fsl_i2c_init(void)
407{ 417{
408 return platform_driver_register(&fsl_i2c_driver); 418 int rv;
419
420 rv = of_register_platform_driver(&mpc_i2c_driver);
421 if (rv)
422 printk(KERN_ERR DRV_NAME
423 " of_register_platform_driver failed (%i)\n", rv);
424 return rv;
409} 425}
410 426
411static void __exit fsl_i2c_exit(void) 427static void __exit fsl_i2c_exit(void)
412{ 428{
413 platform_driver_unregister(&fsl_i2c_driver); 429 of_unregister_platform_driver(&mpc_i2c_driver);
414} 430}
415 431
416module_init(fsl_i2c_init); 432module_init(fsl_i2c_init);
diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
index 6a8995dfd0bb..d1a4cbcf2aa4 100644
--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
@@ -150,6 +150,16 @@ static int __init nforce2_s4985_init(void)
150 int i, error; 150 int i, error;
151 union i2c_smbus_data ioconfig; 151 union i2c_smbus_data ioconfig;
152 152
153 /* Configure the PCA9556 multiplexer */
154 ioconfig.byte = 0x00; /* All I/O to output mode */
155 error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
156 I2C_SMBUS_BYTE_DATA, &ioconfig);
157 if (error) {
158 dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n");
159 error = -EIO;
160 goto ERROR0;
161 }
162
153 /* Unregister physical bus */ 163 /* Unregister physical bus */
154 if (!nforce2_smbus) 164 if (!nforce2_smbus)
155 return -ENODEV; 165 return -ENODEV;
@@ -191,24 +201,13 @@ static int __init nforce2_s4985_init(void)
191 s4985_algo[3].smbus_xfer = nforce2_access_virt3; 201 s4985_algo[3].smbus_xfer = nforce2_access_virt3;
192 s4985_algo[4].smbus_xfer = nforce2_access_virt4; 202 s4985_algo[4].smbus_xfer = nforce2_access_virt4;
193 203
194 /* Configure the PCA9556 multiplexer */
195 ioconfig.byte = 0x00; /* All I/O to output mode */
196 error = nforce2_smbus->algo->smbus_xfer(nforce2_smbus, 0x18, 0,
197 I2C_SMBUS_WRITE, 0x03,
198 I2C_SMBUS_BYTE_DATA, &ioconfig);
199 if (error) {
200 dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n");
201 error = -EIO;
202 goto ERROR3;
203 }
204
205 /* Register virtual adapters */ 204 /* Register virtual adapters */
206 for (i = 0; i < 5; i++) { 205 for (i = 0; i < 5; i++) {
207 error = i2c_add_adapter(s4985_adapter + i); 206 error = i2c_add_adapter(s4985_adapter + i);
208 if (error) { 207 if (error) {
209 dev_err(&nforce2_smbus->dev, 208 printk(KERN_ERR "i2c-nforce2-s4985: "
210 "Virtual adapter %d registration " 209 "Virtual adapter %d registration "
211 "failed, module not inserted\n", i); 210 "failed, module not inserted\n", i);
212 for (i--; i >= 0; i--) 211 for (i--; i >= 0; i--)
213 i2c_del_adapter(s4985_adapter + i); 212 i2c_del_adapter(s4985_adapter + i);
214 goto ERROR3; 213 goto ERROR3;
@@ -245,8 +244,8 @@ static void __exit nforce2_s4985_exit(void)
245 244
246 /* Restore physical bus */ 245 /* Restore physical bus */
247 if (i2c_add_adapter(nforce2_smbus)) 246 if (i2c_add_adapter(nforce2_smbus))
248 dev_err(&nforce2_smbus->dev, "Physical bus restoration " 247 printk(KERN_ERR "i2c-nforce2-s4985: "
249 "failed\n"); 248 "Physical bus restoration failed\n");
250} 249}
251 250
252MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 251MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index 373ea8d8fe8f..2c27193aeaa0 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -47,7 +47,6 @@ enum eeprom_nature {
47 47
48/* Each client has this additional data */ 48/* Each client has this additional data */
49struct eeprom_data { 49struct eeprom_data {
50 struct i2c_client client;
51 struct mutex update_lock; 50 struct mutex update_lock;
52 u8 valid; /* bitfield, bit!=0 if slice is valid */ 51 u8 valid; /* bitfield, bit!=0 if slice is valid */
53 unsigned long last_updated[8]; /* In jiffies, 8 slices */ 52 unsigned long last_updated[8]; /* In jiffies, 8 slices */
@@ -56,19 +55,6 @@ struct eeprom_data {
56}; 55};
57 56
58 57
59static int eeprom_attach_adapter(struct i2c_adapter *adapter);
60static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind);
61static int eeprom_detach_client(struct i2c_client *client);
62
63/* This is the driver that will be inserted */
64static struct i2c_driver eeprom_driver = {
65 .driver = {
66 .name = "eeprom",
67 },
68 .attach_adapter = eeprom_attach_adapter,
69 .detach_client = eeprom_detach_client,
70};
71
72static void eeprom_update_client(struct i2c_client *client, u8 slice) 58static void eeprom_update_client(struct i2c_client *client, u8 slice)
73{ 59{
74 struct eeprom_data *data = i2c_get_clientdata(client); 60 struct eeprom_data *data = i2c_get_clientdata(client);
@@ -148,25 +134,17 @@ static struct bin_attribute eeprom_attr = {
148 .read = eeprom_read, 134 .read = eeprom_read,
149}; 135};
150 136
151static int eeprom_attach_adapter(struct i2c_adapter *adapter) 137/* Return 0 if detection is successful, -ENODEV otherwise */
152{ 138static int eeprom_detect(struct i2c_client *client, int kind,
153 if (!(adapter->class & (I2C_CLASS_DDC | I2C_CLASS_SPD))) 139 struct i2c_board_info *info)
154 return 0;
155 return i2c_probe(adapter, &addr_data, eeprom_detect);
156}
157
158/* This function is called by i2c_probe */
159static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
160{ 140{
161 struct i2c_client *client; 141 struct i2c_adapter *adapter = client->adapter;
162 struct eeprom_data *data;
163 int err = 0;
164 142
165 /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all 143 /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all
166 addresses 0x50-0x57, but we only care about 0x50. So decline 144 addresses 0x50-0x57, but we only care about 0x50. So decline
167 attaching to addresses >= 0x51 on DDC buses */ 145 attaching to addresses >= 0x51 on DDC buses */
168 if (!(adapter->class & I2C_CLASS_SPD) && address >= 0x51) 146 if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51)
169 goto exit; 147 return -ENODEV;
170 148
171 /* There are four ways we can read the EEPROM data: 149 /* There are four ways we can read the EEPROM data:
172 (1) I2C block reads (faster, but unsupported by most adapters) 150 (1) I2C block reads (faster, but unsupported by most adapters)
@@ -177,32 +155,33 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
177 because all known adapters support one of the first two. */ 155 because all known adapters support one of the first two. */
178 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA) 156 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)
179 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) 157 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
180 goto exit; 158 return -ENODEV;
159
160 strlcpy(info->type, "eeprom", I2C_NAME_SIZE);
161
162 return 0;
163}
164
165static int eeprom_probe(struct i2c_client *client,
166 const struct i2c_device_id *id)
167{
168 struct i2c_adapter *adapter = client->adapter;
169 struct eeprom_data *data;
170 int err;
181 171
182 if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { 172 if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
183 err = -ENOMEM; 173 err = -ENOMEM;
184 goto exit; 174 goto exit;
185 } 175 }
186 176
187 client = &data->client;
188 memset(data->data, 0xff, EEPROM_SIZE); 177 memset(data->data, 0xff, EEPROM_SIZE);
189 i2c_set_clientdata(client, data); 178 i2c_set_clientdata(client, data);
190 client->addr = address;
191 client->adapter = adapter;
192 client->driver = &eeprom_driver;
193
194 /* Fill in the remaining client fields */
195 strlcpy(client->name, "eeprom", I2C_NAME_SIZE);
196 mutex_init(&data->update_lock); 179 mutex_init(&data->update_lock);
197 data->nature = UNKNOWN; 180 data->nature = UNKNOWN;
198 181
199 /* Tell the I2C layer a new client has arrived */
200 if ((err = i2c_attach_client(client)))
201 goto exit_kfree;
202
203 /* Detect the Vaio nature of EEPROMs. 182 /* Detect the Vaio nature of EEPROMs.
204 We use the "PCG-" or "VGN-" prefix as the signature. */ 183 We use the "PCG-" or "VGN-" prefix as the signature. */
205 if (address == 0x57 184 if (client->addr == 0x57
206 && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { 185 && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
207 char name[4]; 186 char name[4];
208 187
@@ -221,33 +200,42 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
221 /* create the sysfs eeprom file */ 200 /* create the sysfs eeprom file */
222 err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr); 201 err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr);
223 if (err) 202 if (err)
224 goto exit_detach; 203 goto exit_kfree;
225 204
226 return 0; 205 return 0;
227 206
228exit_detach:
229 i2c_detach_client(client);
230exit_kfree: 207exit_kfree:
231 kfree(data); 208 kfree(data);
232exit: 209exit:
233 return err; 210 return err;
234} 211}
235 212
236static int eeprom_detach_client(struct i2c_client *client) 213static int eeprom_remove(struct i2c_client *client)
237{ 214{
238 int err;
239
240 sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); 215 sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
241
242 err = i2c_detach_client(client);
243 if (err)
244 return err;
245
246 kfree(i2c_get_clientdata(client)); 216 kfree(i2c_get_clientdata(client));
247 217
248 return 0; 218 return 0;
249} 219}
250 220
221static const struct i2c_device_id eeprom_id[] = {
222 { "eeprom", 0 },
223 { }
224};
225
226static struct i2c_driver eeprom_driver = {
227 .driver = {
228 .name = "eeprom",
229 },
230 .probe = eeprom_probe,
231 .remove = eeprom_remove,
232 .id_table = eeprom_id,
233
234 .class = I2C_CLASS_DDC | I2C_CLASS_SPD,
235 .detect = eeprom_detect,
236 .address_data = &addr_data,
237};
238
251static int __init eeprom_init(void) 239static int __init eeprom_init(void)
252{ 240{
253 return i2c_add_driver(&eeprom_driver); 241 return i2c_add_driver(&eeprom_driver);
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 5a0285d8b6f9..033d9d81ec8a 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -53,7 +53,7 @@ I2C_CLIENT_INSMOD_1(max6875);
53 53
54/* Each client has this additional data */ 54/* Each client has this additional data */
55struct max6875_data { 55struct max6875_data {
56 struct i2c_client client; 56 struct i2c_client *fake_client;
57 struct mutex update_lock; 57 struct mutex update_lock;
58 58
59 u32 valid; 59 u32 valid;
@@ -61,19 +61,6 @@ struct max6875_data {
61 unsigned long last_updated[USER_EEPROM_SLICES]; 61 unsigned long last_updated[USER_EEPROM_SLICES];
62}; 62};
63 63
64static int max6875_attach_adapter(struct i2c_adapter *adapter);
65static int max6875_detect(struct i2c_adapter *adapter, int address, int kind);
66static int max6875_detach_client(struct i2c_client *client);
67
68/* This is the driver that will be inserted */
69static struct i2c_driver max6875_driver = {
70 .driver = {
71 .name = "max6875",
72 },
73 .attach_adapter = max6875_attach_adapter,
74 .detach_client = max6875_detach_client,
75};
76
77static void max6875_update_slice(struct i2c_client *client, int slice) 64static void max6875_update_slice(struct i2c_client *client, int slice)
78{ 65{
79 struct max6875_data *data = i2c_get_clientdata(client); 66 struct max6875_data *data = i2c_get_clientdata(client);
@@ -159,96 +146,87 @@ static struct bin_attribute user_eeprom_attr = {
159 .read = max6875_read, 146 .read = max6875_read,
160}; 147};
161 148
162static int max6875_attach_adapter(struct i2c_adapter *adapter) 149/* Return 0 if detection is successful, -ENODEV otherwise */
150static int max6875_detect(struct i2c_client *client, int kind,
151 struct i2c_board_info *info)
163{ 152{
164 return i2c_probe(adapter, &addr_data, max6875_detect); 153 struct i2c_adapter *adapter = client->adapter;
165}
166
167/* This function is called by i2c_probe */
168static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
169{
170 struct i2c_client *real_client;
171 struct i2c_client *fake_client;
172 struct max6875_data *data;
173 int err;
174 154
175 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA 155 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA
176 | I2C_FUNC_SMBUS_READ_BYTE)) 156 | I2C_FUNC_SMBUS_READ_BYTE))
177 return 0; 157 return -ENODEV;
178 158
179 /* Only check even addresses */ 159 /* Only check even addresses */
180 if (address & 1) 160 if (client->addr & 1)
181 return 0; 161 return -ENODEV;
162
163 strlcpy(info->type, "max6875", I2C_NAME_SIZE);
164
165 return 0;
166}
167
168static int max6875_probe(struct i2c_client *client,
169 const struct i2c_device_id *id)
170{
171 struct max6875_data *data;
172 int err;
182 173
183 if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL))) 174 if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL)))
184 return -ENOMEM; 175 return -ENOMEM;
185 176
186 /* A fake client is created on the odd address */ 177 /* A fake client is created on the odd address */
187 if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) { 178 data->fake_client = i2c_new_dummy(client->adapter, client->addr + 1);
179 if (!data->fake_client) {
188 err = -ENOMEM; 180 err = -ENOMEM;
189 goto exit_kfree1; 181 goto exit_kfree;
190 } 182 }
191 183
192 /* Init real i2c_client */ 184 /* Init real i2c_client */
193 real_client = &data->client; 185 i2c_set_clientdata(client, data);
194 i2c_set_clientdata(real_client, data);
195 real_client->addr = address;
196 real_client->adapter = adapter;
197 real_client->driver = &max6875_driver;
198 strlcpy(real_client->name, "max6875", I2C_NAME_SIZE);
199 mutex_init(&data->update_lock); 186 mutex_init(&data->update_lock);
200 187
201 /* Init fake client data */ 188 err = sysfs_create_bin_file(&client->dev.kobj, &user_eeprom_attr);
202 i2c_set_clientdata(fake_client, NULL);
203 fake_client->addr = address | 1;
204 fake_client->adapter = adapter;
205 fake_client->driver = &max6875_driver;
206 strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE);
207
208 if ((err = i2c_attach_client(real_client)) != 0)
209 goto exit_kfree2;
210
211 if ((err = i2c_attach_client(fake_client)) != 0)
212 goto exit_detach1;
213
214 err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
215 if (err) 189 if (err)
216 goto exit_detach2; 190 goto exit_remove_fake;
217 191
218 return 0; 192 return 0;
219 193
220exit_detach2: 194exit_remove_fake:
221 i2c_detach_client(fake_client); 195 i2c_unregister_device(data->fake_client);
222exit_detach1: 196exit_kfree:
223 i2c_detach_client(real_client);
224exit_kfree2:
225 kfree(fake_client);
226exit_kfree1:
227 kfree(data); 197 kfree(data);
228 return err; 198 return err;
229} 199}
230 200
231/* Will be called for both the real client and the fake client */ 201static int max6875_remove(struct i2c_client *client)
232static int max6875_detach_client(struct i2c_client *client)
233{ 202{
234 int err;
235 struct max6875_data *data = i2c_get_clientdata(client); 203 struct max6875_data *data = i2c_get_clientdata(client);
236 204
237 /* data is NULL for the fake client */ 205 i2c_unregister_device(data->fake_client);
238 if (data)
239 sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
240 206
241 err = i2c_detach_client(client); 207 sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
242 if (err) 208 kfree(data);
243 return err;
244 209
245 if (data) /* real client */
246 kfree(data);
247 else /* fake client */
248 kfree(client);
249 return 0; 210 return 0;
250} 211}
251 212
213static const struct i2c_device_id max6875_id[] = {
214 { "max6875", 0 },
215 { }
216};
217
218static struct i2c_driver max6875_driver = {
219 .driver = {
220 .name = "max6875",
221 },
222 .probe = max6875_probe,
223 .remove = max6875_remove,
224 .id_table = max6875_id,
225
226 .detect = max6875_detect,
227 .address_data = &addr_data,
228};
229
252static int __init max6875_init(void) 230static int __init max6875_init(void)
253{ 231{
254 return i2c_add_driver(&max6875_driver); 232 return i2c_add_driver(&max6875_driver);
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index 58ab7f26be26..270de4e56a81 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -14,8 +14,8 @@
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/hwmon-sysfs.h> 15#include <linux/hwmon-sysfs.h>
16 16
17/* Addresses to scan */ 17/* Addresses to scan: none, device is not autodetected */
18static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END}; 18static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
19 19
20/* Insmod parameters */ 20/* Insmod parameters */
21I2C_CLIENT_INSMOD_1(pca9539); 21I2C_CLIENT_INSMOD_1(pca9539);
@@ -32,23 +32,6 @@ enum pca9539_cmd
32 PCA9539_DIRECTION_1 = 7, 32 PCA9539_DIRECTION_1 = 7,
33}; 33};
34 34
35static int pca9539_attach_adapter(struct i2c_adapter *adapter);
36static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind);
37static int pca9539_detach_client(struct i2c_client *client);
38
39/* This is the driver that will be inserted */
40static struct i2c_driver pca9539_driver = {
41 .driver = {
42 .name = "pca9539",
43 },
44 .attach_adapter = pca9539_attach_adapter,
45 .detach_client = pca9539_detach_client,
46};
47
48struct pca9539_data {
49 struct i2c_client client;
50};
51
52/* following are the sysfs callback functions */ 35/* following are the sysfs callback functions */
53static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr, 36static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr,
54 char *buf) 37 char *buf)
@@ -105,77 +88,51 @@ static struct attribute_group pca9539_defattr_group = {
105 .attrs = pca9539_attributes, 88 .attrs = pca9539_attributes,
106}; 89};
107 90
108static int pca9539_attach_adapter(struct i2c_adapter *adapter) 91/* Return 0 if detection is successful, -ENODEV otherwise */
92static int pca9539_detect(struct i2c_client *client, int kind,
93 struct i2c_board_info *info)
109{ 94{
110 return i2c_probe(adapter, &addr_data, pca9539_detect); 95 struct i2c_adapter *adapter = client->adapter;
111}
112
113/* This function is called by i2c_probe */
114static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
115{
116 struct i2c_client *client;
117 struct pca9539_data *data;
118 int err = 0;
119 96
120 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 97 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
121 goto exit; 98 return -ENODEV;
122
123 /* OK. For now, we presume we have a valid client. We now create the
124 client structure, even though we cannot fill it completely yet. */
125 if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
126 err = -ENOMEM;
127 goto exit;
128 }
129
130 client = &data->client;
131 i2c_set_clientdata(client, data);
132 client->addr = address;
133 client->adapter = adapter;
134 client->driver = &pca9539_driver;
135
136 if (kind < 0) {
137 /* Detection: the pca9539 only has 8 registers (0-7).
138 A read of 7 should succeed, but a read of 8 should fail. */
139 if ((i2c_smbus_read_byte_data(client, 7) < 0) ||
140 (i2c_smbus_read_byte_data(client, 8) >= 0))
141 goto exit_kfree;
142 }
143
144 strlcpy(client->name, "pca9539", I2C_NAME_SIZE);
145
146 /* Tell the I2C layer a new client has arrived */
147 if ((err = i2c_attach_client(client)))
148 goto exit_kfree;
149 99
150 /* Register sysfs hooks */ 100 strlcpy(info->type, "pca9539", I2C_NAME_SIZE);
151 err = sysfs_create_group(&client->dev.kobj,
152 &pca9539_defattr_group);
153 if (err)
154 goto exit_detach;
155 101
156 return 0; 102 return 0;
157
158exit_detach:
159 i2c_detach_client(client);
160exit_kfree:
161 kfree(data);
162exit:
163 return err;
164} 103}
165 104
166static int pca9539_detach_client(struct i2c_client *client) 105static int pca9539_probe(struct i2c_client *client,
106 const struct i2c_device_id *id)
167{ 107{
168 int err; 108 /* Register sysfs hooks */
109 return sysfs_create_group(&client->dev.kobj,
110 &pca9539_defattr_group);
111}
169 112
113static int pca9539_remove(struct i2c_client *client)
114{
170 sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); 115 sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group);
171
172 if ((err = i2c_detach_client(client)))
173 return err;
174
175 kfree(i2c_get_clientdata(client));
176 return 0; 116 return 0;
177} 117}
178 118
119static const struct i2c_device_id pca9539_id[] = {
120 { "pca9539", 0 },
121 { }
122};
123
124static struct i2c_driver pca9539_driver = {
125 .driver = {
126 .name = "pca9539",
127 },
128 .probe = pca9539_probe,
129 .remove = pca9539_remove,
130 .id_table = pca9539_id,
131
132 .detect = pca9539_detect,
133 .address_data = &addr_data,
134};
135
179static int __init pca9539_init(void) 136static int __init pca9539_init(void)
180{ 137{
181 return i2c_add_driver(&pca9539_driver); 138 return i2c_add_driver(&pca9539_driver);
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index 1b3db2b3ada9..6ec309894c88 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -38,37 +38,19 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/i2c.h> 39#include <linux/i2c.h>
40 40
41/* Addresses to scan */ 41/* Addresses to scan: none, device can't be detected */
42static const unsigned short normal_i2c[] = { 42static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
43 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
44 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
45 I2C_CLIENT_END
46};
47 43
48/* Insmod parameters */ 44/* Insmod parameters */
49I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); 45I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
50 46
51/* Each client has this additional data */ 47/* Each client has this additional data */
52struct pcf8574_data { 48struct pcf8574_data {
53 struct i2c_client client;
54
55 int write; /* Remember last written value */ 49 int write; /* Remember last written value */
56}; 50};
57 51
58static int pcf8574_attach_adapter(struct i2c_adapter *adapter);
59static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind);
60static int pcf8574_detach_client(struct i2c_client *client);
61static void pcf8574_init_client(struct i2c_client *client); 52static void pcf8574_init_client(struct i2c_client *client);
62 53
63/* This is the driver that will be inserted */
64static struct i2c_driver pcf8574_driver = {
65 .driver = {
66 .name = "pcf8574",
67 },
68 .attach_adapter = pcf8574_attach_adapter,
69 .detach_client = pcf8574_detach_client,
70};
71
72/* following are the sysfs callback functions */ 54/* following are the sysfs callback functions */
73static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf) 55static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf)
74{ 56{
@@ -119,41 +101,22 @@ static const struct attribute_group pcf8574_attr_group = {
119 * Real code 101 * Real code
120 */ 102 */
121 103
122static int pcf8574_attach_adapter(struct i2c_adapter *adapter) 104/* Return 0 if detection is successful, -ENODEV otherwise */
123{ 105static int pcf8574_detect(struct i2c_client *client, int kind,
124 return i2c_probe(adapter, &addr_data, pcf8574_detect); 106 struct i2c_board_info *info)
125}
126
127/* This function is called by i2c_probe */
128static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
129{ 107{
130 struct i2c_client *client; 108 struct i2c_adapter *adapter = client->adapter;
131 struct pcf8574_data *data; 109 const char *client_name;
132 int err = 0;
133 const char *client_name = "";
134 110
135 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 111 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
136 goto exit; 112 return -ENODEV;
137
138 /* OK. For now, we presume we have a valid client. We now create the
139 client structure, even though we cannot fill it completely yet. */
140 if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) {
141 err = -ENOMEM;
142 goto exit;
143 }
144
145 client = &data->client;
146 i2c_set_clientdata(client, data);
147 client->addr = address;
148 client->adapter = adapter;
149 client->driver = &pcf8574_driver;
150 113
151 /* Now, we would do the remaining detection. But the PCF8574 is plainly 114 /* Now, we would do the remaining detection. But the PCF8574 is plainly
152 impossible to detect! Stupid chip. */ 115 impossible to detect! Stupid chip. */
153 116
154 /* Determine the chip type */ 117 /* Determine the chip type */
155 if (kind <= 0) { 118 if (kind <= 0) {
156 if (address >= 0x38 && address <= 0x3f) 119 if (client->addr >= 0x38 && client->addr <= 0x3f)
157 kind = pcf8574a; 120 kind = pcf8574a;
158 else 121 else
159 kind = pcf8574; 122 kind = pcf8574;
@@ -163,40 +126,43 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
163 client_name = "pcf8574a"; 126 client_name = "pcf8574a";
164 else 127 else
165 client_name = "pcf8574"; 128 client_name = "pcf8574";
129 strlcpy(info->type, client_name, I2C_NAME_SIZE);
166 130
167 /* Fill in the remaining client fields and put it into the global list */ 131 return 0;
168 strlcpy(client->name, client_name, I2C_NAME_SIZE); 132}
133
134static int pcf8574_probe(struct i2c_client *client,
135 const struct i2c_device_id *id)
136{
137 struct pcf8574_data *data;
138 int err;
139
140 data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL);
141 if (!data) {
142 err = -ENOMEM;
143 goto exit;
144 }
145
146 i2c_set_clientdata(client, data);
169 147
170 /* Tell the I2C layer a new client has arrived */
171 if ((err = i2c_attach_client(client)))
172 goto exit_free;
173
174 /* Initialize the PCF8574 chip */ 148 /* Initialize the PCF8574 chip */
175 pcf8574_init_client(client); 149 pcf8574_init_client(client);
176 150
177 /* Register sysfs hooks */ 151 /* Register sysfs hooks */
178 err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group); 152 err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group);
179 if (err) 153 if (err)
180 goto exit_detach; 154 goto exit_free;
181 return 0; 155 return 0;
182 156
183 exit_detach:
184 i2c_detach_client(client);
185 exit_free: 157 exit_free:
186 kfree(data); 158 kfree(data);
187 exit: 159 exit:
188 return err; 160 return err;
189} 161}
190 162
191static int pcf8574_detach_client(struct i2c_client *client) 163static int pcf8574_remove(struct i2c_client *client)
192{ 164{
193 int err;
194
195 sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); 165 sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
196
197 if ((err = i2c_detach_client(client)))
198 return err;
199
200 kfree(i2c_get_clientdata(client)); 166 kfree(i2c_get_clientdata(client));
201 return 0; 167 return 0;
202} 168}
@@ -208,6 +174,24 @@ static void pcf8574_init_client(struct i2c_client *client)
208 data->write = -EAGAIN; 174 data->write = -EAGAIN;
209} 175}
210 176
177static const struct i2c_device_id pcf8574_id[] = {
178 { "pcf8574", 0 },
179 { "pcf8574a", 0 },
180 { }
181};
182
183static struct i2c_driver pcf8574_driver = {
184 .driver = {
185 .name = "pcf8574",
186 },
187 .probe = pcf8574_probe,
188 .remove = pcf8574_remove,
189 .id_table = pcf8574_id,
190
191 .detect = pcf8574_detect,
192 .address_data = &addr_data,
193};
194
211static int __init pcf8574_init(void) 195static int __init pcf8574_init(void)
212{ 196{
213 return i2c_add_driver(&pcf8574_driver); 197 return i2c_add_driver(&pcf8574_driver);
diff --git a/drivers/i2c/chips/pcf8575.c b/drivers/i2c/chips/pcf8575.c
index 3ea08ac0bfa3..07fd7cb3c57d 100644
--- a/drivers/i2c/chips/pcf8575.c
+++ b/drivers/i2c/chips/pcf8575.c
@@ -32,11 +32,8 @@
32#include <linux/slab.h> /* kzalloc() */ 32#include <linux/slab.h> /* kzalloc() */
33#include <linux/sysfs.h> /* sysfs_create_group() */ 33#include <linux/sysfs.h> /* sysfs_create_group() */
34 34
35/* Addresses to scan */ 35/* Addresses to scan: none, device can't be detected */
36static const unsigned short normal_i2c[] = { 36static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
37 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
38 I2C_CLIENT_END
39};
40 37
41/* Insmod parameters */ 38/* Insmod parameters */
42I2C_CLIENT_INSMOD; 39I2C_CLIENT_INSMOD;
@@ -44,24 +41,9 @@ I2C_CLIENT_INSMOD;
44 41
45/* Each client has this additional data */ 42/* Each client has this additional data */
46struct pcf8575_data { 43struct pcf8575_data {
47 struct i2c_client client;
48 int write; /* last written value, or error code */ 44 int write; /* last written value, or error code */
49}; 45};
50 46
51static int pcf8575_attach_adapter(struct i2c_adapter *adapter);
52static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind);
53static int pcf8575_detach_client(struct i2c_client *client);
54
55/* This is the driver that will be inserted */
56static struct i2c_driver pcf8575_driver = {
57 .driver = {
58 .owner = THIS_MODULE,
59 .name = "pcf8575",
60 },
61 .attach_adapter = pcf8575_attach_adapter,
62 .detach_client = pcf8575_detach_client,
63};
64
65/* following are the sysfs callback functions */ 47/* following are the sysfs callback functions */
66static ssize_t show_read(struct device *dev, struct device_attribute *attr, 48static ssize_t show_read(struct device *dev, struct device_attribute *attr,
67 char *buf) 49 char *buf)
@@ -126,75 +108,77 @@ static const struct attribute_group pcf8575_attr_group = {
126 * Real code 108 * Real code
127 */ 109 */
128 110
129static int pcf8575_attach_adapter(struct i2c_adapter *adapter) 111/* Return 0 if detection is successful, -ENODEV otherwise */
112static int pcf8575_detect(struct i2c_client *client, int kind,
113 struct i2c_board_info *info)
130{ 114{
131 return i2c_probe(adapter, &addr_data, pcf8575_detect); 115 struct i2c_adapter *adapter = client->adapter;
116
117 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
118 return -ENODEV;
119
120 /* This is the place to detect whether the chip at the specified
121 address really is a PCF8575 chip. However, there is no method known
122 to detect whether an I2C chip is a PCF8575 or any other I2C chip. */
123
124 strlcpy(info->type, "pcf8575", I2C_NAME_SIZE);
125
126 return 0;
132} 127}
133 128
134/* This function is called by i2c_probe */ 129static int pcf8575_probe(struct i2c_client *client,
135static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind) 130 const struct i2c_device_id *id)
136{ 131{
137 struct i2c_client *client;
138 struct pcf8575_data *data; 132 struct pcf8575_data *data;
139 int err = 0; 133 int err;
140
141 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
142 goto exit;
143 134
144 /* OK. For now, we presume we have a valid client. We now create the
145 client structure, even though we cannot fill it completely yet. */
146 data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL); 135 data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL);
147 if (!data) { 136 if (!data) {
148 err = -ENOMEM; 137 err = -ENOMEM;
149 goto exit; 138 goto exit;
150 } 139 }
151 140
152 client = &data->client;
153 i2c_set_clientdata(client, data); 141 i2c_set_clientdata(client, data);
154 client->addr = address;
155 client->adapter = adapter;
156 client->driver = &pcf8575_driver;
157 strlcpy(client->name, "pcf8575", I2C_NAME_SIZE);
158 data->write = -EAGAIN; 142 data->write = -EAGAIN;
159 143
160 /* This is the place to detect whether the chip at the specified
161 address really is a PCF8575 chip. However, there is no method known
162 to detect whether an I2C chip is a PCF8575 or any other I2C chip. */
163
164 /* Tell the I2C layer a new client has arrived */
165 err = i2c_attach_client(client);
166 if (err)
167 goto exit_free;
168
169 /* Register sysfs hooks */ 144 /* Register sysfs hooks */
170 err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group); 145 err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group);
171 if (err) 146 if (err)
172 goto exit_detach; 147 goto exit_free;
173 148
174 return 0; 149 return 0;
175 150
176exit_detach:
177 i2c_detach_client(client);
178exit_free: 151exit_free:
179 kfree(data); 152 kfree(data);
180exit: 153exit:
181 return err; 154 return err;
182} 155}
183 156
184static int pcf8575_detach_client(struct i2c_client *client) 157static int pcf8575_remove(struct i2c_client *client)
185{ 158{
186 int err;
187
188 sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group); 159 sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group);
189
190 err = i2c_detach_client(client);
191 if (err)
192 return err;
193
194 kfree(i2c_get_clientdata(client)); 160 kfree(i2c_get_clientdata(client));
195 return 0; 161 return 0;
196} 162}
197 163
164static const struct i2c_device_id pcf8575_id[] = {
165 { "pcf8575", 0 },
166 { }
167};
168
169static struct i2c_driver pcf8575_driver = {
170 .driver = {
171 .owner = THIS_MODULE,
172 .name = "pcf8575",
173 },
174 .probe = pcf8575_probe,
175 .remove = pcf8575_remove,
176 .id_table = pcf8575_id,
177
178 .detect = pcf8575_detect,
179 .address_data = &addr_data,
180};
181
198static int __init pcf8575_init(void) 182static int __init pcf8575_init(void)
199{ 183{
200 return i2c_add_driver(&pcf8575_driver); 184 return i2c_add_driver(&pcf8575_driver);
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index db735379f22f..16ce3e193776 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -72,28 +72,15 @@ MODULE_PARM_DESC(input_mode,
72#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) 72#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg))
73 73
74struct pcf8591_data { 74struct pcf8591_data {
75 struct i2c_client client;
76 struct mutex update_lock; 75 struct mutex update_lock;
77 76
78 u8 control; 77 u8 control;
79 u8 aout; 78 u8 aout;
80}; 79};
81 80
82static int pcf8591_attach_adapter(struct i2c_adapter *adapter);
83static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind);
84static int pcf8591_detach_client(struct i2c_client *client);
85static void pcf8591_init_client(struct i2c_client *client); 81static void pcf8591_init_client(struct i2c_client *client);
86static int pcf8591_read_channel(struct device *dev, int channel); 82static int pcf8591_read_channel(struct device *dev, int channel);
87 83
88/* This is the driver that will be inserted */
89static struct i2c_driver pcf8591_driver = {
90 .driver = {
91 .name = "pcf8591",
92 },
93 .attach_adapter = pcf8591_attach_adapter,
94 .detach_client = pcf8591_detach_client,
95};
96
97/* following are the sysfs callback functions */ 84/* following are the sysfs callback functions */
98#define show_in_channel(channel) \ 85#define show_in_channel(channel) \
99static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 86static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \
@@ -180,58 +167,46 @@ static const struct attribute_group pcf8591_attr_group_opt = {
180/* 167/*
181 * Real code 168 * Real code
182 */ 169 */
183static int pcf8591_attach_adapter(struct i2c_adapter *adapter)
184{
185 return i2c_probe(adapter, &addr_data, pcf8591_detect);
186}
187 170
188/* This function is called by i2c_probe */ 171/* Return 0 if detection is successful, -ENODEV otherwise */
189static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) 172static int pcf8591_detect(struct i2c_client *client, int kind,
173 struct i2c_board_info *info)
190{ 174{
191 struct i2c_client *client; 175 struct i2c_adapter *adapter = client->adapter;
192 struct pcf8591_data *data;
193 int err = 0;
194 176
195 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE 177 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE
196 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 178 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
197 goto exit; 179 return -ENODEV;
180
181 /* Now, we would do the remaining detection. But the PCF8591 is plainly
182 impossible to detect! Stupid chip. */
183
184 strlcpy(info->type, "pcf8591", I2C_NAME_SIZE);
185
186 return 0;
187}
188
189static int pcf8591_probe(struct i2c_client *client,
190 const struct i2c_device_id *id)
191{
192 struct pcf8591_data *data;
193 int err;
198 194
199 /* OK. For now, we presume we have a valid client. We now create the
200 client structure, even though we cannot fill it completely yet. */
201 if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { 195 if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) {
202 err = -ENOMEM; 196 err = -ENOMEM;
203 goto exit; 197 goto exit;
204 } 198 }
205 199
206 client = &data->client;
207 i2c_set_clientdata(client, data); 200 i2c_set_clientdata(client, data);
208 client->addr = address;
209 client->adapter = adapter;
210 client->driver = &pcf8591_driver;
211
212 /* Now, we would do the remaining detection. But the PCF8591 is plainly
213 impossible to detect! Stupid chip. */
214
215 /* Determine the chip type - only one kind supported! */
216 if (kind <= 0)
217 kind = pcf8591;
218
219 /* Fill in the remaining client fields and put it into the global
220 list */
221 strlcpy(client->name, "pcf8591", I2C_NAME_SIZE);
222 mutex_init(&data->update_lock); 201 mutex_init(&data->update_lock);
223 202
224 /* Tell the I2C layer a new client has arrived */
225 if ((err = i2c_attach_client(client)))
226 goto exit_kfree;
227
228 /* Initialize the PCF8591 chip */ 203 /* Initialize the PCF8591 chip */
229 pcf8591_init_client(client); 204 pcf8591_init_client(client);
230 205
231 /* Register sysfs hooks */ 206 /* Register sysfs hooks */
232 err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); 207 err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group);
233 if (err) 208 if (err)
234 goto exit_detach; 209 goto exit_kfree;
235 210
236 /* Register input2 if not in "two differential inputs" mode */ 211 /* Register input2 if not in "two differential inputs" mode */
237 if (input_mode != 3) { 212 if (input_mode != 3) {
@@ -252,24 +227,16 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
252exit_sysfs_remove: 227exit_sysfs_remove:
253 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); 228 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt);
254 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); 229 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group);
255exit_detach:
256 i2c_detach_client(client);
257exit_kfree: 230exit_kfree:
258 kfree(data); 231 kfree(data);
259exit: 232exit:
260 return err; 233 return err;
261} 234}
262 235
263static int pcf8591_detach_client(struct i2c_client *client) 236static int pcf8591_remove(struct i2c_client *client)
264{ 237{
265 int err;
266
267 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); 238 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt);
268 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); 239 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group);
269
270 if ((err = i2c_detach_client(client)))
271 return err;
272
273 kfree(i2c_get_clientdata(client)); 240 kfree(i2c_get_clientdata(client));
274 return 0; 241 return 0;
275} 242}
@@ -316,6 +283,25 @@ static int pcf8591_read_channel(struct device *dev, int channel)
316 return (10 * value); 283 return (10 * value);
317} 284}
318 285
286static const struct i2c_device_id pcf8591_id[] = {
287 { "pcf8591", 0 },
288 { }
289};
290MODULE_DEVICE_TABLE(i2c, pcf8591_id);
291
292static struct i2c_driver pcf8591_driver = {
293 .driver = {
294 .name = "pcf8591",
295 },
296 .probe = pcf8591_probe,
297 .remove = pcf8591_remove,
298 .id_table = pcf8591_id,
299
300 .class = I2C_CLASS_HWMON, /* Nearest choice */
301 .detect = pcf8591_detect,
302 .address_data = &addr_data,
303};
304
319static int __init pcf8591_init(void) 305static int __init pcf8591_init(void)
320{ 306{
321 if (input_mode < 0 || input_mode > 3) { 307 if (input_mode < 0 || input_mode > 3) {
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 0a79f7661017..7608df83d6d1 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -654,6 +654,10 @@ int i2c_del_adapter(struct i2c_adapter *adap)
654 654
655 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); 655 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
656 656
657 /* Clear the device structure in case this adapter is ever going to be
658 added again */
659 memset(&adap->dev, 0, sizeof(adap->dev));
660
657 out_unlock: 661 out_unlock:
658 mutex_unlock(&core_lock); 662 mutex_unlock(&core_lock);
659 return res; 663 return res;