上层通过读取节点/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函数