aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
authorJean-Michel Hautbois <jhautbois@gmail.com>2016-01-31 10:33:00 -0500
committerWolfram Sang <wsa@the-dreams.de>2016-06-13 16:32:09 -0400
commit0f614d834bccd3537881c5d0933803b407ce3283 (patch)
tree78e72c00ab33827c5d4dff25f3f0ff9c17100753 /drivers/i2c/i2c-core.c
parent5edb56491d4812c42175980759da53388e5d86f5 (diff)
i2c: Add generic support passing secondary devices addresses
Some I2C devices have multiple addresses assigned, for example each address corresponding to a different internal register map page of the device. So far drivers which need support for this have handled this with a driver specific and non-generic implementation, e.g. passing the additional address via platform data. This patch provides a new helper function called i2c_new_secondary_device() which is intended to provide a generic way to get the secondary address as well as instantiate a struct i2c_client for the secondary address. The function expects a pointer to the primary i2c_client, a name for the secondary address and an optional default address. The name is used as a handle to specify which secondary address to get. The default address is used as a fallback in case no secondary address was explicitly specified. In case no secondary address and no default address were specified the function returns NULL. For now the function only supports look-up of the secondary address from devicetree, but it can be extended in the future to for example support board files and/or ACPI. Signed-off-by: Jean-Michel Hautbois <jean-michel.hautbois@veo-labs.com> Acked-by: Rob Herring <robh@kernel.org> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.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.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index af11b658984d..952d2f0c02c5 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1145,6 +1145,47 @@ struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
1145} 1145}
1146EXPORT_SYMBOL_GPL(i2c_new_dummy); 1146EXPORT_SYMBOL_GPL(i2c_new_dummy);
1147 1147
1148/**
1149 * i2c_new_secondary_device - Helper to get the instantiated secondary address
1150 * and create the associated device
1151 * @client: Handle to the primary client
1152 * @name: Handle to specify which secondary address to get
1153 * @default_addr: Used as a fallback if no secondary address was specified
1154 * Context: can sleep
1155 *
1156 * I2C clients can be composed of multiple I2C slaves bound together in a single
1157 * component. The I2C client driver then binds to the master I2C slave and needs
1158 * to create I2C dummy clients to communicate with all the other slaves.
1159 *
1160 * This function creates and returns an I2C dummy client whose I2C address is
1161 * retrieved from the platform firmware based on the given slave name. If no
1162 * address is specified by the firmware default_addr is used.
1163 *
1164 * On DT-based platforms the address is retrieved from the "reg" property entry
1165 * cell whose "reg-names" value matches the slave name.
1166 *
1167 * This returns the new i2c client, which should be saved for later use with
1168 * i2c_unregister_device(); or NULL to indicate an error.
1169 */
1170struct i2c_client *i2c_new_secondary_device(struct i2c_client *client,
1171 const char *name,
1172 u16 default_addr)
1173{
1174 struct device_node *np = client->dev.of_node;
1175 u32 addr = default_addr;
1176 int i;
1177
1178 if (np) {
1179 i = of_property_match_string(np, "reg-names", name);
1180 if (i >= 0)
1181 of_property_read_u32_index(np, "reg", i, &addr);
1182 }
1183
1184 dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
1185 return i2c_new_dummy(client->adapter, addr);
1186}
1187EXPORT_SYMBOL_GPL(i2c_new_secondary_device);
1188
1148/* ------------------------------------------------------------------------- */ 1189/* ------------------------------------------------------------------------- */
1149 1190
1150/* I2C bus adapters -- one roots each I2C or SMBUS segment */ 1191/* I2C bus adapters -- one roots each I2C or SMBUS segment */