[PATCH 2/5] i2c: acpi: Use available IRQ helper functions

From: Charles Keepax
Date: Tue May 21 2019 - 11:08:14 EST


Use the available IRQ helper functions, most of the functions have
additional helpful side affects like configuring the trigger type of the
IRQ.

Signed-off-by: Charles Keepax <ckeepax@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/i2c/i2c-core-acpi.c | 23 ++++++++++++++---------
drivers/i2c/i2c-core-base.c | 4 ++--
drivers/i2c/i2c-core.h | 2 ++
3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index c3ac3ea184317..764cd10420a74 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -137,25 +137,30 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev,
return 0;
}

+static int i2c_acpi_add_resource(struct acpi_resource *ares, void *data)
+{
+ int *irq = data;
+ struct resource r;
+
+ if (*irq < 0 && acpi_dev_resource_interrupt(ares, 0, &r))
+ *irq = i2c_dev_irq_from_resources(&r, 1);
+
+ return 1; /* No need to add resource to the list */
+}
+
static int i2c_acpi_get_irq(struct acpi_device *adev, int *irq)
{
struct list_head resource_list;
- struct resource_entry *entry;
int ret;

INIT_LIST_HEAD(&resource_list);
+ *irq = -ENOENT;

- ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
+ ret = acpi_dev_get_resources(adev, &resource_list,
+ i2c_acpi_add_resource, &irq);
if (ret < 0)
return -EINVAL;

- resource_list_for_each_entry(entry, &resource_list) {
- if (resource_type(entry->res) == IORESOURCE_IRQ) {
- *irq = entry->res->start;
- break;
- }
- }
-
acpi_dev_free_resource_list(&resource_list);

return 0;
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index d389d4fb0623a..84bf11b25a120 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -687,8 +687,8 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
i2c_encode_flags_to_addr(client));
}

-static int i2c_dev_irq_from_resources(const struct resource *resources,
- unsigned int num_resources)
+int i2c_dev_irq_from_resources(const struct resource *resources,
+ unsigned int num_resources)
{
struct irq_data *irqd;
int i;
diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
index c88cfef813431..8f3a08dc73a25 100644
--- a/drivers/i2c/i2c-core.h
+++ b/drivers/i2c/i2c-core.h
@@ -28,6 +28,8 @@ extern struct list_head __i2c_board_list;
extern int __i2c_first_dynamic_bus_num;

int i2c_check_7bit_addr_validity_strict(unsigned short addr);
+int i2c_dev_irq_from_resources(const struct resource *resources,
+ unsigned int num_resources);

/*
* We only allow atomic transfers for very late communication, e.g. to send
--
2.11.0