这一节正式开始使用设备树来写驱动
在上一节我们我们添加了名称属性le_test
这里直接复制别人写的测试程序
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#define DRIVER_NAME "leds_test"
static int leds_probe(struct platform_device * pdev)
{
printk(KERN_ALERT "probe init\n");
return 0;
}
static int leds_remove(struct platform_device * pdev)
{
printk(KERN_ALERT "Goodbye, curel world, this is remove\n");
return 0;
}
static const struct of_device_id of_leds_dt_match[] = {
{.compatible = DRIVER_NAME},
{},
};
MODULE_DEVICE_TABLE(of,of_leds_dt_match);
static struct platform_driver leds_driver = {
.probe = leds_probe,
.remove = leds_remove,
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
.of_match_table = of_leds_dt_match,
},
};
static int leds_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return platform_driver_register(&leds_driver);
return 0;
}
static void leds_exit(void)
{
printk(KERN_ALERT "Goodbye, curel world\n");
platform_driver_unregister(&leds_driver);
}
module_init(leds_init);
module_exit(leds_exit);
MODULE_LICENSE("Dual BSD/GPL");