OF device mappings
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
Signature · 4 lines
------------------------------------------------------------ Gary Thomas | Consulting for the MLB Associates | Embedded world ------------------------------------------------------------
Quoted 12 lines · Gary Thomas
Still looking for some help... =A0I need to be able to locate the kernel
platform_devicewhich 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.
Quoted 3 lines
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.
Quoted 3 lines
=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.
Quoted 2 lines
=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.
Quoted 14 lines
=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
Quoted 10 lines
--
------------------------------------------------------------
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
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Quoted 13 lines · Grant Likely
Quoted 12 lines · Gary Thomas
Still looking for some help... I need to be able to locate the kernel
platform_devicewhich 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.
Quoted 6 lines
Quoted 3 lines
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.
Quoted 11 lines
Quoted 3 lines
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.
Quoted 2 lines
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.
Quoted 5 lines
Once you have a handle to the node, you can iterate through the
of_platformbus 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 structof_device(note well: this will give you anof_device, not aplatform_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.
Quoted 2 lines
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
Quoted 9 lines
Quoted 9 lines
};... 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.
Signature · 4 lines
------------------------------------------------------------ Gary Thomas | Consulting for the MLB Associates | Embedded world ------------------------------------------------------------
Quoted 9 lines · Gary Thomas
Quoted 5 lines · Grant Likely
Once you have a handle to the node, you can iterate through the
of_platformbus 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 structof_device(note well: this will give you anof_device, not aplatform_device.)I have code which does this already, but I could not figure out how to get from the
of_devicenode to the actualplatform_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.
Quoted 3 lines
How do I find the
platform_devicewhich was created when this particularof_devicewas instantiated? =A0I made sure that this code is run late - after all theof_deviceshave been handled.
Again, there is no platform_device. of_device *is* the device that was cre= ated.
g.
Quoted 20 lines · Grant Likely
Quoted 8 lines · Gary Thomas
Quoted 5 lines · Grant Likely
Once you have a handle to the node, you can iterate through the
of_platformbus 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 structof_device(note well: this will give you anof_device, not aplatform_device.)I have code which does this already, but I could not figure out how to get from the
of_devicenode to the actualplatform_device.You can't. There is no
platform_device. There is only theof_device.The bit that you're missing is that the 'platform bus' isn't being used at all for these devices. The '
of_platformbus' is used instead.
platform bus andof_platformbus perform essentially the same job,
but theof_platformbus differs in the way it probes drivers. Specifically, anof_platform_drivercan 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.
Quoted 5 lines
Quoted 3 lines
How do I find the
platform_devicewhich was created when this particularof_devicewas instantiated? I made sure that this code is run late - after all theof_deviceshave 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
Signature · 4 lines
------------------------------------------------------------ Gary Thomas | Consulting for the MLB Associates | Embedded world ------------------------------------------------------------
Quoted 6 lines · Gary Thomas
Quoted 5 lines · Grant Likely
Quoted 3 lines
How do I find the
platform_devicewhich was created when this particularof_devicewas instantiated? =A0I made sure that this code is run late - after all theof_deviceshave been handled.Again, there is no
platform_device. =A0of_device *is* the device that wa=
s created.
Quoted 5 lines
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.
Quoted 5 lines
I've tried both ways. =A0If I look up the
of_platformnode and then pass the 'dev' structure to the DSA driver, it doesn't work. If I look up the actual device instance from theplatform_busand pass that to the driver, it does.
Quoted 7 lines
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.
Quoted 40 lines · Grant Likely
Quoted 9 lines · Gary Thomas
Quoted 4 lines · Grant Likely
Quoted 3 lines
How do I find the
platform_devicewhich was created when this particularof_devicewas instantiated? I made sure that this code is run late - after all theof_deviceshave 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 "structof_device" is another kind of container for "struct device". The board setup code (stuff inarch/powerpc/platforms/*) often calls into theof_platformbus to automatically register anof_devicefor many of the nodes in the device tree.platform_devicesare typically explicitly registered by board setup code and has not relationship whatsoever with theof_platformbus.Quoted 5 lines
I've tried both ways. If I look up the
of_platformnode and then pass the 'dev' structure to the DSA driver, it doesn't work. If I look up the actual device instance from theplatform_busand pass that to the driver, it does.Quoted 7 lines
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 intgfar_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_platformbus driver (see git commitb31a1d8b41513b96e9c7ec2f68c5734cef0b26a4). It will be released as part of 2.6.29.
Quoted 7 lines
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 inarch/powerpc/sysdev/fsl_soc.cwhich creates theplatform_devicewhich you're looking for. Look into that code to figure out how to get a pointer to thatplatform_device. you can probably iterate over the platform bus (hint: look atbus_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?
Signature · 4 lines
------------------------------------------------------------ Gary Thomas | Consulting for the MLB Associates | Embedded world ------------------------------------------------------------
Quoted 10 lines · Gary Thomas
Quoted 9 lines · Grant Likely
Quoted 8 lines · Gary Thomas
Quoted 5 lines · Grant Likely
Once you have a handle to the node, you can iterate through the
of_platformbus 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 structof_device(note well: this will give you anof_device, not aplatform_device.)I have code which does this already, but I could not figure out how to get from the
of_devicenode to the actualplatform_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.