Skip to content

Commit 4124c4e

Browse files
committed
i2c: allow attaching IRQ resources to i2c_board_info
Simple integer for interrupt number is not expressive enough, as it does not convey interrupt trigger type that should be used. Let's allow attaching array of resources to the board info and have i2c core parse first IRQ resource and set up interrupt trigger as needed. Reviewed-by: Wolfram Sang <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 0daaf99 commit 4124c4e

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

drivers/i2c/i2c-boardinfo.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsig
9090
}
9191
}
9292

93+
if (info->resources) {
94+
devinfo->board_info.resources =
95+
kmemdup(info->resources,
96+
info->num_resources *
97+
sizeof(*info->resources),
98+
GFP_KERNEL);
99+
if (!devinfo->board_info.resources) {
100+
status = -ENOMEM;
101+
break;
102+
}
103+
}
104+
93105
list_add_tail(&devinfo->list, &__i2c_board_list);
94106
}
95107

drivers/i2c/i2c-core.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,32 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
12781278
i2c_encode_flags_to_addr(client));
12791279
}
12801280

1281+
static int i2c_dev_irq_from_resources(const struct resource *resources,
1282+
unsigned int num_resources)
1283+
{
1284+
struct irq_data *irqd;
1285+
int i;
1286+
1287+
for (i = 0; i < num_resources; i++) {
1288+
const struct resource *r = &resources[i];
1289+
1290+
if (resource_type(r) != IORESOURCE_IRQ)
1291+
continue;
1292+
1293+
if (r->flags & IORESOURCE_BITS) {
1294+
irqd = irq_get_irq_data(r->start);
1295+
if (!irqd)
1296+
break;
1297+
1298+
irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
1299+
}
1300+
1301+
return r->start;
1302+
}
1303+
1304+
return 0;
1305+
}
1306+
12811307
/**
12821308
* i2c_new_device - instantiate an i2c device
12831309
* @adap: the adapter managing the device
@@ -1313,7 +1339,11 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
13131339

13141340
client->flags = info->flags;
13151341
client->addr = info->addr;
1342+
13161343
client->irq = info->irq;
1344+
if (!client->irq)
1345+
client->irq = i2c_dev_irq_from_resources(info->resources,
1346+
info->num_resources);
13171347

13181348
strlcpy(client->name, info->type, sizeof(client->name));
13191349

include/linux/i2c.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ static inline int i2c_slave_event(struct i2c_client *client,
304304
* @of_node: pointer to OpenFirmware device node
305305
* @fwnode: device node supplied by the platform firmware
306306
* @properties: additional device properties for the device
307+
* @resources: resources associated with the device
308+
* @num_resources: number of resources in the @resources array
307309
* @irq: stored in i2c_client.irq
308310
*
309311
* I2C doesn't actually support hardware probing, although controllers and
@@ -326,6 +328,8 @@ struct i2c_board_info {
326328
struct device_node *of_node;
327329
struct fwnode_handle *fwnode;
328330
const struct property_entry *properties;
331+
const struct resource *resources;
332+
unsigned int num_resources;
329333
int irq;
330334
};
331335

0 commit comments

Comments
 (0)