当前位置: 首页>>代码示例>>C++>>正文


C++ cdev_add函数代码示例

本文整理汇总了C++中cdev_add函数的典型用法代码示例。如果您正苦于以下问题:C++ cdev_add函数的具体用法?C++ cdev_add怎么用?C++ cdev_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cdev_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WIFI_init

static int WIFI_init(void)
{
    dev_t dev = MKDEV(WIFI_major, 0);
    INT32 alloc_ret = 0;
    INT32 cdev_err = 0;
#if WMT_CREATE_NODE_DYNAMIC
    struct device * wmtwifi_dev = NULL;
#endif

    /* static allocate chrdev */
    alloc_ret = register_chrdev_region(dev, 1, WIFI_DRIVER_NAME);
    if (alloc_ret) {
        WIFI_ERR_FUNC("Fail to register chrdev\n");
        return alloc_ret;
    }

    cdev_init(&WIFI_cdev, &WIFI_fops);
    WIFI_cdev.owner = THIS_MODULE;

    cdev_err = cdev_add(&WIFI_cdev, dev, WIFI_devs);
    if (cdev_err) {
        goto error;
    }

#if WMT_CREATE_NODE_DYNAMIC  //mknod replace
    wmtwifi_class = class_create(THIS_MODULE,"wmtWifi");
    if(IS_ERR(wmtwifi_class))
        goto error;
    wmtwifi_dev = device_create(wmtwifi_class,NULL,dev,NULL,"wmtWifi");
    if(IS_ERR(wmtwifi_dev))
        goto error;
#endif

    sema_init(&wr_mtx, 1);

    WIFI_INFO_FUNC("%s driver(major %d) installed.\n", WIFI_DRIVER_NAME, WIFI_major);
    retflag = 0;
    wlan_mode = WLAN_MODE_HALT;
    pf_set_p2p_mode = NULL;

    return 0;

error:
#if WMT_CREATE_NODE_DYNAMIC
    if(!IS_ERR(wmtwifi_dev))
        device_destroy(wmtwifi_class,dev);
    if(!IS_ERR(wmtwifi_class)){
        class_destroy(wmtwifi_class);
        wmtwifi_class = NULL;
    }
#endif

    if (cdev_err == 0) {
        cdev_del(&WIFI_cdev);
    }

    if (alloc_ret == 0) {
        unregister_chrdev_region(dev, WIFI_devs);
    }

    return -1;
}
开发者ID:Elnter,项目名称:j608_kernel,代码行数:62,代码来源:wmt_chrdev_wifi.c

示例2: bt_hwctl_init

static int __init bt_hwctl_init(void)
{
    int ret = -1, err = -1;
    
    BT_HWCTL_DEBUG("bt_hwctl_init\n");
    
    platform_driver_register(&mt6622_driver);
    
    if (!(bh = kzalloc(sizeof(struct bt_hwctl), GFP_KERNEL)))
    {
        BT_HWCTL_ALERT("bt_hwctl_init allocate dev struct failed\n");
        err = -ENOMEM;
        goto ERR_EXIT;
    }
    
    ret = alloc_chrdev_region(&bh->dev_t, 0, 1, BTHWCTL_NAME);
    if (ret) {
        BT_HWCTL_ALERT("alloc chrdev region failed\n");
        goto ERR_EXIT;
    }
    
    BT_HWCTL_DEBUG("alloc %s:%d:%d\n", BTHWCTL_NAME, MAJOR(bh->dev_t), MINOR(bh->dev_t));
    
    cdev_init(&bh->cdev, &bt_hwctl_fops);
    
    bh->cdev.owner = THIS_MODULE;
    bh->cdev.ops = &bt_hwctl_fops;
    
    err = cdev_add(&bh->cdev, bh->dev_t, 1);
    if (err) {
        BT_HWCTL_ALERT("add chrdev failed\n");
        goto ERR_EXIT;
    }
    
    bh->cls = class_create(THIS_MODULE, BTHWCTL_NAME);
    if (IS_ERR(bh->cls)) {
        err = PTR_ERR(bh->cls);
        BT_HWCTL_ALERT("class_create failed, errno:%d\n", err);
        goto ERR_EXIT;
    }
    
    bh->dev = device_create(bh->cls, NULL, bh->dev_t, NULL, BTHWCTL_NAME);
    mutex_init(&bh->sem);
    
    init_waitqueue_head(&eint_wait);
    
    wake_lock_init(&mt6622_irq_wakelock, WAKE_LOCK_SUSPEND, "mt6622_irq_wakelock");
    
    /*INIT_WORK(&mtk_wcn_bt_event_work, mtk_wcn_bt_work_fun);
    mtk_wcn_bt_workqueue = create_singlethread_workqueue("mtk_wcn_bt");
    if (!mtk_wcn_bt_workqueue) {
        printk("create_singlethread_workqueue failed.\n");
        err = -ESRCH;
        goto ERR_EXIT;
    }*/    
    
    /* request gpio used by BT */
    //mt_bt_gpio_init();
    
    BT_HWCTL_DEBUG("bt_hwctl_init ok\n");
    
    return 0;
    
ERR_EXIT:
    if (err == 0)
        cdev_del(&bh->cdev);
    if (ret == 0)
        unregister_chrdev_region(bh->dev_t, 1);
        
    if (bh){
        kfree(bh);
        bh = NULL;
    }     
    return -1;
}
开发者ID:avila-devlogic,项目名称:D33_KK_Kernel,代码行数:75,代码来源:bt_hwctl_dev.c

示例3: init_char_device

