9
0
Fork 0

I2C: Put I2C devices on their own bus

This patch adds a I2C bus on which the I2C devices and drivers register.
This makes it cleaner as I2C devices won't accidently end up probed by
a platform_device driver.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-09-09 22:08:39 +02:00
parent 617bfbcbeb
commit 75265ae527
10 changed files with 40 additions and 9 deletions

View File

@ -251,6 +251,7 @@ struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
strcpy(client->dev.name, chip->type);
client->dev.type_data = client;
client->dev.platform_data = chip->platform_data;
client->dev.bus = &i2c_bus;
client->adapter = adapter;
client->addr = chip->addr;
@ -372,3 +373,25 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
return 0;
}
EXPORT_SYMBOL(i2c_add_numbered_adapter);
static int i2c_match(struct device_d *dev, struct driver_d *drv)
{
return strcmp(dev->name, drv->name) ? -1 : 0;
}
static int i2c_probe(struct device_d *dev)
{
return dev->driver->probe(dev);
}
static void i2c_remove(struct device_d *dev)
{
dev->driver->remove(dev);
}
struct bus_type i2c_bus = {
.name = "i2c",
.match = i2c_match,
.probe = i2c_probe,
.remove = i2c_remove,
};

View File

@ -103,7 +103,7 @@ static struct driver_d lp_driver = {
static int lp_init(void)
{
register_driver(&lp_driver);
i2c_register_driver(&lp_driver);
return 0;
}

View File

@ -349,7 +349,7 @@ static struct driver_d mc_i2c_driver = {
static int mc_i2c_init(void)
{
return register_driver(&mc_i2c_driver);
return i2c_register_driver(&mc_i2c_driver);
}
device_initcall(mc_i2c_init);
#endif

View File

@ -134,7 +134,7 @@ static struct driver_d mc34704_driver = {
static int mc34704_init(void)
{
register_driver(&mc34704_driver);
return 0;
i2c_register_driver(&mc34704_driver);
return 0;
}
device_initcall(mc34704_init);

View File

@ -279,7 +279,7 @@ static struct driver_d mc_i2c_driver = {
static int mc_i2c_init(void)
{
return register_driver(&mc_i2c_driver);
return i2c_register_driver(&mc_i2c_driver);
}
device_initcall(mc_i2c_init);

View File

@ -146,7 +146,7 @@ static struct driver_d mc_driver = {
static int mc_init(void)
{
register_driver(&mc_driver);
i2c_register_driver(&mc_driver);
return 0;
}

View File

@ -146,7 +146,7 @@ static struct driver_d stmpe_driver = {
static int stmpe_init(void)
{
register_driver(&stmpe_driver);
i2c_register_driver(&stmpe_driver);
return 0;
}

View File

@ -53,7 +53,7 @@ static struct driver_d twl_driver = {
static int twl_init(void)
{
register_driver(&twl_driver);
i2c_register_driver(&twl_driver);
return 0;
}

View File

@ -49,7 +49,7 @@ static struct driver_d twl_driver = {
static int twl_init(void)
{
register_driver(&twl_driver);
i2c_register_driver(&twl_driver);
return 0;
}

View File

@ -139,4 +139,12 @@ extern int i2c_write_reg(struct i2c_client *client, u32 addr, const u8 *buf, u16
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
extern struct bus_type i2c_bus;
static inline int i2c_register_driver(struct driver_d *drv)
{
drv->bus = &i2c_bus;
return register_driver(drv);
}
#endif /* I2C_I2C_H */