plat_led_dev.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#define GPC0_CONF_REG 0xe0200060
#define GPC0_SIZE 8 // 24表示需要使用6个寄存器, 8表示使用两个寄存器, 每个寄存器长度为4个字节
struct resource led_res[] = {
//led只有地址资源没有其他
[0] = {
.start = GPC0_CONF_REG ,
.end = GPC0_CONF_REG + GPC0_SIZE -1,
.flags = IORESOURCE_MEM,
},
// 以下代码只是演示如何定义多个资源,led硬件中实际是没有的
[1] = {
.start = 998, // 中断号
.end = 998,
.name = "fake_irq",
.flags = IORESOURCE_IRQ,
},
[2] = {
.start = 0x12345678,
.end = 0x12345678 + 16 - 1,
.name = "fake_mem",
.flags = IORESOURCE_MEM,
},
};
void led_pdev_release(struct device *dev) //解决pdev移除时的警告
{
}
static struct platform_device led_pdev = {
.name = "s5pv210_led", // 用于和pdrv进行匹配的--自定义
.id = -1, // 一般填-1, 表示不同控制器
.dev = {//父类
.release = led_pdev_release,
},
.num_resources = ARRAY_SIZE(led_res),
.resource = led_res ,
};
static int __init plat_led_dev_init(void)//当insmod内核时调用 __init 优化 用完就丢掉
{
//注册pdev
return platform_device_register(&led_pdev);
}
static void __exit plat_led_dev_exit(void)
{
//注销pdev
platform_device_unregister(&led_pdev);
}
module_init(plat_led_dev_init);//告诉内核 加载函数
module_exit(plat_led_dev_exit);//卸载函数
MODULE_A