static int init_char_device(void)
{
	unsigned int i,ret;

	char_device_buf_minor0 = (char *)kmalloc(MAX_LENGTH*sizeof(char), 
					  GFP_KERNEL);
	char_device_buf_minor1 = (char *)kmalloc(MAX_LENGTH*sizeof(char), 
					  GFP_KERNEL);
	char_device_buf_minor2 = (char *)kmalloc(MAX_LENGTH*sizeof(char), 
					  GFP_KERNEL);

	if( !char_device_buf_minor0 ) return -ENOSPC;
	if( !char_device_buf_minor1 ) return -ENOSPC;
	if( !char_device_buf_minor2 ) return -ENOSPC;
	
	char_device_file_ops.owner = THIS_MODULE,
	char_device_file_ops.read = char_device_read;
	char_device_file_ops.read = char_device_read;
	char_device_file_ops.write = char_device_write;
	char_device_file_ops.open = char_device_open;
	char_device_file_ops.release = char_device_release;
	
	
        ret=alloc_chrdev_region(&mydev,0,3,"veda_cdrv");

        char_device_id= MAJOR(mydev);//extract major no

        /* Let's Start Udev stuff */
        
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
        veda_class = class_simple_create(THIS_MODULE,"Veda");
        if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }
	for(i=0;i<3;i++)
        class_simple_device_add(veda_class,MKDEV(char_device_id,i),NULL,"veda_cdrv",i);
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)

	veda_class = class_create(THIS_MODULE,"Veda");
        if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }

	for(i=0;i<3;i++)
        device_create(veda_class,NULL,MKDEV(char_device_id,i),"veda_cdrv");
#endif
        /*Register our character Device*/
        veda_cdev= cdev_alloc();


        veda_cdev->owner=THIS_MODULE;
        veda_cdev->ops= &char_device_file_ops;


	for(i=0;i<3;i++)
        	ret=cdev_add(veda_cdev,MKDEV(char_device_id,i),3);
        if( ret < 0 ) {
                printk("Error registering device driver\n");
                return ret;
        }
        printk("Device Registered with MAJOR NO[%d]\n",char_device_id);
	
	for(i=0; i<MAX_LENGTH; i++) char_device_buf_minor0[i] = 0;
	for(i=0; i<MAX_LENGTH; i++) char_device_buf_minor1[i] = 0;
	for(i=0; i<MAX_LENGTH; i++) char_device_buf_minor2[i] = 0;
	init_waitqueue_head( &veda_queue0 );
	init_waitqueue_head( &veda_queue1 );
	init_waitqueue_head( &veda_queue2 );
	mutex_init(&vmut0);
	mutex_init(&vmut1);
	mutex_init(&vmut2);
	return 0;
}
开发者ID:coder03,项目名称:ldd,代码行数:74,代码来源:char_driver_minors.c

示例4: asuspec_probe

static int __devinit asuspec_probe(struct i2c_client *client,
		const struct i2c_device_id *id)
{
	int err = 0;

	ASUSPEC_INFO("asuspec probe\n");
	err = sysfs_create_group(&client->dev.kobj, &asuspec_smbus_group);
	if (err) {
		ASUSPEC_ERR("Unable to create the sysfs\n");
		goto exit;
	}

	ec_chip = kzalloc(sizeof (struct asuspec_chip), GFP_KERNEL);
	if (!ec_chip) {
		ASUSPEC_ERR("Memory allocation fails\n");
		err = -ENOMEM;
		goto exit;
	}

	ec_chip->pad_pid = tegra3_get_project_id();
	i2c_set_clientdata(client, ec_chip);
	ec_chip->client = client;
	ec_chip->client->driver = &asuspec_driver;
	ec_chip->client->flags = 1;

	init_timer(&ec_chip->asuspec_timer);
	ec_chip->asuspec_timer.function = asuspec_enter_s3_timer;

	wake_lock_init(&ec_chip->wake_lock, WAKE_LOCK_SUSPEND, "asuspec_wake");
	mutex_init(&ec_chip->lock);
	mutex_init(&ec_chip->irq_lock);
	mutex_init(&ec_chip->state_change_lock);

	ec_chip->ec_ram_init = 0;
	ec_chip->audio_recording = 0;
	ec_chip->status = 0;
	ec_chip->ec_in_s3 = 0;
	ec_chip->apwake_disabled = 0;
	ec_chip->storage_total = 0;
	ec_chip->storage_avail = 0;
	asuspec_dockram_init(client);
	cdev_add(asuspec_cdev,asuspec_dev,1) ;

	ec_chip->pad_sdev.name = PAD_SDEV_NAME;
	ec_chip->pad_sdev.print_name = asuspec_switch_name;
	ec_chip->pad_sdev.print_state = asuspec_switch_state;
	if(switch_dev_register(&ec_chip->pad_sdev) < 0){
		ASUSPEC_ERR("switch_dev_register for pad failed!\n");
	}
	switch_set_state(&ec_chip->pad_sdev, 0);

	ec_chip->apower_sdev.name = APOWER_SDEV_NAME;
	ec_chip->apower_sdev.print_name = apower_switch_name;
	ec_chip->apower_sdev.print_state = apower_switch_state;
	ec_chip->apower_state = 0;
	if(switch_dev_register(&ec_chip->apower_sdev) < 0){
		ASUSPEC_ERR("switch_dev_register for apower failed!\n");
	}
	switch_set_state(&ec_chip->apower_sdev, ec_chip->apower_state);

	asuspec_wq = create_singlethread_workqueue("asuspec_wq");
	INIT_DELAYED_WORK_DEFERRABLE(&ec_chip->asuspec_work, asuspec_work_function);
	INIT_DELAYED_WORK_DEFERRABLE(&ec_chip->asuspec_init_work, asuspec_init_work_function);
	INIT_DELAYED_WORK_DEFERRABLE(&ec_chip->asuspec_fw_update_work, asuspec_fw_update_work_function);
	INIT_DELAYED_WORK_DEFERRABLE(&ec_chip->asuspec_enter_s3_work, asuspec_enter_s3_work_function);
	INIT_DELAYED_WORK_DEFERRABLE(&asuspec_stress_work, asuspec_stresstest_work_function);

	asuspec_irq_ec_request(client);
	asuspec_irq_ec_apwake(client);
	queue_delayed_work(asuspec_wq, &ec_chip->asuspec_init_work, 0);

	return 0;

exit:
	return err;
}
开发者ID:JoinTheRealms,项目名称:TF700-dualboot-hunds,代码行数:76,代码来源:asuspec.c

