diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2015-05-18 15:09:12 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2015-08-24 08:05:11 -0400 |
commit | da899f55b359225f85e154765baaddb13ec436ca (patch) | |
tree | 00d1db2a93b72e740a30d4127c6170ce6d1e829f /drivers/i2c/i2c-core.c | |
parent | c5ebb387f4e6b2dd7c74d71caf7b696834d0c887 (diff) |
i2c: apply address offset for slaves, too
We want a separate address range for being an I2C slave. Add an offset
of 0x1000, so it can be combined with ten bit addresses as well. Add a
separate function to create the address value, we will need it later in
other places.
Tested-by: Andrey Danin <danindrey@mail.ru>
Acked-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 07a83f34ed58..47dbe2514741 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -57,6 +57,9 @@ | |||
57 | #define CREATE_TRACE_POINTS | 57 | #define CREATE_TRACE_POINTS |
58 | #include <trace/events/i2c.h> | 58 | #include <trace/events/i2c.h> |
59 | 59 | ||
60 | #define I2C_ADDR_OFFSET_TEN_BIT 0xa000 | ||
61 | #define I2C_ADDR_OFFSET_SLAVE 0x1000 | ||
62 | |||
60 | /* core_lock protects i2c_adapter_idr, and guarantees | 63 | /* core_lock protects i2c_adapter_idr, and guarantees |
61 | that device detection, deletion of detected devices, and attach_adapter | 64 | that device detection, deletion of detected devices, and attach_adapter |
62 | calls are serialized */ | 65 | calls are serialized */ |
@@ -778,6 +781,21 @@ struct i2c_client *i2c_verify_client(struct device *dev) | |||
778 | EXPORT_SYMBOL(i2c_verify_client); | 781 | EXPORT_SYMBOL(i2c_verify_client); |
779 | 782 | ||
780 | 783 | ||
784 | /* Return a unique address which takes the flags of the client into account */ | ||
785 | static unsigned short i2c_encode_flags_to_addr(struct i2c_client *client) | ||
786 | { | ||
787 | unsigned short addr = client->addr; | ||
788 | |||
789 | /* For some client flags, add an arbitrary offset to avoid collisions */ | ||
790 | if (client->flags & I2C_CLIENT_TEN) | ||
791 | addr |= I2C_ADDR_OFFSET_TEN_BIT; | ||
792 | |||
793 | if (client->flags & I2C_CLIENT_SLAVE) | ||
794 | addr |= I2C_ADDR_OFFSET_SLAVE; | ||
795 | |||
796 | return addr; | ||
797 | } | ||
798 | |||
781 | /* This is a permissive address validity check, I2C address map constraints | 799 | /* This is a permissive address validity check, I2C address map constraints |
782 | * are purposely not enforced, except for the general call address. */ | 800 | * are purposely not enforced, except for the general call address. */ |
783 | static int i2c_check_client_addr_validity(const struct i2c_client *client) | 801 | static int i2c_check_client_addr_validity(const struct i2c_client *client) |
@@ -923,10 +941,8 @@ static void i2c_dev_set_name(struct i2c_adapter *adap, | |||
923 | return; | 941 | return; |
924 | } | 942 | } |
925 | 943 | ||
926 | /* For 10-bit clients, add an arbitrary offset to avoid collisions */ | ||
927 | dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), | 944 | dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), |
928 | client->addr | ((client->flags & I2C_CLIENT_TEN) | 945 | i2c_encode_flags_to_addr(client)); |
929 | ? 0xa000 : 0)); | ||
930 | } | 946 | } |
931 | 947 | ||
932 | /** | 948 | /** |