[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20140605103009.85BE4C40A4D@trevor.secretlab.ca>
Date: Thu, 05 Jun 2014 11:30:09 +0100
From: Grant Likely <grant.likely@...aro.org>
To: Lee Jones <lee.jones@...aro.org>,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Cc: wsa@...-dreams.de, linux-i2c@...r.kernel.org,
devicetree@...r.kernel.org, linus.walleij@...aro.org,
Lee Jones <lee.jones@...aro.org>
Subject: Re: [PATCH 7/7] OF/ACPI/I2C: Add generic match function for the
aforementioned systems
On Wed, 4 Jun 2014 13:09:56 +0100, Lee Jones <lee.jones@...aro.org> wrote:
> Currently this is a helper function for the I2C subsystem to aid the
> matching of non-standard compatible strings and devices which use DT
> and/or ACPI, but do not supply any nodes (see: [1] Method 4). However,
> it has been made more generic as it can be used to only make one call
> for drivers which support any mixture of OF, ACPI and/or I2C matching.
>
> The initial aim is for of_match_device() to be replaced by this call
> in all I2C device drivers.
>
> [1] Documentation/i2c/instantiating-devices
>
> Signed-off-by: Lee Jones <lee.jones@...aro.org>
I don't like this. It drops all type safety on the match entry
and the caller has no idea what it got back.
g.
> ---
> include/linux/match.h | 40 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 40 insertions(+)
> create mode 100644 include/linux/match.h
>
> diff --git a/include/linux/match.h b/include/linux/match.h
> new file mode 100644
> index 0000000..20a08e2
> --- /dev/null
> +++ b/include/linux/match.h
> @@ -0,0 +1,40 @@
> +#include <linux/of.h>
> +#include <linux/acpi.h>
> +#include <linux/i2c.h>
> +
> +static void *device_match(struct device *dev)
> +{
> + struct device_driver *driver = dev->driver;
> +
> + if (!driver)
> + return NULL;
> +
> + /* Attempt an OF style match */
> + if (IS_ENABLED(CONFIG_OF)) {
> + const struct of_device_id *of_match =
> + i2c_of_match_device(driver->of_match_table, dev);
> + if (of_match)
> + return (void *)of_match;
> + }
> +
> + /* Then ACPI style match */
> + if (IS_ENABLED(CONFIG_ACPI)) {
> + const struct acpi_device_id *acpi_match =
> + acpi_match_device(driver->acpi_match_table, dev);
> + if (acpi_match)
> + return (void *)acpi_match;
> + }
> +
> + /* Finally an I2C match */
> + if (IS_ENABLED(CONFIG_I2C)) {
> + struct i2c_client *client = i2c_verify_client(dev);
> + struct i2c_driver *i2c_drv = to_i2c_driver(driver);
> + struct i2c_device_id *i2c_match;
> +
> + i2c_match = i2c_match_id(i2c_drv->id_table, client);
> + if (i2c_match)
> + return (void *)i2c_match;
> + }
> +
> + return NULL;
> +}
> --
> 1.8.3.2
>
--
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