Linux驱动---platform进阶

1、platform架构

在这里插入图片描述

硬件资源是在plat from_device里面用u32 num_resources(资源个数)和struct resource *resource(资源)来表示

2、增加硬件信息

在这里插入图片描述
flags:
在这里插入图片描述
start和end:
如果这个寄存器占四个地址,那么
start:开始地址
end:最后一个(开始地址+0x3)

3、举例

在这里插入图片描述


在这里插入图片描述
这是内核里面数组的一种赋值方式,[0]{} 表示数组第一个成员,里面的元素用.来赋值

4、示例代码

device:

#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>


void	hello_release(struct device *dev)
{
	printk("hello_release\n");
	return;
}


struct resource	res[]={
	[0] ={
		.start = 0x139d0000,
		.end  = 0x139d0000 + 0x3,
		.flags = IORESOURCE_MEM,
	},

	[1] ={
		.start = 199,
		.end  = 199,
		.flags = IORESOURCE_IRQ,
	},	
};


struct platform_device hello_device ={
	.name = "yikoulinux",
	.id = -1,
	.dev.release = hello_release,
	//hardware TBD
	.num_resources = ARRAY_SIZE(res),
	.resource = res,
};

static int hello_init(void)
{
	printk("hello_init\n");
	return platform_device_register(&hello_device);
}

static void hello_exit(void)
{
	printk("hello_exit\n");
	platform_device_unregister(&hello_device);
	return;
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);

driver:

#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>


int hello_probe(struct platform_device *pdev)
{
	printk("match ok\n");

	printk("mem = %x \n",pdev->resource[0].start);
	printk("irq = %d \n",pdev->resource[1].start);

	//ioremap
	//request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char * name, void * dev)
	
	return 0;
}
int hello_remove(struct platform_device *pdev)
{
	printk("hello_remove\n");
	return 0 ;
}




struct platform_driver hello_driver = {
	.probe = hello_probe,
	.remove = hello_remove,
	.driver.name = "yikoulinux",
};



static int hello_init(void)
{
	printk("hello_init\n");
	return platform_driver_register(&hello_driver);
}

static void hello_exit(void)
{
	printk("hello_exit\n");
	platform_driver_unregister(&hello_driver);
	return;
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);

5、效果

在这里插入图片描述

6、注册代码流程详解

捋架构的好处,就是可以帮助我们定位问题

1. match函数何时被调用到?

2. probe函数何时被调用到

以下是上述两个问题代码的调用流程:
在这里插入图片描述

7、没有设备树,硬件信息存放在哪里

以三星为例:
●mach-smdkc100.c arch\arm\mach-s5pc100
●arch\arm\plat-samsung

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值