diff options
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 7ca81f42d14..3e31f1d265c 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -127,20 +127,17 @@ static ssize_t show_client_name(struct device *dev, struct device_attribute *att | |||
127 | return sprintf(buf, "%s\n", client->name); | 127 | return sprintf(buf, "%s\n", client->name); |
128 | } | 128 | } |
129 | 129 | ||
130 | /* | 130 | /* |
131 | * We can't use the DEVICE_ATTR() macro here as we want the same filename for a | 131 | * We can't use the DEVICE_ATTR() macro here, as we used the same name for |
132 | * different type of a device. So beware if the DEVICE_ATTR() macro ever | 132 | * an i2c adapter attribute (above). |
133 | * changes, this definition will also have to change. | ||
134 | */ | 133 | */ |
135 | static struct device_attribute dev_attr_client_name = { | 134 | static struct device_attribute dev_attr_client_name = |
136 | .attr = {.name = "name", .mode = S_IRUGO, .owner = THIS_MODULE }, | 135 | __ATTR(name, S_IRUGO, &show_client_name, NULL); |
137 | .show = &show_client_name, | ||
138 | }; | ||
139 | 136 | ||
140 | 137 | ||
141 | /* --------------------------------------------------- | 138 | /* --------------------------------------------------- |
142 | * registering functions | 139 | * registering functions |
143 | * --------------------------------------------------- | 140 | * --------------------------------------------------- |
144 | */ | 141 | */ |
145 | 142 | ||
146 | /* ----- | 143 | /* ----- |
@@ -314,7 +311,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
314 | res = driver_register(&driver->driver); | 311 | res = driver_register(&driver->driver); |
315 | if (res) | 312 | if (res) |
316 | return res; | 313 | return res; |
317 | 314 | ||
318 | mutex_lock(&core_lists); | 315 | mutex_lock(&core_lists); |
319 | 316 | ||
320 | list_add_tail(&driver->list,&drivers); | 317 | list_add_tail(&driver->list,&drivers); |
@@ -338,13 +335,13 @@ int i2c_del_driver(struct i2c_driver *driver) | |||
338 | struct list_head *item1, *item2, *_n; | 335 | struct list_head *item1, *item2, *_n; |
339 | struct i2c_client *client; | 336 | struct i2c_client *client; |
340 | struct i2c_adapter *adap; | 337 | struct i2c_adapter *adap; |
341 | 338 | ||
342 | int res = 0; | 339 | int res = 0; |
343 | 340 | ||
344 | mutex_lock(&core_lists); | 341 | mutex_lock(&core_lists); |
345 | 342 | ||
346 | /* Have a look at each adapter, if clients of this driver are still | 343 | /* Have a look at each adapter, if clients of this driver are still |
347 | * attached. If so, detach them to be able to kill the driver | 344 | * attached. If so, detach them to be able to kill the driver |
348 | * afterwards. | 345 | * afterwards. |
349 | */ | 346 | */ |
350 | list_for_each(item1,&adapters) { | 347 | list_for_each(item1,&adapters) { |
@@ -419,14 +416,14 @@ int i2c_attach_client(struct i2c_client *client) | |||
419 | goto out_unlock; | 416 | goto out_unlock; |
420 | } | 417 | } |
421 | list_add_tail(&client->list,&adapter->clients); | 418 | list_add_tail(&client->list,&adapter->clients); |
422 | 419 | ||
423 | client->usage_count = 0; | 420 | client->usage_count = 0; |
424 | 421 | ||
425 | client->dev.parent = &client->adapter->dev; | 422 | client->dev.parent = &client->adapter->dev; |
426 | client->dev.driver = &client->driver->driver; | 423 | client->dev.driver = &client->driver->driver; |
427 | client->dev.bus = &i2c_bus_type; | 424 | client->dev.bus = &i2c_bus_type; |
428 | client->dev.release = &i2c_client_release; | 425 | client->dev.release = &i2c_client_release; |
429 | 426 | ||
430 | snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), | 427 | snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), |
431 | "%d-%04x", i2c_adapter_id(adapter), client->addr); | 428 | "%d-%04x", i2c_adapter_id(adapter), client->addr); |
432 | dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", | 429 | dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", |
@@ -467,7 +464,7 @@ int i2c_detach_client(struct i2c_client *client) | |||
467 | { | 464 | { |
468 | struct i2c_adapter *adapter = client->adapter; | 465 | struct i2c_adapter *adapter = client->adapter; |
469 | int res = 0; | 466 | int res = 0; |
470 | 467 | ||
471 | if (client->usage_count > 0) { | 468 | if (client->usage_count > 0) { |
472 | dev_warn(&client->dev, "Client [%s] still busy, " | 469 | dev_warn(&client->dev, "Client [%s] still busy, " |
473 | "can't detach\n", client->name); | 470 | "can't detach\n", client->name); |
@@ -535,10 +532,10 @@ int i2c_release_client(struct i2c_client *client) | |||
535 | __FUNCTION__); | 532 | __FUNCTION__); |
536 | return -EPERM; | 533 | return -EPERM; |
537 | } | 534 | } |
538 | 535 | ||
539 | client->usage_count--; | 536 | client->usage_count--; |
540 | i2c_dec_use_client(client); | 537 | i2c_dec_use_client(client); |
541 | 538 | ||
542 | return 0; | 539 | return 0; |
543 | } | 540 | } |
544 | 541 | ||
@@ -603,7 +600,7 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num) | |||
603 | } | 600 | } |
604 | #endif | 601 | #endif |
605 | 602 | ||
606 | mutex_lock(&adap->bus_lock); | 603 | mutex_lock_nested(&adap->bus_lock, adap->level); |
607 | ret = adap->algo->master_xfer(adap,msgs,num); | 604 | ret = adap->algo->master_xfer(adap,msgs,num); |
608 | mutex_unlock(&adap->bus_lock); | 605 | mutex_unlock(&adap->bus_lock); |
609 | 606 | ||
@@ -624,7 +621,7 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count) | |||
624 | msg.flags = client->flags & I2C_M_TEN; | 621 | msg.flags = client->flags & I2C_M_TEN; |
625 | msg.len = count; | 622 | msg.len = count; |
626 | msg.buf = (char *)buf; | 623 | msg.buf = (char *)buf; |
627 | 624 | ||
628 | ret = i2c_transfer(adap, &msg, 1); | 625 | ret = i2c_transfer(adap, &msg, 1); |
629 | 626 | ||
630 | /* If everything went ok (i.e. 1 msg transmitted), return #bytes | 627 | /* If everything went ok (i.e. 1 msg transmitted), return #bytes |
@@ -757,7 +754,7 @@ int i2c_probe(struct i2c_adapter *adapter, | |||
757 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { | 754 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { |
758 | if (address_data->probe[0] == I2C_CLIENT_END | 755 | if (address_data->probe[0] == I2C_CLIENT_END |
759 | && address_data->normal_i2c[0] == I2C_CLIENT_END) | 756 | && address_data->normal_i2c[0] == I2C_CLIENT_END) |
760 | return 0; | 757 | return 0; |
761 | 758 | ||
762 | dev_warn(&adapter->dev, "SMBus Quick command not supported, " | 759 | dev_warn(&adapter->dev, "SMBus Quick command not supported, " |
763 | "can't probe for chips\n"); | 760 | "can't probe for chips\n"); |
@@ -817,7 +814,7 @@ int i2c_probe(struct i2c_adapter *adapter, | |||
817 | struct i2c_adapter* i2c_get_adapter(int id) | 814 | struct i2c_adapter* i2c_get_adapter(int id) |
818 | { | 815 | { |
819 | struct i2c_adapter *adapter; | 816 | struct i2c_adapter *adapter; |
820 | 817 | ||
821 | mutex_lock(&core_lists); | 818 | mutex_lock(&core_lists); |
822 | adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); | 819 | adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); |
823 | if (adapter && !try_module_get(adapter->owner)) | 820 | if (adapter && !try_module_get(adapter->owner)) |
@@ -834,14 +831,14 @@ void i2c_put_adapter(struct i2c_adapter *adap) | |||
834 | 831 | ||
835 | /* The SMBus parts */ | 832 | /* The SMBus parts */ |
836 | 833 | ||
837 | #define POLY (0x1070U << 3) | 834 | #define POLY (0x1070U << 3) |
838 | static u8 | 835 | static u8 |
839 | crc8(u16 data) | 836 | crc8(u16 data) |
840 | { | 837 | { |
841 | int i; | 838 | int i; |
842 | 839 | ||
843 | for(i = 0; i < 8; i++) { | 840 | for(i = 0; i < 8; i++) { |
844 | if (data & 0x8000) | 841 | if (data & 0x8000) |
845 | data = data ^ POLY; | 842 | data = data ^ POLY; |
846 | data = data << 1; | 843 | data = data << 1; |
847 | } | 844 | } |
@@ -891,13 +888,13 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg) | |||
891 | rpec, cpec); | 888 | rpec, cpec); |
892 | return -1; | 889 | return -1; |
893 | } | 890 | } |
894 | return 0; | 891 | return 0; |
895 | } | 892 | } |
896 | 893 | ||
897 | s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value) | 894 | s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value) |
898 | { | 895 | { |
899 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 896 | return i2c_smbus_xfer(client->adapter,client->addr,client->flags, |
900 | value,0,I2C_SMBUS_QUICK,NULL); | 897 | value,0,I2C_SMBUS_QUICK,NULL); |
901 | } | 898 | } |
902 | 899 | ||
903 | s32 i2c_smbus_read_byte(struct i2c_client *client) | 900 | s32 i2c_smbus_read_byte(struct i2c_client *client) |
@@ -996,11 +993,11 @@ s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, | |||
996 | I2C_SMBUS_I2C_BLOCK_DATA, &data); | 993 | I2C_SMBUS_I2C_BLOCK_DATA, &data); |
997 | } | 994 | } |
998 | 995 | ||
999 | /* Simulate a SMBus command using the i2c protocol | 996 | /* Simulate a SMBus command using the i2c protocol |
1000 | No checking of parameters is done! */ | 997 | No checking of parameters is done! */ |
1001 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | 998 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, |
1002 | unsigned short flags, | 999 | unsigned short flags, |
1003 | char read_write, u8 command, int size, | 1000 | char read_write, u8 command, int size, |
1004 | union i2c_smbus_data * data) | 1001 | union i2c_smbus_data * data) |
1005 | { | 1002 | { |
1006 | /* So we need to generate a series of msgs. In the case of writing, we | 1003 | /* So we need to generate a series of msgs. In the case of writing, we |
@@ -1010,7 +1007,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1010 | unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; | 1007 | unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; |
1011 | unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; | 1008 | unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; |
1012 | int num = read_write == I2C_SMBUS_READ?2:1; | 1009 | int num = read_write == I2C_SMBUS_READ?2:1; |
1013 | struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, | 1010 | struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, |
1014 | { addr, flags | I2C_M_RD, 0, msgbuf1 } | 1011 | { addr, flags | I2C_M_RD, 0, msgbuf1 } |
1015 | }; | 1012 | }; |
1016 | int i; | 1013 | int i; |
@@ -1103,14 +1100,14 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1103 | if (i) { | 1100 | if (i) { |
1104 | /* Compute PEC if first message is a write */ | 1101 | /* Compute PEC if first message is a write */ |
1105 | if (!(msg[0].flags & I2C_M_RD)) { | 1102 | if (!(msg[0].flags & I2C_M_RD)) { |
1106 | if (num == 1) /* Write only */ | 1103 | if (num == 1) /* Write only */ |
1107 | i2c_smbus_add_pec(&msg[0]); | 1104 | i2c_smbus_add_pec(&msg[0]); |
1108 | else /* Write followed by read */ | 1105 | else /* Write followed by read */ |
1109 | partial_pec = i2c_smbus_msg_pec(0, &msg[0]); | 1106 | partial_pec = i2c_smbus_msg_pec(0, &msg[0]); |
1110 | } | 1107 | } |
1111 | /* Ask for PEC if last message is a read */ | 1108 | /* Ask for PEC if last message is a read */ |
1112 | if (msg[num-1].flags & I2C_M_RD) | 1109 | if (msg[num-1].flags & I2C_M_RD) |
1113 | msg[num-1].len++; | 1110 | msg[num-1].len++; |
1114 | } | 1111 | } |
1115 | 1112 | ||
1116 | if (i2c_transfer(adapter, msg, num) < 0) | 1113 | if (i2c_transfer(adapter, msg, num) < 0) |
@@ -1130,7 +1127,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1130 | case I2C_SMBUS_BYTE_DATA: | 1127 | case I2C_SMBUS_BYTE_DATA: |
1131 | data->byte = msgbuf1[0]; | 1128 | data->byte = msgbuf1[0]; |
1132 | break; | 1129 | break; |
1133 | case I2C_SMBUS_WORD_DATA: | 1130 | case I2C_SMBUS_WORD_DATA: |
1134 | case I2C_SMBUS_PROC_CALL: | 1131 | case I2C_SMBUS_PROC_CALL: |
1135 | data->word = msgbuf1[0] | (msgbuf1[1] << 8); | 1132 | data->word = msgbuf1[0] | (msgbuf1[1] << 8); |
1136 | break; | 1133 | break; |
@@ -1146,7 +1143,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1146 | 1143 | ||
1147 | 1144 | ||
1148 | s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, | 1145 | s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, |
1149 | char read_write, u8 command, int size, | 1146 | char read_write, u8 command, int size, |
1150 | union i2c_smbus_data * data) | 1147 | union i2c_smbus_data * data) |
1151 | { | 1148 | { |
1152 | s32 res; | 1149 | s32 res; |