示例5: unix98_pty_init

static void __init unix98_pty_init(void)
{
	ptm_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
			TTY_DRIVER_RESET_TERMIOS |
			TTY_DRIVER_REAL_RAW |
			TTY_DRIVER_DYNAMIC_DEV |
			TTY_DRIVER_DEVPTS_MEM |
			TTY_DRIVER_DYNAMIC_ALLOC);
	if (IS_ERR(ptm_driver))
		panic("Couldn't allocate Unix98 ptm driver");
	pts_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
			TTY_DRIVER_RESET_TERMIOS |
			TTY_DRIVER_REAL_RAW |
			TTY_DRIVER_DYNAMIC_DEV |
			TTY_DRIVER_DEVPTS_MEM |
			TTY_DRIVER_DYNAMIC_ALLOC);
	if (IS_ERR(pts_driver))
		panic("Couldn't allocate Unix98 pts driver");

	ptm_driver->driver_name = "pty_master";
	ptm_driver->name = "ptm";
	ptm_driver->major = UNIX98_PTY_MASTER_MAJOR;
	ptm_driver->minor_start = 0;
	ptm_driver->type = TTY_DRIVER_TYPE_PTY;
	ptm_driver->subtype = PTY_TYPE_MASTER;
	ptm_driver->init_termios = tty_std_termios;
	ptm_driver->init_termios.c_iflag = 0;
	ptm_driver->init_termios.c_oflag = 0;
	ptm_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
	ptm_driver->init_termios.c_lflag = 0;
	ptm_driver->init_termios.c_ispeed = 38400;
	ptm_driver->init_termios.c_ospeed = 38400;
	ptm_driver->other = pts_driver;
	tty_set_operations(ptm_driver, &ptm_unix98_ops);

	pts_driver->driver_name = "pty_slave";
	pts_driver->name = "pts";
	pts_driver->major = UNIX98_PTY_SLAVE_MAJOR;
	pts_driver->minor_start = 0;
	pts_driver->type = TTY_DRIVER_TYPE_PTY;
	pts_driver->subtype = PTY_TYPE_SLAVE;
	pts_driver->init_termios = tty_std_termios;
	pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
	pts_driver->init_termios.c_ispeed = 38400;
	pts_driver->init_termios.c_ospeed = 38400;
	pts_driver->other = ptm_driver;
	tty_set_operations(pts_driver, &pty_unix98_ops);

	if (tty_register_driver(ptm_driver))
		panic("Couldn't register Unix98 ptm driver");
	if (tty_register_driver(pts_driver))
		panic("Couldn't register Unix98 pts driver");

	/* Now create the /dev/ptmx special device */
	tty_default_fops(&ptmx_fops);
	ptmx_fops.open = ptmx_open;

	cdev_init(&ptmx_cdev, &ptmx_fops);
	if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
		panic("Couldn't register /dev/ptmx driver");
	device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
}
开发者ID:LuweiLight,项目名称:linux-3.14.35-vbal,代码行数:63,代码来源:pty.c

示例6: frandom_init_module

static int frandom_init_module(void)
{
	int result;

	if (frandom_bufsize < 256) {
		printk(KERN_ERR "frandom: Refused to load because frandom_bufsize=%d < 256\n",frandom_bufsize);
		return -EINVAL;
	}
	if ((frandom_chunklimit != 0) && (frandom_chunklimit < 256)) {
		printk(KERN_ERR "frandom: Refused to load because frandom_chunklimit=%d < 256 and != 0\n",frandom_chunklimit);
		return -EINVAL;
	}

	erandom_state = kmalloc(sizeof(struct frandom_state), GFP_KERNEL);
	if (!erandom_state)
		return -ENOMEM;

	erandom_state->buf = kmalloc(256, GFP_KERNEL);
	if (!erandom_state->buf) {
		kfree(erandom_state);
		return -ENOMEM;
	}

	sema_init(&erandom_state->sem, 1);
	erandom_seeded = 0;
	frandom_class = class_create(THIS_MODULE, "fastrng");

	if (IS_ERR(frandom_class)) {
		result = PTR_ERR(frandom_class);
		printk(KERN_WARNING "frandom: Failed to register class fastrng\n");
		goto error0;
	}
	
	cdev_init(&frandom_cdev, &frandom_fops);
	frandom_cdev.owner = THIS_MODULE;
	result = cdev_add(&frandom_cdev, MKDEV(frandom_major, frandom_minor), 1);

	if (result) {
	  printk(KERN_WARNING "frandom: Failed to add cdev for /dev/frandom\n");
	  goto error1;
	}

	result = register_chrdev_region(MKDEV(frandom_major, frandom_minor), 1, "/dev/frandom");
	if (result < 0) {
		printk(KERN_WARNING "frandom: can't get major/minor %d/%d\n", frandom_major, frandom_minor);
	  goto error2;
	}

	frandom_device = device_create(frandom_class, NULL, MKDEV(frandom_major, frandom_minor), NULL, "frandom");

	if (IS_ERR(frandom_device)) {
		printk(KERN_WARNING "frandom: Failed to create frandom device\n");
		goto error3;
	}

	cdev_init(&erandom_cdev, &frandom_fops);
	erandom_cdev.owner = THIS_MODULE;
	result = cdev_add(&erandom_cdev, MKDEV(frandom_major, erandom_minor), 1);
	if (result) {
	  printk(KERN_WARNING "frandom: Failed to add cdev for /dev/erandom\n");
	  goto error4;
	}

	result = register_chrdev_region(MKDEV(frandom_major, erandom_minor), 1, "/dev/erandom");
	if (result < 0) {
		printk(KERN_WARNING "frandom: can't get major/minor %d/%d\n", frandom_major, erandom_minor);
		goto error5;
	}

	erandom_device = device_create(frandom_class, NULL, MKDEV(frandom_major, erandom_minor), NULL, "erandom");

	if (IS_ERR(erandom_device)) {
		printk(KERN_WARNING "frandom: Failed to create erandom device\n");
		goto error6;
	}
	return 0;

 error6:
	unregister_chrdev_region(MKDEV(frandom_major, erandom_minor), 1);
 error5:
	cdev_del(&erandom_cdev);
 error4:
	device_destroy(frandom_class, MKDEV(frandom_major, frandom_minor));
 error3:
	unregister_chrdev_region(MKDEV(frandom_major, frandom_minor), 1);
 error2:
	cdev_del(&frandom_cdev);
 error1:
	class_destroy(frandom_class);
 error0:
	kfree(erandom_state->buf);
	kfree(erandom_state);

	return result;	
}
开发者ID:Malpa73,项目名称:FeraLab_GB_Firmware--archive,代码行数:95,代码来源:frandom.c

