* OF device mappings
@ 2009-02-28 17:46 Gary Thomas
2009-02-28 18:04 ` Grant Likely
0 siblings, 1 reply; 8+ messages in thread
From: Gary Thomas @ 2009-02-28 17:46 UTC (permalink / raw)
To: Linux PPC Development
Still looking for some help... I need to be able to locate
the kernel platform_device which corresponds to an instance
from my OF tree. Basically, I have a [somewhat] unrelated
driver which needs to know these things, so the drivers in
question should not have to be affected.
In particular, I'm working with the net/dsa drivers (Distributed
Switch Architecture) which need access to the network driver as
well as the MII/MDIO bus driver. It doesn't make sense to tie
those drivers back to DSA, but rather let the DSA driver find
its way to them.
I've defined this in by DTS tree:
lan1 {
cell-index = <0x01>;
compatible = "marvell,m88e609x";
net_dev = "fsl-gianfar.0";
mii_bus = "fsl-gianfar_mdio.14";
net_devX = <ð0>;
mii_busX = <&mii_bus>;
};
... two ways to find the same node.
Using 'net_dev' (which I admit is pretty hokey), I can look
up the corresponding platform device, which does work for
the DSA layer. What I want is to be able to get to this
from the 'net_devX' pointer, but I don't seem to be able
to get out of the OF tree and into the actual platform
device tree to find the appropriate instance.
Any pointers?
Thanks
--
------------------------------------------------------------
Gary Thomas | Consulting for the
MLB Associates | Embedded world
------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: OF device mappings
2009-02-28 17:46 OF device mappings Gary Thomas
@ 2009-02-28 18:04 ` Grant Likely
2009-02-28 18:21 ` Gary Thomas
0 siblings, 1 reply; 8+ messages in thread
From: Grant Likely @ 2009-02-28 18:04 UTC (permalink / raw)
To: Gary Thomas; +Cc: Linux PPC Development
On Sat, Feb 28, 2009 at 10:46 AM, Gary Thomas <gary@mlbassoc.com> wrote:
> Still looking for some help... =A0I need to be able to locate
> the kernel platform_device which corresponds to an instance
> from my OF tree. =A0Basically, I have a [somewhat] unrelated
> driver which needs to know these things, so the drivers in
> question should not have to be affected.
>
> In particular, I'm working with the net/dsa drivers (Distributed
> Switch Architecture) which need access to the network driver as
> well as the MII/MDIO bus driver. =A0It doesn't make sense to tie
> those drivers back to DSA, but rather let the DSA driver find
> its way to them.
>
> I've defined this in by DTS tree:
> =A0 =A0 =A0 =A0lan1 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cell-index =3D <0x01>;
Side note, why do you have cell-index here? I suspect that you're
using it incorrectly.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0compatible =3D "marvell,m88e609x";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0net_dev =3D "fsl-gianfar.0";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mii_bus =3D "fsl-gianfar_mdio.14";
These two lines don't make much sense. They are encoding Linux
internal details with could very well change in the future.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0net_devX =3D <ð0>;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mii_busX =3D <&mii_bus>;
This is the right thing to do. This give you the phandle to the relevant n=
ode.
Once you have a handle to the node, you can iterate through the
of_platform bus devices and look for a node which has a matching node
pointer stored in archdata. That will give you a struct device which
is contained by a struct of_device (note well: this will give you an
of_device, not a platform_device.)
I'm working on a set of patches which should make this much easier.
I'll try to remember to CC you when I post them to the list.
> =A0 =A0 =A0 =A0};
> ... two ways to find the same node.
>
> Using 'net_dev' (which I admit is pretty hokey), I can look
> up the corresponding platform device, which does work for
> the DSA layer. =A0What I want is to be able to get to this
> from the 'net_devX' pointer, but I don't seem to be able
> to get out of the OF tree and into the actual platform
> device tree to find the appropriate instance.
>
> Any pointers?
>
> Thanks
>
> --
> ------------------------------------------------------------
> Gary Thomas =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0Consulting for the
> MLB Associates =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A0Embedded world
> ------------------------------------------------------------
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
>
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: OF device mappings
2009-02-28 18:04 ` Grant Likely
@ 2009-02-28 18:21 ` Gary Thomas
2009-02-28 18:44 ` Grant Likely
0 siblings, 1 reply; 8+ messages in thread
From: Gary Thomas @ 2009-02-28 18:21 UTC (permalink / raw)
To: Grant Likely; +Cc: Linux PPC Development
Grant Likely wrote:
> On Sat, Feb 28, 2009 at 10:46 AM, Gary Thomas <gary@mlbassoc.com> wrote:
>> Still looking for some help... I need to be able to locate
>> the kernel platform_device which corresponds to an instance
>> from my OF tree. Basically, I have a [somewhat] unrelated
>> driver which needs to know these things, so the drivers in
>> question should not have to be affected.
>>
>> In particular, I'm working with the net/dsa drivers (Distributed
>> Switch Architecture) which need access to the network driver as
>> well as the MII/MDIO bus driver. It doesn't make sense to tie
>> those drivers back to DSA, but rather let the DSA driver find
>> its way to them.
>>
>> I've defined this in by DTS tree:
>> lan1 {
>> cell-index = <0x01>;
>
> Side note, why do you have cell-index here? I suspect that you're
> using it incorrectly.
Probably - I don't think I need it anyway.
>> compatible = "marvell,m88e609x";
>> net_dev = "fsl-gianfar.0";
>> mii_bus = "fsl-gianfar_mdio.14";
>
> These two lines don't make much sense. They are encoding Linux
> internal details with could very well change in the future.
>
>> net_devX = <ð0>;
>> mii_busX = <&mii_bus>;
>
> This is the right thing to do. This give you the phandle to the relevant node.
As I suspected.
> Once you have a handle to the node, you can iterate through the
> of_platform bus devices and look for a node which has a matching node
> pointer stored in archdata. That will give you a struct device which
> is contained by a struct of_device (note well: this will give you an
> of_device, not a platform_device.)
I have code which does this already, but I could not figure out
how to get from the of_device node to the actual platform_device.
for_each_compatible_node(np, NULL, "marvell,m88e609x") {
const phandle *ph;
struct device *dev;
struct of_device *of_dev;
ph = of_get_property(np, "net_devX", NULL);
if (ph == NULL) {
printk("%s: missing 'net_dev'\n", np->name);
break;
}
of_dev = of_find_device_by_phandle(*ph);
}
How do I find the platform_device which was created when this
particular of_device was instantiated? I made sure that this code
is run late - after all the of_devices have been handled.
> I'm working on a set of patches which should make this much easier.
> I'll try to remember to CC you when I post them to the list.
Looking forward to your code/ideas
>> };
>> ... two ways to find the same node.
>>
>> Using 'net_dev' (which I admit is pretty hokey), I can look
>> up the corresponding platform device, which does work for
>> the DSA layer. What I want is to be able to get to this
>> from the 'net_devX' pointer, but I don't seem to be able
>> to get out of the OF tree and into the actual platform
>> device tree to find the appropriate instance.
--
------------------------------------------------------------
Gary Thomas | Consulting for the
MLB Associates | Embedded world
------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: OF device mappings
2009-02-28 18:21 ` Gary Thomas
@ 2009-02-28 18:44 ` Grant Likely
2009-02-28 19:18 ` Gary Thomas
0 siblings, 1 reply; 8+ messages in thread
From: Grant Likely @ 2009-02-28 18:44 UTC (permalink / raw)
To: Gary Thomas; +Cc: Linux PPC Development
On Sat, Feb 28, 2009 at 11:21 AM, Gary Thomas <gary@mlbassoc.com> wrote:
> Grant Likely wrote:
>> Once you have a handle to the node, you can iterate through the
>> of_platform bus devices and look for a node which has a matching node
>> pointer stored in archdata. =A0That will give you a struct device which
>> is contained by a struct of_device (note well: this will give you an
>> of_device, not a platform_device.)
>
> I have code which does this already, but I could not figure out
> how to get from the of_device node to the actual platform_device.
You can't. There is no platform_device. There is only the of_device.
The bit that you're missing is that the 'platform bus' isn't being
used at all for these devices. The 'of_platform bus' is used instead.
platform bus and of_platform bus perform essentially the same job,
but the of_platform bus differs in the way it probes drivers.
Specifically, an of_platform_driver can be handed a list of values
that it will match against, and it has a 1:1 relationship with a node
in the device tree.
> How do I find the platform_device which was created when this
> particular of_device was instantiated? =A0I made sure that this code
> is run late - after all the of_devices have been handled.
Again, there is no platform_device. of_device *is* the device that was cre=
ated.
g.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: OF device mappings
2009-02-28 18:44 ` Grant Likely
@ 2009-02-28 19:18 ` Gary Thomas
2009-02-28 20:19 ` Grant Likely
2009-02-28 21:05 ` Benjamin Herrenschmidt
0 siblings, 2 replies; 8+ messages in thread
From: Gary Thomas @ 2009-02-28 19:18 UTC (permalink / raw)
To: Grant Likely; +Cc: Linux PPC Development
Grant Likely wrote:
> On Sat, Feb 28, 2009 at 11:21 AM, Gary Thomas <gary@mlbassoc.com> wrote:
>> Grant Likely wrote:
>>> Once you have a handle to the node, you can iterate through the
>>> of_platform bus devices and look for a node which has a matching node
>>> pointer stored in archdata. That will give you a struct device which
>>> is contained by a struct of_device (note well: this will give you an
>>> of_device, not a platform_device.)
>> I have code which does this already, but I could not figure out
>> how to get from the of_device node to the actual platform_device.
>
> You can't. There is no platform_device. There is only the of_device.
>
> The bit that you're missing is that the 'platform bus' isn't being
> used at all for these devices. The 'of_platform bus' is used instead.
> platform bus and of_platform bus perform essentially the same job,
> but the of_platform bus differs in the way it probes drivers.
> Specifically, an of_platform_driver can be handed a list of values
> that it will match against, and it has a 1:1 relationship with a node
> in the device tree.
>
>> How do I find the platform_device which was created when this
>> particular of_device was instantiated? I made sure that this code
>> is run late - after all the of_devices have been handled.
>
> Again, there is no platform_device. of_device *is* the device that was created.
But this doesn't work :-( I also don't understand how you
can say "there is no platform_device" - they are everywhere,
corresponding to actual device instances, as the system
creates them, typically in a driver 'probe' function.
I've tried both ways. If I look up the of_platform node and
then pass the 'dev' structure to the DSA driver, it doesn't work.
If I look up the actual device instance from the platform_bus
and pass that to the driver, it does.
How do I get to the proper 'dev' structure which will make the
DSA driver work?
More details - the DSA driver is expecting to get the 'dev'
structure pointer which was created in the gianfar driver,
static int gfar_probe(struct platform_device *pdev)
namely '&pdev->dev' -- this works.
If I look up the of_platform device like this:
for_each_compatible_node(np, NULL, "marvell,m88e609x") {
const phandle *ph;
struct device *dev;
struct of_device *of_dev;
ph = of_get_property(np, "net_devX", NULL);
if (ph == NULL) {
printk("%s: missing 'net_dev'\n", np->name);
break;
}
of_dev = of_find_device_by_phandle(*ph);
and pass '&of_dev->dev', the DSA driver fails.
What am I missing and how do I solve this?
I'm not trying to be obstinate; I just need this to work
and I'm trying to make it work in an extensible, "play nice
in the OF sandbox" way.
Thanks for your help
--
------------------------------------------------------------
Gary Thomas | Consulting for the
MLB Associates | Embedded world
------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: OF device mappings
2009-02-28 19:18 ` Gary Thomas
@ 2009-02-28 20:19 ` Grant Likely
2009-02-28 20:25 ` Gary Thomas
2009-02-28 21:05 ` Benjamin Herrenschmidt
1 sibling, 1 reply; 8+ messages in thread
From: Grant Likely @ 2009-02-28 20:19 UTC (permalink / raw)
To: Gary Thomas; +Cc: Linux PPC Development
On Sat, Feb 28, 2009 at 12:18 PM, Gary Thomas <gary@mlbassoc.com> wrote:
> Grant Likely wrote:
>>> How do I find the platform_device which was created when this
>>> particular of_device was instantiated? =A0I made sure that this code
>>> is run late - after all the of_devices have been handled.
>>
>> Again, there is no platform_device. =A0of_device *is* the device that wa=
s created.
>
> But this doesn't work :-( =A0I also don't understand how you
> can say "there is no platform_device" - they are everywhere,
> corresponding to actual device instances, as the system
> creates them, typically in a driver 'probe' function.
No, "struct device" is everywhere. "struct platform_device" is a
particular container for a "struct device", just like "struct
of_device" is another kind of container for "struct device". The
board setup code (stuff in arch/powerpc/platforms/*) often calls into
the of_platform bus to automatically register an of_device for many of
the nodes in the device tree. platform_devices are typically
explicitly registered by board setup code and has not relationship
whatsoever with the of_platform bus.
> I've tried both ways. =A0If I look up the of_platform node and
> then pass the 'dev' structure to the DSA driver, it doesn't work.
> If I look up the actual device instance from the platform_bus
> and pass that to the driver, it does.
>
> How do I get to the proper 'dev' structure which will make the
> DSA driver work?
>
> More details - the DSA driver is expecting to get the 'dev'
> structure pointer which was created in the gianfar driver,
> =A0static int gfar_probe(struct platform_device *pdev)
> namely '&pdev->dev' -- this works.
Ah, it becomes clear now. I seen that the gianfar driver has only
recently been converted from a platform bus driver to an of_platform
bus driver (see git commit b31a1d8b41513b96e9c7ec2f68c5734cef0b26a4).
It will be released as part of 2.6.29.
http://git.kernel.org/?p=3Dlinux/kernel/git/torvalds/linux-2.6.git;a=3Dcomm=
it;h=3Db31a1d8b41513b96e9c7ec2f68c5734cef0b26a4
So, for the kernel version you're using, the
of_find_device_by_phandle() call will never work. It will for 2.6.29
and beyond. Currently, there is code in arch/powerpc/sysdev/fsl_soc.c
which creates the platform_device which you're looking for. Look into
that code to figure out how to get a pointer to that platform_device.
you can probably iterate over the platform bus (hint: look at
bus_find_device() and friends) to find it.
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: OF device mappings
2009-02-28 20:19 ` Grant Likely
@ 2009-02-28 20:25 ` Gary Thomas
0 siblings, 0 replies; 8+ messages in thread
From: Gary Thomas @ 2009-02-28 20:25 UTC (permalink / raw)
To: Grant Likely; +Cc: Linux PPC Development
Grant Likely wrote:
> On Sat, Feb 28, 2009 at 12:18 PM, Gary Thomas <gary@mlbassoc.com> wrote:
>> Grant Likely wrote:
>>>> How do I find the platform_device which was created when this
>>>> particular of_device was instantiated? I made sure that this code
>>>> is run late - after all the of_devices have been handled.
>>> Again, there is no platform_device. of_device *is* the device that was created.
>> But this doesn't work :-( I also don't understand how you
>> can say "there is no platform_device" - they are everywhere,
>> corresponding to actual device instances, as the system
>> creates them, typically in a driver 'probe' function.
>
> No, "struct device" is everywhere. "struct platform_device" is a
> particular container for a "struct device", just like "struct
> of_device" is another kind of container for "struct device". The
> board setup code (stuff in arch/powerpc/platforms/*) often calls into
> the of_platform bus to automatically register an of_device for many of
> the nodes in the device tree. platform_devices are typically
> explicitly registered by board setup code and has not relationship
> whatsoever with the of_platform bus.
>
>> I've tried both ways. If I look up the of_platform node and
>> then pass the 'dev' structure to the DSA driver, it doesn't work.
>> If I look up the actual device instance from the platform_bus
>> and pass that to the driver, it does.
>>
>> How do I get to the proper 'dev' structure which will make the
>> DSA driver work?
>>
>> More details - the DSA driver is expecting to get the 'dev'
>> structure pointer which was created in the gianfar driver,
>> static int gfar_probe(struct platform_device *pdev)
>> namely '&pdev->dev' -- this works.
>
> Ah, it becomes clear now. I seen that the gianfar driver has only
> recently been converted from a platform bus driver to an of_platform
> bus driver (see git commit b31a1d8b41513b96e9c7ec2f68c5734cef0b26a4).
> It will be released as part of 2.6.29.
>
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=b31a1d8b41513b96e9c7ec2f68c5734cef0b26a4
>
> So, for the kernel version you're using, the
> of_find_device_by_phandle() call will never work. It will for 2.6.29
> and beyond. Currently, there is code in arch/powerpc/sysdev/fsl_soc.c
> which creates the platform_device which you're looking for. Look into
> that code to figure out how to get a pointer to that platform_device.
> you can probably iterate over the platform bus (hint: look at
> bus_find_device() and friends) to find it.
Glad we're singing from the same score now :-)
I'm working from a stock 2.6.28 kernel - upgrading to anything
newer is a bit iffy. Is the code you are referring to in the
latest 2.6.29-rc? and I should steal from there?
--
------------------------------------------------------------
Gary Thomas | Consulting for the
MLB Associates | Embedded world
------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: OF device mappings
2009-02-28 19:18 ` Gary Thomas
2009-02-28 20:19 ` Grant Likely
@ 2009-02-28 21:05 ` Benjamin Herrenschmidt
1 sibling, 0 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2009-02-28 21:05 UTC (permalink / raw)
To: Gary Thomas; +Cc: Linux PPC Development
On Sat, 2009-02-28 at 12:18 -0700, Gary Thomas wrote:
> Grant Likely wrote:
> > On Sat, Feb 28, 2009 at 11:21 AM, Gary Thomas <gary@mlbassoc.com> wrote:
> >> Grant Likely wrote:
> >>> Once you have a handle to the node, you can iterate through the
> >>> of_platform bus devices and look for a node which has a matching node
> >>> pointer stored in archdata. That will give you a struct device which
> >>> is contained by a struct of_device (note well: this will give you an
> >>> of_device, not a platform_device.)
> >> I have code which does this already, but I could not figure out
> >> how to get from the of_device node to the actual platform_device.
.../...
You may want to look how I do something similar in
drivers/net/ibm_newemac
Not necessarily the nicest approach but works for now, until we have
something better.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-02-28 21:05 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-28 17:46 OF device mappings Gary Thomas
2009-02-28 18:04 ` Grant Likely
2009-02-28 18:21 ` Gary Thomas
2009-02-28 18:44 ` Grant Likely
2009-02-28 19:18 ` Gary Thomas
2009-02-28 20:19 ` Grant Likely
2009-02-28 20:25 ` Gary Thomas
2009-02-28 21:05 ` Benjamin Herrenschmidt
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).