Porting a driver to powerpc using FDT

Grant Likely grant.likely at secretlab.ca
Thu Jun 17 08:43:19 EST 2010


On Wed, Jun 16, 2010 at 4:06 PM, Chris Alfred <c.alfred at internode.on.net> wrote:
> Grant Likely wrote:
>> On Tue, Jun 15, 2010 at 4:19 PM, Chris Alfred
>> <c.alfred at internode.on.net> wrote:
>>> I am trying to port a DSA (Distributed Switch Architecture) driver
>>> for the Micrel KS8995M managed switch connected to a MPC5200. There
>>> is an SPI interface and MII interface managed by the DSA driver.
>>>
>>> I can't understand how probe gets called when the flatted device
>>> tree
>>> (FDT) system is used, and how to bind such a driver using the FDT
>>> (if
>>> you have to at all).
>>>
>>> The DSA driver is initialised via:
>>>
>>> // net/dsa/dsa.c
>>>
>>> static struct platform_driver dsa_driver = {
>>> .probe = dsa_probe,
>>> .remove = dsa_remove,
>>> .shutdown = dsa_shutdown,
>>> .driver = {
>>> .name = "dsa",
>>> .owner = THIS_MODULE,
>>> },
>>> };
>>>
>>> static int __init dsa_init_module(void)
>>> {
>>> return platform_driver_register(&dsa_driver);
>>> }
>>>
>>> dsa_init_module is being called; but how do I get the system to
>>> call
>>> .probe?
>>
>> To avoid writing new machine-specific code in
>> arch/powerpc/platforms,
>> then I recommend that you add a node to your .dts file to describe
>> the
>> DSA complex and write a very simple of_platform_driver that binds
>> against it.  Then use the probe hook to extract data out of the
>> device
>> tree node (if needed) and register the appropriate platform_device
>> (don't forget to make the of_device the parent of the
>> platform_device).  This can be considered a temporary solution, but
>> it
>> will not break when I make the infrastructure changes, and then you
>> can migrate over to the new method at your leisure.
>
>
> Thanks for the great response.
>
> I still have some learning to do. To start, I tried to get a simple
> of_platform_driver going.
> In my .dts I added:
>
>    / {
>        ...
>         dsa {
>          compatible = "dsa-of";

This is too generic.  Until there is a real generic binding for DSA
devices, use a name specific to your board.  An of driver can bind to
more than one compatible value.  Don't forget to include the vendor
prefix in your compatible value.

>          reg = <0 0>;   // TODO: might need config values e.g. number
> of phys, cpu port

Just drop this property until you have real data to populate it with.
For a virtual device like this you probably don't need a reg property.
 What you probably do need in this node is references (phandles) to
the node for the marvel switch which I imagine hangs off of an MDIO or
SPI bus.

>         };
>        ...
>    };
>
> I created net/dsa/dsa_of.c - the simple of_platform_driver that will
> bind to the DSA platform driver (in net/dsa/dsa.c):
>
>    #include <linux/of.h>
>    #include <linux/kernel.h>
>    #include <linux/of_platform.h>
>
>    static int __devinit dsa_of_probe(struct of_device *ofdev, const
> struct of_device_id *match)
>    {
>     printk("dsa_of_probe\n");
>     return 0;
>    }
>
>    static int dsa_of_remove(struct of_device *ofdev)
>    {
>     printk("dsa_of_remove\n");
>     return 0;
>    }
>
>
>    static const struct of_device_id dsa_of_match[] = {
>     {
>      .compatible = "dsa-of",
>     },
>     {}
>    };
>
>    static struct of_platform_driver dsa_of_driver = {
>     .name = "dsa-of",
>     .match_table = dsa_of_match,
>     .probe = dsa_of_probe,
>     .remove = dsa_of_remove,
>    };
>
>    static int __init dsa_of_init(void)
>    {
>     printk("dsa_of_init\n");
>
>     if (of_register_platform_driver(&dsa_of_driver))
>      printk(KERN_ERR "Unable to register DSA OF platform driver\n");
>
>     return 0;
>    }
>    module_init(dsa_of_init);
>
>    static void __exit dsa_of_cleanup(void)
>    {
>     printk("dsa_of_cleanup\n");
>
>     of_unregister_platform_driver(&dsa_of_driver);
>    }
>    module_exit(dsa_of_cleanup);
>
>    MODULE_DESCRIPTION("DSA OF platform driver");
>    MODULE_AUTHOR("Chris Alfred <chris at greyfog.com.au");
>    MODULE_LICENSE("GPL v2");
>
> dsa_of_init is successfully called; but dsa_of_probe is not called.

That means the node is not being used to register an of_device.  I
need some more information to suggest how best to fix this.  What SoC
are you using?  What file in arch/powerpc/platforms/* is used to setup
your machine?  It would help to have a copy of your full .dts file.

Cheers,
g.


More information about the Linuxppc-dev mailing list