platform_device
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
//3.创建并填充设备信息结构体
struct resource res[] = {
[0] = {
//资源起始地址
.start = 0x12345678,
//资源末尾地址
.end = 0x12345678 + 49,
//资源类型(内存)
.flags = IORESOURCE_MEM,
},
[1] = {
//资源起始中断号
.start = 71,
//资源末尾中断号
.end = 71,
//资源类型(中断)
.flags = IORESOURCE_IRQ,
}
};
//2.填充释放资源函数(可以为空)
void pdev_release(struct device* dev){
}
//1.创建并填充platform_device结构体
struct platform_device pdev = {
//用于匹配的名字
.name = "123",
//总线号(自动分配)
.id = PLATFORM_DEVID_AUTO,
//父类,用于构建链表,必须写释放资源函数
.dev = {
//释放资源的函数
.release = pdev_release,
},
//设备信息结构体
.resource = res,
//设备信息结构体成员个数
.num_resources = ARRAY_SIZE(res),
};
static int __init pdev_init(void){
//4.注册platform_device
return platform_device_register(&pdev);
}
static void __exit pdev_exit(void){
//5.注销platform_device
platform_device_unregister(&pdev);
}
module_init(pdev_init);
module_exit(pdev_exit);
MODULE_LICENSE("GPL");
platform_driver
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h> //没有platform_driver.h头文件
#include <linux/mod_devicetable.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
/*
myplatform{
compatible = "123,myplatform";
interrupt-parent = <&gpiof>;
interrupts = <9 0>;
reg = <0x12345678 0x40>;
led1 = <&gpioe 10 0>;
};
*/
struct resource*