Re: [PATCH 11/15] i2c: core: Allow getting ACPI info by index

From: Andy Shevchenko
Date: Fri Mar 17 2017 - 13:36:53 EST


On Fri, 2017-03-17 at 10:55 +0100, Hans de Goede wrote:
> Modify struct i2c_acpi_lookup and i2c_acpi_fill_info() to allow
> using them to get the info from a certain index in the ACPI-resource
> list rather then taking the first I2cSerialBus resource.
>

+Cc: Jarkko (our main I2C guy)

> Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx>
> ---
> Âdrivers/i2c/i2c-core.c | 7 +++++++
> Â1 file changed, 7 insertions(+)
>
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index d2402bb..32b58fb 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -112,6 +112,8 @@ struct i2c_acpi_lookup {
> Â acpi_handle adapter_handle;
> Â acpi_handle device_handle;
> Â acpi_handle search_handle;
> + int n;
> + int index;
> Â u32 speed;
> Â u32 min_speed;
> Â};
> @@ -123,6 +125,9 @@ static int i2c_acpi_fill_info(struct acpi_resource
> *ares, void *data)
> Â struct acpi_resource_i2c_serialbus *sb;
> Â acpi_status status;
> Â
> + if (lookup->index != -1 && lookup->n++ != lookup->index)
> + return 1;
> +
> Â if (info->addr || ares->type !=
> ACPI_RESOURCE_TYPE_SERIAL_BUS)
> Â return 1;
> Â
> @@ -182,6 +187,7 @@ static int i2c_acpi_get_info(struct acpi_device
> *adev,
> Â
> Â memset(&lookup, 0, sizeof(lookup));
> Â lookup.info = info;
> + lookup.index = -1;
> Â
> Â ret = i2c_acpi_do_lookup(adev, &lookup);
> Â if (ret)
> @@ -328,6 +334,7 @@ u32 i2c_acpi_find_bus_speed(struct device *dev)
> Â lookup.search_handle = ACPI_HANDLE(dev);
> Â lookup.min_speed = UINT_MAX;
> Â lookup.info = &dummy;
> + lookup.index = -1;
> Â
> Â status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
> ACPI_ROOT_OBJECT,
> Â ÂÂÂÂÂI2C_ACPI_MAX_SCAN_DEPTH,

--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy