From: "Chris Alfred" <c.alfred@internode.on.net>
To: "Grant Likely" <grant.likely@secretlab.ca>
Cc: linuxppc-dev <linuxppc-dev@lists.ozlabs.org>
Subject: Re: Porting a driver to powerpc using FDT
Date: Thu, 17 Jun 2010 21:11:47 +1000 [thread overview]
Message-ID: <6EAB45775B71486B8E72844E797E1D0F@kos> (raw)
In-Reply-To: AANLkTim8kD9PH7BqOIV0GvElIfOgUDMw1VfWcOJhj-8r@mail.gmail.com
> virtual-devices {
> compatible = "simple-bus";
> dsa {
> compatible = "<vendor>,jkc5200n8-dsa";
> };
> };
Ok, after correcting the names, the basic OF driver is probed.
Now to try and use probe to register the DSA platform driver with the
OF driver as its parent.
=======
For those interested in how to get a very basic OF (uses FDT) driver
going, the steps I did are below.
'myvendor' is your company name, and 'mydevice' is the name of the
device - use better names in real code.
(1) The .dts file - this is the Flattened Device Tree (FDT)
descriptor:
/ {
...
virtual-device {
compatible = "simple-bus";
mydevice0 {
compatible = "myvendor,mydevice";
};
};
...
};
For my board "simple-bus" is an already defined bus in the .dts.
In my case the .dts had:
/ {
...
localbus {
compatible =
"fsl,mpc5200b-lpb","fsl,mpc5200-lpb","simple-bus";
...
};
...
};
(2) Create the OF driver:
#include <linux/of.h>
#include <linux/kernel.h>
#include <linux/of_platform.h>
static int __devinit mydevice_probe(struct of_device *ofdev, const
struct of_device_id *match)
{
printk("mydevice_probe\n");
return 0;
}
static int mydevice_remove(struct of_device *ofdev)
{
printk("mydevice_remove\n");
return 0;
}
static const struct of_device_id mydevice_match[] = {
{
.compatible = "myvendor,mydevice",
},
{}
};
static struct of_platform_driver mydevice_driver = {
.name = "mydevice-driver",
.match_table = mydevice_match,
.probe = mydevice_probe,
.remove = mydevice_remove,
};
static int __init mydevice_driver_init(void)
{
printk("mydevice_drver_init\n");
if (of_register_platform_driver(&mydevice_driver))
printk(KERN_ERR "Unable to register platform driver\n");
return 0;
}
module_init(mydevice_driver_init);
static void __exit mydevice_driver_cleanup(void)
{
printk("mydevice_driver_cleanup\n");
of_unregister_platform_driver(&mydevice_driver);
}
module_exit(mydevice_driver_cleanup);
MODULE_DESCRIPTION("mydevice driver");
MODULE_AUTHOR("name <email>");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:mydevice-driver");
(3) Change the appropriate Makefile and Kconfig to compile the OF
driver.
During kernel boot you should see the lines:
mydevice_driver_init
mydevice_probe
If not, you probably have one of the strings (text in " ") incorrect.
In /sys/bus/of_platform/drivers, you should have a directory named
'mydevice-driver'.
In /sys/bus/of_platform/drivers/mydevice-driver you should have a
directory named 'mydevice0.1'. The name 'mydevice0' comes from the
.dts above.
==========
Brief explaination of how I think this is all tied together:
(1) The Flattened Device Tree is included with the compiled kernel
image.
(2) The module_init(...) macro is like declaring a 'main' for drivers.
The kernel calls all of the functions declared in the module_init(...)
macros during startup.
(3) When a device driver is registered via
of_register_platform_driver(), this invokes a scan of the FDT to find
matches with strings in the .match_table. If a match is found, the
.probe is called for the created device instance.
Chris
next prev parent reply other threads:[~2010-06-17 11:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-15 22:19 Porting a driver to powerpc using FDT Chris Alfred
2010-06-16 18:22 ` Grant Likely
2010-06-16 22:06 ` Chris Alfred
2010-06-16 22:43 ` Grant Likely
2010-06-16 22:48 ` Chris Alfred
2010-06-16 23:14 ` Grant Likely
2010-06-17 4:25 ` Chris Alfred
2010-06-17 4:29 ` Chris Alfred
2010-06-17 14:55 ` Grant Likely
2010-06-17 11:11 ` Chris Alfred [this message]
2010-06-17 16:37 ` Grant Likely
2010-06-17 22:15 ` Chris Alfred
-- strict thread matches above, loose matches on Subject: below --
2010-06-15 22:18 Chris Alfred (Internode)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6EAB45775B71486B8E72844E797E1D0F@kos \
--to=c.alfred@internode.on.net \
--cc=grant.likely@secretlab.ca \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox