版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kakascx/article/details/83089614
通过 s3c_device_leds_ctl->*smdk4x12_devices[]->platform_add_devices()->platform_device_register()
可以直接使用“platform_device_register()”来注册设备
#include <linux/init.h>
#include <linux/module.h>
/*驱动注册的头文件,包含驱动的结构体和注册和卸载的函数*/
#include <linux/platform_device.h>
#define DRIVER_NAME "hello_ctl"
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("TOPEET");
static void leds_release(struct device *dev)
{
printk("leds_release");
}
struct platform_device platform_device_hello = {
.name = "my_code_led",
.id = -1,
.dev = {
.release = leds_release,//必须向内核提供一个 release 函数,否则释放的时候会报错
}
};
static int hello_init(void)
{
platform_device_register(&platform_device_hello);
return 0;
}
static void hello_exit(void)
{
platform_device_unregister(&platform_device_hello);
}
module_init(hello_init);
module_exit(hello_exit);
-
platform_device_register(struct platform_device *pde)
功能:注册设备
参数:要注册设备的结构体 -
platform_device_unregister(struct platform_device *pde)
-
功能:卸载设备 参数:要卸载设备的结构体
platform_device 结构体包括名字、id和释放函数三要素