2014-10-08 86 views
1

我正在将平台驱动程序代码移植到PCIe变体,我不明白为什么我没有得到/dev/条目显示。已被修改的平台驱动程序代码:为什么此device_create()调用不会创建一个/ dev/entry?

static dev_t first; 
static struct class * class; 
ATTRIBUTE_GROUPS(my); 
static int __init my_pci_init(void) 
{ 

    int ret; 
    /* Create a class entry in sysfs */ 
    if ((class = class_create(THIS_MODULE, "test_driver")) == NULL) { 
     pr_err("Couldn't create 'struct class' structure."); 
     ret = -ENODEV; 
     goto exit; 
    } 
    class->dev_groups = my_groups; 
    /* Create the /dev/ file system entry */ 
    /* return value ignored: there's a 'struct class' to 'struct device' mapping */ 
    if (device_create(class, NULL, first, NULL, KBUILD_MODNAME) == NULL) { 
     pr_err("Couldn't create entry in '/dev/' file system."); 
     ret = -ENODEV; 
     goto exit; 
    } else { 
     pr_info("Created a /dev/ entry."); 
    } 

    if ((ret = pci_register_driver(&pci_driver)) < 0) { 
     pr_err("Couldn't register pci driver."); 
    } 
exit: 
    if (ret < 0) { 
     my_pci_exit(); 
     pr_err(" ret = %d", ret); 
    } 
    return ret; 
} 

module_init(my_pci_init); 

如果模块名称是“cz_tdm”,我希望上面的代码将创建一个条目/dev/cz_tdm。至少当我把它编译成平台驱动程序的时候就是这样。

的驱动程序枚举就好了,的lspci输出显示驱动程序加载和细读sysfs表明我在/sys/devices/virtual/...所有属性,我希望他们是。

什么给?

回答

2

哎呦。

因为它不应该太。代码的过度删除扯掉了这个必要的元素:

/* Add the char device to the system. */ 
cdev_init(&cdev, &fops); 
if ((ret = cdev_add(&cdev, first, DEV_MINOR_NUMBER_COUNT)) < 0) { 
    pr_err("Couldn't add device to system: %d", ret); 
    ret = -ENODEV; 
    goto exit; 
} 
相关问题