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


C++ register_chrdev_region函数代码示例

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


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

示例1: fm_cdev_setup

static fm_s32 fm_cdev_setup(struct fm *fm)
{
    fm_s32 ret = 0;
    struct fm_platform *plat = &fm->platform;

#ifdef FM_DEV_STATIC_ALLOC
    /*static allocate chrdev*/
    plat->dev_t = MKDEV(FM_major, 0);
    ret = register_chrdev_region(plat->dev_t, 1, FM_NAME);

    if (ret) {
        WCN_DBG(FM_ERR | MAIN, "%s():fail to register chrdev\n", __func__);
        return ret;
    }

#endif

#ifndef FM_DEV_STATIC_ALLOC
    ret = alloc_chrdev_region(&plat->dev_t, 0, 1, FM_NAME);

    if (ret) {
        WCN_DBG(FM_ALT | MAIN, "alloc dev_t failed\n");
        return ret;
    }

#endif

    WCN_DBG(FM_NTC | MAIN, "alloc %s:%d:%d\n", FM_NAME, MAJOR(plat->dev_t), MINOR(plat->dev_t));

    cdev_init(&plat->cdev, &fm_ops);

    plat->cdev.owner = THIS_MODULE;
    plat->cdev.ops = &fm_ops;

    ret = cdev_add(&plat->cdev, plat->dev_t, 1);

    if (ret) {
        WCN_DBG(FM_ALT | MAIN, "add dev_t failed\n");
        return ret;
    }

//#ifndef FM_DEV_STATIC_ALLOC
    plat->cls = class_create(THIS_MODULE, FM_NAME);

    if (IS_ERR(plat->cls)) {
        ret = PTR_ERR(plat->cls);
        WCN_DBG(FM_ALT | MAIN, "class_create err:%d\n", ret);
        return ret;
    }

    plat->dev = device_create(plat->cls, NULL, plat->dev_t, NULL, FM_NAME);
//#endif

    return ret;
}
开发者ID:Android-Dongyf,项目名称:itop-kernel,代码行数:55,代码来源:fm_module.c

示例2: BT_init

static int BT_init(void)
{
    dev_t dev = MKDEV(BT_major, 0);
    int alloc_ret = 0;
    int cdev_err = 0;

    /*static allocate chrdev*/
    alloc_ret = register_chrdev_region(dev, 1, BT_DRIVER_NAME);
    if (alloc_ret) {
        BT_ERR_FUNC("fail to register chrdev\n");
        return alloc_ret;
    }

    cdev_init(&BT_cdev, &BT_fops);
    BT_cdev.owner = THIS_MODULE;

    cdev_err = cdev_add(&BT_cdev, dev, BT_devs);
    if (cdev_err)
        goto error;

    BT_INFO_FUNC("%s driver(major %d) installed.\n", BT_DRIVER_NAME, BT_major);
#if WMT_CREATE_NODE_DYNAMIC
	bt_class = class_create(THIS_MODULE,"stpbt");
	if(IS_ERR(bt_class))
		goto error;
	bt_dev = device_create(bt_class,NULL,dev,NULL,"stpbt");
	if(IS_ERR(bt_dev))
		goto error;
#endif
	retflag = 0;
    mtk_wcn_stp_register_event_cb(BT_TASK_INDX, NULL);

    /* init wait queue */
    init_waitqueue_head(&(inq));

    return 0;

error:
#if WMT_CREATE_NODE_DYNAMIC
	if(!(IS_ERR(bt_dev)))
		device_destroy(bt_class,dev);
	if(!(IS_ERR(bt_class)))
	{
		class_destroy(bt_class);
		bt_class = NULL;
	}
#endif
    if (cdev_err == 0)
        cdev_del(&BT_cdev);

    if (alloc_ret == 0)
        unregister_chrdev_region(dev, BT_devs);

    return -1;
}
开发者ID:kim-ryuzaki,项目名称:android_mediatek_muse72,代码行数:55,代码来源:stp_chrdev_bt.c

示例3: bootkey_init

