2017-12-02 04:28:03

by Sinan Kaya

[permalink] [raw]
Subject: [PATCH V5 4/7] OF: properties: Implement get_match_data() callback

Now that we have a get_match_data() callback as part of the firmware node,
implement the OF specific piece for it.

Signed-off-by: Sinan Kaya <[email protected]>
---
drivers/of/property.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 264c355..adcde1a 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -981,6 +981,22 @@ static int of_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
return 0;
}

+void *of_fwnode_get_match_data(const struct fwnode_handle *fwnode,
+ const struct device_driver *drv)
+{
+ const struct device_node *node = to_of_node(fwnode);
+ const struct of_device_id *match;
+
+ if (!node)
+ return NULL;
+
+ match = of_match_node(drv->of_match_table, node);
+ if (!match)
+ return NULL;
+
+ return (void *)match->data;
+}
+
const struct fwnode_operations of_fwnode_ops = {
.get = of_fwnode_get,
.put = of_fwnode_put,
@@ -996,5 +1012,6 @@ static int of_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
.graph_get_port_parent = of_fwnode_graph_get_port_parent,
.graph_parse_endpoint = of_fwnode_graph_parse_endpoint,
+ .get_match_data = of_fwnode_get_match_data,
};
EXPORT_SYMBOL_GPL(of_fwnode_ops);
--
1.9.1


2017-12-04 16:23:40

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH V5 4/7] OF: properties: Implement get_match_data() callback

On Fri, Dec 1, 2017 at 10:27 PM, Sinan Kaya <[email protected]> wrote:
> Now that we have a get_match_data() callback as part of the firmware node,
> implement the OF specific piece for it.
>
> Signed-off-by: Sinan Kaya <[email protected]>
> ---
> drivers/of/property.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index 264c355..adcde1a 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -981,6 +981,22 @@ static int of_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
> return 0;
> }
>
> +void *of_fwnode_get_match_data(const struct fwnode_handle *fwnode,
> + const struct device_driver *drv)
> +{
> + const struct device_node *node = to_of_node(fwnode);
> + const struct of_device_id *match;
> +
> + if (!node)
> + return NULL;

of_match_node checks this.

> +
> + match = of_match_node(drv->of_match_table, node);
> + if (!match)
> + return NULL;
> +
> + return (void *)match->data;

Don't need a cast here.

of_device_get_match_data() already does most of this, but getting a
device ptr from fwnode_handle may not be possible?

Rob

2017-12-04 18:05:56

by Sinan Kaya

[permalink] [raw]
Subject: Re: [PATCH V5 4/7] OF: properties: Implement get_match_data() callback

On 12/4/2017 11:23 AM, Rob Herring wrote:
> On Fri, Dec 1, 2017 at 10:27 PM, Sinan Kaya <[email protected]> wrote:
>> Now that we have a get_match_data() callback as part of the firmware node,
>> implement the OF specific piece for it.
>>
>> Signed-off-by: Sinan Kaya <[email protected]>
>> ---
>> drivers/of/property.c | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>>
..

>>
>> +void *of_fwnode_get_match_data(const struct fwnode_handle *fwnode,
>> + const struct device_driver *drv)
>> +{
>> + const struct device_node *node = to_of_node(fwnode);
>> + const struct of_device_id *match;
>> +
>> + if (!node)
>> + return NULL;
>
> of_match_node checks this.

I see a check for the matches argument but not for the node argument.
Am I missing something?

>
>> +
>> + match = of_match_node(drv->of_match_table, node);
>> + if (!match)
>> + return NULL;
>> +
>> + return (void *)match->data;
>
> Don't need a cast here.

I can fix this.

>
> of_device_get_match_data() already does most of this, but getting a
> device ptr from fwnode_handle may not be possible?

I couldn't figure out how to do that. Do you have a suggestion?
I have been looking for examples with no luck.

>
> Rob
>


--
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

2017-12-04 22:25:33

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH V5 4/7] OF: properties: Implement get_match_data() callback

On Mon, Dec 04, 2017 at 01:05:51PM -0500, Sinan Kaya wrote:
> On 12/4/2017 11:23 AM, Rob Herring wrote:
> > On Fri, Dec 1, 2017 at 10:27 PM, Sinan Kaya <[email protected]> wrote:
> >> Now that we have a get_match_data() callback as part of the firmware node,
> >> implement the OF specific piece for it.
> >>
> >> Signed-off-by: Sinan Kaya <[email protected]>
> >> ---
> >> drivers/of/property.c | 17 +++++++++++++++++
> >> 1 file changed, 17 insertions(+)
> >>
> ..
>
> >>
> >> +void *of_fwnode_get_match_data(const struct fwnode_handle *fwnode,
> >> + const struct device_driver *drv)
> >> +{
> >> + const struct device_node *node = to_of_node(fwnode);
> >> + const struct of_device_id *match;
> >> +
> >> + if (!node)
> >> + return NULL;
> >
> > of_match_node checks this.
>
> I see a check for the matches argument but not for the node argument.
> Am I missing something?

Ah yes, you are right.

>
> >
> >> +
> >> + match = of_match_node(drv->of_match_table, node);
> >> + if (!match)
> >> + return NULL;
> >> +
> >> + return (void *)match->data;
> >
> > Don't need a cast here.
>
> I can fix this.
>
> >
> > of_device_get_match_data() already does most of this, but getting a
> > device ptr from fwnode_handle may not be possible?
>
> I couldn't figure out how to do that. Do you have a suggestion?
> I have been looking for examples with no luck.

Change the property API to pass struct device instead. That's maybe not
worth it.

Rob