* [PATCH] of: add helper function to retrive match data
@ 2015-05-06 18:09 Joachim Eastwood
[not found] ` <1430935749-3881-1-git-send-email-manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Joachim Eastwood @ 2015-05-06 18:09 UTC (permalink / raw)
To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
grant.likely-QSEj5FYQhm4dnm+yROfE0A,
devicetree-u79uwXL29TY76Z2rM5mHXA
Cc: arnd-r2nGTMty4D4, Joachim Eastwood
It's a common operation for device drivers to retrive the data
member from of_device_id struct in their probe function.
Most driver end up doing:
const struct of_device_id *match;
match = of_match_device(driver_of_match, &pdev->dev);
driver->data = match->data;
With the of_device_get_match_data helper function all this can
done in one go.
Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
Hi DT maintainers,
Here is the patch to add of_device_get_match_data as indicated in:
http://marc.info/?l=devicetree&m=143068795621692&w=2
There are lot of device driver that can be simplified with this
helper function. After the function has gone upstream I will
spend some time getting some of them converted over.
Maybe someone with Coccinelle skills could create a script to
do some of the work also.
regards,
Joachim Eastwood
drivers/of/device.c | 12 ++++++++++++
include/linux/of_device.h | 7 +++++++
2 files changed, 19 insertions(+)
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 20c1332a0018..8b91ea241b10 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -163,6 +163,18 @@ void of_device_unregister(struct platform_device *ofdev)
}
EXPORT_SYMBOL(of_device_unregister);
+const void *of_device_get_match_data(const struct device *dev)
+{
+ const struct of_device_id *match;
+
+ match = of_match_device(dev->driver->of_match_table, dev);
+ if (!match)
+ return NULL;
+
+ return match->data;
+}
+EXPORT_SYMBOL(of_device_get_match_data);
+
ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
{
const char *compat;
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 22801b10cef5..3237d34e2ab1 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -33,6 +33,8 @@ extern int of_device_add(struct platform_device *pdev);
extern int of_device_register(struct platform_device *ofdev);
extern void of_device_unregister(struct platform_device *ofdev);
+extern const void *of_device_get_match_data(const struct device *dev);
+
extern ssize_t of_device_get_modalias(struct device *dev,
char *str, ssize_t len);
@@ -65,6 +67,11 @@ static inline int of_driver_match_device(struct device *dev,
static inline void of_device_uevent(struct device *dev,
struct kobj_uevent_env *env) { }
+static const void *of_device_get_match_data(const struct device *dev)
+{
+ return NULL;
+}
+
static inline int of_device_get_modalias(struct device *dev,
char *str, ssize_t len)
{
--
1.8.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] of: add helper function to retrive match data
[not found] ` <1430935749-3881-1-git-send-email-manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-05-29 15:00 ` Rob Herring
0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2015-05-29 15:00 UTC (permalink / raw)
To: Joachim Eastwood
Cc: Rob Herring, Grant Likely,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Arnd Bergmann
On Wed, May 6, 2015 at 1:09 PM, Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> It's a common operation for device drivers to retrive the data
> member from of_device_id struct in their probe function.
>
> Most driver end up doing:
> const struct of_device_id *match;
> match = of_match_device(driver_of_match, &pdev->dev);
> driver->data = match->data;
>
> With the of_device_get_match_data helper function all this can
> done in one go.
>
> Signed-off-by: Joachim Eastwood <manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Applied with inline fixup, thanks.
Rob
> ---
> Hi DT maintainers,
>
> Here is the patch to add of_device_get_match_data as indicated in:
> http://marc.info/?l=devicetree&m=143068795621692&w=2
>
> There are lot of device driver that can be simplified with this
> helper function. After the function has gone upstream I will
> spend some time getting some of them converted over.
>
> Maybe someone with Coccinelle skills could create a script to
> do some of the work also.
>
> regards,
> Joachim Eastwood
>
> drivers/of/device.c | 12 ++++++++++++
> include/linux/of_device.h | 7 +++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 20c1332a0018..8b91ea241b10 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -163,6 +163,18 @@ void of_device_unregister(struct platform_device *ofdev)
> }
> EXPORT_SYMBOL(of_device_unregister);
>
> +const void *of_device_get_match_data(const struct device *dev)
> +{
> + const struct of_device_id *match;
> +
> + match = of_match_device(dev->driver->of_match_table, dev);
> + if (!match)
> + return NULL;
> +
> + return match->data;
> +}
> +EXPORT_SYMBOL(of_device_get_match_data);
> +
> ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
> {
> const char *compat;
> diff --git a/include/linux/of_device.h b/include/linux/of_device.h
> index 22801b10cef5..3237d34e2ab1 100644
> --- a/include/linux/of_device.h
> +++ b/include/linux/of_device.h
> @@ -33,6 +33,8 @@ extern int of_device_add(struct platform_device *pdev);
> extern int of_device_register(struct platform_device *ofdev);
> extern void of_device_unregister(struct platform_device *ofdev);
>
> +extern const void *of_device_get_match_data(const struct device *dev);
> +
> extern ssize_t of_device_get_modalias(struct device *dev,
> char *str, ssize_t len);
>
> @@ -65,6 +67,11 @@ static inline int of_driver_match_device(struct device *dev,
> static inline void of_device_uevent(struct device *dev,
> struct kobj_uevent_env *env) { }
>
> +static const void *of_device_get_match_data(const struct device *dev)
> +{
> + return NULL;
> +}
> +
> static inline int of_device_get_modalias(struct device *dev,
> char *str, ssize_t len)
> {
> --
> 1.8.0
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-29 15:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-06 18:09 [PATCH] of: add helper function to retrive match data Joachim Eastwood
[not found] ` <1430935749-3881-1-git-send-email-manabian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-29 15:00 ` Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).