static int __init bootkey_init(void)
{
	// Setup devno and lasterr
	devno = MKDEV(BOOTKEY_MAJOR, BOOTKEY_MINOR);
	int lasterr = 0;

	printk(KERN_ALERT "BOOT_KEY interrupt module inserted.\n");

	// Requesting GPIO
	lasterr = gpio_request(BOOT_GPIO, "bootkey");
	if (lasterr < 0)
	{
		printk(KERN_ALERT "Error requesting gpio: %d for GPIO %d\n", lasterr, BOOT_GPIO);
		goto err_exit;
	}

	// GPIO direction
	lasterr = gpio_direction_input(BOOT_GPIO);
	if (lasterr < 0)
	{
		printk(KERN_ALERT "Error changing gpio direction: %d for GPIO %d\n", lasterr, BOOT_GPIO);
		goto err_gpiofree;
	}

	// Registering char device number regions (static)
	lasterr = register_chrdev_region(devno, BOOTKEY_NO, "bootkey");
	if (lasterr < 0)
	{
		printk(KERN_ALERT "Error registering char device: %d\n", lasterr);
		goto err_gpiofree;
	}

	// Init char device
	cdevStruct = cdev_alloc();
	cdev_init(cdevStruct, &bootkey_fops);

	// Add char device
	lasterr = cdev_add(cdevStruct, devno, BOOTKEY_NO);
	if (lasterr < 0)
	{
		printk(KERN_ALERT "Error adding char device: %d\n", lasterr);
		goto err_unregister_chrdev;
	}

	// All succesful
	return 0;

	// Proper cleanup
	err_unregister_chrdev:
		unregister_chrdev_region(devno, BOOTKEY_NO);
	err_gpiofree:
		gpio_free(BOOT_GPIO);
	err_exit:
		return lasterr;
}
开发者ID:mikrj,项目名称:MPS_Exercises,代码行数:55,代码来源:interrupt.c

示例4: rmidev_init_device

static int rmidev_init_device(struct rmidev_data *data)
{
	dev_t dev_no;
	int retval;
	struct device *device_ptr;

	if (rmidev_major_num) {
		dev_no = MKDEV(rmidev_major_num, 0);
		retval = register_chrdev_region(dev_no, 1, CHAR_DEVICE_NAME);
	} else {
		retval = alloc_chrdev_region(&dev_no, 0, 1, CHAR_DEVICE_NAME);
		/* let kernel allocate a major for us */
		rmidev_major_num = MAJOR(dev_no);
		dev_info(&data->pdev->dev, "Major number of rmidev: %d\n",
				 rmidev_major_num);
	}
	if (retval < 0) {
		dev_err(&data->pdev->dev,
			"Failed to register or allocate char dev, code %d.\n",
				retval);
		goto exit;
	} else {
		dev_info(&data->pdev->dev, "Allocated rmidev %d %d.\n",
			 MAJOR(dev_no), MINOR(dev_no));
	}

	mutex_init(&data->file_mutex);

	cdev_init(&data->main_dev, &rmidev_fops);

	retval = cdev_add(&data->main_dev, dev_no, 1);
	if (retval) {
		dev_err(&data->pdev->dev, "Error %d adding rmi_char_dev.\n",
			retval);
		rmidev_device_cleanup(data);
		goto exit;
	}

	dev_set_name(&data->pdev->dev, "rmidev%d", MINOR(dev_no));
	data->device_class = rmidev_device_class;
	device_ptr = device_create(
			data->device_class,
			NULL, dev_no, NULL,
			CHAR_DEVICE_NAME"%d",
			MINOR(dev_no));

	if (IS_ERR(device_ptr)) {
		dev_err(&data->pdev->dev,
			"Failed to create rmi device.\n");
		rmidev_device_cleanup(data);
		retval = -ENODEV;
	}
exit:
	return retval;
}
开发者ID:Hadramos,项目名称:android_sony_xperiaz_kernel_sources,代码行数:55,代码来源:clearpad_rmi_dev.c

示例5: l2_drv_init

