linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] platform: set of_node in platform_device_register_full()
@ 2019-02-16 16:45 Mans Rullgard
  2019-02-17 21:36 ` Rafael J. Wysocki
  2019-02-20 11:35 ` Mans Rullgard
  0 siblings, 2 replies; 15+ messages in thread
From: Mans Rullgard @ 2019-02-16 16:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki; +Cc: linux-kernel

If the provided fwnode is an OF node, set dev.of_node as well.

Signed-off-by: Mans Rullgard <mans@mansr.com>
---
 drivers/base/platform.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index dff82a3c2caa..853a1d0e5845 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
 
 	pdev->dev.parent = pdevinfo->parent;
 	pdev->dev.fwnode = pdevinfo->fwnode;
+	pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
 
 	if (pdevinfo->dma_mask) {
 		/*
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-16 16:45 [PATCH] platform: set of_node in platform_device_register_full() Mans Rullgard
@ 2019-02-17 21:36 ` Rafael J. Wysocki
  2019-02-18 11:03   ` Måns Rullgård
  2019-02-20 11:35 ` Mans Rullgard
  1 sibling, 1 reply; 15+ messages in thread
From: Rafael J. Wysocki @ 2019-02-17 21:36 UTC (permalink / raw)
  To: Mans Rullgard
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Linux Kernel Mailing List

On Sat, Feb 16, 2019 at 5:50 PM Mans Rullgard <mans@mansr.com> wrote:
>
> If the provided fwnode is an OF node, set dev.of_node as well.
>
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
>  drivers/base/platform.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index dff82a3c2caa..853a1d0e5845 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
>
>         pdev->dev.parent = pdevinfo->parent;
>         pdev->dev.fwnode = pdevinfo->fwnode;
> +       pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));

of_node_get() generally does a kobject_get() on the node's kobject, so
when is that reference dropped?  Or if it doesn't need to be dropped
at all, why is this the case?

>
>         if (pdevinfo->dma_mask) {
>                 /*
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-17 21:36 ` Rafael J. Wysocki
@ 2019-02-18 11:03   ` Måns Rullgård
  2019-02-20  9:50     ` Rafael J. Wysocki
  0 siblings, 1 reply; 15+ messages in thread
From: Måns Rullgård @ 2019-02-18 11:03 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Greg Kroah-Hartman, Linux Kernel Mailing List

"Rafael J. Wysocki" <rafael@kernel.org> writes:

> On Sat, Feb 16, 2019 at 5:50 PM Mans Rullgard <mans@mansr.com> wrote:
>>
>> If the provided fwnode is an OF node, set dev.of_node as well.
>>
>> Signed-off-by: Mans Rullgard <mans@mansr.com>
>> ---
>>  drivers/base/platform.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
>> index dff82a3c2caa..853a1d0e5845 100644
>> --- a/drivers/base/platform.c
>> +++ b/drivers/base/platform.c
>> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
>>
>>         pdev->dev.parent = pdevinfo->parent;
>>         pdev->dev.fwnode = pdevinfo->fwnode;
>> +       pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
>
> of_node_get() generally does a kobject_get() on the node's kobject, so
> when is that reference dropped?  Or if it doesn't need to be dropped
> at all, why is this the case?

platform_device_release() calls of_device_node_put().

-- 
Måns Rullgård

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-18 11:03   ` Måns Rullgård
@ 2019-02-20  9:50     ` Rafael J. Wysocki
  2019-02-20 10:41       ` Måns Rullgård
  0 siblings, 1 reply; 15+ messages in thread
From: Rafael J. Wysocki @ 2019-02-20  9:50 UTC (permalink / raw)
  To: Måns Rullgård
  Cc: Rafael J. Wysocki, Greg Kroah-Hartman, Linux Kernel Mailing List

On Mon, Feb 18, 2019 at 12:10 PM Måns Rullgård <mans@mansr.com> wrote:
>
> "Rafael J. Wysocki" <rafael@kernel.org> writes:
>
> > On Sat, Feb 16, 2019 at 5:50 PM Mans Rullgard <mans@mansr.com> wrote:
> >>
> >> If the provided fwnode is an OF node, set dev.of_node as well.
> >>
> >> Signed-off-by: Mans Rullgard <mans@mansr.com>
> >> ---
> >>  drivers/base/platform.c | 1 +
> >>  1 file changed, 1 insertion(+)
> >>
> >> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> >> index dff82a3c2caa..853a1d0e5845 100644
> >> --- a/drivers/base/platform.c
> >> +++ b/drivers/base/platform.c
> >> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
> >>
> >>         pdev->dev.parent = pdevinfo->parent;
> >>         pdev->dev.fwnode = pdevinfo->fwnode;
> >> +       pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
> >
> > of_node_get() generally does a kobject_get() on the node's kobject, so
> > when is that reference dropped?  Or if it doesn't need to be dropped
> > at all, why is this the case?
>
> platform_device_release() calls of_device_node_put().

Yes, it does, but this is the reference that's already acquired for
devices added while parsing DT, isn't it?

Your change adds an extra reference AFAICS.

Also, why is this patch needed?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20  9:50     ` Rafael J. Wysocki
@ 2019-02-20 10:41       ` Måns Rullgård
  2019-02-20 10:51         ` Rafael J. Wysocki
  0 siblings, 1 reply; 15+ messages in thread
From: Måns Rullgård @ 2019-02-20 10:41 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Greg Kroah-Hartman, Linux Kernel Mailing List

"Rafael J. Wysocki" <rafael@kernel.org> writes:

> On Mon, Feb 18, 2019 at 12:10 PM Måns Rullgård <mans@mansr.com> wrote:
>>
>> "Rafael J. Wysocki" <rafael@kernel.org> writes:
>>
>> > On Sat, Feb 16, 2019 at 5:50 PM Mans Rullgard <mans@mansr.com> wrote:
>> >>
>> >> If the provided fwnode is an OF node, set dev.of_node as well.
>> >>
>> >> Signed-off-by: Mans Rullgard <mans@mansr.com>
>> >> ---
>> >>  drivers/base/platform.c | 1 +
>> >>  1 file changed, 1 insertion(+)
>> >>
>> >> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
>> >> index dff82a3c2caa..853a1d0e5845 100644
>> >> --- a/drivers/base/platform.c
>> >> +++ b/drivers/base/platform.c
>> >> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
>> >>
>> >>         pdev->dev.parent = pdevinfo->parent;
>> >>         pdev->dev.fwnode = pdevinfo->fwnode;
>> >> +       pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
>> >
>> > of_node_get() generally does a kobject_get() on the node's kobject, so
>> > when is that reference dropped?  Or if it doesn't need to be dropped
>> > at all, why is this the case?
>>
>> platform_device_release() calls of_device_node_put().
>
> Yes, it does, but this is the reference that's already acquired for
> devices added while parsing DT, isn't it?
>
> Your change adds an extra reference AFAICS.
>
> Also, why is this patch needed?

Some drivers are just shims that create extra "glue" devices with the DT
device as parent and have the real driver bind to these.  In other
cases, the same real driver matches the DT node directly.  When a glue
device is used, it needs to get a reference to the original DT node in
order for the main driver to access properties and child nodes.

Right now, my problem is that the suxi-musb driver creates such a glue
device for the musb core driver to bind to without setting of_node.
This means devices attached to this USB interface don't get associated
with DT nodes, if present, the way they do with EHCI.

The sunxi-musb driver uses platform_device_register_full(), so this
seemed like the easiest way to let it set of_node of the new device.
Since this creates a second reference to the same node, of_node_get()
is required.

If you'd prefer solving this in some other way, please tell me how.

-- 
Måns Rullgård

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 10:41       ` Måns Rullgård
@ 2019-02-20 10:51         ` Rafael J. Wysocki
  2019-02-20 11:02           ` Måns Rullgård
  0 siblings, 1 reply; 15+ messages in thread
From: Rafael J. Wysocki @ 2019-02-20 10:51 UTC (permalink / raw)
  To: Måns Rullgård
  Cc: Rafael J. Wysocki, Greg Kroah-Hartman, Linux Kernel Mailing List

On Wed, Feb 20, 2019 at 11:41 AM Måns Rullgård <mans@mansr.com> wrote:
>
> "Rafael J. Wysocki" <rafael@kernel.org> writes:
>
> > On Mon, Feb 18, 2019 at 12:10 PM Måns Rullgård <mans@mansr.com> wrote:
> >>
> >> "Rafael J. Wysocki" <rafael@kernel.org> writes:
> >>
> >> > On Sat, Feb 16, 2019 at 5:50 PM Mans Rullgard <mans@mansr.com> wrote:
> >> >>
> >> >> If the provided fwnode is an OF node, set dev.of_node as well.
> >> >>
> >> >> Signed-off-by: Mans Rullgard <mans@mansr.com>
> >> >> ---
> >> >>  drivers/base/platform.c | 1 +
> >> >>  1 file changed, 1 insertion(+)
> >> >>
> >> >> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> >> >> index dff82a3c2caa..853a1d0e5845 100644
> >> >> --- a/drivers/base/platform.c
> >> >> +++ b/drivers/base/platform.c
> >> >> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
> >> >>
> >> >>         pdev->dev.parent = pdevinfo->parent;
> >> >>         pdev->dev.fwnode = pdevinfo->fwnode;
> >> >> +       pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
> >> >
> >> > of_node_get() generally does a kobject_get() on the node's kobject, so
> >> > when is that reference dropped?  Or if it doesn't need to be dropped
> >> > at all, why is this the case?
> >>
> >> platform_device_release() calls of_device_node_put().
> >
> > Yes, it does, but this is the reference that's already acquired for
> > devices added while parsing DT, isn't it?
> >
> > Your change adds an extra reference AFAICS.
> >
> > Also, why is this patch needed?
>
> Some drivers are just shims that create extra "glue" devices with the DT
> device as parent and have the real driver bind to these.  In other
> cases, the same real driver matches the DT node directly.  When a glue
> device is used, it needs to get a reference to the original DT node in
> order for the main driver to access properties and child nodes.
>
> Right now, my problem is that the suxi-musb driver creates such a glue
> device for the musb core driver to bind to without setting of_node.
> This means devices attached to this USB interface don't get associated
> with DT nodes, if present, the way they do with EHCI.

You really should describe problems that you want to address in patch
changelogs.  This helps a lot to understand the motivation for the
changes.

> The sunxi-musb driver uses platform_device_register_full(), so this
> seemed like the easiest way to let it set of_node of the new device.
> Since this creates a second reference to the same node, of_node_get()
> is required.

But what about devices that already have of_node set at this point?

Maybe check if of_node is NULL before trying to set it?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 10:51         ` Rafael J. Wysocki
@ 2019-02-20 11:02           ` Måns Rullgård
  2019-02-20 11:08             ` Rafael J. Wysocki
  0 siblings, 1 reply; 15+ messages in thread
From: Måns Rullgård @ 2019-02-20 11:02 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Greg Kroah-Hartman, Linux Kernel Mailing List

"Rafael J. Wysocki" <rafael@kernel.org> writes:

> On Wed, Feb 20, 2019 at 11:41 AM Måns Rullgård <mans@mansr.com> wrote:
>>
>> "Rafael J. Wysocki" <rafael@kernel.org> writes:
>>
>> > On Mon, Feb 18, 2019 at 12:10 PM Måns Rullgård <mans@mansr.com> wrote:
>> >>
>> >> "Rafael J. Wysocki" <rafael@kernel.org> writes:
>> >>
>> >> > On Sat, Feb 16, 2019 at 5:50 PM Mans Rullgard <mans@mansr.com> wrote:
>> >> >>
>> >> >> If the provided fwnode is an OF node, set dev.of_node as well.
>> >> >>
>> >> >> Signed-off-by: Mans Rullgard <mans@mansr.com>
>> >> >> ---
>> >> >>  drivers/base/platform.c | 1 +
>> >> >>  1 file changed, 1 insertion(+)
>> >> >>
>> >> >> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
>> >> >> index dff82a3c2caa..853a1d0e5845 100644
>> >> >> --- a/drivers/base/platform.c
>> >> >> +++ b/drivers/base/platform.c
>> >> >> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
>> >> >>
>> >> >>         pdev->dev.parent = pdevinfo->parent;
>> >> >>         pdev->dev.fwnode = pdevinfo->fwnode;
>> >> >> +       pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
>> >> >
>> >> > of_node_get() generally does a kobject_get() on the node's kobject, so
>> >> > when is that reference dropped?  Or if it doesn't need to be dropped
>> >> > at all, why is this the case?
>> >>
>> >> platform_device_release() calls of_device_node_put().
>> >
>> > Yes, it does, but this is the reference that's already acquired for
>> > devices added while parsing DT, isn't it?
>> >
>> > Your change adds an extra reference AFAICS.
>> >
>> > Also, why is this patch needed?
>>
>> Some drivers are just shims that create extra "glue" devices with the DT
>> device as parent and have the real driver bind to these.  In other
>> cases, the same real driver matches the DT node directly.  When a glue
>> device is used, it needs to get a reference to the original DT node in
>> order for the main driver to access properties and child nodes.
>>
>> Right now, my problem is that the suxi-musb driver creates such a glue
>> device for the musb core driver to bind to without setting of_node.
>> This means devices attached to this USB interface don't get associated
>> with DT nodes, if present, the way they do with EHCI.
>
> You really should describe problems that you want to address in patch
> changelogs.  This helps a lot to understand the motivation for the
> changes.

Do you want me to send a new patch with the above explanation in the
commit message?

>> The sunxi-musb driver uses platform_device_register_full(), so this
>> seemed like the easiest way to let it set of_node of the new device.
>> Since this creates a second reference to the same node, of_node_get()
>> is required.
>
> But what about devices that already have of_node set at this point?
>
> Maybe check if of_node is NULL before trying to set it?

It's a brand new device allocated a few lines above.  of_node has to be
null here.

-- 
Måns Rullgård

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 11:02           ` Måns Rullgård
@ 2019-02-20 11:08             ` Rafael J. Wysocki
  0 siblings, 0 replies; 15+ messages in thread
From: Rafael J. Wysocki @ 2019-02-20 11:08 UTC (permalink / raw)
  To: Måns Rullgård
  Cc: Rafael J. Wysocki, Greg Kroah-Hartman, Linux Kernel Mailing List

On Wed, Feb 20, 2019 at 12:02 PM Måns Rullgård <mans@mansr.com> wrote:
>
> "Rafael J. Wysocki" <rafael@kernel.org> writes:
>
> > On Wed, Feb 20, 2019 at 11:41 AM Måns Rullgård <mans@mansr.com> wrote:
> >>
> >> "Rafael J. Wysocki" <rafael@kernel.org> writes:
> >>
> >> > On Mon, Feb 18, 2019 at 12:10 PM Måns Rullgård <mans@mansr.com> wrote:
> >> >>
> >> >> "Rafael J. Wysocki" <rafael@kernel.org> writes:
> >> >>
> >> >> > On Sat, Feb 16, 2019 at 5:50 PM Mans Rullgard <mans@mansr.com> wrote:
> >> >> >>
> >> >> >> If the provided fwnode is an OF node, set dev.of_node as well.
> >> >> >>
> >> >> >> Signed-off-by: Mans Rullgard <mans@mansr.com>
> >> >> >> ---
> >> >> >>  drivers/base/platform.c | 1 +
> >> >> >>  1 file changed, 1 insertion(+)
> >> >> >>
> >> >> >> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> >> >> >> index dff82a3c2caa..853a1d0e5845 100644
> >> >> >> --- a/drivers/base/platform.c
> >> >> >> +++ b/drivers/base/platform.c
> >> >> >> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
> >> >> >>
> >> >> >>         pdev->dev.parent = pdevinfo->parent;
> >> >> >>         pdev->dev.fwnode = pdevinfo->fwnode;
> >> >> >> +       pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
> >> >> >
> >> >> > of_node_get() generally does a kobject_get() on the node's kobject, so
> >> >> > when is that reference dropped?  Or if it doesn't need to be dropped
> >> >> > at all, why is this the case?
> >> >>
> >> >> platform_device_release() calls of_device_node_put().
> >> >
> >> > Yes, it does, but this is the reference that's already acquired for
> >> > devices added while parsing DT, isn't it?
> >> >
> >> > Your change adds an extra reference AFAICS.
> >> >
> >> > Also, why is this patch needed?
> >>
> >> Some drivers are just shims that create extra "glue" devices with the DT
> >> device as parent and have the real driver bind to these.  In other
> >> cases, the same real driver matches the DT node directly.  When a glue
> >> device is used, it needs to get a reference to the original DT node in
> >> order for the main driver to access properties and child nodes.
> >>
> >> Right now, my problem is that the suxi-musb driver creates such a glue
> >> device for the musb core driver to bind to without setting of_node.
> >> This means devices attached to this USB interface don't get associated
> >> with DT nodes, if present, the way they do with EHCI.
> >
> > You really should describe problems that you want to address in patch
> > changelogs.  This helps a lot to understand the motivation for the
> > changes.
>
> Do you want me to send a new patch with the above explanation in the
> commit message?

Yes, please.

> >> The sunxi-musb driver uses platform_device_register_full(), so this
> >> seemed like the easiest way to let it set of_node of the new device.
> >> Since this creates a second reference to the same node, of_node_get()
> >> is required.
> >
> > But what about devices that already have of_node set at this point?
> >
> > Maybe check if of_node is NULL before trying to set it?
>
> It's a brand new device allocated a few lines above.  of_node has to be
> null here.

Right, sorry for the confusion.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-16 16:45 [PATCH] platform: set of_node in platform_device_register_full() Mans Rullgard
  2019-02-17 21:36 ` Rafael J. Wysocki
@ 2019-02-20 11:35 ` Mans Rullgard
  2019-02-20 11:51   ` Johan Hovold
  2019-02-20 11:53   ` Måns Rullgård
  1 sibling, 2 replies; 15+ messages in thread
From: Mans Rullgard @ 2019-02-20 11:35 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Greg Kroah-Hartman, linux-kernel

If the provided fwnode is an OF node, set dev.of_node as well.

Some drivers are just shims that create extra "glue" devices with the
DT device as parent and have the real driver bind to these.  In these
cases, the glue device needs to get a reference to the original DT node
in order for the main driver to access properties and child nodes.

For example, the sunxi-musb driver creates such a glue device using
platform_device_register_full().  Consequently, devices attached to
this USB interface don't get associated with DT nodes, if present,
the way they do with EHCI.

This change will allow sunxi-musb and similar driver to easily
propagate the DT node to child devices as required.

Signed-off-by: Mans Rullgard <mans@mansr.com>
---
 drivers/base/platform.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index dff82a3c2caa..853a1d0e5845 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
 
 	pdev->dev.parent = pdevinfo->parent;
 	pdev->dev.fwnode = pdevinfo->fwnode;
+	pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
 
 	if (pdevinfo->dma_mask) {
 		/*
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 11:35 ` Mans Rullgard
@ 2019-02-20 11:51   ` Johan Hovold
  2019-02-20 12:12     ` Måns Rullgård
  2019-02-20 11:53   ` Måns Rullgård
  1 sibling, 1 reply; 15+ messages in thread
From: Johan Hovold @ 2019-02-20 11:51 UTC (permalink / raw)
  To: Mans Rullgard; +Cc: Rafael J. Wysocki, Greg Kroah-Hartman, linux-kernel

On Wed, Feb 20, 2019 at 11:35:06AM +0000, Mans Rullgard wrote:
> If the provided fwnode is an OF node, set dev.of_node as well.
> 
> Some drivers are just shims that create extra "glue" devices with the
> DT device as parent and have the real driver bind to these.  In these
> cases, the glue device needs to get a reference to the original DT node
> in order for the main driver to access properties and child nodes.
> 
> For example, the sunxi-musb driver creates such a glue device using
> platform_device_register_full().  Consequently, devices attached to
> this USB interface don't get associated with DT nodes, if present,
> the way they do with EHCI.
> 
> This change will allow sunxi-musb and similar driver to easily
> propagate the DT node to child devices as required.

Just a drive-by comment, didn't look to closely at this patch, but this
all sounds familiar.

Note that if both platform devices are bound to drivers you may end up
with some resources like pinctrl which are handled automatically by
driver core at probe time to be requested twice (and failing the second
time).

Take a look at 4e75e1d7dac9 ("driver core: add helper to reuse a
device-tree node"), which provides a means to avoid this, and
49484abd93ab ("USB: musb: dsps: propagate device-tree node").

> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
>  drivers/base/platform.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index dff82a3c2caa..853a1d0e5845 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
>  
>  	pdev->dev.parent = pdevinfo->parent;
>  	pdev->dev.fwnode = pdevinfo->fwnode;
> +	pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
>  
>  	if (pdevinfo->dma_mask) {
>  		/*

Johan

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 11:35 ` Mans Rullgard
  2019-02-20 11:51   ` Johan Hovold
@ 2019-02-20 11:53   ` Måns Rullgård
  1 sibling, 0 replies; 15+ messages in thread
From: Måns Rullgård @ 2019-02-20 11:53 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Greg Kroah-Hartman, linux-kernel

Mans Rullgard <mans@mansr.com> writes:

> If the provided fwnode is an OF node, set dev.of_node as well.
>
> Some drivers are just shims that create extra "glue" devices with the
> DT device as parent and have the real driver bind to these.  In these
> cases, the glue device needs to get a reference to the original DT node
> in order for the main driver to access properties and child nodes.
>
> For example, the sunxi-musb driver creates such a glue device using
> platform_device_register_full().  Consequently, devices attached to
> this USB interface don't get associated with DT nodes, if present,
> the way they do with EHCI.
>
> This change will allow sunxi-musb and similar driver to easily
> propagate the DT node to child devices as required.
>
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
>  drivers/base/platform.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index dff82a3c2caa..853a1d0e5845 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
>
>  	pdev->dev.parent = pdevinfo->parent;
>  	pdev->dev.fwnode = pdevinfo->fwnode;
> +	pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
>
>  	if (pdevinfo->dma_mask) {
>  		/*
> -- 

Sorry, I forgot to add a v2 to this.  Anyway, the only change is the
commit message.

-- 
Måns Rullgård

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 11:51   ` Johan Hovold
@ 2019-02-20 12:12     ` Måns Rullgård
  2019-02-20 12:18       ` Rafael J. Wysocki
  0 siblings, 1 reply; 15+ messages in thread
From: Måns Rullgård @ 2019-02-20 12:12 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Rafael J. Wysocki, Greg Kroah-Hartman, linux-kernel

Johan Hovold <johan@kernel.org> writes:

> On Wed, Feb 20, 2019 at 11:35:06AM +0000, Mans Rullgard wrote:
>> If the provided fwnode is an OF node, set dev.of_node as well.
>> 
>> Some drivers are just shims that create extra "glue" devices with the
>> DT device as parent and have the real driver bind to these.  In these
>> cases, the glue device needs to get a reference to the original DT node
>> in order for the main driver to access properties and child nodes.
>> 
>> For example, the sunxi-musb driver creates such a glue device using
>> platform_device_register_full().  Consequently, devices attached to
>> this USB interface don't get associated with DT nodes, if present,
>> the way they do with EHCI.
>> 
>> This change will allow sunxi-musb and similar driver to easily
>> propagate the DT node to child devices as required.
>
> Just a drive-by comment, didn't look to closely at this patch, but this
> all sounds familiar.
>
> Note that if both platform devices are bound to drivers you may end up
> with some resources like pinctrl which are handled automatically by
> driver core at probe time to be requested twice (and failing the second
> time).
>
> Take a look at 4e75e1d7dac9 ("driver core: add helper to reuse a
> device-tree node"), which provides a means to avoid this, and
> 49484abd93ab ("USB: musb: dsps: propagate device-tree node").

Thanks, and ugh.  So we should be setting the of_node_reused flag when
this is the case.  It's easy for the musb-dsps driver since it doesn't
use platform_device_register_full() and can do this before the
device_add() call.  How can we convey that this flag needs to be set?

>> Signed-off-by: Mans Rullgard <mans@mansr.com>
>> ---
>>  drivers/base/platform.c | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
>> index dff82a3c2caa..853a1d0e5845 100644
>> --- a/drivers/base/platform.c
>> +++ b/drivers/base/platform.c
>> @@ -512,6 +512,7 @@ struct platform_device *platform_device_register_full(
>>  
>>  	pdev->dev.parent = pdevinfo->parent;
>>  	pdev->dev.fwnode = pdevinfo->fwnode;
>> +	pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
>>  
>>  	if (pdevinfo->dma_mask) {
>>  		/*
>
> Johan

-- 
Måns Rullgård

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 12:12     ` Måns Rullgård
@ 2019-02-20 12:18       ` Rafael J. Wysocki
  2019-02-20 12:26         ` Måns Rullgård
  0 siblings, 1 reply; 15+ messages in thread
From: Rafael J. Wysocki @ 2019-02-20 12:18 UTC (permalink / raw)
  To: Måns Rullgård
  Cc: Johan Hovold, Rafael J. Wysocki, Greg Kroah-Hartman,
	Linux Kernel Mailing List

On Wed, Feb 20, 2019 at 1:12 PM Måns Rullgård <mans@mansr.com> wrote:
>
> Johan Hovold <johan@kernel.org> writes:
>
> > On Wed, Feb 20, 2019 at 11:35:06AM +0000, Mans Rullgard wrote:
> >> If the provided fwnode is an OF node, set dev.of_node as well.
> >>
> >> Some drivers are just shims that create extra "glue" devices with the
> >> DT device as parent and have the real driver bind to these.  In these
> >> cases, the glue device needs to get a reference to the original DT node
> >> in order for the main driver to access properties and child nodes.
> >>
> >> For example, the sunxi-musb driver creates such a glue device using
> >> platform_device_register_full().  Consequently, devices attached to
> >> this USB interface don't get associated with DT nodes, if present,
> >> the way they do with EHCI.
> >>
> >> This change will allow sunxi-musb and similar driver to easily
> >> propagate the DT node to child devices as required.
> >
> > Just a drive-by comment, didn't look to closely at this patch, but this
> > all sounds familiar.
> >
> > Note that if both platform devices are bound to drivers you may end up
> > with some resources like pinctrl which are handled automatically by
> > driver core at probe time to be requested twice (and failing the second
> > time).
> >
> > Take a look at 4e75e1d7dac9 ("driver core: add helper to reuse a
> > device-tree node"), which provides a means to avoid this, and
> > 49484abd93ab ("USB: musb: dsps: propagate device-tree node").
>
> Thanks, and ugh.  So we should be setting the of_node_reused flag when
> this is the case.  It's easy for the musb-dsps driver since it doesn't
> use platform_device_register_full() and can do this before the
> device_add() call.  How can we convey that this flag needs to be set?

Through pdevinfo I guess?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 12:18       ` Rafael J. Wysocki
@ 2019-02-20 12:26         ` Måns Rullgård
  2019-02-20 21:50           ` Rafael J. Wysocki
  0 siblings, 1 reply; 15+ messages in thread
From: Måns Rullgård @ 2019-02-20 12:26 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Johan Hovold, Greg Kroah-Hartman, Linux Kernel Mailing List

"Rafael J. Wysocki" <rafael@kernel.org> writes:

> On Wed, Feb 20, 2019 at 1:12 PM Måns Rullgård <mans@mansr.com> wrote:
>>
>> Johan Hovold <johan@kernel.org> writes:
>>
>> > On Wed, Feb 20, 2019 at 11:35:06AM +0000, Mans Rullgard wrote:
>> >> If the provided fwnode is an OF node, set dev.of_node as well.
>> >>
>> >> Some drivers are just shims that create extra "glue" devices with the
>> >> DT device as parent and have the real driver bind to these.  In these
>> >> cases, the glue device needs to get a reference to the original DT node
>> >> in order for the main driver to access properties and child nodes.
>> >>
>> >> For example, the sunxi-musb driver creates such a glue device using
>> >> platform_device_register_full().  Consequently, devices attached to
>> >> this USB interface don't get associated with DT nodes, if present,
>> >> the way they do with EHCI.
>> >>
>> >> This change will allow sunxi-musb and similar driver to easily
>> >> propagate the DT node to child devices as required.
>> >
>> > Just a drive-by comment, didn't look to closely at this patch, but this
>> > all sounds familiar.
>> >
>> > Note that if both platform devices are bound to drivers you may end up
>> > with some resources like pinctrl which are handled automatically by
>> > driver core at probe time to be requested twice (and failing the second
>> > time).
>> >
>> > Take a look at 4e75e1d7dac9 ("driver core: add helper to reuse a
>> > device-tree node"), which provides a means to avoid this, and
>> > 49484abd93ab ("USB: musb: dsps: propagate device-tree node").
>>
>> Thanks, and ugh.  So we should be setting the of_node_reused flag when
>> this is the case.  It's easy for the musb-dsps driver since it doesn't
>> use platform_device_register_full() and can do this before the
>> device_add() call.  How can we convey that this flag needs to be set?
>
> Through pdevinfo I guess?

Not without adding another field to it.  The most direct is of course to
simply add an of_node_reused flag there too and copy it over.  Would
that be OK, or is there a better way?

-- 
Måns Rullgård

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] platform: set of_node in platform_device_register_full()
  2019-02-20 12:26         ` Måns Rullgård
@ 2019-02-20 21:50           ` Rafael J. Wysocki
  0 siblings, 0 replies; 15+ messages in thread
From: Rafael J. Wysocki @ 2019-02-20 21:50 UTC (permalink / raw)
  To: Måns Rullgård
  Cc: Rafael J. Wysocki, Johan Hovold, Greg Kroah-Hartman,
	Linux Kernel Mailing List

On Wed, Feb 20, 2019 at 1:26 PM Måns Rullgård <mans@mansr.com> wrote:
>
> "Rafael J. Wysocki" <rafael@kernel.org> writes:
>
> > On Wed, Feb 20, 2019 at 1:12 PM Måns Rullgård <mans@mansr.com> wrote:
> >>
> >> Johan Hovold <johan@kernel.org> writes:
> >>
> >> > On Wed, Feb 20, 2019 at 11:35:06AM +0000, Mans Rullgard wrote:
> >> >> If the provided fwnode is an OF node, set dev.of_node as well.
> >> >>
> >> >> Some drivers are just shims that create extra "glue" devices with the
> >> >> DT device as parent and have the real driver bind to these.  In these
> >> >> cases, the glue device needs to get a reference to the original DT node
> >> >> in order for the main driver to access properties and child nodes.
> >> >>
> >> >> For example, the sunxi-musb driver creates such a glue device using
> >> >> platform_device_register_full().  Consequently, devices attached to
> >> >> this USB interface don't get associated with DT nodes, if present,
> >> >> the way they do with EHCI.
> >> >>
> >> >> This change will allow sunxi-musb and similar driver to easily
> >> >> propagate the DT node to child devices as required.
> >> >
> >> > Just a drive-by comment, didn't look to closely at this patch, but this
> >> > all sounds familiar.
> >> >
> >> > Note that if both platform devices are bound to drivers you may end up
> >> > with some resources like pinctrl which are handled automatically by
> >> > driver core at probe time to be requested twice (and failing the second
> >> > time).
> >> >
> >> > Take a look at 4e75e1d7dac9 ("driver core: add helper to reuse a
> >> > device-tree node"), which provides a means to avoid this, and
> >> > 49484abd93ab ("USB: musb: dsps: propagate device-tree node").
> >>
> >> Thanks, and ugh.  So we should be setting the of_node_reused flag when
> >> this is the case.  It's easy for the musb-dsps driver since it doesn't
> >> use platform_device_register_full() and can do this before the
> >> device_add() call.  How can we convey that this flag needs to be set?
> >
> > Through pdevinfo I guess?
>
> Not without adding another field to it.  The most direct is of course to
> simply add an of_node_reused flag there too and copy it over.  Would
> that be OK, or is there a better way?

That's what I meant. :-)

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-02-20 21:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-16 16:45 [PATCH] platform: set of_node in platform_device_register_full() Mans Rullgard
2019-02-17 21:36 ` Rafael J. Wysocki
2019-02-18 11:03   ` Måns Rullgård
2019-02-20  9:50     ` Rafael J. Wysocki
2019-02-20 10:41       ` Måns Rullgård
2019-02-20 10:51         ` Rafael J. Wysocki
2019-02-20 11:02           ` Måns Rullgård
2019-02-20 11:08             ` Rafael J. Wysocki
2019-02-20 11:35 ` Mans Rullgard
2019-02-20 11:51   ` Johan Hovold
2019-02-20 12:12     ` Måns Rullgård
2019-02-20 12:18       ` Rafael J. Wysocki
2019-02-20 12:26         ` Måns Rullgård
2019-02-20 21:50           ` Rafael J. Wysocki
2019-02-20 11:53   ` Måns Rullgård

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).