itop4412 设备注册、驱动注册、设备、platform总线之间的关系,和流程

itop4412 设备注册、驱动注册、设备、platform总线之间的关系,和流程;

废话少说,直接上干货。

一、platform之设备:
要想在platform 的杂项下(misc) 加载一个新的设备,需要在
1、在 arch\arm\mach-exynos\mach-itop4412.c 中进行修改。
2、新定义一个设备的结构体(struct platform_device s3c_device_hello_ctl) 。
3、在 static struct platform_device *smdk4x12_devices[] __initdata[] 加入这个结构体到平台设备列表中,如下所示:

// 定义对应设备的结构体。
#ifdef CONFIG_HELLO_CTL
struct platform_device s3c_device_hello_ctl = {
.name = “hello_ctl”, // 设备的名字,只要编译进内核中,不管驱动加载与否,在 /sys/bus/platform/devices 中,都会出现。
.id = -1,
};
#endif

// 在平台设备列表中,将会加载这个设备。
static struct platform_device *smdk4x12_devices[] __initdata = {

#ifdef CONFIG_HELLO_CTL
&s3c_device_hello_ctl,
#endif


}

二、platform设备之menuconfig:
1、要想在menuconfig中,可以通过菜单选项来加载设备与否,添加如下步骤。
2、把设备挂载到杂项设备中(当然,也可以在其它之中),
在: …/iTop4412_Kernel_3.0/drivers/Kconfig 中添加
config HELLO_CTL
tristate “HELLO_CTL”
default m
—help—
This only add menuconfig menu, use for select.
3、当选择编译进内核后,生成的内核,将会在:/sys/bus/platform/devices 中,出现设备“HELLO_CTL”。

三、platform之驱动:
1、编写一个简单的驱动,执行流程如下:
2、驱动注册。
module_init(hello_init) -> platform_driver_register(&hello_driver) -> hello_probe()

struct platform_driver hello_driver = {
.probe = hello_probe,
.remove = hello_remove,
.shutdown = hello_shutdown,
.suspend = hello_suspend,
.resume = hello_resume,
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
}
};

static int hello_probe(struct platform_device *pdv){
int ret;
printk(KERN_EMERG “\tinitialized\n”);
ret = gpio_request(EXYNOS4_GPL2(0),“LEDS”); // GPIO 申请;
if(ret < 0){
printk(KERN_EMERG “gpio_request EXYNOS4_GPL2(0) failed!\n”);
return ret;
}
s3c_gpio_cfgpin(EXYNOS4_GPL2(0),S3C_GPIO_OUTPUT); // GPIO 配置输出;
gpio_set_value(EXYNOS4_GPL2(0),0); // GPIO 设置;
misc_register(&hello_dev); // 驱动注册;
return 0;
}

3、驱动卸载
module_exit(hello_exit) -> platform_driver_unregister(&hello_driver -> hello_remove()

static int hello_remove(struct platform_device *pdv){
printk(KERN_EMERG “\tremove\n”);

// new add for test.
gpio_free(EXYNOS4_GPL2(0));         // GPIO 释放;
misc_deregister(&hello_dev);          // 驱动注消;
return 0;

}

编译驱动,拷贝到开发板上。
特别说明一下:
当没有加载驱动时:
1、当重新编译内核,并重新烧写后,此时在没有加载驱动时,只有:/sys/bus/platform/devices/ 目录下有“HELLO_CTL”。
2、在 /dev 和 /sys/bus/platform/drivers/ 均没有“HELLO_CTL”。

当用: insmod 加载驱动后:
1、在:/sys/bus/platform/devices/ 和 /dev 和 /sys/bus/platform/drivers/ 均有“HELLO_CTL”。
2、表示驱动设备匹配成功,并成功执行了,probe()函数。

在应用端编写一个简单的应用程序,可以控制GPIO的高低。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值