static int __init l2_drv_init(void)
{
    int result;

    dev_t dev = MKDEV(l2_drv_major, 0);

    /*
     * Register your major, and accept a dynamic number.
     */
    if (l2_drv_major)
    {
        result = register_chrdev_region(dev, l2_drv_devs, "l2_drv");
    }
    else 
    {
        result = alloc_chrdev_region(&dev, 0, l2_drv_devs, "l2_drv");
        l2_drv_major = MAJOR(dev);
    }

    if (result < 0)
    {
        L2_DBG(KERN_ERR, "get chrdev_region fail l2_drv_major %d result %d\r\n", l2_drv_major, result);
        return result;
    }

    /* 
     * allocate the devices -- we can't have them static, as the number
     * can be specified at load time
     */

    memset(&l2_drv_dev_data, 0, sizeof (l2_drv_dev_data));
    sema_init(&l2_drv_dev_data.sem,1);


    l2_drv_setup_cdev(&l2_drv_dev_data, 0);

    l2_drv_devclass = class_create(THIS_MODULE, L2_DEV_NAME);
    device_create(l2_drv_devclass, NULL, dev, NULL, L2_DEV_NAME);
//    class_device_create(l2_drv_devclass, NULL, dev, NULL, L2_DEV_NAME);

    L2_DBG(KERN_NOTICE, L2_DEV_NAME " Init Done\r\n");

    igs_drv_init();
//    L2_bl2k_drv_init();
    //l2_drv_evt_init();
   // l2_drv_evtDev_BufInit();

    
    l2_drv_dbg_sysfs_init();
    //BGM_init_mv_pack();
//extern    void kerpthread_test();
//    kerpthread_test();    
    return 0; /* succeed */

}
开发者ID:KHATEEBNSIT,项目名称:AP,代码行数:55,代码来源:l2_drv_main.c

示例6: scull_init_module

int scull_init_module(void)
{
	int result, i;
	dev_t dev = 0;

    /*
     * Get a range of minor numbers to work with, asking for a dynamic
     * major unless directed otherwise at load time.
     */
	if (scull_major) {
		dev = MKDEV(scull_major, scull_minor);
		result = register_chrdev_region(dev, scull_nr_devs, "scull");
	} else {
		result = alloc_chrdev_region(&dev, scull_minor, scull_nr_devs,
				"scull");
		scull_major = MAJOR(dev);
	}
	if (result < 0) {
		printk(KERN_WARNING "scull: can't get major %d\n", scull_major);
		return result;
	}

    /* 
     * allocate the devices -- we can't have them static, as the number
     * can be specified at load time
     */
	scull_devices = kmalloc(scull_nr_devs * sizeof(struct scull_dev), GFP_KERNEL);
	if (!scull_devices) {
		result = -ENOMEM;
		goto fail;  /* Make this more graceful */
	}
	memset(scull_devices, 0, scull_nr_devs * sizeof(struct scull_dev));

    /* Initialize each device. */
	for (i = 0; i < scull_nr_devs; i++) {
		scull_devices[i].quantum = scull_quantum;
		scull_devices[i].qset = scull_qset;
		init_MUTEX(&scull_devices[i].sem);
		scull_setup_cdev(&scull_devices[i], i);
	}

    /* At this point call the init function for any friend device */
	dev = MKDEV(scull_major, scull_minor + scull_nr_devs);
    dev += scull_p_init(dev);

#ifdef SCULL_DEBUG /* only when debugging */
	scull_create_proc();
#endif

	return 0; /* succeed */

fail:
	scull_cleanup_module();
	return result;
}
开发者ID:bambreeze,项目名称:ldd3,代码行数:55,代码来源:scull_basic.c

示例7: hello_probe

