summaryrefslogtreecommitdiff
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)
int i, error;
union i2c_smbus_data ioconfig;
+ /* Configure the PCA9556 multiplexer */
+ ioconfig.byte = 0x00; /* All I/O to output mode */
+ error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
+ I2C_SMBUS_BYTE_DATA, &ioconfig);
+ if (error) {
+ dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n");
+ error = -EIO;
+ goto ERROR0;
+ }
+
/* Unregister physical bus */
error = i2c_del_adapter(&amd756_smbus);
if (error) {
@@ -198,22 +208,11 @@ static int __init amd756_s4882_init(void)
s4882_algo[3].smbus_xfer = amd756_access_virt3;
s4882_algo[4].smbus_xfer = amd756_access_virt4;
- /* Configure the PCA9556 multiplexer */
- ioconfig.byte = 0x00; /* All I/O to output mode */
- error = amd756_smbus.algo->smbus_xfer(&amd756_smbus, 0x18, 0,
- I2C_SMBUS_WRITE, 0x03,
- I2C_SMBUS_BYTE_DATA, &ioconfig);
- if (error) {
- dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n");
- error = -EIO;
- goto ERROR3;
- }
-
/* Register virtual adapters */
for (i = 0; i < 5; i++) {
error = i2c_add_adapter(s4882_adapter+i);
if (error) {
- dev_err(&amd756_smbus.dev,
+ printk(KERN_ERR "i2c-amd756-s4882: "
"Virtual adapter %d registration "
"failed, module not inserted\n", i);
for (i--; i >= 0; i--)
@@ -252,8 +251,8 @@ static void __exit amd756_s4882_exit(void)
/* Restore physical bus */
if (i2c_add_adapter(&amd756_smbus))
- dev_err(&amd756_smbus.dev, "Physical bus restoration "
- "failed\n");
+ printk(KERN_ERR "i2c-amd756-s4882: "
+ "Physical bus restoration failed\n");
}
MODULE_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 @@
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/init.h>
-#include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/of_i2c.h>
#include <asm/io.h>
#include <linux/fsl_devices.h>
@@ -25,13 +26,13 @@
#include <linux/interrupt.h>
#include <linux/delay.h>
-#define MPC_I2C_ADDR 0x00
+#define DRV_NAME "mpc-i2c"
+
#define MPC_I2C_FDR 0x04
#define MPC_I2C_CR 0x08
#define MPC_I2C_SR 0x0c
#define MPC_I2C_DR 0x10
#define MPC_I2C_DFSRR 0x14
-#define MPC_I2C_REGION 0x20
#define CCR_MEN 0x80
#define CCR_MIEN 0x40
@@ -315,102 +316,117 @@ static struct i2c_adapter mpc_ops = {
.timeout = 1,
};
-static int fsl_i2c_probe(struct platform_device *pdev)
+static int __devinit fsl_i2c_probe(struct of_device *op, const struct of_device_id *match)
{
int result = 0;
struct mpc_i2c *i2c;
- struct fsl_i2c_platform_data *pdata;
- struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
- pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
if (!i2c)
return -ENOMEM;
- i2c->irq = platform_get_irq(pdev, 0);
- if (i2c->irq < 0)
- i2c->irq = NO_IRQ; /* Use polling */
+ if (of_get_property(op->node, "dfsrr", NULL))
+ i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
- i2c->flags = pdata->device_flags;
- init_waitqueue_head(&i2c->queue);
+ if (of_device_is_compatible(op->node, "fsl,mpc5200-i2c") ||
+ of_device_is_compatible(op->node, "mpc5200-i2c"))
+ i2c->flags |= FSL_I2C_DEV_CLOCK_5200;
- i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
+ init_waitqueue_head(&i2c->queue);
+ i2c->base = of_iomap(op->node, 0);
if (!i2c->base) {
printk(KERN_ERR "i2c-mpc - failed to map controller\n");
result = -ENOMEM;
goto fail_map;
}
- if (i2c->irq != NO_IRQ)
- if ((result = request_irq(i2c->irq, mpc_i2c_isr,
- IRQF_SHARED, "i2c-mpc", i2c)) < 0) {
- printk(KERN_ERR
- "i2c-mpc - failed to attach interrupt\n");
- goto fail_irq;
+ i2c->irq = irq_of_parse_and_map(op->node, 0);
+ if (i2c->irq != NO_IRQ) { /* i2c->irq = NO_IRQ implies polling */
+ result = request_irq(i2c->irq, mpc_i2c_isr,
+ IRQF_SHARED, "i2c-mpc", i2c);
+ if (result < 0) {
+ printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
+ goto fail_request;
}
-
+ }
+
mpc_i2c_setclock(i2c);
- platform_set_drvdata(pdev, i2c);
+
+ dev_set_drvdata(&op->dev, i2c);
i2c->adap = mpc_ops;
- i2c->adap.nr = pdev->id;
i2c_set_adapdata(&i2c->adap, i2c);
- i2c->adap.dev.parent = &pdev->dev;
- if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
+ i2c->adap.dev.parent = &op->dev;
+
+ result = i2c_add_adapter(&i2c->adap);
+ if (result < 0) {
printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
goto fail_add;
}
+ of_register_i2c_devices(&i2c->adap, op->node);
return result;
- fail_add:
- if (i2c->irq != NO_IRQ)
- free_irq(i2c->irq, i2c);
- fail_irq:
- iounmap(i2c->base);
- fail_map:
+ fail_add:
+ dev_set_drvdata(&op->dev, NULL);
+ free_irq(i2c->irq, i2c);
+ fail_request:
+ irq_dispose_mapping(i2c->irq);
+ iounmap(i2c->base);
+ fail_map:
kfree(i2c);
return result;
};
-static int fsl_i2c_remove(struct platform_device *pdev)
+static int __devexit fsl_i2c_remove(struct of_device *op)
{
- struct mpc_i2c *i2c = platform_get_drvdata(pdev);
+ struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
i2c_del_adapter(&i2c->adap);
- platform_set_drvdata(pdev, NULL);
+ dev_set_drvdata(&op->dev, NULL);
if (i2c->irq != NO_IRQ)
free_irq(i2c->irq, i2c);
+ irq_dispose_mapping(i2c->irq);
iounmap(i2c->base);
kfree(i2c);
return 0;
};
-/* work with hotplug and coldplug */
-MODULE_ALIAS("platform:fsl-i2c");
+static const struct of_device_id mpc_i2c_of_match[] = {
+ {.compatible = "fsl-i2c",},
+ {},
+};
+MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
+
/* Structure for a device driver */
-static struct platform_driver fsl_i2c_driver = {
- .probe = fsl_i2c_probe,
- .remove = fsl_i2c_remove,
- .driver = {
- .owner = THIS_MODULE,
- .name = "fsl-i2c",
+static struct of_platform_driver mpc_i2c_driver = {
+ .match_table = mpc_i2c_of_match,
+ .probe = fsl_i2c_probe,
+ .remove = __devexit_p(fsl_i2c_remove),
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = DRV_NAME,
},
};
static int __init fsl_i2c_init(void)
{
- return platform_driver_register(&fsl_i2c_driver);
+ int rv;
+
+ rv = of_register_platform_driver(&mpc_i2c_driver);
+ if (rv)
+ printk(KERN_ERR DRV_NAME
+ " of_register_platform_driver failed (%i)\n", rv);
+ return rv;
}
static void __exit fsl_i2c_exit(void)
{
- platform_driver_unregister(&fsl_i2c_driver);
+ of_unregister_platform_driver(&mpc_i2c_driver);
}
module_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)
int i, error;
union i2c_smbus_data ioconfig;
+ /* Configure the PCA9556 multiplexer */
+ ioconfig.byte = 0x00; /* All I/O to output mode */
+ error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
+ I2C_SMBUS_BYTE_DATA, &ioconfig);
+ if (error) {
+ dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n");
+ error = -EIO;
+ goto ERROR0;
+ }
+
/* Unregister physical bus */
if (!nforce2_smbus)
return -ENODEV;
@@ -191,24 +201,13 @@ static int __init nforce2_s4985_init(void)
s4985_algo[3].smbus_xfer = nforce2_access_virt3;
s4985_algo[4].smbus_xfer = nforce2_access_virt4;
- /* Configure the PCA9556 multiplexer */
- ioconfig.byte = 0x00; /* All I/O to output mode */
- error = nforce2_smbus->algo->smbus_xfer(nforce2_smbus, 0x18, 0,
- I2C_SMBUS_WRITE, 0x03,
- I2C_SMBUS_BYTE_DATA, &ioconfig);
- if (error) {
- dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n");
- error = -EIO;
- goto ERROR3;
- }
-
/* Register virtual adapters */
for (i = 0; i < 5; i++) {
error = i2c_add_adapter(s4985_adapter + i);
if (error) {
- dev_err(&nforce2_smbus->dev,
- "Virtual adapter %d registration "
- "failed, module not inserted\n", i);
+ printk(KERN_ERR "i2c-nforce2-s4985: "
+ "Virtual adapter %d registration "
+ "failed, module not inserted\n", i);
for (i--; i >= 0; i--)
i2c_del_adapter(s4985_adapter + i);
goto ERROR3;
@@ -245,8 +244,8 @@ static void __exit nforce2_s4985_exit(void)
/* Restore physical bus */
if (i2c_add_adapter(nforce2_smbus))
- dev_err(&nforce2_smbus->dev, "Physical bus restoration "
- "failed\n");
+ printk(KERN_ERR "i2c-nforce2-s4985: "
+ "Physical bus restoration failed\n");
}
MODULE_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 {
/* Each client has this additional data */
struct eeprom_data {
- struct i2c_client client;
struct mutex update_lock;
u8 valid; /* bitfield, bit!=0 if slice is valid */
unsigned long last_updated[8]; /* In jiffies, 8 slices */
@@ -56,19 +55,6 @@ struct eeprom_data {
};
-static int eeprom_attach_adapter(struct i2c_adapter *adapter);
-static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind);
-static int eeprom_detach_client(struct i2c_client *client);
-
-/* This is the driver that will be inserted */
-static struct i2c_driver eeprom_driver = {
- .driver = {
- .name = "eeprom",
- },
- .attach_adapter = eeprom_attach_adapter,
- .detach_client = eeprom_detach_client,
-};
-
static void eeprom_update_client(struct i2c_client *client, u8 slice)
{
struct eeprom_data *data = i2c_get_clientdata(client);
@@ -148,25 +134,17 @@ static struct bin_attribute eeprom_attr = {
.read = eeprom_read,
};
-static int eeprom_attach_adapter(struct i2c_adapter *adapter)
-{
- if (!(adapter->class & (I2C_CLASS_DDC | I2C_CLASS_SPD)))
- return 0;
- return i2c_probe(adapter, &addr_data, eeprom_detect);
-}
-
-/* This function is called by i2c_probe */
-static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int eeprom_detect(struct i2c_client *client, int kind,
+ struct i2c_board_info *info)
{
- struct i2c_client *client;
- struct eeprom_data *data;
- int err = 0;
+ struct i2c_adapter *adapter = client->adapter;
/* EDID EEPROMs are often 24C00 EEPROMs, which answer to all
addresses 0x50-0x57, but we only care about 0x50. So decline
attaching to addresses >= 0x51 on DDC buses */
- if (!(adapter->class & I2C_CLASS_SPD) && address >= 0x51)
- goto exit;
+ if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51)
+ return -ENODEV;
/* There are four ways we can read the EEPROM data:
(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)
because all known adapters support one of the first two. */
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)
&& !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
- goto exit;
+ return -ENODEV;
+
+ strlcpy(info->type, "eeprom", I2C_NAME_SIZE);
+
+ return 0;
+}
+
+static int eeprom_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct i2c_adapter *adapter = client->adapter;
+ struct eeprom_data *data;
+ int err;
if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
- client = &data->client;
memset(data->data, 0xff, EEPROM_SIZE);
i2c_set_clientdata(client, data);
- client->addr = address;
- client->adapter = adapter;
- client->driver = &eeprom_driver;
-
- /* Fill in the remaining client fields */
- strlcpy(client->name, "eeprom", I2C_NAME_SIZE);
mutex_init(&data->update_lock);
data->nature = UNKNOWN;
- /* Tell the I2C layer a new client has arrived */
- if ((err = i2c_attach_client(client)))
- goto exit_kfree;
-
/* Detect the Vaio nature of EEPROMs.
We use the "PCG-" or "VGN-" prefix as the signature. */
- if (address == 0x57
+ if (client->addr == 0x57
&& i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
char name[4];
@@ -221,33 +200,42 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
/* create the sysfs eeprom file */
err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr);
if (err)
- goto exit_detach;
+ goto exit_kfree;
return 0;
-exit_detach:
- i2c_detach_client(client);
exit_kfree:
kfree(data);
exit:
return err;
}
-static int eeprom_detach_client(struct i2c_client *client)
+static int eeprom_remove(struct i2c_client *client)
{
- int err;
-
sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
-
- err = i2c_detach_client(client);
- if (err)
- return err;
-
kfree(i2c_get_clientdata(client));
return 0;
}
+static const struct i2c_device_id eeprom_id[] = {
+ { "eeprom", 0 },
+ { }
+};
+
+static struct i2c_driver eeprom_driver = {
+ .driver = {
+ .name = "eeprom",
+ },
+ .probe = eeprom_probe,
+ .remove = eeprom_remove,
+ .id_table = eeprom_id,
+
+ .class = I2C_CLASS_DDC | I2C_CLASS_SPD,
+ .detect = eeprom_detect,
+ .address_data = &addr_data,
+};
+
static int __init eeprom_init(void)
{
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);
/* Each client has this additional data */
struct max6875_data {
- struct i2c_client client;
+ struct i2c_client *fake_client;
struct mutex update_lock;
u32 valid;
@@ -61,19 +61,6 @@ struct max6875_data {
unsigned long last_updated[USER_EEPROM_SLICES];
};
-static int max6875_attach_adapter(struct i2c_adapter *adapter);
-static int max6875_detect(struct i2c_adapter *adapter, int address, int kind);
-static int max6875_detach_client(struct i2c_client *client);
-
-/* This is the driver that will be inserted */
-static struct i2c_driver max6875_driver = {
- .driver = {
- .name = "max6875",
- },
- .attach_adapter = max6875_attach_adapter,
- .detach_client = max6875_detach_client,
-};
-
static void max6875_update_slice(struct i2c_client *client, int slice)
{
struct max6875_data *data = i2c_get_clientdata(client);
@@ -159,96 +146,87 @@ static struct bin_attribute user_eeprom_attr = {
.read = max6875_read,
};
-static int max6875_attach_adapter(struct i2c_adapter *adapter)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int max6875_detect(struct i2c_client *client, int kind,
+ struct i2c_board_info *info)
{
- return i2c_probe(adapter, &addr_data, max6875_detect);
-}
-
-/* This function is called by i2c_probe */
-static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
-{
- struct i2c_client *real_client;
- struct i2c_client *fake_client;
- struct max6875_data *data;
- int err;
+ struct i2c_adapter *adapter = client->adapter;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA
| I2C_FUNC_SMBUS_READ_BYTE))
- return 0;
+ return -ENODEV;
/* Only check even addresses */
- if (address & 1)
- return 0;
+ if (client->addr & 1)
+ return -ENODEV;
+
+ strlcpy(info->type, "max6875", I2C_NAME_SIZE);
+
+ return 0;
+}
+
+static int max6875_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct max6875_data *data;
+ int err;
if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL)))
return -ENOMEM;
/* A fake client is created on the odd address */
- if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
+ data->fake_client = i2c_new_dummy(client->adapter, client->addr + 1);
+ if (!data->fake_client) {
err = -ENOMEM;
- goto exit_kfree1;
+ goto exit_kfree;
}
/* Init real i2c_client */
- real_client = &data->client;
- i2c_set_clientdata(real_client, data);
- real_client->addr = address;
- real_client->adapter = adapter;
- real_client->driver = &max6875_driver;
- strlcpy(real_client->name, "max6875", I2C_NAME_SIZE);
+ i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);
- /* Init fake client data */
- i2c_set_clientdata(fake_client, NULL);
- fake_client->addr = address | 1;
- fake_client->adapter = adapter;
- fake_client->driver = &max6875_driver;
- strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE);
-
- if ((err = i2c_attach_client(real_client)) != 0)
- goto exit_kfree2;
-
- if ((err = i2c_attach_client(fake_client)) != 0)
- goto exit_detach1;
-
- err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
+ err = sysfs_create_bin_file(&client->dev.kobj, &user_eeprom_attr);
if (err)
- goto exit_detach2;
+ goto exit_remove_fake;
return 0;
-exit_detach2:
- i2c_detach_client(fake_client);
-exit_detach1:
- i2c_detach_client(real_client);
-exit_kfree2:
- kfree(fake_client);
-exit_kfree1:
+exit_remove_fake:
+ i2c_unregister_device(data->fake_client);
+exit_kfree:
kfree(data);
return err;
}
-/* Will be called for both the real client and the fake client */
-static int max6875_detach_client(struct i2c_client *client)
+static int max6875_remove(struct i2c_client *client)
{
- int err;
struct max6875_data *data = i2c_get_clientdata(client);
- /* data is NULL for the fake client */
- if (data)
- sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
+ i2c_unregister_device(data->fake_client);
- err = i2c_detach_client(client);
- if (err)
- return err;
+ sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
+ kfree(data);
- if (data) /* real client */
- kfree(data);
- else /* fake client */
- kfree(client);
return 0;
}
+static const struct i2c_device_id max6875_id[] = {
+ { "max6875", 0 },
+ { }
+};
+
+static struct i2c_driver max6875_driver = {
+ .driver = {
+ .name = "max6875",
+ },
+ .probe = max6875_probe,
+ .remove = max6875_remove,
+ .id_table = max6875_id,
+
+ .detect = max6875_detect,
+ .address_data = &addr_data,
+};
+
static int __init max6875_init(void)
{
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 @@
#include <linux/i2c.h>
#include <linux/hwmon-sysfs.h>
-/* Addresses to scan */
-static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END};
+/* Addresses to scan: none, device is not autodetected */
+static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
/* Insmod parameters */
I2C_CLIENT_INSMOD_1(pca9539);
@@ -32,23 +32,6 @@ enum pca9539_cmd
PCA9539_DIRECTION_1 = 7,
};
-static int pca9539_attach_adapter(struct i2c_adapter *adapter);
-static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind);
-static int pca9539_detach_client(struct i2c_client *client);
-
-/* This is the driver that will be inserted */
-static struct i2c_driver pca9539_driver = {
- .driver = {
- .name = "pca9539",
- },
- .attach_adapter = pca9539_attach_adapter,
- .detach_client = pca9539_detach_client,
-};
-
-struct pca9539_data {
- struct i2c_client client;
-};
-
/* following are the sysfs callback functions */
static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr,
char *buf)
@@ -105,77 +88,51 @@ static struct attribute_group pca9539_defattr_group = {
.attrs = pca9539_attributes,
};
-static int pca9539_attach_adapter(struct i2c_adapter *adapter)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int pca9539_detect(struct i2c_client *client, int kind,
+ struct i2c_board_info *info)
{
- return i2c_probe(adapter, &addr_data, pca9539_detect);
-}
-
-/* This function is called by i2c_probe */
-static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
-{
- struct i2c_client *client;
- struct pca9539_data *data;
- int err = 0;
+ struct i2c_adapter *adapter = client->adapter;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
- goto exit;
-
- /* OK. For now, we presume we have a valid client. We now create the
- client structure, even though we cannot fill it completely yet. */
- if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
- err = -ENOMEM;
- goto exit;
- }
-
- client = &data->client;
- i2c_set_clientdata(client, data);
- client->addr = address;
- client->adapter = adapter;
- client->driver = &pca9539_driver;
-
- if (kind < 0) {
- /* Detection: the pca9539 only has 8 registers (0-7).
- A read of 7 should succeed, but a read of 8 should fail. */
- if ((i2c_smbus_read_byte_data(client, 7) < 0) ||
- (i2c_smbus_read_byte_data(client, 8) >= 0))
- goto exit_kfree;
- }
-
- strlcpy(client->name, "pca9539", I2C_NAME_SIZE);
-
- /* Tell the I2C layer a new client has arrived */
- if ((err = i2c_attach_client(client)))
- goto exit_kfree;
+ return -ENODEV;
- /* Register sysfs hooks */
- err = sysfs_create_group(&client->dev.kobj,
- &pca9539_defattr_group);
- if (err)
- goto exit_detach;
+ strlcpy(info->type, "pca9539", I2C_NAME_SIZE);
return 0;
-
-exit_detach:
- i2c_detach_client(client);
-exit_kfree:
- kfree(data);
-exit:
- return err;
}
-static int pca9539_detach_client(struct i2c_client *client)
+static int pca9539_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
{
- int err;
+ /* Register sysfs hooks */
+ return sysfs_create_group(&client->dev.kobj,
+ &pca9539_defattr_group);
+}
+static int pca9539_remove(struct i2c_client *client)
+{
sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group);
-
- if ((err = i2c_detach_client(client)))
- return err;
-
- kfree(i2c_get_clientdata(client));
return 0;
}
+static const struct i2c_device_id pca9539_id[] = {
+ { "pca9539", 0 },
+ { }
+};
+
+static struct i2c_driver pca9539_driver = {
+ .driver = {
+ .name = "pca9539",
+ },
+ .probe = pca9539_probe,
+ .remove = pca9539_remove,
+ .id_table = pca9539_id,
+
+ .detect = pca9539_detect,
+ .address_data = &addr_data,
+};
+
static int __init pca9539_init(void)
{
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 @@
#include <linux/slab.h>
#include <linux/i2c.h>
-/* Addresses to scan */
-static const unsigned short normal_i2c[] = {
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
- I2C_CLIENT_END
-};
+/* Addresses to scan: none, device can't be detected */
+static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
/* Insmod parameters */
I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
/* Each client has this additional data */
struct pcf8574_data {
- struct i2c_client client;
-
int write; /* Remember last written value */
};
-static int pcf8574_attach_adapter(struct i2c_adapter *adapter);
-static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind);
-static int pcf8574_detach_client(struct i2c_client *client);
static void pcf8574_init_client(struct i2c_client *client);
-/* This is the driver that will be inserted */
-static struct i2c_driver pcf8574_driver = {
- .driver = {
- .name = "pcf8574",
- },
- .attach_adapter = pcf8574_attach_adapter,
- .detach_client = pcf8574_detach_client,
-};
-
/* following are the sysfs callback functions */
static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -119,41 +101,22 @@ static const struct attribute_group pcf8574_attr_group = {
* Real code
*/
-static int pcf8574_attach_adapter(struct i2c_adapter *adapter)
-{
- return i2c_probe(adapter, &addr_data, pcf8574_detect);
-}
-
-/* This function is called by i2c_probe */
-static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int pcf8574_detect(struct i2c_client *client, int kind,
+ struct i2c_board_info *info)
{
- struct i2c_client *client;
- struct pcf8574_data *data;
- int err = 0;
- const char *client_name = "";
+ struct i2c_adapter *adapter = client->adapter;
+ const char *client_name;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
- goto exit;
-
- /* OK. For now, we presume we have a valid client. We now create the
- client structure, even though we cannot fill it completely yet. */
- if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) {
- err = -ENOMEM;
- goto exit;
- }
-
- client = &data->client;
- i2c_set_clientdata(client, data);
- client->addr = address;
- client->adapter = adapter;
- client->driver = &pcf8574_driver;
+ return -ENODEV;
/* Now, we would do the remaining detection. But the PCF8574 is plainly
impossible to detect! Stupid chip. */
/* Determine the chip type */
if (kind <= 0) {
- if (address >= 0x38 && address <= 0x3f)
+ if (client->addr >= 0x38 && client->addr <= 0x3f)
kind = pcf8574a;
else
kind = pcf8574;
@@ -163,40 +126,43 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
client_name = "pcf8574a";
else
client_name = "pcf8574";
+ strlcpy(info->type, client_name, I2C_NAME_SIZE);
- /* Fill in the remaining client fields and put it into the global list */
- strlcpy(client->name, client_name, I2C_NAME_SIZE);
+ return 0;
+}
+
+static int pcf8574_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct pcf8574_data *data;
+ int err;
+
+ data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL);
+ if (!data) {
+ err = -ENOMEM;
+ goto exit;
+ }
+
+ i2c_set_clientdata(client, data);
- /* Tell the I2C layer a new client has arrived */
- if ((err = i2c_attach_client(client)))
- goto exit_free;
-
/* Initialize the PCF8574 chip */
pcf8574_init_client(client);
/* Register sysfs hooks */
err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group);
if (err)
- goto exit_detach;
+ goto exit_free;
return 0;
- exit_detach:
- i2c_detach_client(client);
exit_free:
kfree(data);
exit:
return err;
}
-static int pcf8574_detach_client(struct i2c_client *client)
+static int pcf8574_remove(struct i2c_client *client)
{
- int err;
-
sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
-
- if ((err = i2c_detach_client(client)))
- return err;
-
kfree(i2c_get_clientdata(client));
return 0;
}
@@ -208,6 +174,24 @@ static void pcf8574_init_client(struct i2c_client *client)
data->write = -EAGAIN;
}
+static const struct i2c_device_id pcf8574_id[] = {
+ { "pcf8574", 0 },
+ { "pcf8574a", 0 },
+ { }
+};
+
+static struct i2c_driver pcf8574_driver = {
+ .driver = {
+ .name = "pcf8574",
+ },
+ .probe = pcf8574_probe,
+ .remove = pcf8574_remove,
+ .id_table = pcf8574_id,
+
+ .detect = pcf8574_detect,
+ .address_data = &addr_data,
+};
+
static int __init pcf8574_init(void)
{
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 @@
#include <linux/slab.h> /* kzalloc() */
#include <linux/sysfs.h> /* sysfs_create_group() */
-/* Addresses to scan */
-static const unsigned short normal_i2c[] = {
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- I2C_CLIENT_END
-};
+/* Addresses to scan: none, device can't be detected */
+static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
/* Insmod parameters */
I2C_CLIENT_INSMOD;
@@ -44,24 +41,9 @@ I2C_CLIENT_INSMOD;
/* Each client has this additional data */
struct pcf8575_data {
- struct i2c_client client;
int write; /* last written value, or error code */
};
-static int pcf8575_attach_adapter(struct i2c_adapter *adapter);
-static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind);
-static int pcf8575_detach_client(struct i2c_client *client);
-
-/* This is the driver that will be inserted */
-static struct i2c_driver pcf8575_driver = {
- .driver = {
- .owner = THIS_MODULE,
- .name = "pcf8575",
- },
- .attach_adapter = pcf8575_attach_adapter,
- .detach_client = pcf8575_detach_client,
-};
-
/* following are the sysfs callback functions */
static ssize_t show_read(struct device *dev, struct device_attribute *attr,
char *buf)
@@ -126,75 +108,77 @@ static const struct attribute_group pcf8575_attr_group = {
* Real code
*/
-static int pcf8575_attach_adapter(struct i2c_adapter *adapter)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int pcf8575_detect(struct i2c_client *client, int kind,
+ struct i2c_board_info *info)
{
- return i2c_probe(adapter, &addr_data, pcf8575_detect);
+ struct i2c_adapter *adapter = client->adapter;
+
+ if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
+ return -ENODEV;
+
+ /* This is the place to detect whether the chip at the specified
+ address really is a PCF8575 chip. However, there is no method known
+ to detect whether an I2C chip is a PCF8575 or any other I2C chip. */
+
+ strlcpy(info->type, "pcf8575", I2C_NAME_SIZE);
+
+ return 0;
}
-/* This function is called by i2c_probe */
-static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind)
+static int pcf8575_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
{
- struct i2c_client *client;
struct pcf8575_data *data;
- int err = 0;
-
- if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
- goto exit;
+ int err;
- /* OK. For now, we presume we have a valid client. We now create the
- client structure, even though we cannot fill it completely yet. */
data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL);
if (!data) {
err = -ENOMEM;
goto exit;
}
- client = &data->client;
i2c_set_clientdata(client, data);
- client->addr = address;
- client->adapter = adapter;
- client->driver = &pcf8575_driver;
- strlcpy(client->name, "pcf8575", I2C_NAME_SIZE);
data->write = -EAGAIN;
- /* This is the place to detect whether the chip at the specified
- address really is a PCF8575 chip. However, there is no method known
- to detect whether an I2C chip is a PCF8575 or any other I2C chip. */
-
- /* Tell the I2C layer a new client has arrived */
- err = i2c_attach_client(client);
- if (err)
- goto exit_free;
-
/* Register sysfs hooks */
err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group);
if (err)
- goto exit_detach;
+ goto exit_free;
return 0;
-exit_detach:
- i2c_detach_client(client);
exit_free:
kfree(data);
exit:
return err;
}
-static int pcf8575_detach_client(struct i2c_client *client)
+static int pcf8575_remove(struct i2c_client *client)
{
- int err;
-
sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group);
-
- err = i2c_detach_client(client);
- if (err)
- return err;
-
kfree(i2c_get_clientdata(client));
return 0;
}
+static const struct i2c_device_id pcf8575_id[] = {
+ { "pcf8575", 0 },
+ { }
+};
+
+static struct i2c_driver pcf8575_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "pcf8575",
+ },
+ .probe = pcf8575_probe,
+ .remove = pcf8575_remove,
+ .id_table = pcf8575_id,
+
+ .detect = pcf8575_detect,
+ .address_data = &addr_data,
+};
+
static int __init pcf8575_init(void)
{
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,
#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg))
struct pcf8591_data {
- struct i2c_client client;
struct mutex update_lock;
u8 control;
u8 aout;
};
-static int pcf8591_attach_adapter(struct i2c_adapter *adapter);
-static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind);
-static int pcf8591_detach_client(struct i2c_client *client);
static void pcf8591_init_client(struct i2c_client *client);
static int pcf8591_read_channel(struct device *dev, int channel);
-/* This is the driver that will be inserted */
-static struct i2c_driver pcf8591_driver = {
- .driver = {
- .name = "pcf8591",
- },
- .attach_adapter = pcf8591_attach_adapter,
- .detach_client = pcf8591_detach_client,
-};
-
/* following are the sysfs callback functions */
#define show_in_channel(channel) \
static 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 = {
/*
* Real code
*/
-static int pcf8591_attach_adapter(struct i2c_adapter *adapter)
-{
- return i2c_probe(adapter, &addr_data, pcf8591_detect);
-}
-/* This function is called by i2c_probe */
-static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int pcf8591_detect(struct i2c_client *client, int kind,
+ struct i2c_board_info *info)
{
- struct i2c_client *client;
- struct pcf8591_data *data;
- int err = 0;
+ struct i2c_adapter *adapter = client->adapter;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE
| I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
- goto exit;
+ return -ENODEV;
+
+ /* Now, we would do the remaining detection. But the PCF8591 is plainly
+ impossible to detect! Stupid chip. */
+
+ strlcpy(info->type, "pcf8591", I2C_NAME_SIZE);
+
+ return 0;
+}
+
+static int pcf8591_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct pcf8591_data *data;
+ int err;
- /* OK. For now, we presume we have a valid client. We now create the
- client structure, even though we cannot fill it completely yet. */
if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) {
err = -ENOMEM;
goto exit;
}
- client = &data->client;
i2c_set_clientdata(client, data);
- client->addr = address;
- client->adapter = adapter;
- client->driver = &pcf8591_driver;
-
- /* Now, we would do the remaining detection. But the PCF8591 is plainly
- impossible to detect! Stupid chip. */
-
- /* Determine the chip type - only one kind supported! */
- if (kind <= 0)
- kind = pcf8591;
-
- /* Fill in the remaining client fields and put it into the global
- list */
- strlcpy(client->name, "pcf8591", I2C_NAME_SIZE);
mutex_init(&data->update_lock);
- /* Tell the I2C layer a new client has arrived */
- if ((err = i2c_attach_client(client)))
- goto exit_kfree;
-
/* Initialize the PCF8591 chip */
pcf8591_init_client(client);
/* Register sysfs hooks */
err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group);
if (err)
- goto exit_detach;
+ goto exit_kfree;
/* Register input2 if not in "two differential inputs" mode */
if (input_mode != 3) {
@@ -252,24 +227,16 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
exit_sysfs_remove:
sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt);
sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group);
-exit_detach:
- i2c_detach_client(client);
exit_kfree:
kfree(data);
exit:
return err;
}
-static int pcf8591_detach_client(struct i2c_client *client)
+static int pcf8591_remove(struct i2c_client *client)
{
- int err;
-
sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt);
sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group);
-
- if ((err = i2c_detach_client(client)))
- return err;
-
kfree(i2c_get_clientdata(client));
return 0;
}
@@ -316,6 +283,25 @@ static int pcf8591_read_channel(struct device *dev, int channel)
return (10 * value);
}
+static const struct i2c_device_id pcf8591_id[] = {
+ { "pcf8591", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, pcf8591_id);
+
+static struct i2c_driver pcf8591_driver = {
+ .driver = {
+ .name = "pcf8591",
+ },
+ .probe = pcf8591_probe,
+ .remove = pcf8591_remove,
+ .id_table = pcf8591_id,
+
+ .class = I2C_CLASS_HWMON, /* Nearest choice */
+ .detect = pcf8591_detect,
+ .address_data = &addr_data,
+};
+
static int __init pcf8591_init(void)
{
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)
dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
+ /* Clear the device structure in case this adapter is ever going to be
+ added again */
+ memset(&adap->dev, 0, sizeof(adap->dev));
+
out_unlock:
mutex_unlock(&core_lock);
return res;