小板匹配 从上层到下层

上层通过读取节点/proc/oppo_smallboard_id的值来获取是否匹配,如果值是1,则表明匹配。

那么这个节点的值是怎么来的了,通过全局搜索可以发现在devices_list.c文件中有定义

static ssize_t mallboard_id_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{

        char temp_buffer[2];
	int num_read_chars = 0;
	
    num_read_chars += sprintf(temp_buffer, "%d\n",smallboard);
	num_read_chars = simple_read_from_buffer(buf, count, pos, temp_buffer, strlen(temp_buffer));
	return num_read_chars; 
}


static ssize_t  smallboard_id_write(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
	/*not support write now*/
	return count;
}
static const struct file_operations smallboard_id = {
	.write       = smallboard_id_write,
	.read	     = smallboard_id_read,
};

上面可以看出定义了一个结构体 smallboard_id,并且定义了它的读写方法,写方法不支持,读方法调用了simple_read_from_buffer,这个方法的作用是讲内核的数据搞到用户空间。明显就是把smallboard的数据搞到节点proc/oppo_smallboard_id,多简单。那看看这个数据是怎么来的吧

static void smallboard_version_check(void)
{
	switch(get_project()) {
			int id0 = 0;
			id0 = mt_get_gpio_in(GPIO16);
			
			printk("smallboard_version_check id1 = %d\n",id0);
			if(id0 == 1)
				smallboard = SMALLBOARD_VERSION__1;
			else
				smallboard = SMALLBOARD_VERSION__0;
			break;
		}
	}
	printk("smallboard_version_check oppo_smallboard = %d\n",oppo_smallboard);
}
由函数mt_get_gpio_in名字都可以知道,是读取一个gpio的电压值,电压值不同表示不同的小板。

那么这个smallboard_version_check函数是谁调用的呢?

static int oppo_dev_platform_probe(struct platform_device *pdev)
{
  	
   smallboard_version_check();
   proc_create("smallboard_id", 0666, NULL, &smallboard_id);	
    return 0;
}
原来是在probe函数调用的,那么这个probe函数又是谁调用的呢?

肯定是register函数了,我们知道驱动注册都是调用probe函数啦,就是module_init函数




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值