- 论坛徽章:
- 0
|
我 成功创建了字符设备, 写了 一个 用戶程序去打开它 , 反回到是没错 ,但是底下driver的 open中 的打印信息 却没有,
似乎设备文件没真正被打开 ,
这样現象 的 原因会 是 什们呢 ?
主要 的代码
494 cdev_init(tcd->cdev,&tw_fops); --------> (1)
495 //tcd->cdev->ops = &tw_fops;
496 tcd->cdev->owner = tcd->tcd_fops->owner;
497 ret = cdev_add(tcd->cdev,MKDEV(TW_CHIP_MAJOR,minor),1);
498 if(ret < 0){
499 flag = 1;
500 printk("cdev_add failed!\n");
501 goto cleanup;
502 }
........
tcd->minor = minor;
509
510 //tcd->dev.class = &twell_class;
511 tcd->dev.parent = NULL;
512 tcd->dev.kobj.parent = NULL;//kobj;
513 tcd->dev.devt = MKDEV(TW_CHIP_MAJOR,minor);
514 snprintf(tcd->dev.bus_id,sizeof(tcd->dev.bus_id),"%scontrol%02d",tcd->name,minor);
515 ret = device_register(&tcd->dev);
516 if(ret < 0){
517 printk("device register failed!\n");
518 goto cleanup;
519 }
而 cdev的fop tw_fops的 定义如下
293 struct file_operations tw_fops = {
294 .owner = THIS_MODULE,
295 .open = twc_open,
296 .release = twc_release,
297 .read = twc_read,
298 .write = twc_write,
299 .ioctl = twc_ioctl,
300 };
打印信息就 在 twc_open函数中 , 但就是 始终没 看到. |
|