• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ register_chrdev_region函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GPS_init

static int GPS_init(void)
{
	dev_t dev = MKDEV(GPS_major, 0);
	INT32 alloc_ret = 0;
	INT32 cdev_err = 0;
#if REMOVE_MK_NODE
	struct device *stpgps_dev = NULL;
#endif

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

	cdev_init(&GPS_cdev, &GPS_fops);
	GPS_cdev.owner = THIS_MODULE;

	cdev_err = cdev_add(&GPS_cdev, dev, GPS_devs);
	if (cdev_err)
		goto error;
#if REMOVE_MK_NODE

	stpgps_class = class_create(THIS_MODULE, "stpgps");
	if (IS_ERR(stpgps_class))
		goto error;
	stpgps_dev = device_create(stpgps_class, NULL, dev, NULL, "stpgps");
	if (IS_ERR(stpgps_dev))
		goto error;
#endif
	pr_warn(KERN_ALERT "%s driver(major %d) installed.\n", GPS_DRIVER_NAME, GPS_major);

	return 0;

error:

#if REMOVE_MK_NODE
	if (!IS_ERR(stpgps_dev))
		device_destroy(stpgps_class, dev);
	if (!IS_ERR(stpgps_class)) {
		class_destroy(stpgps_class);
		stpgps_class = NULL;
	}
#endif
	if (cdev_err == 0)
		cdev_del(&GPS_cdev);

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

	return -1;
}
开发者ID:John677,项目名称:Kernal_k3note,代码行数:53,代码来源:stp_chrdev_gps.c


示例17: init_module

int init_module(void)
{
    word divisor;
    unsigned char reg;
    
    struct resource *base_res;

    printk("<1>""uart: INIT_MOD\n");
    // To do: request the IO port region
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
#else

#endif

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
    if(uart_major) {
        if ( register_chrdev_region(MKDEV(uart_major,0), 1, "uart") < 0 ) {
            printk ("register_chrdev_region() fail\n");
            release_region(PORT_COM1,8);
            return -1;
        }
    }
    else {
        if (alloc_chrdev_region(&devno, 0, 1, "uart") < 0) {
            printk ("alloc_chrdev_region() fail\n");
            release_region(PORT_COM1,8);
            return -1;
        }
        uart_major=MAJOR(devno);
    }
    cdev_init(&mycdev, &uart_fops);
    mycdev.owner=THIS_MODULE;
    if(cdev_add(&mycdev, MKDEV(uart_major,0), 1)) {
        printk ("Error adding cdev\n");
        unregister_chrdev_region(MKDEV(uart_major, 0), 1);
        release_region(PORT_COM1,8);
    }
#else
    uart_major = register_chrdev(0, "uart", &uart_fops);
    if (uart_major < 0) {
	printk("<1>" "uart: can't get major number\n");
        release_region(PORT_COM1,8);
        return -1;
    }
#endif


    // To do: PORT_COM1, set the baud: 2400,

    // To do: BITS_8 | PARITY_NONE | STOP_ONE  
    
    return 0;
}
开发者ID:bryan0806,项目名称:LinuxDriver,代码行数:53,代码来源:uart.c


示例18: reg_dev

/*
 * reg_dev() - registers a device & initializes the structure components
 */
static int reg_dev(int base_addr, int minor, int irq)
{
	int err;
	err = register_chrdev_region(MKDEV(major, minor), 1, MODULE_NAME);
	if (err != 0) {
		printk(LOG_LEVEL "ERROR registering chrdev region: error %d\n",
		       err);
		goto out_reg_chrdev;
	}

	if ((request_irq(irq, uart_interrupt_handler, IRQF_SHARED, MODULE_NAME,
			 &devs[minor])) != 0) {
		printk(LOG_LEVEL "ERROR requesting irq: error %d\n", err);
		goto out_req_irq;
	}

	if (!request_region(base_addr, COM_NR_PORTS, MODULE_NAME)) {
		printk(LOG_LEVEL "ERROR registering region\n");
		err = -ENODEV;
		goto out_req_reg;
	}

	atomic_set(&devs[minor].access, 1);
	devs[minor].base_addr = base_addr;

	INIT_KFIFO(devs[minor].read_buffer);
	spin_lock_init(&devs[minor].read_lock);
	init_waitqueue_head(&devs[minor].read_wq);

	INIT_KFIFO(devs[minor].write_buffer);
	spin_lock_init(&devs[minor].write_lock);
	init_waitqueue_head(&devs[minor].write_wq);

	outb(0x0, base_addr + IER);
	outb(0x1, base_addr + IER);
	outb(0x0, base_addr + FCR);
	outb(0x7, base_addr + FCR);
	outb(0xb, base_addr + MCR);

	cdev_init(&devs[minor].cdev, &uart_fops);
	cdev_add(&devs[minor].cdev, MKDEV(major, minor), 1);
	return 0;

 out_reg_chrdev:
	return err;
 out_req_reg:
	free_irq(irq, &devs[minor]);
 out_req_irq:
	unregister_chrdev_region(MKDEV(major, minor), 1);
	return err;

}
开发者ID:evelinad,项目名称:school,代码行数:55,代码来源:uart16550.c