int hello_probe(struct platform_device *pdev)
{
	int ret;
	//platform_get_resource(struct platform_device *dev,unsigned int type,unsigned int num);
	//                            描述设备的结构体        资源的类型                                
	struct resource *memres = platform_get_resource(pdev,IORESOURCE_MEM,0);//从pdev中获取第num个类型为type的资源,num默认从0开始
	struct resource *irqres = platform_get_resource(pdev,IORESOURCE_IRQ,0);
	if( memres==NULL || irqres == NULL)//判断资源是否合法
	{
		printk("get resource fail\n" );
		return -ENOMEM;
	}
	
	clk = clk_get(NULL,"adc"); //获得时钟
	clk_enable(clk);//使能时钟
	adccon = ioremap(memres->start,memres->end - memres->start);//物理地址到虚拟地址的映射
	if(adccon == NULL)
	{
		printk("ioremap fail\n");
		return -ENOMEM;
	}
	
	ret = request_irq(irqres->start,adc_func,IRQF_DISABLED,"adc",NULL);//注册中断
	if(0 != ret)
	{
		printk("request_irq fail\n");
		return -ENOMEM;
	}
	init_waitqueue_head(&myread);//初始化读等待头队列

	writel(0,ADC_MUTEX + adccon);//选择0通道
	writel((1<<16 | 1<<14 |0xff<<6),adccon);  //1<<16设置为12位精度  1<<14使能预分频 oxff<<6 预分频 
	        
	devno = MKDEV(MAJOR,MINOR);//申请设备号
	ret = register_chrdev_region(devno,1,"hello12");//注册设备号
	if(0 != ret)
	{
		printk("register_chrdev_region error \n");
		return -ENOMEM;
	}
	cdev_init(&cdev,&hello_file_operations);//初始化设备
	ret = cdev_add(&cdev,devno,1);//注册设备
	if(0 != ret)
	{
		printk("cdev_add error \n");
		goto err1;
	}
		
	printk("hello_probe\n");
	return 0;
err1:
	unregister_chrdev_region(devno,1);//如注册设备不成功,卸载设备号

	return 0;
}
开发者ID:chenkun0702,项目名称:shiyandaima,代码行数:55,代码来源:platform_driver.c

示例8: my_init

static int __init my_init (void)
{
    first = MKDEV (my_major, my_minor);
    register_chrdev_region (first, count, MYDEV_NAME);
    my_cdev = cdev_alloc ();
    cdev_init (my_cdev, &mycdrv_fops);
    cdev_add (my_cdev, first, count);
    printk (KERN_INFO "\nSucceeded in registering character device %s\n",
            MYDEV_NAME);
    return 0;
}
开发者ID:YorkZ,项目名称:docs_utils,代码行数:11,代码来源:mmapdrv.c

示例9: my_init

static int __init my_init(void)
{
	ramdisk = kmalloc(ramdisk_size, GFP_KERNEL);
	first = MKDEV(my_major, my_minor);
	register_chrdev_region(first, count, MYDEV_NAME);
	my_cdev = cdev_alloc();
	cdev_init(my_cdev, &mycdrv_fops);
	cdev_add(my_cdev, first, count);
	pr_info("\nSucceeded in registering character device %s\n", MYDEV_NAME);
	return 0;
}
开发者ID:iamjy,项目名称:ldd,代码行数:11,代码来源:test.c

示例10: vuln_init

static int __init vuln_init(void)
{
	ramdisk = kmalloc(MAX_RW,GFP_KERNEL);
	first = MKDEV(vuln_major,vuln_minor);
	register_chrdev_region(first,count,DEVNAME);
	cdev = cdev_alloc();
	cdev_init(cdev,&fps);
	cdev_add(cdev,first,count);
	printk(KERN_INFO"Registring device %s\n",DEVNAME);
	return 0;
}
开发者ID:0x36,项目名称:MCSC2014,代码行数:11,代码来源:vuln_kmod.c

示例11: scull_init_module

static int scull_init_module(void)
{
	int res = 0;
	dev_t dev;
	int i;
	
#ifdef __DEBUG_INFO
     printk(KERN_ALERT "In init!!!\n");
#endif

	if(scull_major){
		dev = MKDEV(scull_major, scull_minor);
		res = register_chrdev_region(dev, scull_num, "gzhSCULL");
	}else{
		res = alloc_chrdev_region(&dev, scull_minor, scull_num, "gzhSCULL");		
		scull_major = MAJOR(dev);
	}
	if(res != 0 ){
		printk(KERN_ALERT "In scull_init_module(), register dev error");
		return res;
	}

	printk(KERN_ALERT "tht major is %d\n", scull_major);


	scull_devices = kmalloc(scull_num * sizeof(struct scull_dev), GFP_KERNEL);

	if(scull_devices == NULL){
		printk(KERN_ALERT "scull_devices malloc error\n");
		goto fail;
	}


	memset(scull_devices, 0, scull_num * sizeof(struct scull_dev));

	for(i = 0; i < scull_num; i++)
	{
		scull_devices[i].quantum = scull_quantum;
		scull_devices[i].qset = scull_qset;
        sema_init(&scull_devices[i].sem, 1);
        init_completion(&scull_devices[i].comp);
		scull_setup_cdev(&(scull_devices[i]), i);
	}
	
	return 0;

	fail:
	{
		printk(KERN_ALERT "In Failed\n");
		scull_cleanup_module();
	}

	return 0;
}
开发者ID:guozhenhong,项目名称:KernelDev,代码行数:54,代码来源:scull.c

