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.c69
1 files changed, 11 insertions, 58 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index e388590b44ab..991d38daa87d 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -935,25 +935,17 @@ out_list:
935 */ 935 */
936int i2c_add_adapter(struct i2c_adapter *adapter) 936int i2c_add_adapter(struct i2c_adapter *adapter)
937{ 937{
938 int id, res = 0; 938 int id;
939
940retry:
941 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
942 return -ENOMEM;
943 939
944 mutex_lock(&core_lock); 940 mutex_lock(&core_lock);
945 /* "above" here means "above or equal to", sigh */ 941 id = idr_alloc(&i2c_adapter_idr, adapter,
946 res = idr_get_new_above(&i2c_adapter_idr, adapter, 942 __i2c_first_dynamic_bus_num, 0, GFP_KERNEL);
947 __i2c_first_dynamic_bus_num, &id);
948 mutex_unlock(&core_lock); 943 mutex_unlock(&core_lock);
949 944 if (id < 0)
950 if (res < 0) { 945 return id;
951 if (res == -EAGAIN)
952 goto retry;
953 return res;
954 }
955 946
956 adapter->nr = id; 947 adapter->nr = id;
948
957 return i2c_register_adapter(adapter); 949 return i2c_register_adapter(adapter);
958} 950}
959EXPORT_SYMBOL(i2c_add_adapter); 951EXPORT_SYMBOL(i2c_add_adapter);
@@ -984,33 +976,17 @@ EXPORT_SYMBOL(i2c_add_adapter);
984int i2c_add_numbered_adapter(struct i2c_adapter *adap) 976int i2c_add_numbered_adapter(struct i2c_adapter *adap)
985{ 977{
986 int id; 978 int id;
987 int status;
988 979
989 if (adap->nr == -1) /* -1 means dynamically assign bus id */ 980 if (adap->nr == -1) /* -1 means dynamically assign bus id */
990 return i2c_add_adapter(adap); 981 return i2c_add_adapter(adap);
991 if (adap->nr & ~MAX_IDR_MASK)
992 return -EINVAL;
993
994retry:
995 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
996 return -ENOMEM;
997 982
998 mutex_lock(&core_lock); 983 mutex_lock(&core_lock);
999 /* "above" here means "above or equal to", sigh; 984 id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1,
1000 * we need the "equal to" result to force the result 985 GFP_KERNEL);
1001 */
1002 status = idr_get_new_above(&i2c_adapter_idr, adap, adap->nr, &id);
1003 if (status == 0 && id != adap->nr) {
1004 status = -EBUSY;
1005 idr_remove(&i2c_adapter_idr, id);
1006 }
1007 mutex_unlock(&core_lock); 986 mutex_unlock(&core_lock);
1008 if (status == -EAGAIN) 987 if (id < 0)
1009 goto retry; 988 return id == -ENOSPC ? -EBUSY : id;
1010 989 return i2c_register_adapter(adap);
1011 if (status == 0)
1012 status = i2c_register_adapter(adap);
1013 return status;
1014} 990}
1015EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); 991EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
1016 992
@@ -1866,29 +1842,6 @@ s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command,
1866EXPORT_SYMBOL(i2c_smbus_write_word_data); 1842EXPORT_SYMBOL(i2c_smbus_write_word_data);
1867 1843
1868/** 1844/**
1869 * i2c_smbus_process_call - SMBus "process call" protocol
1870 * @client: Handle to slave device
1871 * @command: Byte interpreted by slave
1872 * @value: 16-bit "word" being written
1873 *
1874 * This executes the SMBus "process call" protocol, returning negative errno
1875 * else a 16-bit unsigned "word" received from the device.
1876 */
1877s32 i2c_smbus_process_call(const struct i2c_client *client, u8 command,
1878 u16 value)
1879{
1880 union i2c_smbus_data data;
1881 int status;
1882 data.word = value;
1883
1884 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1885 I2C_SMBUS_WRITE, command,
1886 I2C_SMBUS_PROC_CALL, &data);
1887 return (status < 0) ? status : data.word;
1888}
1889EXPORT_SYMBOL(i2c_smbus_process_call);
1890
1891/**
1892 * i2c_smbus_read_block_data - SMBus "block read" protocol 1845 * i2c_smbus_read_block_data - SMBus "block read" protocol
1893 * @client: Handle to slave device 1846 * @client: Handle to slave device
1894 * @command: Byte interpreted by slave 1847 * @command: Byte interpreted by slave