Skip to content

Commit b4e2f6a

Browse files
Wolfram SangWolfram Sang
authored andcommitted
i2c: apply DT flags when probing
Check for slave and 10-bit flags when probing and mark the client when found. Improve the address validity check, too 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>
1 parent c4019b7 commit b4e2f6a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/i2c/i2c-core.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
I2C slave support (c) 2014 by Wolfram Sang <wsa@sang-engineering.com>
2828
*/
2929

30+
#include <dt-bindings/i2c/i2c.h>
3031
#include <linux/module.h>
3132
#include <linux/kernel.h>
3233
#include <linux/delay.h>
@@ -1288,7 +1289,8 @@ static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
12881289
struct i2c_client *result;
12891290
struct i2c_board_info info = {};
12901291
struct dev_archdata dev_ad = {};
1291-
const __be32 *addr;
1292+
const __be32 *addr_be;
1293+
u32 addr;
12921294
int len;
12931295

12941296
dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name);
@@ -1299,20 +1301,31 @@ static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
12991301
return ERR_PTR(-EINVAL);
13001302
}
13011303

1302-
addr = of_get_property(node, "reg", &len);
1303-
if (!addr || (len < sizeof(*addr))) {
1304+
addr_be = of_get_property(node, "reg", &len);
1305+
if (!addr_be || (len < sizeof(*addr_be))) {
13041306
dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",
13051307
node->full_name);
13061308
return ERR_PTR(-EINVAL);
13071309
}
13081310

1309-
info.addr = be32_to_cpup(addr);
1310-
if (info.addr > (1 << 10) - 1) {
1311+
addr = be32_to_cpup(addr_be);
1312+
if (addr & I2C_TEN_BIT_ADDRESS) {
1313+
addr &= ~I2C_TEN_BIT_ADDRESS;
1314+
info.flags |= I2C_CLIENT_TEN;
1315+
}
1316+
1317+
if (addr & I2C_OWN_SLAVE_ADDRESS) {
1318+
addr &= ~I2C_OWN_SLAVE_ADDRESS;
1319+
info.flags |= I2C_CLIENT_SLAVE;
1320+
}
1321+
1322+
if (i2c_check_addr_validity(addr, info.flags)) {
13111323
dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n",
13121324
info.addr, node->full_name);
13131325
return ERR_PTR(-EINVAL);
13141326
}
13151327

1328+
info.addr = addr;
13161329
info.of_node = of_node_get(node);
13171330
info.archdata = &dev_ad;
13181331

0 commit comments

Comments
 (0)