示例12: RegisterCAM_CALCharDrv

static inline int RegisterCAM_CALCharDrv(void)
{
	struct device *CAM_CAL_device = NULL;

#if CAM_CAL_DYNAMIC_ALLOCATE_DEVNO
	if (alloc_chrdev_region(&g_CAM_CALdevno, 0, 1, CAM_CAL_DRVNAME)) {
		CAM_CALDB("[CAM_CAL] Allocate device no failed\n");

		return -EAGAIN;
	}
#else
	if (register_chrdev_region(g_CAM_CALdevno , 1 , CAM_CAL_DRVNAME)) {
		CAM_CALDB("[CAM_CAL] Register device no failed\n");

		return -EAGAIN;
	}
#endif

	/* Allocate driver */
	g_pCAM_CAL_CharDrv = cdev_alloc();

	if (NULL == g_pCAM_CAL_CharDrv) {
		unregister_chrdev_region(g_CAM_CALdevno, 1);

		CAM_CALDB("[CAM_CAL] Allocate mem for kobject failed\n");

		return -ENOMEM;
	}

	/* Attatch file operation. */
	cdev_init(g_pCAM_CAL_CharDrv, &g_stCAM_CAL_fops);

	g_pCAM_CAL_CharDrv->owner = THIS_MODULE;

	/* Add to system */
	if (cdev_add(g_pCAM_CAL_CharDrv, g_CAM_CALdevno, 1)) {
		CAM_CALDB("[CAM_CAL] Attatch file operation failed\n");

		unregister_chrdev_region(g_CAM_CALdevno, 1);

		return -EAGAIN;
	}

	CAM_CAL_class = class_create(THIS_MODULE, "CAM_CALdrv");
	if (IS_ERR(CAM_CAL_class)) {
		int ret = PTR_ERR(CAM_CAL_class);

		CAM_CALDB("Unable to create class, err = %d\n", ret);
		return ret;
	}
	CAM_CAL_device = device_create(CAM_CAL_class, NULL, g_CAM_CALdevno, NULL, CAM_CAL_DRVNAME);

	return 0;
}
开发者ID:P-D-A,项目名称:android_kernel_lge_mt6753,代码行数:54,代码来源:dummy_cam_cal.c

示例13: scull_init_module

static int __init scull_init_module( void )
{
	int	ret, i;
	dev_t	devno = 0;

	if ( scull_major )
	{
		devno	= MKDEV( scull_major, scull_mino );
		ret	= register_chrdev_region( devno, 1, "scull" );
	}else{
		ret		= alloc_chrdev_region( &devno, scull_mino, 1, "scull" );
		scull_major	= MAJOR( devno );
	}

	if ( ret < 0 )
	{
		printk( KERN_WARNING "scull: can't get major %d\n", scull_major );
		return(ret);
	}

	scull_devices = kmalloc( sizeof(struct scull_dev) * scull_nr_dev, GFP_KERNEL );
	if ( !scull_devices )
	{
		ret = -ENOMEM;
		goto fail;
	}

	for ( i = 0; i < scull_nr_dev; i++ )
	{
		scull_devices[i].quantum	= SCULL_QUANTUM;
		scull_devices[i].qset		= SCULL_QSET;
		sema_init( &scull_devices[i].sem, 1 );
		scull_setup_dev( &scull_devices[i], i );
	}

	PDEBUG( "device open\n" );
	/*
	 * if(printk_ratelimit())
	 * PDEBUG("device open\n");
	 */

	/*
	 * print_dev_t(buffer, dev);
	 * format_dev_t(buffer, dev)
	 */
#ifdef SCULL_DEBUG
	scull_create_proc();
#endif
	return(0);

fail:
	scull_cleanup_module();
	return(ret);
}
开发者ID:jianghong-023,项目名称:dirver,代码行数:54,代码来源:scull.c