示例19: keyint1_driver_init

__init static int keyint1_driver_init (void)
{
	int ret ; 
	dev_t devno = MKDEV (major, minor) ;
	
	ret = register_chrdev_region (devno, 1, "keyint1_device") ;
	if (ret) {
		printk (KERN_ALERT"char device num fail!\r\n") ;
		goto err ;
	}
	
	cdev_init (&keyint1_cdev, &keyint1_ops) ;
	ret = cdev_add (&keyint1_cdev, devno, 1) ;
	
	if (ret) {
		printk (KERN_ALERT"CDEV ADD ERROR") ;
		goto err1;
	}

	gph0base = ioremap (0xE0300C00, sizeof (gph0)) ;
	WKUP_INT0_7_MASK  = ioremap(0XE0300F00, 4) ;
	PEND = ioremap (0XE0300F40, 4) ;
	
	GPH0.GPH0CON = (GPH0.GPH0CON & (~(0xf<<4))) | (2 << 4) ;
	GPH0.GPH0CON = (GPH0.GPH0CON & (~(0xf<<8))) | (2 << 8) ;  //GPH0_2 EXT2

	*WKUP_INT0_7_MASK = *WKUP_INT0_7_MASK &  (~(1<<1)) ;
	*WKUP_INT0_7_MASK = *WKUP_INT0_7_MASK &  (~(1<<2)) ;
	ret = request_irq (32 + 1, key_int_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING, "KEY1_IRQ", NULL) ;
	if (ret) {
		printk (KERN_ALERT"REQUEST IRQ ERROR\n") ;
		goto err2 ;
	}

	ret = request_irq (32 + 2, key_int_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING, "KEY2_IRQ", NULL) ;
	if (ret) {
		printk (KERN_ALERT"REQUEST IRQ ERROR\n") ;
		goto err3 ;
	}

	printk (KERN_ALERT"keyint1 DRIVER INSMOD DONE!\n") ; 
	return 0 ;

err3:
	free_irq (32 + 1, NULL) ;
err2:
	cdev_del (&keyint1_cdev) ;
err1:
	unregister_chrdev_region (devno, 1);
err:
	return ret ;
}
开发者ID:kk821521286,项目名称:kangkai,代码行数:52,代码来源:key2irq_tasklet.c


示例20: ds18b20_drv_init

static int __init ds18b20_drv_init(void)
{
	int ret = 0;
    dev_t devno = MKDEV(mars_ds18b20_major, 0);

    /* Allocating mars_ds18b20_dev structure dynamically */
    mars_ds18b20_devp = kmalloc(sizeof(struct mars_ds18b20_dev), GFP_KERNEL);
    if (!mars_ds18b20_devp) {
        return -ENOMEM;
    }

    memset(mars_ds18b20_devp, 0, sizeof(struct mars_ds18b20_dev));

    mars_ds18b20_devp->ds18b20_name = MARS_DS18B20_NAME;

    /* Register char devices region */
    if (mars_ds18b20_major) {
        ret = register_chrdev_region(devno, 1, mars_ds18b20_devp->ds18b20_name);
    }else {
        /* Allocating major number dynamically */
        ret = alloc_chrdev_region(&devno, 0, 1, mars_ds18b20_devp->ds18b20_name);
        mars_ds18b20_major = MAJOR(devno);
    }

    if (ret < 0)
        return ret;
    
    /* Helper function to initialize and add cdev structure */
    mars_ds18b20_setup_cdev(mars_ds18b20_devp, 0);

    /* mdev - automatically create the device node */
    mars_ds18b20_devp->ds18b20_cls = class_create(THIS_MODULE, mars_ds18b20_devp->ds18b20_name);
    if (IS_ERR(mars_ds18b20_devp->ds18b20_cls))
        return PTR_ERR(mars_ds18b20_devp->ds18b20_cls);

    mars_ds18b20_devp->ds18b20_dev = device_create(mars_ds18b20_devp->ds18b20_cls, NULL, devno, NULL, mars_ds18b20_devp->ds18b20_name);    
	if (IS_ERR(mars_ds18b20_devp->ds18b20_dev)) {
        class_destroy(mars_ds18b20_devp->ds18b20_cls);
        cdev_del(&mars_ds18b20_devp->cdev);
        unregister_chrdev_region(devno, 1);
        kfree(mars_ds18b20_devp);
		return PTR_ERR(mars_ds18b20_devp->ds18b20_dev);
	}

    ret = mars_ds18b20_hw_init();
    if (ret)
        return ret;
        
	printk(MARS_DS18B20_NAME" is initialized!!\n");
    
    return 0;
}
开发者ID:kyyang28,项目名称:wifiVehicleDrivers,代码行数:52,代码来源:mars_ds18b20_drv.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ register_class_devname函数代码示例发布时间:2022-05-30
下一篇:
C++ register_chrdev函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap