aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r--drivers/i2c/i2c-core.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index b346a687ab59..42e852d79ffa 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -437,6 +437,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
437{ 437{
438 int res = 0, dummy; 438 int res = 0, dummy;
439 439
440 /* Can't register until after driver model init */
441 if (unlikely(WARN_ON(!i2c_bus_type.p)))
442 return -EAGAIN;
443
440 mutex_init(&adap->bus_lock); 444 mutex_init(&adap->bus_lock);
441 mutex_init(&adap->clist_lock); 445 mutex_init(&adap->clist_lock);
442 INIT_LIST_HEAD(&adap->clients); 446 INIT_LIST_HEAD(&adap->clients);
@@ -696,6 +700,10 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
696{ 700{
697 int res; 701 int res;
698 702
703 /* Can't register until after driver model init */
704 if (unlikely(WARN_ON(!i2c_bus_type.p)))
705 return -EAGAIN;
706
699 /* new style driver methods can't mix with legacy ones */ 707 /* new style driver methods can't mix with legacy ones */
700 if (is_newstyle_driver(driver)) { 708 if (is_newstyle_driver(driver)) {
701 if (driver->attach_adapter || driver->detach_adapter 709 if (driver->attach_adapter || driver->detach_adapter
@@ -978,7 +986,10 @@ static void __exit i2c_exit(void)
978 bus_unregister(&i2c_bus_type); 986 bus_unregister(&i2c_bus_type);
979} 987}
980 988
981subsys_initcall(i2c_init); 989/* We must initialize early, because some subsystems register i2c drivers
990 * in subsys_initcall() code, but are linked (and initialized) before i2c.
991 */
992postcore_initcall(i2c_init);
982module_exit(i2c_exit); 993module_exit(i2c_exit);
983 994
984/* ---------------------------------------------------- 995/* ----------------------------------------------------
@@ -1677,6 +1688,28 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1677EXPORT_SYMBOL(i2c_smbus_write_word_data); 1688EXPORT_SYMBOL(i2c_smbus_write_word_data);
1678 1689
1679/** 1690/**
1691 * i2c_smbus_process_call - SMBus "process call" protocol
1692 * @client: Handle to slave device
1693 * @command: Byte interpreted by slave
1694 * @value: 16-bit "word" being written
1695 *
1696 * This executes the SMBus "process call" protocol, returning negative errno
1697 * else a 16-bit unsigned "word" received from the device.
1698 */
1699s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value)
1700{
1701 union i2c_smbus_data data;
1702 int status;
1703 data.word = value;
1704
1705 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1706 I2C_SMBUS_WRITE, command,
1707 I2C_SMBUS_PROC_CALL, &data);
1708 return (status < 0) ? status : data.word;
1709}
1710EXPORT_SYMBOL(i2c_smbus_process_call);
1711
1712/**
1680 * i2c_smbus_read_block_data - SMBus "block read" protocol 1713 * i2c_smbus_read_block_data - SMBus "block read" protocol
1681 * @client: Handle to slave device 1714 * @client: Handle to slave device
1682 * @command: Byte interpreted by slave 1715 * @command: Byte interpreted by slave