示例14: devblast_init_module

int devblast_init_module(void)
{
	
	int result,i;
	dev_t devblast_devno = 0;			/* Our first device number */
	initProcessInformationList();
	sema_init(&sem, 1);
	init_waitqueue_head(&queue_provider);
	providerPid = -1;
	flagSendToProvider = 0;
	
	if (devblast_major) {
		devblast_devno = MKDEV(devblast_major, devblast_minor);
		result = register_chrdev_region(devblast_devno,  devblast_nr_devices, "devblast");
	} else {
		result = alloc_chrdev_region(&devblast_devno, devblast_minor, devblast_nr_devices,
				"devblast");
		devblast_major = MAJOR(devblast_devno);
	}
	if (result < 0) {
		printk(KERN_WARNING "devblast: can't get major %d\n", devblast_major);
		return result;
	}
	
	   /* 
	 * allocate the devices -- we can't have them static, as the number
	 * can be specified at load time
	 */
	blast_devices = kmalloc(devblast_nr_devices * sizeof(struct devblast_dev), GFP_KERNEL);
	if (!blast_devices) {
		result = -ENOMEM;
		goto fail;  /* Make this more graceful */
	}
	memset(blast_devices, 0, devblast_nr_devices * sizeof(struct devblast_dev));

        /* Initialize each device. */
	for (i = 0; i < devblast_nr_devices; i++) {
		 devblast_setup_cdev(&blast_devices[i], i);
	}
	
	//SET_MODULE_OWNER(&devblast_fops);

	//major = register_chrdev(0, "devblast", &devblast_fops);
	//ERROR_TRACE1("Modulo devblast carregado com sucesso. Major Number=%d\n", major);
	printk(KERN_NOTICE "Modulo devblast carregado com sucesso. Major Number=%d\n", devblast_major);
	
	
	return 0;
	
fail:	
	devblast_cleanup_module();
	return result;
}
开发者ID:joprietoe,项目名称:provider,代码行数:53,代码来源:devblast.c

示例15: startup

static int startup(void)
{
    dev_t dev = MKDEV(major, minor);
    int result = 0;
    memory = NULL;
    

    printk(KERN_INFO "hello: startup\n");
    
    if (! request_region(lpt_port, SHORT_NR_PORTS, "MY_LPT"))  {
            printk(KERN_INFO "hello: can't get I/O mem address 0x%lx\n", lpt_port);
            return -ENODEV;
    }
    printk(KERN_WARNING "hello: request_region: port 0x%lx hooked\n", lpt_port);

    // get a driver number
    if (major) {
            dev = MKDEV(major, minor);
            result = register_chrdev_region(dev, 1, "hello");
    } else {
            result = alloc_chrdev_region(&dev, minor, 1, "hello");
            major = MAJOR(dev);
    }
    
    if (result < 0) {
            printk(KERN_WARNING "hello: can't get version %d:%d\n", major, minor);
            return result;
    }

       
    // Initialize the device.	
    my_cdev = cdev_alloc();
    if(!my_cdev) {
            printk(KERN_WARNING "hello:  cdev_alloc failed");
            return -1;
    }

    my_cdev->ops = &my_ops;
    
    if(cdev_add(my_cdev, dev, 1) < 0) {
            printk(KERN_WARNING "hello:  cdev_add failed");
            return -1;
    }

    
    hello_create_proc(); // proc debugging

    printk(KERN_WARNING "hello: got version %d:%d\n", major, minor);
    printk(KERN_WARNING "hello: my_cdev allocated\n");
    printk(KERN_WARNING "hello: my_cdev added\n");

    return 0;
}
开发者ID:hukka-mail-ru,项目名称:hukka,代码行数:53,代码来源:hello.c


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