示例7: WMT_init

static int WMT_init(void)
{
    dev_t devID = MKDEV(gWmtMajor, 0);
    INT32 cdevErr = -1;
    INT32 ret = -1;
#if REMOVE_MK_NODE
	struct device * wmt_dev = NULL;
#endif

    WMT_INFO_FUNC("WMT Version= %s DATE=%s\n" , MTK_WMT_VERSION, MTK_WMT_DATE);
    WMT_INFO_FUNC("COMBO Driver Version= %s\n" , MTK_COMBO_DRIVER_VERSION);
    /* Prepare a UCHAR device */
    /*static allocate chrdev*/

    stp_drv_init();

    ret = register_chrdev_region(devID, WMT_DEV_NUM, WMT_DRIVER_NAME);
    if (ret) {
        WMT_ERR_FUNC("fail to register chrdev\n");
        return ret;
    }

    cdev_init(&gWmtCdev, &gWmtFops);
    gWmtCdev.owner = THIS_MODULE;

    cdevErr = cdev_add(&gWmtCdev, devID, WMT_DEV_NUM);
    if (cdevErr) {
        WMT_ERR_FUNC("cdev_add() fails (%d) \n", cdevErr);
        goto error;
    }
    WMT_INFO_FUNC("driver(major %d) installed \n", gWmtMajor);
	#if REMOVE_MK_NODE  //mknod replace

	wmt_class = class_create(THIS_MODULE,"stpwmt");
	if(IS_ERR(wmt_class))
		goto error;
	wmt_dev = device_create(wmt_class,NULL,devID,NULL,"stpwmt");
	if(IS_ERR(wmt_dev))
		goto error;
	#endif

#if 0
    pWmtDevCtx = wmt_drv_create();
    if (!pWmtDevCtx) {
        WMT_ERR_FUNC("wmt_drv_create() fails \n");
        goto error;
    }

    ret = wmt_drv_init(pWmtDevCtx);
    if (ret) {
        WMT_ERR_FUNC("wmt_drv_init() fails (%d) \n", ret);
        goto error;
    }

    WMT_INFO_FUNC("stp_btmcb_reg\n");
    wmt_cdev_btmcb_reg();

    ret = wmt_drv_start(pWmtDevCtx);
    if (ret) {
        WMT_ERR_FUNC("wmt_drv_start() fails (%d) \n", ret);
        goto error;
    }
#endif

	platform_driver_register(&wmt_platform_driver);	

    ret = wmt_lib_init();
    if (ret) {
        WMT_ERR_FUNC("wmt_lib_init() fails (%d) \n", ret);
        goto error;
    }
#if CFG_WMT_DBG_SUPPORT
    wmt_dev_dbg_setup();
#endif

#if  defined(CONFIG_THERMAL) &&  defined(CONFIG_THERMAL_OPEN)
    WMT_INFO_FUNC("wmt_dev_tm_setup\n");
    wmt_dev_tm_setup();
    mtk_wcn_hif_sdio_update_cb_reg(wmt_dev_tra_sdio_update);
#endif

    WMT_INFO_FUNC("success \n");
    return 0;

error:
    wmt_lib_deinit();
#if CFG_WMT_DBG_SUPPORT    
    wmt_dev_dbg_remove();
#endif
#if REMOVE_MK_NODE
	if(!IS_ERR(wmt_dev))
		device_destroy(wmt_class,devID);
	if(!IS_ERR(wmt_class)){
		class_destroy(wmt_class);
		wmt_class = NULL;
	}
#endif

    if (cdevErr == 0) {
        cdev_del(&gWmtCdev);
//.........这里部分代码省略.........
开发者ID:Dee-UK,项目名称:RK3188_KK_4.4.02_Beta,代码行数:101,代码来源:wmt_dev.c

示例8: spec_probe

static int spec_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
    int i;
    int ret;
    int minor;
    struct spec_dev *dev;

    dev = kzalloc(sizeof(struct spec_dev), GFP_KERNEL);
    if (!dev) {
        dev_err(&pdev->dev, "failed to allocate spec_dev\n");
        ret = -ENOMEM;
        goto err_alloc;
    }
    dev->dev = &pdev->dev;
    dev->pdev = pdev;
    pci_set_drvdata(pdev, dev);
    INIT_WORK(&dev->work, spec_load_firmware);
    init_waitqueue_head(&dev->irq_queue);
    cdev_init(&dev->cdev, &spec_file_ops);
    mutex_init(&dev->mutex);

    if (dmasize > SPEC_MAX_DMABUFSIZE) {
        pr_warning(KBUILD_MODNAME
                   ": %s: DMA buffer size too big, using 0x%x\n",
                   __func__,
                   SPEC_MAX_DMABUFSIZE);
        dmasize = SPEC_MAX_DMABUFSIZE;
    }

    dev->dmabuf = __vmalloc(dmasize, GFP_KERNEL | __GFP_ZERO,
                            PAGE_KERNEL);
    if (!dev->dmabuf) {
        ret = -ENOMEM;
        goto err_dmaalloc;
    }

    mutex_lock(&spec_minors_mutex);
    minor = spec_get_free();
    if (minor == SPEC_MAX_MINORS) {
        dev_err(&pdev->dev, "too many devices!\n");
        ret = -EIO;
        goto err_dis;
    }
    mutex_unlock(&spec_minors_mutex);

    if (pdev->irq > 0) {
        i = request_irq(pdev->irq, spec_irq_handler, IRQF_SHARED,
                        driver_name, dev);
        if (i < 0)
            pr_err(KBUILD_MODNAME
                   "can't request irq %i, error %i\n",
                   pdev->irq, i);
        else
            dev->flags |= SPEC_FLAG_IRQREQUEST;
    }

    ret = pci_enable_device(pdev);
    if (ret < 0) {
        dev_err(&pdev->dev, "failed to enable SPEC device\n");
        goto err_enable;
    }

    ret = pci_request_regions(pdev, driver_name);
    if (ret) {
        dev_err(&pdev->dev, "failed to request PCI resources\n");
        goto err_resource;
    }

    /* Save BAR0, BAR2 and BAR4 and try to remap them */
    for (i = 0; i < 3; i++) {
        struct resource *r = &pdev->resource[2*i];
        if (!r->start)
            continue;
        dev->area[i] = r;
        if (r->flags & IORESOURCE_MEM)
            dev->remap[i] = ioremap(r->start,
                                    r->end - r->start + 1);
        if (SPEC_DEBUG) {
            pr_info(KBUILD_MODNAME
                    ": %s: BAR%i: %llx-%llx (size: 0x%llx) - %08lx\n",
                    __func__, i,
                    (long long)r->start,
                    (long long)r->end,
                    (long long)(r->end - r->start + 1),
                    r->flags);
        }
    }

    ret = cdev_add(&dev->cdev, MKDEV(spec_major, minor), 1);
    if (ret) {
        dev_err(&pdev->dev, "chardev registration failed\n");
        goto err_cdev;
    }

#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
    if (IS_ERR(device_create(spec_class, &pdev->dev,
                             MKDEV(spec_major, minor), NULL,
                             "spec%u", minor)))
#else
    if (IS_ERR(device_create(spec_class, &pdev->dev,
//.........这里部分代码省略.........
开发者ID:mvanga,项目名称:SPEC-Driver,代码行数:101,代码来源:spec.c

示例9: xordev_probe

static int
xordev_probe(struct pci_dev *dev, const struct pci_device_id *id)
/* PCI device initializer */
{
  uint32_t i, j;
  int err = 0;
  struct xordev_str *xordev;
  dev_t devt;

  mutex_lock(&global_lock);

  /* find empty slot and initialize */
  for (i = 0; xordev_data[i].devno != 0 && i < MAX_DEVICES; i++);
  if (i == MAX_DEVICES){
    printk (KERN_NOTICE "Too many xordev devices!");
    return -1;
  }
  xordev = &xordev_data[i];
  memset(xordev, 0, sizeof(struct xordev_str)); /* clear everything */

  xordev->devno = MKDEV(major, i * 3);
  mutex_init(&xordev->lock);
  xordev->spinlock = SPIN_LOCK_UNLOCKED;

  for (j = 0; j < 3; j++) {
    devt = MKDEV(major, i * 3 + j);

    /* creating char device */
    cdev_init(&xordev->cdev[j], &xordev_fops);
    xordev->cdev[j].ops = &xordev_fops;
    err = cdev_add(&xordev->cdev[j], devt, 1);
    if (err) {
      printk(KERN_NOTICE "Error %d adding XorDev %d", err, i);
      goto fail;
    }

    /* udev device create */
    xordev->dev[j] = device_create(xordev_class, 0, devt,
                                   xordev, dev_names[j], i);
    if (IS_ERR(xordev->dev[j])) {
      err = PTR_ERR(xordev->dev[j]);
      printk(KERN_NOTICE "Error %d creating udev device", err);
      goto udev_create_fail;
    }
  }

  pci_set_drvdata(dev, xordev);
  /* enable PCI device */
  err = pci_enable_device(dev);
  if (err) {
    printk(KERN_NOTICE "Error %d enabling XorDev PCI device %d", err, i);
    goto pci_enable_fail;
  }
  err = pci_request_regions(dev, DRVNAME);
  if (err) {
    printk(KERN_NOTICE "Error %d requesting XorDev %d regions", err, i);
    goto pci_regions_fail;
  }
  xordev->bar = pci_iomap(dev, 0, 4096);
  if (NULL == xordev->bar) {
    printk(KERN_NOTICE "Can't map XorDev %d iomem", i);
    goto pci_iomap_fail;
  }
  /* enable DMA */
  pci_set_master(dev);
  err = pci_set_dma_mask(dev, DMA_BIT_MASK(32));
  if (err) {
    printk(KERN_NOTICE "Can't set DMA mask for XorDev %d", i);
    goto pci_iomap_fail;
  }
  err = pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(32));
  if (err) {
    printk(KERN_NOTICE "Can't set consistent DMA mask for XorDev %d", i);
    goto pci_iomap_fail;
  }
  /* alloc buffers */
  xordev->cpu_addr[0] = dma_alloc_coherent(&dev->dev, BUFFER_SIZE * 3,
                                           &xordev->dma_addr[0], 0);
  if (xordev->cpu_addr) {
    xordev->cpu_addr[1] = xordev->cpu_addr[0] + BUFFER_SIZE;
    xordev->dma_addr[1] = xordev->dma_addr[0] + BUFFER_SIZE;
    xordev->cpu_addr[2] = xordev->cpu_addr[1] + BUFFER_SIZE;
    xordev->dma_addr[2] = xordev->dma_addr[1] + BUFFER_SIZE;
    memset(xordev->offset, 0, 12);
    iowrite32(xordev->dma_addr[0], xordev->bar + BAR_SRC1);
    iowrite32(xordev->dma_addr[1], xordev->bar + BAR_SRC2);
    iowrite32(xordev->dma_addr[2], xordev->bar + BAR_DST);
  } else {
    printk(KERN_NOTICE "Can't allocate DMA memory for XorDev %d", i);
    goto pci_iomap_fail;
  }
  /* waiting queue */
  init_waitqueue_head(&xordev->queue);
  /* interruptions */
  err = request_irq(dev->irq, xordev_irq, IRQF_SHARED, DRVNAME, xordev);
  if (err) {
    printk(KERN_NOTICE "Can't register irq handler for XorDev %d", i);
    goto request_irq_fail;
  }

//.........这里部分代码省略.........
开发者ID:wojtekzozlak,项目名称:Studia.Archiwum,代码行数:101,代码来源:xordev.c

示例10: mic_init

static int __init
mic_init(void)
{
	int ret, i;

	adapter_init();

	unaligned_cache = micscif_kmem_cache_create();
	if (!unaligned_cache) {
		ret = -ENOMEM;
		goto init_free_ports;
	}

	mic_lindata.dd_pcidriver.name = "mic";
	mic_lindata.dd_pcidriver.id_table = mic_pci_tbl;
	mic_lindata.dd_pcidriver.probe = mic_probe;
	mic_lindata.dd_pcidriver.remove = mic_remove;
	mic_lindata.dd_pcidriver.driver.pm = &pci_dev_pm_ops;
	mic_lindata.dd_pcidriver.shutdown = mic_shutdown;


	if ((ret = alloc_chrdev_region(&mic_lindata.dd_dev,
				       0, MAX_DLDR_MINORS, "mic") != 0)) {
		printk("Error allocating device nodes: %d\n", ret);
		goto init_free_ports;
	}

	cdev_init(&mic_lindata.dd_cdev, &mic_fops);
	mic_lindata.dd_cdev.owner = THIS_MODULE;
	mic_lindata.dd_cdev.ops = &mic_fops;

	if ((ret = cdev_add(&mic_lindata.dd_cdev,
			    mic_lindata.dd_dev, MAX_DLDR_MINORS) != 0)) {
		kobject_put(&mic_lindata.dd_cdev.kobj);
		goto init_free_region;
	}

	mic_lindata.dd_class = class_create(THIS_MODULE, "mic");
	if (IS_ERR(mic_lindata.dd_class)) {
		printk("MICDLDR: Error createing mic class\n");
		cdev_del(&mic_lindata.dd_cdev);
		ret = PTR_ERR(mic_lindata.dd_class);
		goto init_free_region;
	}

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31)
	mic_lindata.dd_class->devnode = mic_devnode;
#endif

	mic_lindata.dd_hostdev = device_create(mic_lindata.dd_class, NULL,
					    mic_lindata.dd_dev, NULL, "ctrl");
	mic_lindata.dd_scifdev = device_create(mic_lindata.dd_class, NULL,
					    mic_lindata.dd_dev + 1, NULL, "scif");
	ret = sysfs_create_group(&mic_lindata.dd_hostdev->kobj, &host_attr_group);
	ret = sysfs_create_group(&mic_lindata.dd_scifdev->kobj, &scif_attr_group);

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31)
	mic_lindata.dd_class->devnode = NULL;
#endif

	if (micveth_init(mic_lindata.dd_hostdev))
		printk(KERN_ERR "%s: micveth_init failed\n", __func__);

	ret = pci_register_driver(&mic_lindata.dd_pcidriver);
	if (ret) {
		micscif_destroy();
		printk("mic: failed to register pci driver %d\n", ret);
		goto clean_unregister;
	}

	if (!mic_data.dd_numdevs) {
		printk("mic: No MIC boards present.  SCIF available in loopback mode\n");
	} else {
		printk("mic: number of devices detected %d \n", mic_data.dd_numdevs);
	}

	for (i = 0; i < mic_data.dd_numdevs; i++) {
		mic_ctx_t *mic_ctx = get_per_dev_ctx(i);
		wait_event(mic_ctx->ioremapwq,
			mic_ctx->aper.va || mic_ctx->state == MIC_RESETFAIL);
		destroy_workqueue(mic_ctx->ioremapworkq);
	}

	micveth_init_legacy(mic_data.dd_numdevs, mic_lindata.dd_hostdev);

	ret = acptboot_init();

#ifdef USE_VCONSOLE
	micvcons_create(mic_data.dd_numdevs);
#endif

	/* Initialize Data structures for PM Disconnect */
	ret = micpm_disconn_init(mic_data.dd_numdevs + 1);
	if (ret)
		printk(KERN_ERR "%s: Failed to initialize PM disconnect"
			" data structures. PM may not work as expected."
			" ret = %d\n", __func__, ret);
	register_pm_notifier(&mic_pm_notifer);
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,34))
	ret = pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "mic", mic_pm_qos_cpu_dma_lat);
//.........这里部分代码省略.........
开发者ID:pwntoast512,项目名称:mpss-modules-3.4.6,代码行数:101,代码来源:linux.c

示例11: communication_device_init

static int __must_check communication_device_init(
    struct communication_device *self,
    dev_t major_minor,
    struct class *class)
{
    int err;

    self->class = class;

    /* initialize lock and wait queue */
    spin_lock_init(&self->lock);
    init_waitqueue_head(&self->wq);

    /* create good old cdev at (major,0) */
    cdev_init(&self->good_old_cdev, &communication_device_cdev_fops);
    err = cdev_add(&self->good_old_cdev, major_minor, 1);
    BUG_ON(err);

    /* add sysfs bahoowazoo */
    self->sysfs_device = 
        device_create(
            /*class*/ self->class, 
            /*parent device*/ NULL, 
            /*char device*/ major_minor, 
            /*device private data*/ self, 
            /*printf format for device node name in /dev*/ DRIVER_NAME "-%d",
            /*format-filling data*/ MINOR(major_minor));
    BUG_ON(self->sysfs_device == NULL);

    return 0;
}
开发者ID:jfasch,项目名称:jf-kernel-course,代码行数:31,代码来源:60-cdev-waitqueue.c

示例12: msm_gemini_init

static int msm_gemini_init(struct platform_device *pdev)
{
	int rc = -1;
	struct device *dev;

	GMN_DBG("%s:%d]\n", __func__, __LINE__);

	msm_gemini_device_p = __msm_gemini_init(pdev);
	if (msm_gemini_device_p == NULL) {
		GMN_PR_ERR("%s: initialization failed\n", __func__);
		goto fail;
	}

	rc = alloc_chrdev_region(&msm_gemini_devno, 0, 1, MSM_GEMINI_NAME);
	if (rc < 0) {
		GMN_PR_ERR("%s: failed to allocate chrdev\n", __func__);
		goto fail_1;
	}

	if (!msm_gemini_class) {
		msm_gemini_class = class_create(THIS_MODULE, MSM_GEMINI_NAME);
		if (IS_ERR(msm_gemini_class)) {
			rc = PTR_ERR(msm_gemini_class);
			GMN_PR_ERR("%s: create device class failed\n",
				__func__);
			goto fail_2;
		}
	}

	dev = device_create(msm_gemini_class, NULL,
		MKDEV(MAJOR(msm_gemini_devno), MINOR(msm_gemini_devno)), NULL,
		"%s%d", MSM_GEMINI_NAME, 0);

	if (IS_ERR(dev)) {
		GMN_PR_ERR("%s: error creating device\n", __func__);
		rc = -ENODEV;
		goto fail_3;
	}

	cdev_init(&msm_gemini_device_p->cdev, &msm_gemini_fops);
	msm_gemini_device_p->cdev.owner = THIS_MODULE;
	msm_gemini_device_p->cdev.ops   =
		(const struct file_operations *) &msm_gemini_fops;
	rc = cdev_add(&msm_gemini_device_p->cdev, msm_gemini_devno, 1);
	if (rc < 0) {
		GMN_PR_ERR("%s: error adding cdev\n", __func__);
		rc = -ENODEV;
		goto fail_4;
	}

	printk(KERN_INFO "%s %s: success\n", __func__, MSM_GEMINI_NAME);

	return rc;

fail_4:
	device_destroy(msm_gemini_class, msm_gemini_devno);

fail_3:
	class_destroy(msm_gemini_class);

fail_2:
	unregister_chrdev_region(msm_gemini_devno, 1);

fail_1:
	__msm_gemini_exit(msm_gemini_device_p);

fail:
	return rc;
}
开发者ID:325116067,项目名称:semc-qsd8x50,代码行数:69,代码来源:msm_gemini_dev.c

示例13: SiiMhlInit

static int __init SiiMhlInit(void)
{
    int32_t	ret;
    dev_t	devno;

	printk("\n============================================\n");
	printk("%s driver starting!\n", MHL_DRIVER_NAME);
    sprintf(BUILT_TIME,"Build: %s", __TIME__"-"__DATE__);
    printk("Version: %s \n%s \n",DRV_VERSION,BUILT_TIME);
    printk("register_chrdev %s\n", MHL_DRIVER_NAME);
	printk("============================================\n");
    //InitDebugSW();
    if (devMajor) {
        devno = MKDEV(devMajor, 0);
        ret = register_chrdev_region(devno, MHL_DRIVER_MINOR_MAX,
                MHL_DRIVER_NAME);
    } else {
        ret = alloc_chrdev_region(&devno,
                        0, MHL_DRIVER_MINOR_MAX,
                        MHL_DRIVER_NAME);
        devMajor = MAJOR(devno);
    }
    if (ret) {
    	printk("register_chrdev %d, %s failed, error code: %d\n",
    					devMajor, MHL_DRIVER_NAME, ret);
        return ret;
    }
    cdev_init(&siiMhlCdev, &siiMhlFops);
    siiMhlCdev.owner = THIS_MODULE;
    ret = cdev_add(&siiMhlCdev, devno, MHL_DRIVER_MINOR_MAX);
    if (ret) {
    	printk("cdev_add %s failed %d\n", MHL_DRIVER_NAME, ret);
        goto free_chrdev;
    }
    siiMhlClass = class_create(THIS_MODULE, "mhl");
    if (IS_ERR(siiMhlClass)) {
    	printk("class_create failed %d\n", ret);
        ret = PTR_ERR(siiMhlClass);
        goto free_cdev;
    }
    siiMhlClass->dev_attrs = driver_attribs;
    gDriverContext.pDevice  = device_create(siiMhlClass, NULL,
    									 MKDEV(devMajor, 0),  NULL,
    									 "%s", MHL_DEVICE_NAME);
    if (IS_ERR(gDriverContext.pDevice)) {
    	printk("class_device_create failed %s %d\n", MHL_DEVICE_NAME, ret);
        ret = PTR_ERR(gDriverContext.pDevice);
        goto free_class;
    }
    ret = StartMhlTxDevice();
    if(ret == 0) {
#ifdef USE_PROC
        mhldrv_create_proc();
#endif
        printk(KERN_NOTICE" mhldrv initialized successfully\n");
    	return 0;
    } else {
    	device_destroy(siiMhlClass, MKDEV(devMajor, 0));
    }
free_class:
	class_destroy(siiMhlClass);
free_cdev:
	cdev_del(&siiMhlCdev);
free_chrdev:
	unregister_chrdev_region(MKDEV(devMajor, 0), MHL_DRIVER_MINOR_MAX);
	return ret;
}
开发者ID:4Fwolf,项目名称:motorola-hawk-kernel-3.4.67,代码行数:67,代码来源:mhl_linuxdrv_main.c

示例14: dsps_probe

/**
 * platform driver
 *
 */
static int __devinit dsps_probe(struct platform_device *pdev)
{
	int ret;

	pr_debug("%s.\n", __func__);

	if (pdev->dev.platform_data == NULL) {
		pr_err("%s: platform data is NULL.\n", __func__);
		return -ENODEV;
	}

	drv = kzalloc(sizeof(*drv), GFP_KERNEL);
	if (drv == NULL) {
		pr_err("%s: kzalloc fail.\n", __func__);
		goto alloc_err;
	}
	atomic_set(&drv->wd_crash, 0);
	atomic_set(&drv->crash_in_progress, 0);

	drv->pdata = pdev->dev.platform_data;

	drv->dev_class = class_create(THIS_MODULE, DRV_NAME);
	if (drv->dev_class == NULL) {
		pr_err("%s: class_create fail.\n", __func__);
		goto res_err;
	}

	ret = alloc_chrdev_region(&drv->dev_num, 0, 1, DRV_NAME);
	if (ret) {
		pr_err("%s: alloc_chrdev_region fail.\n", __func__);
		goto alloc_chrdev_region_err;
	}

	drv->dev = device_create(drv->dev_class, NULL,
				     drv->dev_num,
				     drv, DRV_NAME);
	if (IS_ERR(drv->dev)) {
		pr_err("%s: device_create fail.\n", __func__);
		goto device_create_err;
	}

	drv->cdev = cdev_alloc();
	if (drv->cdev == NULL) {
		pr_err("%s: cdev_alloc fail.\n", __func__);
		goto cdev_alloc_err;
	}
	cdev_init(drv->cdev, &dsps_fops);
	drv->cdev->owner = THIS_MODULE;

	ret = cdev_add(drv->cdev, drv->dev_num, 1);
	if (ret) {
		pr_err("%s: cdev_add fail.\n", __func__);
		goto cdev_add_err;
	}

	ret = dsps_alloc_resources(pdev);
	if (ret) {
		pr_err("%s: failed to allocate dsps resources.\n", __func__);
		goto cdev_add_err;
	}

	ret =
	    smsm_state_cb_register(SMSM_DSPS_STATE, SMSM_RESET,
				   dsps_smsm_state_cb, 0);
	if (ret) {
		pr_err("%s: smsm_state_cb_register fail %d\n", __func__,
		       ret);
		goto smsm_register_err;
	}

	ret = ssr_register_subsystem(&dsps_ssrops);
	if (ret) {
		pr_err("%s: ssr_register_subsystem fail %d\n", __func__,
		       ret);
		goto ssr_register_err;
	}

	return 0;

ssr_register_err:
	smsm_state_cb_deregister(SMSM_DSPS_STATE, SMSM_RESET,
				 dsps_smsm_state_cb,
				 0);
smsm_register_err:
	cdev_del(drv->cdev);
cdev_add_err:
	kfree(drv->cdev);
cdev_alloc_err:
	device_destroy(drv->dev_class, drv->dev_num);
device_create_err:
	unregister_chrdev_region(drv->dev_num, 1);
alloc_chrdev_region_err:
	class_destroy(drv->dev_class);
res_err:
	kfree(drv);
	drv = NULL;
//.........这里部分代码省略.........
开发者ID:DAGr8,项目名称:gp-peak-kernel,代码行数:101,代码来源:msm_dsps.c

示例15: dm_init

static int dm_init(void)
{
	int result;
	int devno;
	struct drvr_mem * memDev;
	struct drvr_prog * progDev;
	struct i2c_adapter *i2c_adap;

	dev_t dev = 0;
	result = alloc_chrdev_region(&dev, 0, 2, DEVICE_NAME);
	gDrvrMajor = MAJOR(dev);

	if (result < 0) {
		printk(KERN_ALERT "Registering char device failed with %d\n", gDrvrMajor);

		return result;
	}

	drvr_devices = kmalloc(2 * sizeof(struct drvr_device), GFP_KERNEL);

	if (!drvr_devices) {
		dm_exit();

		return -ENOMEM;
	}

	drvr_class = class_create(THIS_MODULE, DEVICE_NAME);
	memset(drvr_devices, 0, 2 * sizeof(struct drvr_device));

	/*Initializing main mdevice for prog*/
	devno = MKDEV(gDrvrMajor, 0);
	drvr_devices[0].type = prog;
	progDev = &(drvr_devices[0].data.prog);
	prog_device = device_create(drvr_class, NULL, devno, NULL, DEVICE_NAME);	// should create /dev entry for main node
	drvr_devices[0].opened = 0;

	/*Do the i2c stuff*/
	i2c_adap = i2c_get_adapter(1); // todo need to check i2c adapter id

	if (i2c_adap == NULL) {
		printk("Cannot get adapter 1 \n");
		dm_exit();

		return -1;
	}

	progDev->i2c_io = i2c_new_device(i2c_adap, &io_exp_info);
	i2c_put_adapter(i2c_adap); //don't know what it does, seems to release the adapter ...

	if (prog_device == NULL) {
		class_destroy(drvr_class);
		drvr_devices[0].opened = 0;
		dm_exit();

		return -ENOMEM;;
	}

	cdev_init(&(drvr_devices[0].cdev), &dm_ops);
	drvr_devices[0].cdev.owner = THIS_MODULE;
	drvr_devices[0].cdev.ops = &dm_ops;
	cdev_add(&(drvr_devices[0].cdev), devno, 1);
	//printk(KERN_INFO "'mknod /dev/%s c %d %d'.\n", DEVICE_NAME, gDrvrMajor, 0);
	/* Initialize each device. */
	devno = MKDEV(gDrvrMajor, 1);
	drvr_devices[1].type = mem;
	memDev = &(drvr_devices[1].data.mem);
	memDev->base_addr = (unsigned short *) (FPGA_BASE_ADDR);
	device_create(drvr_class, prog_device, devno, NULL, DEVICE_NAME_MEM);
	cdev_init(&(drvr_devices[1].cdev), &dm_ops);
	(drvr_devices[1].cdev).owner = THIS_MODULE;
	(drvr_devices[1].cdev).ops = &dm_ops;
	cdev_add(&(drvr_devices[1].cdev), devno, 1);
	drvr_devices[1].opened = 0;
	init_completion(&dma_comp);

	return ioctl_init();
}
开发者ID:genba,项目名称:Logi-kernel,代码行数:77,代码来源:main_dma.c


注:本文中的cdev_add函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。