[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140602135722.GC4146@lee--X1>
Date: Mon, 2 Jun 2014 14:57:22 +0100
From: Lee Jones <lee.jones@...aro.org>
To: linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
wsa@...-dreams.de
Cc: linus.walleij@...aro.org, grant.likely@...aro.org,
linux-i2c@...r.kernel.org
Subject: Re: [PATCH 1/3] i2c: Provide 'device type' to 'OF device node'
look-up
> We have a problem. There are lots of I2C device ID tables scattered
> around the kernel which are redundant in all Device Tree and/or ACPI
> only supported device drivers. After recent discussions it has become
> apparent that the only thing blocking the complete removal of these
> tables is the continued support of 'register an I2C device via sysfs'
> functionality. As the sysfs method doesn't know anything about Device
> Tree or ACPI, we can not pass any nodes in. This patch searches all
> known Device Tree nodes and attempts to acquire a match from the
> device name provided via sysfs. It can not fail, but if found assigns
> the matching of_node to i2c_board_info prior to registering.
>
> Signed-off-by: Lee Jones <lee.jones@...aro.org>
> ---
> drivers/i2c/i2c-core.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
[...]
> +static struct device_node *of_i2c_type_to_node(char *type)
> +{
> + struct device_node *np;
> + const char *compatible, *name;
> + int len;
> +
> + if (!type)
> + return NULL;
> +
> + for_each_of_allnodes(np) {
> + compatible = of_get_property(np, "compatible", &len);
> + if (!compatible)
> + continue;
> +
> + name = strchr(compatible, ',');
> + if (!name)
> + name = compatible;
> + else
> + name++;
> +
> + if (!strncmp(name, type, len - (name - compatible)))
> + return np;
> + }
> +
> + return NULL;
> +}
Ah, this _might_ not work if there are more than one devices of the
same type. I guess I need to check the 'reg' property too.
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists