static int __init msm_idle_stats_init(void)
{
	unsigned int nr_cpus = num_possible_cpus();
	struct device *dev;
	int rc;
	int i;

	if (msm_idle_stats_debug_mask & MSM_IDLE_STATS_DEBUG_API)
		pr_info("%s: enter\n", __func__);

	rc = alloc_chrdev_region(&msm_idle_stats_dev_nr,
			0, nr_cpus, MSM_IDLE_STATS_DRIVER_NAME);
	if (rc) {
		pr_err("%s: failed to allocate device number, rc %d\n",
			__func__, rc);
		goto init_bail;
	}

	msm_idle_stats_class = class_create(THIS_MODULE,
					MSM_IDLE_STATS_DRIVER_NAME);
	if (IS_ERR(msm_idle_stats_class)) {
		pr_err("%s: failed to create device class\n", __func__);
		rc = -ENOMEM;
		goto init_unreg_bail;
	}

	for (i = 0; i < nr_cpus; i++) {
		dev = device_create(msm_idle_stats_class, NULL,
				msm_idle_stats_dev_nr + i, NULL,
				MSM_IDLE_STATS_DRIVER_NAME "%d", i);

		if (!dev) {
			pr_err("%s: failed to create device %d\n",
				__func__, i);
			rc = -ENOMEM;
			goto init_remove_bail;
		}
	}

	cdev_init(&msm_idle_stats_cdev, &msm_idle_stats_fops);
	msm_idle_stats_cdev.owner = THIS_MODULE;

	/*
	 * Call cdev_add() last, after everything else is initialized and
	 * the driver is ready to accept system calls.
	 */
	rc = cdev_add(&msm_idle_stats_cdev, msm_idle_stats_dev_nr, nr_cpus);
	if (rc) {
		pr_err("%s: failed to register char device, rc %d\n",
			__func__, rc);
		goto init_remove_bail;
	}

	if (msm_idle_stats_debug_mask & MSM_IDLE_STATS_DEBUG_API)
		pr_info("%s: done\n", __func__);
	return 0;

init_remove_bail:
	for (i = i - 1; i >= 0; i--)
		device_destroy(
			msm_idle_stats_class, msm_idle_stats_dev_nr + i);

	class_destroy(msm_idle_stats_class);

init_unreg_bail:
	unregister_chrdev_region(msm_idle_stats_dev_nr, nr_cpus);

init_bail:
	if (msm_idle_stats_debug_mask & MSM_IDLE_STATS_DEBUG_API)
		pr_info("%s: exit, %d\n", __func__, rc);
	return rc;
}
Example #2
0
/*----------------------------------------------------------
 *	fcsmd_init
 *---------------------------------------------------------*/
static int fcsmd_init(void)
{
	dev_t dev = MKDEV(fcsmd_major, 0);
	int alloc_ret = 0;
	int cdev_err = 0;
	/* FUJITSU:2011-04-22 start */
    struct device *class_dev = NULL;
	/* FUJITSU:2011-04-22 end   */

	/*
	* register major number
	*/
	/* reserve major number */
	if (fcsmd_major) {
		alloc_ret = register_chrdev_region(dev, fcsmd_dev_count, DRIVER_NAME);
		if (alloc_ret < 0) {
			printk(KERN_ERR "fcsmd: unable to get major %d\n", fcsmd_major);
			goto error;
		}
		if (fcsmd_major == 0)
			fcsmd_major = alloc_ret;
	}
	else {
		alloc_ret = alloc_chrdev_region(&dev, fcsmd_minor, fcsmd_dev_count, DRIVER_NAME);
		if (alloc_ret) {
			printk(KERN_ERR "fcsmd: unable to get major \n");
			goto error;
		}
		fcsmd_major = MAJOR(dev);
	}

	/* register system call handler(fops) */
	cdev_init(&fcsmd_cdev, &fcsmd_ops);

	/* register to kernel */
	fcsmd_cdev.owner = THIS_MODULE;
	fcsmd_cdev.ops = &fcsmd_ops;
	cdev_err = cdev_add (&fcsmd_cdev, MKDEV(fcsmd_major, fcsmd_minor), fcsmd_dev_count);

	if (cdev_err) {
		goto error;
	}

	/* register class */
	fcsmd_class = class_create(THIS_MODULE, DRIVER_NAME);
	if (IS_ERR(fcsmd_class)) {
		goto error;
	}
	class_dev = device_create(fcsmd_class, NULL, MKDEV(fcsmd_major, fcsmd_minor), NULL, DRIVER_NAME);

	if (IS_ERR(class_dev))
		printk(KERN_ERR "fcsmd: can't create device\n");

	wake_lock_init(&fcsmd_wakelock, WAKE_LOCK_SUSPEND, "fcsmd");

	return 0;
  
error:
	if (cdev_err == 0)
		cdev_del(&fcsmd_cdev);
	
	if (alloc_ret == 0)
		unregister_chrdev_region(MKDEV(fcsmd_major, 0), fcsmd_dev_count);

	return -1;
}
static int __init p_serial_init(void)
{

	printk("1>alloc_chrdev_region(...!\n");

	if (alloc_chrdev_region(&p_device_id, 0,1, "pseudo_serial_driver"))
	{
		printk("Error in allocating the serial device driver region..!\n");
		
		return -EINVAL;
	}

	printk("2>request_region(...!\n");

	rs = request_region(base_addr,NO_OF_PORTS,"pseudo_serial_device0");	
        if(rs==NULL)
        { 
		unregister_chrdev_region(p_device_id, 1);

		
		return -EBUSY;
	}


	printk("3>my_dev = kzalloc...!\n");
	my_dev = kmalloc(sizeof(P_SERIAL_DEV),GFP_KERNEL);
        if(my_dev==NULL)
        { 
		printk("Error in creating a private object...!\n");
		unregister_chrdev_region(p_device_id, 1);
		release_region(base_addr,NO_OF_PORTS);  
		return -EBUSY;
	}



	printk("4>my_dev->read_buff = kzalloc(...!\n");
	my_dev->read_buff = kmalloc(MAX_BUFFER_AREA,GFP_KERNEL);
        if(my_dev->read_buff==NULL)
        {
	      printk("error in read_buff's memory allocation...\n");
		unregister_chrdev_region(p_device_id, 1);

	      kfree(my_dev); 
	      release_region(base_addr,NO_OF_PORTS);  
	      return -ENOMEM;
	}
	

	printk("5>kfifo_init(&(my_dev->read_kfifo)...!\n");

	kfifo_init(&(my_dev->read_kfifo), my_dev->read_buff, (unsigned int) MAX_BUFFER_AREA);


	printk("6>my_dev->write_buff = kzalloc(...!\n");
	
	my_dev->write_buff = kmalloc(MAX_BUFFER_AREA,GFP_KERNEL);
        if(my_dev->write_buff==NULL)
	{
	      printk("error in read_buff's memory allocation...\n");
		unregister_chrdev_region(p_device_id, 1);

	      kfifo_free(&(my_dev->read_kfifo));
	      kfree(my_dev); 
	      release_region(base_addr,NO_OF_PORTS);  
	      return -ENOMEM;
	}
	
	printk("7>kfifo_init(&(my_dev->write_kfifo)...!\n");

	kfifo_init(&(my_dev->write_kfifo), my_dev->read_buff, (unsigned int) MAX_BUFFER_AREA);

	printk("8>spin_lock...!\n");

	spin_lock_init(&(my_dev->wr_spinlock));
	spin_lock_init(&(my_dev->rd_spinlock));


	printk("9>init_waitqueue...!\n");

	init_waitqueue_head(&(my_dev->read_queue));
	init_waitqueue_head(&(my_dev->write_queue));

	

	printk("10>Device ID is %u (MAJOR:%d,Minor:%d)\n",p_device_id,MAJOR(p_device_id),MINOR(p_device_id));	

	cdev_init(&my_dev->cdev,&p_device_fops);


	printk("11>kobject_set_name(...!\n");

	kobject_set_name(&(my_dev->cdev.kobj),"p_serial_dev0");

printk("12>:  my_dev->cdev.ops\n");
		my_dev->cdev.ops = &p_device_fops;
		
printk("13>:  cdev_add(\n");
    
	if ((cdev_add(&my_dev->cdev, p_device_id , 1)) < 0)
	{
		printk("Error in adding the serial device to the driver region..!\n");
//		kobject_put(&(my_dev->cdev.kobj));
		unregister_chrdev_region(p_device_id, 1);
              	kfifo_free(&(my_dev->read_kfifo));
              	kfifo_free(&(my_dev->write_kfifo));
		kfree(my_dev);
		release_region(base_addr,NO_OF_PORTS);
		return -EINVAL;
	}
	return 0;

	
}
Example #4
0
static int __init diagchar_init(void)
{
	dev_t dev;
	int error;

	pr_debug("diagfwd initializing ..\n");
	driver = kzalloc(sizeof(struct diagchar_dev) + 5, GFP_KERNEL);

	if (driver) {
		driver->used = 0;
		timer_in_progress = 0;
		driver->debug_flag = 1;
		driver->dci_state = DIAG_DCI_NO_ERROR;
		setup_timer(&drain_timer, drain_timer_func, 1234);
		driver->itemsize = itemsize;
		driver->poolsize = poolsize;
		driver->itemsize_hdlc = itemsize_hdlc;
		driver->poolsize_hdlc = poolsize_hdlc;
		driver->itemsize_write_struct = itemsize_write_struct;
		driver->poolsize_write_struct = poolsize_write_struct;
		driver->num_clients = max_clients;
		driver->logging_mode = USB_MODE;
		driver->mask_check = 0;
		mutex_init(&driver->diagchar_mutex);
		init_waitqueue_head(&driver->wait_q);
		INIT_WORK(&(driver->diag_drain_work), diag_drain_work_fn);
		INIT_WORK(&(driver->diag_read_smd_work), diag_read_smd_work_fn);
		INIT_WORK(&(driver->diag_read_smd_cntl_work),
						 diag_read_smd_cntl_work_fn);
		INIT_WORK(&(driver->diag_read_smd_qdsp_work),
			   diag_read_smd_qdsp_work_fn);
		INIT_WORK(&(driver->diag_read_smd_qdsp_cntl_work),
			   diag_read_smd_qdsp_cntl_work_fn);
		INIT_WORK(&(driver->diag_read_smd_wcnss_work),
			diag_read_smd_wcnss_work_fn);
		INIT_WORK(&(driver->diag_read_smd_wcnss_cntl_work),
			diag_read_smd_wcnss_cntl_work_fn);
		INIT_WORK(&(driver->diag_read_smd_dci_work),
						 diag_read_smd_dci_work_fn);
		INIT_WORK(&(driver->diag_clean_modem_reg_work),
						 diag_clean_modem_reg_fn);
		INIT_WORK(&(driver->diag_clean_lpass_reg_work),
						 diag_clean_lpass_reg_fn);
		INIT_WORK(&(driver->diag_clean_wcnss_reg_work),
						 diag_clean_wcnss_reg_fn);
		diag_debugfs_init();
		diagfwd_init();
		diagfwd_cntl_init();
		driver->dci_state = diag_dci_init();
		diag_sdio_fn(INIT);
		diag_bridge_fn(INIT);
		pr_debug("diagchar initializing ..\n");
		driver->num = 1;
		driver->name = ((void *)driver) + sizeof(struct diagchar_dev);
		strlcpy(driver->name, "diag", 4);

		/* Get major number from kernel and initialize */
		error = alloc_chrdev_region(&dev, driver->minor_start,
					    driver->num, driver->name);
		if (!error) {
			driver->major = MAJOR(dev);
			driver->minor_start = MINOR(dev);
		} else {
			printk(KERN_INFO "Major number not allocated\n");
			goto fail;
		}
		driver->cdev = cdev_alloc();
		error = diagchar_setup_cdev(dev);
		if (error)
			goto fail;
	} else {
		printk(KERN_INFO "kzalloc failed\n");
		goto fail;
	}

	pr_info("diagchar initialized now");
	return 0;

fail:
	diag_debugfs_cleanup();
	diagchar_cleanup();
	diagfwd_exit();
	diagfwd_cntl_exit();
	diag_sdio_fn(EXIT);
	diag_bridge_fn(EXIT);
	return -1;
}
Example #5
0
/*
=====================rsz_init===========================
function to	register resizer character driver
*/
static __init int rsz_init(void)
{

	int result;

	/* Register     the     driver in the kernel */

	result = alloc_chrdev_region(&dev, 0, 1, DRIVER_NAME);
	if (result < 0) {
		printk(KERN_ERR
		       "DaVinciresizer: could not register character device");
		return -ENODEV;
	}
	/* Initialize of character device */
	cdev_init(&c_dev, &rsz_fops);
	c_dev.owner = THIS_MODULE;
	c_dev.ops = &rsz_fops;

	/* addding character device */
	result = cdev_add(&c_dev, dev, 1);

	if (result) {
		printk(KERN_ERR
		       "DaVinciresizer:Error %d adding"
			" Davinciresizer ..error no:",
		       result);
		unregister_chrdev_region(dev, 1);
		return result;
	}

	/* registeration of     character device */
	register_chrdev(MAJOR(dev), DRIVER_NAME, &rsz_fops);

	/* register driver as a platform driver */
	if (driver_register(&resizer_driver) != 0) {
		unregister_chrdev_region(dev, 1);
		cdev_del(&c_dev);
		return -EINVAL;
	}

	/* Register the drive as a platform device */
	if (platform_device_register(&resizer_device) != 0) {
		driver_unregister(&resizer_driver);
		unregister_chrdev_region(dev, 1);
		unregister_chrdev(MAJOR(dev), DRIVER_NAME);
		cdev_del(&c_dev);
		return -EINVAL;
	}

	rsz_class = class_create(THIS_MODULE, "davinci_resizer");

	if (!rsz_class) {

		platform_device_unregister(&resizer_device);
		cdev_del(&c_dev);
		unregister_chrdev(MAJOR(dev), DRIVER_NAME);

		return -EIO;
	}

	device_create(rsz_class, NULL, dev, NULL, "davinci_resizer");

	rsz_dev.users = 0;

	mutex_init(&rsz_dev.lock);
	/* Initialize the serializer */
	imp_init_serializer();
	imp_hw_if = imp_get_hw_if();
	printk(KERN_NOTICE "davinci_resizer initialized\n");
	return 0;
}				/* End   of function  resizer_init */
static int cmdq_probe(struct platform_device *pDevice)
{
	int status;
	struct device *object;

	CMDQ_MSG("CMDQ driver probe begin\n");

	/* init cmdq device related data */
	cmdq_dev_init(pDevice);

	/* init cmdq context */
	cmdqCoreInitialize();

	status = alloc_chrdev_region(&gCmdqDevNo, 0, 1, CMDQ_DRIVER_DEVICE_NAME);
	if (status != 0) {
		CMDQ_ERR("Get CMDQ device major number(%d) failed(%d)\n", gCmdqDevNo, status);
	} else {
		CMDQ_MSG("Get CMDQ device major number(%d) success(%d)\n", gCmdqDevNo, status);
	}

	/* ioctl access point (/dev/mtk_cmdq) */
	gCmdqCDev = cdev_alloc();
	gCmdqCDev->owner = THIS_MODULE;
	gCmdqCDev->ops = &cmdqOP;

	status = cdev_add(gCmdqCDev, gCmdqDevNo, 1);

	gCMDQClass = class_create(THIS_MODULE, CMDQ_DRIVER_DEVICE_NAME);
	object = device_create(gCMDQClass, NULL, gCmdqDevNo, NULL, CMDQ_DRIVER_DEVICE_NAME);

	status =
	    request_irq(cmdq_dev_get_irq_id(), cmdq_irq_handler, IRQF_TRIGGER_LOW | IRQF_SHARED,
			CMDQ_DRIVER_DEVICE_NAME, gCmdqCDev);
	if (status != 0) {
		CMDQ_ERR("Register cmdq driver irq handler(%d) failed(%d)\n", gCmdqDevNo, status);
		return -EFAULT;
	}

	/* although secusre CMDQ driver is responsible for handle secure IRQ, */
	/* MUST registet secure IRQ to GIC in normal world to ensure it will be initialize correctly */
	/* (that's because t-base does not support GIC init IRQ in secure world...) */
#ifdef CMDQ_SECURE_PATH_SUPPORT	
	status =
	    request_irq(cmdq_dev_get_irq_secure_id(), cmdq_irq_handler, IRQF_TRIGGER_LOW,
			CMDQ_DRIVER_DEVICE_NAME, gCmdqCDev);
	CMDQ_MSG("register sec IRQ:%d\n", cmdq_dev_get_irq_secure_id());
	if (status != 0) {
		CMDQ_ERR("Register cmdq driver secure irq handler(%d) failed(%d)\n", gCmdqDevNo, status);
		return -EFAULT;
	}
#endif

	/* global ioctl access point (/proc/mtk_cmdq) */
	if (NULL == proc_create(CMDQ_DRIVER_DEVICE_NAME, 0644, NULL, &cmdqOP)) {
		CMDQ_ERR("CMDQ procfs node create failed\n");
		return -EFAULT;
	}

	/* proc debug access point */
	cmdq_create_debug_entries();

	/* device attributes for debugging */
	device_create_file(&pDevice->dev, &dev_attr_status);
	device_create_file(&pDevice->dev, &dev_attr_error);
	device_create_file(&pDevice->dev, &dev_attr_record);
	device_create_file(&pDevice->dev, &dev_attr_log_level);
	device_create_file(&pDevice->dev, &dev_attr_profile_enable);

	CMDQ_MSG("CMDQ driver probe end\n");

	return 0;
}
Example #7
0
static int amhdmitx_probe(struct platform_device *pdev)
{
    int r;
    HDMI_DEBUG();
    pr_dbg("amhdmitx_probe\n");
    r = alloc_chrdev_region(&hdmitx_id, 0, HDMI_TX_COUNT, DEVICE_NAME);
    if (r < 0) {
        pr_error("Can't register major for amhdmitx device\n");
        return r;
    }
    hdmitx_class = class_create(THIS_MODULE, DEVICE_NAME);
    if (IS_ERR(hdmitx_class))
    {
        unregister_chrdev_region(hdmitx_id, HDMI_TX_COUNT);
        return -1;
        //return PTR_ERR(aoe_class);
    }
    hdmitx_device.unplug_powerdown=0;
    hdmitx_device.vic_count=0;
    hdmitx_device.auth_process_timer=0;
    hdmitx_device.force_audio_flag=0;
    if(init_flag&INIT_FLAG_CEC_FUNC){
        hdmitx_device.cec_func_flag = 1;
    }
    else{
        hdmitx_device.cec_func_flag = 0;
    }
    if((init_flag&INIT_FLAG_POWERDOWN)&&(hpdmode==2)){
        hdmitx_device.mux_hpd_if_pin_high_flag=0;
    }
    else{
        hdmitx_device.mux_hpd_if_pin_high_flag=1;
    }
    hdmitx_device.audio_param_update_flag=0;
    cdev_init(&(hdmitx_device.cdev), &amhdmitx_fops);
    hdmitx_device.cdev.owner = THIS_MODULE;
    cdev_add(&(hdmitx_device.cdev), hdmitx_id, HDMI_TX_COUNT);

    //hdmitx_dev = device_create(hdmitx_class, NULL, hdmitx_id, "amhdmitx%d", 0);
    hdmitx_dev = device_create(hdmitx_class, NULL, hdmitx_id, NULL, "amhdmitx%d", 0); //kernel>=2.6.27 

    device_create_file(hdmitx_dev, &dev_attr_disp_mode);
    device_create_file(hdmitx_dev, &dev_attr_aud_mode);
    device_create_file(hdmitx_dev, &dev_attr_edid);
    device_create_file(hdmitx_dev, &dev_attr_config);
    device_create_file(hdmitx_dev, &dev_attr_debug);
    device_create_file(hdmitx_dev, &dev_attr_disp_cap);
    device_create_file(hdmitx_dev, &dev_attr_hpd_state);
    device_create_file(hdmitx_dev, &dev_attr_log);
    device_create_file(hdmitx_dev, &dev_attr_cec);
    
    if (hdmitx_dev == NULL) {
        pr_error("device_create create error\n");
        class_destroy(hdmitx_class);
        r = -EEXIST;
        return r;
    }
    vout_register_client(&hdmitx_notifier_nb_v);
#ifndef DISABLE_AUDIO
    aout_register_client(&hdmitx_notifier_nb_a);
#endif
    hdmitx_device.task = kthread_run(hdmi_task_handle, &hdmitx_device, "kthread_hdmi");
    
	switch_dev_register(&sdev);
	if (r < 0){
		printk(KERN_ERR "hdmitx: register switch dev failed\n");
		return r;
	}    

    return r;
}
static int __init smem_sleep_log_init(void)
{
	dev_t	dev_id;
	int	retval;
    int error;
        
	smem_log_dev = kzalloc(sizeof(struct smem_log_data), GFP_KERNEL);	
    if (!smem_log_dev)
    {
        SMEM_SLEEP_LOG_DEBUG(KERN_ERR "smem_sleep_log_init: Unable to alloc memory for device\n"); 
		return (-ENOMEM);
    }


	/*init mutex*/
	init_MUTEX(&smem_log_dev->open_sem); 

	if (major) {
		dev_id = MKDEV(major, 0);
		retval = register_chrdev_region(dev_id, SMEM_SLEEP_LOG_COUNT,
						NAME);
	} else {
		retval = alloc_chrdev_region(&dev_id, 0, SMEM_SLEEP_LOG_COUNT,
					     NAME);
		major = MAJOR(dev_id);
	}

	if (retval) {
        SMEM_SLEEP_LOG_DEBUG(KERN_ERR "smem_sleep_log cant get major\n");
        kfree(smem_log_dev);
		return -1;
	}
    
    smem_log_dev->kt_class = class_create(THIS_MODULE, NAME); 
    if (IS_ERR(smem_log_dev->kt_class)) 
    {
        SMEM_SLEEP_LOG_DEBUG(KERN_ERR "failed to class_create\n"); 
        goto can_not_create_class; 
    }

    smem_log_dev->pdevice = device_create(smem_log_dev->kt_class, NULL, dev_id, "%s", NAME); 
	if (IS_ERR(smem_log_dev->pdevice)) {
		SMEM_SLEEP_LOG_DEBUG(KERN_ERR "Can't create smem log device\n");
		goto can_not_create_class;
	}

	cdev_init(&(smem_log_dev->cdev), &smem_sleep_log_fops);
    smem_log_dev->cdev.owner = THIS_MODULE;
    
	error = cdev_add(&(smem_log_dev->cdev), dev_id, SMEM_SLEEP_LOG_COUNT);
    if (error) {
        SMEM_SLEEP_LOG_DEBUG(KERN_ERR "init_key_test_cdev: Failed  cdev_add\n");
        error = ENOENT;
        goto can_not_add_cdev;
    }
  
    return 0;
    can_not_add_cdev:
       class_unregister(smem_log_dev->kt_class); 
    can_not_create_class:
       unregister_chrdev_region(dev_id, 1);
       kfree(smem_log_dev);
       return error;
}
Example #9
0
static int vdin_probe(struct platform_device *pdev)
{
    int ret;
    int i;
    struct device *devp;
    struct resource *res;
    char name[12];

    ret = alloc_chrdev_region(&vdin_devno, 0, VDIN_COUNT, VDIN_NAME);
	if (ret < 0) {
		printk(KERN_ERR "vdin: failed to allocate major number\n");
		return 0;
	}

    vdin_clsp = class_create(THIS_MODULE, VDIN_NAME);
    if (IS_ERR(vdin_clsp))
    {
        unregister_chrdev_region(vdin_devno, VDIN_COUNT);
        return PTR_ERR(vdin_clsp);
    }

    for (i = 0; i < VDIN_COUNT; ++i)
    {
        /* allocate memory for the per-device structure */
        vdin_devp[i] = kmalloc(sizeof(struct vdin_dev_s), GFP_KERNEL);
        if (!vdin_devp[i])
        {
            printk(KERN_ERR "vdin: failed to allocate memory for vdin device\n");
            return -ENOMEM;
        }
        vdin_devp[i]->index = i;

        vdin_devp[i]->declock = SPIN_LOCK_UNLOCKED;
        vdin_devp[i]->decop = NULL;

        /* connect the file operations with cdev */
        cdev_init(&vdin_devp[i]->cdev, &vdin_fops);
        vdin_devp[i]->cdev.owner = THIS_MODULE;
        /* connect the major/minor number to the cdev */
        ret = cdev_add(&vdin_devp[i]->cdev, (vdin_devno + i), 1);
    	if (ret) {
    		printk(KERN_ERR "vdin: failed to add device\n");
            /* @todo do with error */
    		return ret;
    	}
        /* create /dev nodes */
        devp = device_create(vdin_clsp, NULL, MKDEV(MAJOR(vdin_devno), i),
                            NULL, "vdin%d", i);
        if (IS_ERR(devp)) {
            printk(KERN_ERR "vdin: failed to create device node\n");
            class_destroy(vdin_clsp);
            /* @todo do with error */
            return PTR_ERR(devp);;
    	}


        /* get device memory */
        res = platform_get_resource(pdev, IORESOURCE_MEM, i);
        if (!res) {
            printk(KERN_ERR "vdin: can't get memory resource\n");
            return -EFAULT;
        }
        vdin_devp[i]->mem_start = res->start;
        vdin_devp[i]->mem_size  = res->end - res->start + 1;
        pr_dbg(" vdin[%d] memory start addr is %x, mem_size is %x . \n",i,
            vdin_devp[i]->mem_start,vdin_devp[i]->mem_size);

        /* get device irq */
        res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
        if (!res) {
            printk(KERN_ERR "vdin: can't get memory resource\n");
            return -EFAULT;
        }
        vdin_devp[i]->irq = res->start;

        vdin_devp[i]->addr_offset = 0;

        sprintf(name, "vdin%d-irq", i);
        /* register vdin irq */
        ret = request_irq(vdin_devp[i]->irq, vdin_isr, IRQF_SHARED, name, (void *)vdin_devp[i]);
        if (ret) {
            printk(KERN_ERR "vdin: irq regist error.\n");
            return -ENOENT;
        }

        /* init timer */
        init_timer(&vdin_devp[i]->timer);
        vdin_devp[i]->timer.data = (ulong) &vdin_devp[i]->timer;
        vdin_devp[i]->timer.function = vdin_put_timer_func;
        vdin_devp[i]->timer.expires = jiffies + VDIN_PUT_INTERVAL;
        add_timer(&vdin_devp[i]->timer);
    }

    device_create_file(pdev->dev, &dev_attr_debug);

    printk(KERN_INFO "vdin: driver initialized ok\n");
    return 0;
}
Example #10
0
static int fdev_init(void)
{
	int result = 0;
	char *name = "firstdev";

	pr_alert("DEVICE:%s\n", name);
	pr_alert("The process is \"%s\" (pid %i)\n",
	       current->comm, current->pid);
	pr_alert("UTS_RELEASE:%s", UTS_RELEASE);
	pr_alert("KERNEL_VERSION:%d", KERNEL_VERSION(2, 6, 10));

	unsigned int firstminor = 0;
	int err;

	err = alloc_chrdev_region(&dev, firstminor, count, name);
	if (!err) {
		pr_alert("alloc_chrdev_region successful.");
		pr_alert("dev_t:%d,Major=%d,Minor=%d",
			dev, MAJOR(dev), MINOR(dev));
	} else {
		pr_alert("alloc_chrdev_region failed.");
	}

	fdev_p = kmalloc_array(count, sizeof(struct fdev), GFP_KERNEL);
	if (!fdev_p) {
		result = -ENOMEM;
		pr_alert("kmalloc fdev_p failed.");
		goto fail;
	} else {
		pr_alert("kmalloc fdev_p successful.");
	}

	memset(fdev_p, 0, count * sizeof(struct fdev));

	int i, major, devno;

	major = MAJOR(dev);
	for (i = 0; i < count; ++i) {
		struct fdev *devp = &fdev_p[i];

		sema_init(&devp->sem, 1);
		devno = MKDEV(major, i);
		devp->major = major;
		devp->minor = i;

		devp->quantum_count = QUANTUM_DEFAULT;
		devp->qset_count = QSET_DEFAULT;

		cdev_init(&devp->cdev, &fops);
		devp->cdev.owner = THIS_MODULE;
		devp->cdev.ops = &fops;
		err = cdev_add(&devp->cdev, devno, 1);
		if (err)
			pr_alert("Error %d adding firstdev %d", err, i);
		else
			pr_alert("Successful adding firstdev %d", i);
	}
	return 0;
fail:
	fdev_exit();
	return result;
}
int phys_mem_init(void) {
    int result, i;
    dev_t dev = MKDEV(phys_mem_major, 0);

    /*
     * Register your major, and accept a dynamic number.
     */
    if (phys_mem_major)
        result = register_chrdev_region(dev, phys_mem_devs, CHAR_DEVICE_NAME);
    else {
        result = alloc_chrdev_region(&dev, 0, phys_mem_devs, CHAR_DEVICE_NAME);
        phys_mem_major = MAJOR(dev);
    }
    if (result < 0)
        return result;

    device_class = class_create(THIS_MODULE, DEVICE_CLASS_NAME);
    if (IS_ERR(device_class)) {
        printk(KERN_WARNING "no udev support\n");
    }

    phys_mem_devices = kmalloc(phys_mem_devs * sizeof (struct phys_mem_dev), GFP_KERNEL);
    if (!phys_mem_devices) {
        result = -ENOMEM;
        goto fail_malloc;
    }
    memset(phys_mem_devices, 0, phys_mem_devs * sizeof (struct phys_mem_dev));
    for (i = 0; i < phys_mem_devs; i++) {
        sema_init(&phys_mem_devices[i].sem, 1);
        phys_mem_setup_cdev(phys_mem_devices + i, i);
        if (!IS_ERR(device_class)) {
            device_create(device_class, NULL, MKDEV(phys_mem_major, i), NULL, CHAR_DEVICE_NAME);
        }

    }

    session_mem_cache = kmem_cache_create("session_mem", sizeof (struct phys_mem_session),
            0, SLAB_HWCACHE_ALIGN, NULL); /* no ctor/dtor */
    if (!session_mem_cache) {
        phys_mem_cleanup();
        return -ENOMEM;
    }



    PRINT_SIZE(void*);
    PRINT_SIZE(short);
    PRINT_SIZE(int);
    PRINT_SIZE(long);
    PRINT_SIZE(long long);

    printk(KERN_NOTICE "IOCTL for PHYS_MEM_IOC_MARK_FRAME_BAD: 0x%lx\n", PHYS_MEM_IOC_MARK_FRAME_BAD);
    PRINT_SIZE(struct mark_page_poison);

    printk(KERN_NOTICE "IOCTL for PHYS_MEM_IOC_REQUEST_PAGES: 0x%lx\n", PHYS_MEM_IOC_REQUEST_PAGES);
    PRINT_SIZE(struct phys_mem_request);
    PRINT_SIZE(struct phys_mem_frame_status);
    PRINT_SIZE(struct phys_mem_frame_request);

    return 0; /* succeed */

fail_malloc:
    unregister_chrdev_region(dev, phys_mem_devs);
    return result;
}
int cc2520_interface_init()
{
	int result;

	interface_bottom->tx_done = cc2520_interface_tx_done;
	interface_bottom->rx_done = cc2520_interface_rx_done;

	sema_init(&tx_sem, 1);
	sema_init(&rx_sem, 1);

	sema_init(&tx_done_sem, 0);
	sema_init(&rx_done_sem, 0);

	tx_buf_c = kmalloc(PKT_BUFF_SIZE, GFP_KERNEL);
	if (!tx_buf_c) {
		result = -EFAULT;
		goto error;
	}

	rx_buf_c = kmalloc(PKT_BUFF_SIZE, GFP_KERNEL);
	if (!rx_buf_c) {
		result = -EFAULT;
		goto error;
	}

	// Allocate a major number for this device
	result = alloc_chrdev_region(&char_d_mm, 0, 1, cc2520_name);
	if (result < 0) {
		printk(KERN_INFO "[cc2520] - Could not allocate a major number\n");
		goto error;
	}
	major = MAJOR(char_d_mm);

	// Register the character device
	cdev_init(&char_d_cdev, &fops);
	char_d_cdev.owner = THIS_MODULE;
	result = cdev_add(&char_d_cdev, char_d_mm, 1);
	if (result < 0) {
		printk(KERN_INFO "[cc2520] - Unable to register char dev\n");
		goto error;
	}
	printk(KERN_INFO "[cc2520] - Char interface registered on %d\n", major);

	cl = class_create(THIS_MODULE, "cc2520");
	if (cl == NULL) {
		printk(KERN_INFO "[cc2520] - Could not create device class\n");
		goto error;
	}

	// Create the device in /dev/radio
	de = device_create(cl, NULL, char_d_mm, NULL, "radio");
	if (de == NULL) {
		printk(KERN_INFO "[cc2520] - Could not create device\n");
		goto error;
	}

	return 0;

	error:

	if (rx_buf_c) {
		kfree(rx_buf_c);
		rx_buf_c = 0;
	}

	if (tx_buf_c) {
		kfree(tx_buf_c);
		tx_buf_c = 0;
	}

	return result;
}
Example #13
0
int rmnet_usb_ctrl_init(void)
{
	struct rmnet_ctrl_dev	*dev;
	int			n;
	int			status;

	
	if (get_radio_flag() & 0x0001)
		usb_pm_debug_enabled  = true;

	if (get_radio_flag() & 0x0002)
		enable_ctl_msg_debug = true;
	

#ifdef HTC_LOG_RMNET_USB_CTRL
	if (get_radio_flag() & 0x0008)
		enable_dbg_rmnet_usb_ctrl = true;
#endif	

	for (n = 0; n < NUM_CTRL_CHANNELS; ++n) {

		dev = kzalloc(sizeof(*dev), GFP_KERNEL);
		if (!dev) {
			status = -ENOMEM;
			goto error0;
		}
		
		snprintf(dev->name, CTRL_DEV_MAX_LEN, "hsicctl%d", n);

		dev->wq = create_singlethread_workqueue(dev->name);
		if (!dev->wq) {
			pr_err("unable to allocate workqueue");
			kfree(dev);
			goto error0;
		}

		mutex_init(&dev->dev_lock);
		spin_lock_init(&dev->rx_lock);
		init_waitqueue_head(&dev->read_wait_queue);
		init_waitqueue_head(&dev->open_wait_queue);
		INIT_LIST_HEAD(&dev->rx_list);
		init_usb_anchor(&dev->tx_submitted);
		init_usb_anchor(&dev->rx_submitted);
		INIT_WORK(&dev->get_encap_work, get_encap_work);

		status = rmnet_usb_ctrl_alloc_rx(dev);
		if (status < 0) {
			kfree(dev);
			goto error0;
		}

		ctrl_dev[n] = dev;
	}

	status = alloc_chrdev_region(&ctrldev_num, 0, NUM_CTRL_CHANNELS,
			DEVICE_NAME);
	if (IS_ERR_VALUE(status)) {
		pr_err("ERROR:%s: alloc_chrdev_region() ret %i.\n",
		       __func__, status);
		goto error0;
	}

	ctrldev_classp = class_create(THIS_MODULE, DEVICE_NAME);
	if (IS_ERR(ctrldev_classp)) {
		pr_err("ERROR:%s: class_create() ENOMEM\n", __func__);
		status = -ENOMEM;
		goto error1;
	}
	for (n = 0; n < NUM_CTRL_CHANNELS; ++n) {
		cdev_init(&ctrl_dev[n]->cdev, &ctrldev_fops);
		ctrl_dev[n]->cdev.owner = THIS_MODULE;

		status = cdev_add(&ctrl_dev[n]->cdev, (ctrldev_num + n), 1);

		if (IS_ERR_VALUE(status)) {
			pr_err("%s: cdev_add() ret %i\n", __func__, status);
			kfree(ctrl_dev[n]);
			goto error2;
		}

		ctrl_dev[n]->devicep =
				device_create(ctrldev_classp, NULL,
				(ctrldev_num + n), NULL,
				DEVICE_NAME "%d", n);

		if (IS_ERR(ctrl_dev[n]->devicep)) {
			pr_err("%s: device_create() ENOMEM\n", __func__);
			status = -ENOMEM;
			cdev_del(&ctrl_dev[n]->cdev);
			kfree(ctrl_dev[n]);
			goto error2;
		}
		
		status = device_create_file(ctrl_dev[n]->devicep,
					&dev_attr_modem_wait);
		if (status) {
			device_destroy(ctrldev_classp,
				MKDEV(MAJOR(ctrldev_num), n));
			cdev_del(&ctrl_dev[n]->cdev);
			kfree(ctrl_dev[n]);
			goto error2;
		}

		dev_set_drvdata(ctrl_dev[n]->devicep, ctrl_dev[n]);
	}

	rmnet_usb_ctrl_debugfs_init();
	pr_info("rmnet usb ctrl Initialized.\n");
	return 0;

error2:
		while (--n >= 0) {
			cdev_del(&ctrl_dev[n]->cdev);
			device_destroy(ctrldev_classp,
				MKDEV(MAJOR(ctrldev_num), n));
		}

		class_destroy(ctrldev_classp);
		n = NUM_CTRL_CHANNELS;
error1:
	unregister_chrdev_region(MAJOR(ctrldev_num), NUM_CTRL_CHANNELS);
error0:
	while (--n >= 0)
		kfree(ctrl_dev[n]);

	return status;
}
static int __devinit user_rc_input_probe(struct platform_device *pdev)
{
	struct user_rc_input_dev *user_rc_dev;
	struct rc_dev *rcdev;
	int retval;

	user_rc_dev = kzalloc(sizeof(struct user_rc_input_dev), GFP_KERNEL);
	if (!user_rc_dev)
		return -ENOMEM;

	user_rc_dev->rc_input_class = class_create(THIS_MODULE,
						"user-rc-input-loopback");

	if (IS_ERR(user_rc_dev->rc_input_class)) {
		retval = PTR_ERR(user_rc_dev->rc_input_class);
		goto err;
	}

	retval = alloc_chrdev_region(&user_rc_dev->rc_input_base_dev, 0,
				MAX_RC_DEVICES,	USER_RC_INPUT_DEV_NAME);

	if (retval) {
		dev_err(&pdev->dev,
			"alloc_chrdev_region failed\n");
		goto alloc_chrdev_err;
	}

	dev_info(&pdev->dev, "User space report key event input "
					"loopback driver registered, "
		"major %d\n", MAJOR(user_rc_dev->rc_input_base_dev));

	cdev_init(&user_rc_dev->rc_input_cdev, &fops);
	retval = cdev_add(&user_rc_dev->rc_input_cdev,
				user_rc_dev->rc_input_base_dev,
							MAX_RC_DEVICES);
	if (retval) {
		dev_err(&pdev->dev, "cdev_add failed\n");
		goto cdev_add_err;
	}
	user_rc_dev->rc_input_dev =
				device_create(user_rc_dev->rc_input_class,
									NULL,
				MKDEV(MAJOR(user_rc_dev->rc_input_base_dev),
				0), NULL, "user-rc-input-dev%d", 0);

	if (IS_ERR(user_rc_dev->rc_input_dev)) {
		retval = PTR_ERR(user_rc_dev->rc_input_dev);
		dev_err(&pdev->dev, "device_create failed\n");
		goto device_create_err;
	}

	rcdev = rc_allocate_device();
	if (!rcdev) {
		dev_err(&pdev->dev, "failed to allocate rc device");
		retval = -ENOMEM;
		goto err_allocate_device;
	}

	rcdev->driver_type = RC_DRIVER_SCANCODE;
	rcdev->allowed_protos = RC_TYPE_OTHER;
	rcdev->input_name = USER_RC_INPUT_DEV_NAME;
	rcdev->input_id.bustype = BUS_HOST;
	rcdev->driver_name = USER_RC_INPUT_DRV_NAME;
	rcdev->map_name = RC_MAP_UE_RF4CE;

	retval = rc_register_device(rcdev);
	if (retval < 0) {
		dev_err(&pdev->dev, "failed to register rc device\n");
		goto rc_register_err;
	}
	user_rc_dev->rcdev = rcdev;
	user_rc_dev->dev = &pdev->dev;
	platform_set_drvdata(pdev, user_rc_dev);
	user_rc_dev->in_use = 0;

	return 0;

rc_register_err:
	rc_free_device(rcdev);
err_allocate_device:
	device_destroy(user_rc_dev->rc_input_class,
			MKDEV(MAJOR(user_rc_dev->rc_input_base_dev), 0));
device_create_err:
	cdev_del(&user_rc_dev->rc_input_cdev);
cdev_add_err:
	unregister_chrdev_region(user_rc_dev->rc_input_base_dev,
							MAX_RC_DEVICES);
alloc_chrdev_err:
	class_destroy(user_rc_dev->rc_input_class);
err:
	kfree(user_rc_dev);
	return retval;
}
Example #15
0
/**
 * gpio_pmodoled_of_probe - Probe method for PmodOLED device (over GPIO).
 * @pdev: pointer to platform devices
 *
 * This function probes the OLED device in the device tree. It initializes the
 * OLED driver data structure. It returns 0, if the driver is bound to the OLED
 * device, or a negative value if there is an error.
 */
static int gpio_pmodoled_of_probe(struct platform_device *pdev)
{
	struct gpio_pmodoled_device *gpio_pmodoled_dev;
	struct platform_device *gpio_pmodoled_pdev;
	struct spi_gpio_platform_data *gpio_pmodoled_pdata;

	struct device_node *np = pdev->dev.of_node;

	const u32 *tree_info;
	int status = 0;

	/* Alloc Space for platform device structure */
	gpio_pmodoled_dev = kzalloc(sizeof(*gpio_pmodoled_dev), GFP_KERNEL);
	if (!gpio_pmodoled_dev) {
		status = -ENOMEM;
		goto dev_alloc_err;
	}

	/* Alloc Graphic Buffer for device */
	gpio_pmodoled_dev->disp_buf = kmalloc(DISPLAY_BUF_SZ, GFP_KERNEL);
	if (!gpio_pmodoled_dev->disp_buf) {
		status = -ENOMEM;
		dev_err(&pdev->dev, "Device Display data buffer allocation failed: %d\n", status);
		goto disp_buf_alloc_err;
	}

	/* Get the GPIO Pins */
	gpio_pmodoled_dev->iVBAT = of_get_named_gpio(np, "vbat-gpio", 0);
	gpio_pmodoled_dev->iVDD = of_get_named_gpio(np, "vdd-gpio", 0);
	gpio_pmodoled_dev->iRES = of_get_named_gpio(np, "res-gpio", 0);
	gpio_pmodoled_dev->iDC = of_get_named_gpio(np, "dc-gpio", 0);
	gpio_pmodoled_dev->iSCLK = of_get_named_gpio(np, "spi-sclk-gpio", 0);
	gpio_pmodoled_dev->iSDIN = of_get_named_gpio(np, "spi-sdin-gpio", 0);
	status = of_get_named_gpio(np, "spi-cs-gpio", 0);
	gpio_pmodoled_dev->iCS = (status < 0) ? SPI_GPIO_NO_CHIPSELECT : status;
#ifdef CONFIG_PMODS_DEBUG
	pr_info(DRIVER_NAME " %s: iVBAT: 0x%lx\n", np->name, gpio_pmodoled_dev->iVBAT);
	pr_info(DRIVER_NAME " %s: iVDD : 0x%lx\n", np->name, gpio_pmodoled_dev->iVDD);
	pr_info(DRIVER_NAME " %s: iRES : 0x%lx\n", np->name, gpio_pmodoled_dev->iRES);
	pr_info(DRIVER_NAME " %s: iDC : 0x%lx\n", np->name, gpio_pmodoled_dev->iDC);
	pr_info(DRIVER_NAME " %s: iSCLK: 0x%lx\n", np->name, gpio_pmodoled_dev->iSCLK);
	pr_info(DRIVER_NAME " %s: iSDIN: 0x%lx\n", np->name, gpio_pmodoled_dev->iSDIN);
	pr_info(DRIVER_NAME " %s: iCS : 0x%lx\n", np->name, gpio_pmodoled_dev->iCS);
#endif

	/* Get SPI Related Params */
	tree_info = of_get_property(np, "spi-bus-num", NULL);
	if (tree_info) {
		gpio_pmodoled_dev->spi_id = be32_to_cpup((tree_info));
#ifdef CONFIG_PMODS_DEBUG
		pr_info(DRIVER_NAME " %s: BUS_ID\t%x\n", np->name, gpio_pmodoled_dev->spi_id);
#endif
	}

	/* Alloc Space for platform data structure */
	gpio_pmodoled_pdata = kzalloc(sizeof(*gpio_pmodoled_pdata), GFP_KERNEL);
	if (!gpio_pmodoled_pdata) {
		status = -ENOMEM;
		goto pdata_alloc_err;
	}

	/* Fill up Platform Data Structure */
	gpio_pmodoled_pdata->sck = gpio_pmodoled_dev->iSCLK;
	gpio_pmodoled_pdata->miso = SPI_GPIO_NO_MISO;
	gpio_pmodoled_pdata->mosi = gpio_pmodoled_dev->iSDIN;
	gpio_pmodoled_pdata->num_chipselect = 1;

	/* Alloc Space for platform data structure */
	gpio_pmodoled_pdev = kzalloc(sizeof(*gpio_pmodoled_pdev), GFP_KERNEL);
	if (!gpio_pmodoled_pdev) {
		status = -ENOMEM;
		goto pdev_alloc_err;
	}

	/* Fill up Platform Device Structure */
	gpio_pmodoled_pdev->name = "spi_gpio";
	gpio_pmodoled_pdev->id = gpio_pmodoled_dev->spi_id;
	gpio_pmodoled_pdev->dev.platform_data = gpio_pmodoled_pdata;
	gpio_pmodoled_dev->pdev = gpio_pmodoled_pdev;

	/* Register spi_gpio master */
	status = platform_device_register(gpio_pmodoled_dev->pdev);
	if (status < 0) {
		dev_err(&pdev->dev, "platform_device_register failed: %d\n", status);
		goto pdev_reg_err;
	}

#ifdef CONFIG_PMODS_DEBUG
	pr_info(DRIVER_NAME " %s: spi_gpio platform device registered.\n", np->name);
#endif
	gpio_pmodoled_dev->name = np->name;

	/* Fill up Board Info for SPI device */
	status = add_gpio_pmodoled_device_to_bus(gpio_pmodoled_dev);
	if (status < 0) {
		dev_err(&pdev->dev, "add_gpio_pmodoled_device_to_bus failed: %d\n", status);
		goto spi_add_err;
	}

#ifdef CONFIG_PMODS_DEBUG
	pr_info(DRIVER_NAME " %s: spi device registered.\n", np->name);
#endif

	/* Point device node data to gpio_pmodoled_device structure */
	if (np->data == NULL)
		np->data = gpio_pmodoled_dev;

	if (gpio_pmodoled_dev_id == 0) {
		/* Alloc Major & Minor number for char device */
		status = alloc_chrdev_region(&gpio_pmodoled_dev_id, 0, MAX_PMODOLED_GPIO_DEV_NUM, DRIVER_NAME);
		if (status) {
			dev_err(&pdev->dev, "Character device region not allocated correctly: %d\n", status);
			goto err_alloc_chrdev_region;
		}
#ifdef CONFIG_PMODS_DEBUG
		pr_info(DRIVER_NAME " : Char Device Region Registered, with Major: %d.\n",
			MAJOR(gpio_pmodoled_dev_id));
#endif
	}

	if (gpio_pmodoled_class == NULL) {
		/* Create Pmodoled-gpio Device Class */
		gpio_pmodoled_class = class_create(THIS_MODULE, DRIVER_NAME);
		if (IS_ERR(gpio_pmodoled_class)) {
			status = PTR_ERR(gpio_pmodoled_class);
			goto err_create_class;
		}
#ifdef CONFIG_PMODS_DEBUG
		pr_info(DRIVER_NAME " : pmodoled_gpio device class registered.\n");
#endif
	}

	if (spi_drv_registered == 0) {
		/* Register SPI Driver for Pmodoled Device */
		status = spi_register_driver(&gpio_pmodoled_spi_driver);
		if (status < 0) {
			dev_err(&pdev->dev, "gpio_pmodoled_spi_driver register failed: %d\n", status);
			goto err_spi_register;
		}
		spi_drv_registered = 1;
	}

	device_num++;

	return status;

err_spi_register:
	class_destroy(gpio_pmodoled_class);
	gpio_pmodoled_class = NULL;
err_create_class:
	unregister_chrdev_region(gpio_pmodoled_dev_id, MAX_PMODOLED_GPIO_DEV_NUM);
	gpio_pmodoled_dev_id = 0;
err_alloc_chrdev_region:
	spi_unregister_device(gpio_pmodoled_dev->spi);
spi_add_err:
	platform_device_unregister(gpio_pmodoled_dev->pdev);
pdev_reg_err:
	kfree(gpio_pmodoled_pdev);
pdev_alloc_err:
	kfree(gpio_pmodoled_pdata);
pdata_alloc_err:
	kfree(gpio_pmodoled_dev->disp_buf);
disp_buf_alloc_err:
	kfree(gpio_pmodoled_dev);
dev_alloc_err:
	return status;
}
Example #16
0
static int __init pc8736x_gpio_init(void)
{
    int rc;
    dev_t devid;

    pdev = platform_device_alloc(DEVNAME, 0);
    if (!pdev)
        return -ENOMEM;

    rc = platform_device_add(pdev);
    if (rc) {
        rc = -ENODEV;
        goto undo_platform_dev_alloc;
    }
    dev_info(&pdev->dev, "NatSemi pc8736x GPIO Driver Initializing\n");

    if (!pc8736x_superio_present()) {
        rc = -ENODEV;
        dev_err(&pdev->dev, "no device found\n");
        goto undo_platform_dev_add;
    }
    pc8736x_gpio_ops.dev = &pdev->dev;

    /* Verify that chip and it's GPIO unit are both enabled.
       My BIOS does this, so I take minimum action here
     */
    rc = superio_inb(SIO_CF1);
    if (!(rc & 0x01)) {
        rc = -ENODEV;
        dev_err(&pdev->dev, "device not enabled\n");
        goto undo_platform_dev_add;
    }
    device_select(SIO_GPIO_UNIT);
    if (!superio_inb(SIO_UNIT_ACT)) {
        rc = -ENODEV;
        dev_err(&pdev->dev, "GPIO unit not enabled\n");
        goto undo_platform_dev_add;
    }

    /* read the GPIO unit base addr that chip responds to */
    pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8
                 | superio_inb(SIO_BASE_LADDR));

    if (!request_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE, DEVNAME)) {
        rc = -ENODEV;
        dev_err(&pdev->dev, "GPIO ioport %x busy\n",
            pc8736x_gpio_base);
        goto undo_platform_dev_add;
    }
    dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base);

    if (major) {
        devid = MKDEV(major, 0);
        rc = register_chrdev_region(devid, PC8736X_GPIO_CT, DEVNAME);
    } else {
        rc = alloc_chrdev_region(&devid, 0, PC8736X_GPIO_CT, DEVNAME);
        major = MAJOR(devid);
    }

    if (rc < 0) {
        dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc);
        goto undo_request_region;
    }
    if (!major) {
        major = rc;
        dev_dbg(&pdev->dev, "got dynamic major %d\n", major);
    }

    pc8736x_init_shadow();

    /* ignore minor errs, and succeed */
    cdev_init(&pc8736x_gpio_cdev, &pc8736x_gpio_fileops);
    cdev_add(&pc8736x_gpio_cdev, devid, PC8736X_GPIO_CT);

    return 0;

undo_request_region:
    release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE);
undo_platform_dev_add:
    platform_device_del(pdev);
undo_platform_dev_alloc:
    platform_device_put(pdev);

    return rc;
}
static int jpeg_probe(struct platform_device *pdev)
{

#ifdef CONFIG_OF

    int new_count;
    struct JpegDeviceStruct* jpegDev;
    struct device_node *node = NULL;

    new_count = nrJpegDevs + 1;
    gJpegqDevs = krealloc(gJpegqDevs, 
        sizeof(struct JpegDeviceStruct) * new_count, GFP_KERNEL);
    if (!gJpegqDevs) {
        dev_err(&pdev->dev, "Unable to allocate cam_isp_devs\n");
        return -ENOMEM;
    }

    jpegDev = &(gJpegqDevs[nrJpegDevs]);
    jpegDev->pDev = &pdev->dev;

    memset(&gJpegqDev, 0x0, sizeof(JpegDeviceStruct));

    node = of_find_compatible_node(NULL, NULL, "mediatek,JPGENC");
    jpegDev->encRegBaseVA = (unsigned long)of_iomap(node, 0);
    jpegDev->encIrqId = irq_of_parse_and_map(node, 0);

    node = of_find_compatible_node(NULL, NULL, "mediatek,JPGDEC");
    jpegDev->decRegBaseVA = (unsigned long)of_iomap(node, 0);
    jpegDev->decIrqId = irq_of_parse_and_map(node, 0);

    gJpegqDev = *jpegDev;

#else

    gJpegqDev.encRegBaseVA = (0L | 0xF7003000);
    gJpegqDev.decRegBaseVA = (0L | 0xF7004000);
    gJpegqDev.encIrqId = JPGENC_IRQ_BIT_ID;
    gJpegqDev.decIrqId = JPGDEC_IRQ_BIT_ID;

    gJpegqDev.pDev = &pdev->dev;

#endif

#ifdef JPEG_DEV    
	int ret;
    struct class_device *class_dev = NULL;
    
    JPEG_MSG("-------------jpeg driver probe-------\n");
	ret = alloc_chrdev_region(&jpeg_devno, 0, 1, JPEG_DEVNAME);

	if(ret)
	{
	    JPEG_ERR("Error: Can't Get Major number for JPEG Device\n");
	}
	else
	{
	    JPEG_MSG("Get JPEG Device Major number (%d)\n", jpeg_devno);
    }

	jpeg_cdev = cdev_alloc();
    jpeg_cdev->owner = THIS_MODULE;
	jpeg_cdev->ops = &jpeg_fops;

	ret = cdev_add(jpeg_cdev, jpeg_devno, 1);

    jpeg_class = class_create(THIS_MODULE, JPEG_DEVNAME);
    class_dev = (struct class_device *)device_create(jpeg_class, NULL, jpeg_devno, NULL, JPEG_DEVNAME);
#else
    
    proc_create("mtk_jpeg", 0, NULL, &jpeg_fops);

#endif

    spin_lock_init(&jpeg_dec_lock);
    spin_lock_init(&jpeg_enc_lock);

    // initial codec, register codec ISR
    dec_status = 0;
    enc_status = 0;
    _jpeg_dec_int_status = 0;
    _jpeg_enc_int_status = 0;
    _jpeg_dec_mode = 0;

#ifndef FPGA_VERSION

#ifdef JPEG_DEC_DRIVER
    init_waitqueue_head(&dec_wait_queue);
#endif    
    init_waitqueue_head(&enc_wait_queue);  
    
    //mt6575_irq_set_sens(MT6575_JPEG_CODEC_IRQ_ID, MT65xx_LEVEL_SENSITIVE);
    //mt6575_irq_set_polarity(MT6575_JPEG_CODEC_IRQ_ID, MT65xx_POLARITY_LOW);
    //mt6575_irq_unmask(MT6575_JPEG_CODEC_IRQ_ID);
    JPEG_MSG("request JPEG Encoder IRQ \n");
    enable_irq(gJpegqDev.encIrqId);
    if(request_irq(gJpegqDev.encIrqId, jpeg_drv_enc_isr, IRQF_TRIGGER_LOW, "jpeg_enc_driver" , NULL))
    //if(request_irq(JPGENC_IRQ_BIT_ID, jpeg_drv_enc_isr, /*IRQF_TRIGGER_RISING*/ IRQF_TRIGGER_HIGH, "jpeg_enc_driver" , NULL))
    //if(request_irq(JPGENC_IRQ_BIT_ID, jpeg_drv_enc_isr, IRQF_TRIGGER_RISING , "jpeg_enc_driver" , NULL))
    {
        JPEG_ERR("JPEG ENC Driver request irq failed\n");
    }

#ifdef JPEG_DEC_DRIVER    
    enable_irq(gJpegqDev.decIrqId);
    JPEG_MSG("request JPEG Decoder IRQ \n");
    //if(request_irq(JPGDEC_IRQ_BIT_ID, jpeg_drv_dec_isr, IRQF_TRIGGER_LOW, "jpeg_dec_driver" , NULL))
    //if(request_irq(JPGDEC_IRQ_BIT_ID, jpeg_drv_dec_isr, /*IRQF_TRIGGER_RISING*/ IRQF_TRIGGER_HIGH, "jpeg_dec_driver" , NULL))
    //if(request_irq(JPGDEC_IRQ_BIT_ID, jpeg_drv_dec_isr, IRQF_TRIGGER_RISING , "jpeg_dec_driver" , NULL))
    if(request_irq(gJpegqDev.decIrqId, jpeg_drv_dec_isr, IRQF_TRIGGER_FALLING , "jpeg_dec_driver" , NULL))
    {
        JPEG_ERR("JPEG DEC Driver request irq failed\n");
    }    
#endif    
    
#endif
	JPEG_MSG("JPEG Probe Done\n");

#ifdef JPEG_DEV    
	NOT_REFERENCED(class_dev);
#endif
	return 0;
}
Example #18
0
static int __devinit nvhost_user_init(struct nvhost_master *host)
{
	int i, err, devno;

	host->nvhost_class = class_create(THIS_MODULE, IFACE_NAME);
	if (IS_ERR(host->nvhost_class)) {
		err = PTR_ERR(host->nvhost_class);
		dev_err(&host->pdev->dev, "failed to create class\n");
		goto fail;
	}

	if (nvhost_major) {
		devno = MKDEV(nvhost_major, nvhost_minor);
		err = register_chrdev_region(devno, host->nb_channels + 1,
					     IFACE_NAME);
	} else {
		err = alloc_chrdev_region(&devno, nvhost_minor,
					host->nb_channels + 1, IFACE_NAME);
		nvhost_major = MAJOR(devno);
	}
	if (err < 0) {
		dev_err(&host->pdev->dev, "failed to reserve chrdev region\n");
		goto fail;
	}

	for (i = 0; i < host->nb_channels; i++) {
		struct nvhost_channel *ch = &host->channels[i];

		cdev_init(&ch->cdev, &nvhost_channelops);
		ch->cdev.owner = THIS_MODULE;

		devno = MKDEV(nvhost_major, nvhost_minor + i);
		err = cdev_add(&ch->cdev, devno, 1);
		if (err < 0) {
			dev_err(&host->pdev->dev, "failed to add chan %i cdev\n", i);
			goto fail;
		}
		ch->node = device_create(host->nvhost_class, NULL, devno, NULL,
				IFACE_NAME "-%s", ch->desc->name);
		if (IS_ERR(ch->node)) {
			err = PTR_ERR(ch->node);
			dev_err(&host->pdev->dev, "failed to create chan %i device\n", i);
			goto fail;
		}
	}

	cdev_init(&host->cdev, &nvhost_ctrlops);
	host->cdev.owner = THIS_MODULE;
	devno = MKDEV(nvhost_major, nvhost_minor + host->nb_channels);
	err = cdev_add(&host->cdev, devno, 1);
	if (err < 0)
		goto fail;
	host->ctrl = device_create(host->nvhost_class, NULL, devno, NULL,
			IFACE_NAME "-ctrl");
	if (IS_ERR(host->ctrl)) {
		err = PTR_ERR(host->ctrl);
		dev_err(&host->pdev->dev, "failed to create ctrl device\n");
		goto fail;
	}

	return 0;
fail:
	return err;
}
static long mtkfb_vsync_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	int ret = 0;
	MTKFB_VSYNC_FUNC();
	switch (cmd) {
	case MTKFB_VSYNC_IOCTL:
		{
			MTKFB_VSYNC_LOG("[MTKFB_VSYNC]: enter MTKFB_VSYNC_IOCTL %ld\n", arg);

#if defined(CONFIG_SINGLE_PANEL_OUTPUT)
			if (is_hdmi_active()) {
#else
			if (arg == MTKFB_VSYNC_SOURCE_HDMI) {
#endif
#if defined(CONFIG_MTK_HDMI_SUPPORT)
				if (down_interruptible(&mtkfb_vsync_sem)) {
					MTKFB_MSG("[mtkfb_vsync_ioctl] can't get semaphore,%d\n",
						  __LINE__);
					msleep(20);
					return ret;
				}
				hdmi_waitVsync();
				up(&mtkfb_vsync_sem);
				MTKFB_VSYNC_LOG("[MTKFB_VSYNC]: leave MTKFB_VSYNC_IOCTL, %d\n",
						__LINE__);
#else
				MTKFB_VSYNC_LOG("[MTKFB_VSYNC]: NS leave MTKFB_VSYNC_IOCTL, %d\n",
						__LINE__);
				ret = -EFAULT;
#endif
				return ret;
			}

			if (down_interruptible(&mtkfb_vsync_sem)) {
				MTKFB_MSG("[mtkfb_vsync_ioctl] can't get semaphore,%d\n", __LINE__);
				msleep(20);
				return ret;
			}
			mtkfb_waitVsync();
			up(&mtkfb_vsync_sem);
			MTKFB_VSYNC_LOG("[MTKFB_VSYNC]: leave MTKFB_VSYNC_IOCTL\n");
		}
		break;
	}
	return ret;
}


static const struct file_operations mtkfb_vsync_fops = {
	.owner = THIS_MODULE,
	.unlocked_ioctl = mtkfb_vsync_unlocked_ioctl,
	.open = mtkfb_vsync_open,
	.release = mtkfb_vsync_release,
	.flush = mtkfb_vsync_flush,
	.read = mtkfb_vsync_read,
};

static int mtkfb_vsync_probe(struct platform_device *pdev)
{
	struct class_device;
	struct class_device *class_dev = NULL;

	MTKFB_MSG("\n=== MTKFB_VSYNC probe ===\n");

	if (alloc_chrdev_region(&mtkfb_vsync_devno, 0, 1, MTKFB_VSYNC_DEVNAME)) {
		VSYNC_ERR("can't get device major number...\n");
		return -EFAULT;
	}

	MTKFB_MSG("get device major number (%d)\n", mtkfb_vsync_devno);

	mtkfb_vsync_cdev = cdev_alloc();
	mtkfb_vsync_cdev->owner = THIS_MODULE;
	mtkfb_vsync_cdev->ops = &mtkfb_vsync_fops;

	cdev_add(mtkfb_vsync_cdev, mtkfb_vsync_devno, 1);

	mtkfb_vsync_class = class_create(THIS_MODULE, MTKFB_VSYNC_DEVNAME);
	class_dev =
	    (struct class_device *)device_create(mtkfb_vsync_class, NULL, mtkfb_vsync_devno, NULL,
						 MTKFB_VSYNC_DEVNAME);

	VSYNC_INF("probe is done\n");
	return 0;
}

static int mtkfb_vsync_remove(struct platform_device *pdev)
{
	VSYNC_INF("device remove\n");
	return 0;
}
Example #20
0
int __init ar7240_simple_config_init(void)
{
    int req;

	/* restore factory default and system led */
	dev_t dev;
    int rt;
    int ar7240_gpio_major = gpio_major;
    int ar7240_gpio_minor = gpio_minor;

	init_timer(&rst_timer);
	rst_timer.function = check_rst;
	
#ifdef CONFIG_PID_MR302001
	printk("\n\nWhoops! This kernel is for product mr3020 v1.0!\n\n");
#endif
#ifdef CONFIG_PID_WR74104
	printk("\n\nWhoops! This kernel is for product wr741 v4.0!\n\n");
#endif
#ifdef CONFIG_PID_MR322001
	printk("\n\nWhoops! This kernel is for product mr3220 v1.0!\n\n");
#endif
#ifdef CONFIG_PID_MR322002
	printk("\n\nWhoops! This kernel is for product mr3220 v2.0!\n\n");
#endif
#ifdef CONFIG_PID_WR70301
	printk("\n\nWhoops! This kernel is for product wr703 v1.0!\n\n");
#endif

#ifdef SUPPORT_HARDWARE_MULTI_MODE
	/* added by ZCF, 20110420 */
	init_sysMode();
	init_timer(&sysMode_timer);
	sysMode_timer.function = check_sysMode;
	mod_timer(&sysMode_timer, jiffies + 1 * HZ);
#endif

#ifndef JUMPSTART_RST_MULTIPLEXED
#ifdef JUMPSTART_GPIO
	init_timer(&wps_timer);
	wps_timer.function = check_wps;
	/* This is NECESSARY, lsz 090109 */
	ar7240_gpio_config_input(JUMPSTART_GPIO);
	 /* configure JUMPSTART_GPIO as level triggered interrupt */
    	ar7240_gpio_config_int (JUMPSTART_GPIO, INT_TYPE_LEVEL, INT_POL_ACTIVE_HIGH);

	 req = request_irq (AR7240_GPIO_IRQn(JUMPSTART_GPIO), jumpstart_irq, 0,
                       "SW_JUMPSTART", NULL);
    if (req != 0)
	{
        printk (KERN_ERR "unable to request IRQ for SWJUMPSTART GPIO (error %d)\n", req);
    }
#endif
#endif

#ifdef GPIO_INTERNET_LED_BIT
	g_internetLedPin = GPIO_INTERNET_LED_BIT;
#endif
#ifdef AP_USB_LED_GPIO
	ar7240_gpio_config_output(AP_USB_LED_GPIO);
	/* init Internet LED status (off) */
	ar7240_gpio_out_val(AP_USB_LED_GPIO, USB_LED_OFF);
#endif

#ifdef GPIO_WLAN_LED_BIT
	/* init WLAN LED status (off) */
	ar7240_gpio_out_val(WLAN_LED_GPIO, WLAN_LED_OFF);
#endif

#ifdef SYS_LED_GPIO
	/* configure SYS_LED_GPIO as output led */
	ar7240_gpio_config_output(SYS_LED_GPIO);
	//ar7240_gpio_out_val(SYS_LED_GPIO, SYS_LED_OFF);
#endif

#ifdef GPIO_SLOW_ETH_LED
	init_timer(&slow_led_timer);
	slow_led_timer.function = slow_led_expire;
	mod_timer(&slow_led_timer, jiffies + 1 * HZ);
#endif

#ifdef GPIO_JUMPSTART_LED_BIT
	/* configure gpio as outputs */
    ar7240_gpio_config_output (TRICOLOR_LED_GREEN_PIN); 
    /* switch off the led */
    ar7240_gpio_out_val(TRICOLOR_LED_GREEN_PIN, OFF);
#endif

#ifdef GPIO_USB_POWER_SUPPORT
	/* configure gpio as outputs */
    ar7240_gpio_config_output (SYS_USB_POWER_GPIO); 
    /* power on usb modem */
    ar7240_gpio_out_val(SYS_USB_POWER_GPIO, USB_POWER_ON);
#endif

    create_simple_config_led_proc_entry ();

	ar7240_gpio_config_input(RST_DFT_GPIO);

	/* configure GPIO RST_DFT_GPIO as level triggered interrupt */
	ar7240_gpio_config_int (RST_DFT_GPIO, INT_TYPE_LEVEL, INT_POL_ACTIVE_HIGH);

    rt = request_irq (AR7240_GPIO_IRQn(RST_DFT_GPIO), rst_irq, 0,
                       "RESTORE_FACTORY_DEFAULT", NULL);
    if (rt != 0)
	{
        printk (KERN_ERR "unable to request IRQ for RESTORE_FACTORY_DEFAULT GPIO (error %d)\n", rt);
    }

    if (ar7240_gpio_major)
	{
        dev = MKDEV(ar7240_gpio_major, ar7240_gpio_minor);
        rt = register_chrdev_region(dev, 1, "ar7240_gpio_chrdev");
    }
	else
	{
        rt = alloc_chrdev_region(&dev, ar7240_gpio_minor, 1, "ar7240_gpio_chrdev");
        ar7240_gpio_major = MAJOR(dev);
    }

    if (rt < 0)
	{
        printk(KERN_WARNING "ar7240_gpio_chrdev : can`t get major %d\n", ar7240_gpio_major);
        return rt;
    }

    cdev_init (&gpio_device_cdev, &gpio_device_op);
    rt = cdev_add(&gpio_device_cdev, dev, 1);
	
    if (rt < 0) 
		printk(KERN_NOTICE "Error %d adding ar7240_gpio_chrdev ", rt);

    return 0;
}
Example #21
0
static int __init ofcd_init(void) /* Constructor */
{
	int err;
	printk(KERN_INFO DRV_NAME " : Registered\n");

	test_data.irq_pin = 46;
	test_data.gpio_pin = 38;
	test_data.led_pin = 54;

	if (alloc_chrdev_region(&first, 0, 1, "JON") < 0) { goto err_return;	}
	if ((cl = class_create(THIS_MODULE, "gpio-irq-test")) == NULL) { goto err_unregister_chrdev_return; }
	if (device_create(cl, NULL, first, NULL, "gpio-irq-test") == NULL) { goto err_class_destroy_return; }
	cdev_init(&c_dev, &pugs_fops);
	if (cdev_add(&c_dev, first, 1) == -1) { goto err_device_destroy_return; }

	/* Confiure GPIO Pins*/
	if (gpio_request(test_data.gpio_pin, "out pin")) {
		printk(KERN_ALERT DRV_NAME " : Unable to register output pin %d\n", test_data.gpio_pin);
		goto err_device_destroy_return;
	}

	if(gpio_request(test_data.led_pin, "led pin")) {
		printk(KERN_ALERT DRV_NAME " : Unable to register led pin %d\n", test_data.led_pin);
		goto err_free_outpin_return;
	}

	if (gpio_request(test_data.irq_pin, "irq pin")) {
		printk(KERN_ALERT DRV_NAME " : Unable to register irq pin %d\n", test_data.led_pin);
		goto err_free_ledpin_return;
	}

	gpio_direction_output(test_data.led_pin, 0);
	gpio_direction_output(test_data.gpio_pin, 0);
	gpio_direction_input(test_data.irq_pin);
	
	/* Confiure IRQ*/

   err = gpio_to_irq(test_data.irq_pin);
   if (err < 0) {
      printk(KERN_ALERT DRV_NAME " : failed to get IRQ for pin %d.\n", test_data.irq_pin);
      goto err_free_irqpin_return;
   } else {
      test_data.irq = (u16)err;
      err = 0;
   }

	err = request_any_context_irq(test_data.irq, gpio_test_irq_interrupt_handler, IRQF_TRIGGER_RISING | IRQF_DISABLED, DRV_NAME, (void*)&test_data);
   if (err < 0) {
      printk(KERN_ALERT DRV_NAME " : failed to enable IRQ %d for pin %d.\n", test_data.irq, test_data.irq_pin);
      goto err_free_irqpin_return;
   } else
      test_data.irq_enabled = 1;


	return 0;

/* Cleanup of registers */	
err_free_irqpin_return:
	gpio_free(test_data.irq_pin);
err_free_ledpin_return:
	gpio_free(test_data.led_pin);
err_free_outpin_return:
	gpio_free(test_data.gpio_pin);
err_device_destroy_return:	
	device_destroy(cl, first);
err_class_destroy_return:
	class_destroy(cl);
err_unregister_chrdev_return:
	unregister_chrdev_region(first, 1);
err_return:
	return -1;
}
Example #22
0
int cctdev_init_module(void)
{
	int result, i;
	dev_t dev = 0;
	char name[256];

	F_ENTER();

	/*
	 * Get a range of minor numbers to work with, asking for a dynamic
	 * major unless directed otherwise at load time.
	 */
	if (cctdev_major) {
		dev = MKDEV(cctdev_major, cctdev_minor);
		result = register_chrdev_region(dev, cctdev_nr_devs, "cctdev");
	} else {
		result = alloc_chrdev_region(&dev, cctdev_minor, cctdev_nr_devs,
					     "cctdev");
		cctdev_major = MAJOR(dev);
	}

	if (result < 0) {
		pr_warn("cctdev: can't get major %d\n",
		       cctdev_major);
		return result;
	}

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

	cctdev_class = class_create(THIS_MODULE, "cctdev");
	/* Initialize each device. */
	for (i = 0; i < cctdev_nr_devs; i++) {
		sprintf(name, "%s%d", "cctdev", i);
		mutex_init(&cctdev_devices[i].lock);
		cctdev_setup_cdev(&cctdev_devices[i], i);
		device_create(cctdev_class, NULL,
			      MKDEV(cctdev_major, cctdev_minor + i), NULL,
			      name);
	}

	/* At this point call the init function for any friend device */
	dev = MKDEV(cctdev_major, cctdev_minor + cctdev_nr_devs);

#ifdef cctdev_DEBUG		/* only when debugging */
	cctdev_create_proc();
#endif

	F_LEAVE();
	cctdev_ready = 1;
	return 0;		/* succeed */

fail:
	cctdev_cleanup_module();

	return result;
}
Example #23
0
/**
 * 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;
	}
	drv->pdata = pdev->dev.platform_data;

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

	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;
	}

	return 0;

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;
alloc_err:
	return -ENODEV;
}
Example #24
0
static int __init cs5535_gpio_init(void)
{
	dev_t	dev_id;
	u32	low, hi;
	int	retval;

	if (pci_dev_present(divil_pci) == 0) {
		printk(KERN_WARNING NAME ": DIVIL not found\n");
		return -ENODEV;
	}

	/* Grab the GPIO I/O range */
	rdmsr(MSR_LBAR_GPIO, low, hi);

	/* Check the mask and whether GPIO is enabled (sanity check) */
	if (hi != 0x0000f001) {
		printk(KERN_WARNING NAME ": GPIO not enabled\n");
		return -ENODEV;
	}

	/* Mask off the IO base address */
	gpio_base = low & 0x0000ff00;

	/**
	 * Some GPIO pins
	 *  31-29,23 : reserved (always mask out)
	 *  28       : Power Button
	 *  26       : PME#
	 *  22-16    : LPC
	 *  14,15    : SMBus
	 *  9,8      : UART1
	 *  7        : PCI INTB
	 *  3,4      : UART2/DDC
	 *  2        : IDE_IRQ0
	 *  0        : PCI INTA
	 *
	 * If a mask was not specified, be conservative and only allow:
	 *  1,2,5,6,10-13,24,25,27
	 */
	if (mask != 0)
		mask &= 0x1f7fffff;
	else
		mask = 0x0b003c66;

	if (request_region(gpio_base, CS5535_GPIO_SIZE, NAME) == 0) {
		printk(KERN_ERR NAME ": can't allocate I/O for GPIO\n");
		return -ENODEV;
	}

	if (major) {
		dev_id = MKDEV(major, 0);
		retval = register_chrdev_region(dev_id, CS5535_GPIO_COUNT,
						NAME);
	} else {
		retval = alloc_chrdev_region(&dev_id, 0, CS5535_GPIO_COUNT,
					     NAME);
		major = MAJOR(dev_id);
	}

	if (retval) {
		release_region(gpio_base, CS5535_GPIO_SIZE);
		return -1;
	}

	printk(KERN_DEBUG NAME ": base=%#x mask=%#lx major=%d\n",
	       gpio_base, mask, major);

	cdev_init(&cs5535_gpio_cdev, &cs5535_gpio_fops);
	cdev_add(&cs5535_gpio_cdev, dev_id, CS5535_GPIO_COUNT);

	return 0;
}
Example #25
0
static int rmidev_init_device(struct rmi_char_device *cd)
{
	struct rmi_device *rmi_dev = cd->rmi_dev;
	struct rmidev_data *data;
	dev_t dev_no;
	int retval;
	struct device *device_ptr;

	if (rmidev_major_num) {
		dev_no = MKDEV(rmidev_major_num, cd->rmi_dev->number);
		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(&rmi_dev->dev, "Major number of rmidev: %d\n",
				 rmidev_major_num);
	}
	if (retval < 0) {
		dev_err(&rmi_dev->dev,
			"Failed to get minor dev number %d, code %d.\n",
			cd->rmi_dev->number, retval);
		return retval;
	} else
		dev_info(&rmi_dev->dev, "Allocated rmidev %d %d.\n",
			 MAJOR(dev_no), MINOR(dev_no));

	data = kzalloc(sizeof(struct rmidev_data), GFP_KERNEL);
	if (!data) {
		dev_err(&rmi_dev->dev, "Failed to allocate rmidev_data.\n");
		/* unregister the char device region */
		__unregister_chrdev(rmidev_major_num, MINOR(dev_no), 1,
				CHAR_DEVICE_NAME);
		return -ENOMEM;
	}

	mutex_init(&data->file_mutex);

	data->rmi_dev = cd->rmi_dev;
	cd->data = data;

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

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

	dev_set_name(&cd->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(&cd->rmi_dev->dev, "Failed to create rmi device.\n");
		rmidev_device_cleanup(data);
		return -ENODEV;
	}

	return 0;
}
Example #26
0
/*****************************************************************************************
| Module initialization: Allocate device numbers, register device, setup ADC and timer |
| counter registers for 100 msec periodic sampling. |
*****************************************************************************************/
static int __init at91adc_init (void)
{
	int ret;

	// Dynamically allocate major number and minor number
	ret = alloc_chrdev_region(&at91adc_devno, // pointer to where the device number to be stored
	0, // first minor number requested
	1, // number of devices
	"at91adc"); // device name

	if (ret < 0)
	{
		printk(KERN_INFO "at91adc: Device number allocation failed\n");
		ret = -ENODEV;
		goto exit_1;
	}

	// Initialize cdev structure.
	cdev_init(&at91adc_cdev, // pointer to the cdev structure
	&at91adc_fops); // pointer to the file operations structure.
	at91adc_cdev.owner = THIS_MODULE;
	at91adc_cdev.ops = &at91adc_fops;

	// Register the device with kernel
	ret = cdev_add(&at91adc_cdev, // pointer to the initialized cdev structure
	at91adc_devno, // device number allocated
	1); // number of devices
	
	if (ret != 0)
	{
		printk(KERN_INFO "at91adc: Device registration failed\n");
		ret = -ECANCELED;
		goto exit_2;
	}

	// Character device driver initialization complete. Do device specific initialization now.

	// Allocate ring buffer memory for storing ADC values for both channels.
	at91adc_pbuf0 = (unsigned short *)kmalloc((MAX_ADCSAMPLES * sizeof(unsigned short)), // Number of bytes
	GFP_KERNEL); // Flags
	at91adc_pbuf1 = (unsigned short *)kmalloc((MAX_ADCSAMPLES * sizeof(unsigned short)), // Number of bytes
	GFP_KERNEL); // Flags
	at91adc_pbuf2 = (unsigned short *)kmalloc((MAX_ADCSAMPLES * sizeof(unsigned short)), // Number of bytes
	GFP_KERNEL); // Flags
	at91adc_pbuf3 = (unsigned short *)kmalloc((MAX_ADCSAMPLES * sizeof(unsigned short)), // Number of bytes
	GFP_KERNEL); // Flags
	if ((at91adc_pbuf0 == NULL) || (at91adc_pbuf1 == NULL) || (at91adc_pbuf2 == NULL) || (at91adc_pbuf3 == NULL))
	{
		printk(KERN_INFO "at91adc: Memory allocation failed\n");
		ret = -ECANCELED;
		goto exit_3;
	}

	// Initialize the ring buffer and append index.
	at91adc_appidx = MAX_ADCSAMPLES;
	for (ret = 0; ret < MAX_ADCSAMPLES; ret++)
	{
		at91adc_pbuf0[ret] = 0;
		at91adc_pbuf1[ret] = 0;
		at91adc_pbuf2[ret] = 0;
		at91adc_pbuf3[ret] = 0;
	}

	// Initialize ADC. The following two lines set the appropriate PMC bit
	// for the ADC. Easier than mapping PMC registers and then setting the bit.
	at91adc_clk = clk_get(NULL, // Device pointer - not required.
	"adc_clk"); // Clock name.
	clk_enable(at91adc_clk);

	// Map ADC registers to the current address space.
	at91adc_base = ioremap_nocache(AT91SAM9260_BASE_ADC, // Physical address
	64); // Number of bytes to be mapped.
	
	if (at91adc_base == NULL)
	{
		printk(KERN_INFO "at91adc: ADC memory mapping failed\n");
		ret = -EACCES;
		goto exit_4;
	}

	// MUX GPIO pins for ADC (peripheral A) operation
	at91_set_A_periph(AT91_PIN_PC0, 0);
	at91_set_A_periph(AT91_PIN_PC1, 0);
	at91_set_A_periph(AT91_PIN_PC2, 0);
	at91_set_A_periph(AT91_PIN_PC3, 0);

	// Reset the ADC
	iowrite32(AT91_ADC_SWRST, (at91adc_base + AT91_ADC_CR));

	// Enable all ADC channels
	iowrite32((AT91_ADC_CH(3) | AT91_ADC_CH(2) | AT91_ADC_CH(1) | AT91_ADC_CH(0)), (at91adc_base + AT91_ADC_CHER));

	// Configure ADC mode register.
	// From table 43-31 in page #775 and page#741 of AT91SAM9260 user manual:
	// Maximum ADC clock frequency = 5MHz = MCK / ((PRESCAL+1) * 2)
	// PRESCAL = ((MCK / 5MHz) / 2) -1 = ((100MHz / 5MHz)/2)-1) = 9
	// Maximum startup time = 15uS = (STARTUP+1)*8/ADC_CLOCK
	// STARTUP = ((15uS*ADC_CLOK)/8)-1 = ((15uS*5MHz)/8)-1 = 9
	// Minimum hold time = 1.2uS = (SHTIM+1)/ADC_CLOCK
	// SHTIM = (1.2uS*ADC_CLOCK)-1 = (1.2uS*5MHz)-1 = 5, Use 9 to ensure 2uS hold time.
	// Enable sleep mode and hardware trigger from TIOA output from TC0.
	iowrite32((AT91_ADC_TRGSEL_TC0 | AT91_ADC_SHTIM_(9) | AT91_ADC_STARTUP_(9) | AT91_ADC_PRESCAL_(9) |
	/*AT91_ADC_SLEEP |*/ AT91_ADC_TRGEN), (at91adc_base + AT91_ADC_MR));

	// Initialize Timer Counter module 0. The following two lines set the appropriate
	// PMC bit for TC0. Easier than mapping PMC registers and then setting the bit.
	at91tc0_clk = clk_get(NULL, // Device pointer - not required.
	"tc0_clk"); // Clock name.
	clk_enable(at91tc0_clk);

	// Map TC0 registers to the current address space.
	at91tc0_base = ioremap_nocache(AT91SAM9260_BASE_TC0, // Physical address
	64); // Number of bytes to be mapped.
	if (at91tc0_base == NULL)
	{
		printk(KERN_INFO "at91adc: TC0 memory mapping failed\n");
		ret = -EACCES;
		goto exit_5;
	}

	// Configure TC0 in waveform mode, TIMER_CLK1 and to generate interrupt on RC compare.
	// Load 50000 to RC so that with TIMER_CLK1 = MCK/2 = 50MHz, the interrupt will be
	// generated every 1/50MHz * 50000 = 20nS * 50000 = 1 milli second.
	// NOTE: Even though AT91_TC_RC is a 32-bit register, only 16-bits are programmble.

	//printk(KERN_INFO "RC: %08X\n",ioread32(at91tc0_base + AT91_TC_RC));
	//printk(KERN_INFO "CMR: %08X\n",ioread32(at91tc0_base + AT91_TC_CMR));
	//printk(KERN_INFO "IMR: %08X\n",ioread32(at91tc0_base + AT91_TC_IMR));
	//printk(KERN_INFO "BMR: %08X\n",ioread32(at91tc0_base + AT91_TC_BMR));
	//printk(KERN_INFO "SR: %08X\n",ioread32(at91tc0_base + AT91_TC_SR));

	iowrite32(1134 /*50000*/, (at91tc0_base + AT91_TC_RC));  /// konfiguracja timera 44khz jak zmiana to zmieniæ wartoœæ w rej AT91_TC_RC  // skopiowac do ioctl z odpowiednimi case'ami od argumentu arg. 
	iowrite32((AT91_TC_WAVE | AT91_TC_WAVESEL_UP_AUTO), (at91tc0_base + AT91_TC_CMR));
	iowrite32(AT91_TC_CPCS, (at91tc0_base + AT91_TC_IDR)); // wy³¹czane przerwanie od timera  
	iowrite32((AT91_TC_SWTRG | AT91_TC_CLKEN), (at91tc0_base + AT91_TC_CCR));

	// Install interrupt for TC0.
	ret = request_irq(AT91SAM9260_ID_TC0, // Interrupt number
	at91tc0_isr, // Pointer to the interrupt sub-routine
	IRQF_DISABLED | IRQF_NOBALANCING | IRQF_IRQPOLL, // Flags - fast, shared or contributing to entropy pool
	"at91adc", // Device name to show as owner in /proc/interrupts
	NULL); // Private data for shared interrupts

	ret = 0;
	
	if (ret != 0)
	{
		printk(KERN_INFO "at91adc: Timer interrupt request failed\n");
		ret = -EBUSY;
		goto exit_6;
	}

	printk(KERN_INFO "at91adc: Loaded module\n");
	return 0;

exit_6:
	iounmap(at91tc0_base);

exit_5:
	clk_disable(at91tc0_clk);
	iounmap(at91adc_base);

exit_4:
	clk_disable(at91adc_clk);

exit_3:
	kfree(at91adc_pbuf0);
	kfree(at91adc_pbuf1);
	kfree(at91adc_pbuf2);
	kfree(at91adc_pbuf3);

exit_2:
	// Free device number allocated.
	unregister_chrdev_region(at91adc_devno, // allocated device number
	1); // number of devices

exit_1:
	return ret;
}
Example #27
0
File: i2c_gvc.c Project: 7LK/McWRT
static int __init i2c_register( void )
{
    int res;
#ifdef CONFIG_ETRAX_I2C_DYN_ALLOC
    dev_t devt;
    struct cdev *my_i2cdev = NULL;
#endif

    res = i2c_init();

    if ( res < 0 )
    {
        return res;
    }

#ifdef CONFIG_ETRAX_I2C_DYN_ALLOC
    res = alloc_chrdev_region( &devt, 0, 1, i2c_name );

    if ( res < 0 )
    {
        printk( KERN_DEBUG "I2C: EI2CNOMNUMBR\n" );
        return ( res );
    }

    my_i2cdev = cdev_alloc();
    my_i2cdev->ops = &i2c_fops;
    my_i2cdev->owner = THIS_MODULE;

    /* make device "alive" */
    res = cdev_add( my_i2cdev, devt, 1 );

    if ( res < 0 )
    {
        printk( KERN_DEBUG "I2C: EI2CDADDFAIL\n" );
        return ( res );
    }

    int i2c_major = MAJOR( devt );
#else
    res = register_chrdev( I2C_MAJOR, i2c_name, &i2c_fops );

    if ( res < 0 )
    {
        printk( KERN_ERR "i2c: couldn't get a major number.\n" );
        return res;
    }
   
    int i2c_major = I2C_MAJOR;
#endif

    printk( KERN_INFO "I2C: driver v2.3, (c) 1999-2004 Axis Communications AB\n" );
    printk( KERN_INFO "I2C: Improvements by Geert Vancompernolle, Positive Going, BK srl\n" );

#ifdef CONFIG_ETRAX_I2C_SLAVE_DELAY
    printk( KERN_INFO "I2C: with master/slave delay patch\n" );
#endif

    i2c_class = class_create (THIS_MODULE, "i2c_etrax");
    device_create (i2c_class, NULL,
		   MKDEV(i2c_major,0), NULL, i2c_name);

    return ( 0 );
}   /* i2c_register */
Example #28
0
/**
 * This function is called by the PCI core when it has a struct pci_dev that it 
 * thinks the driver wants to control. It will allocate the memory for the struct
 * alt_up_pci_dev, initialize it correctly and dynamically allocate a character
 * device node.
 *
 * @param[in] dev The pointer to the pci device that evokes the probe function.
 * @param[in] id  The pci_id_table of the driver.
 * 
 * @return Return 0 on success.
 */
static int  __devinit alt_up_pci_probe (struct pci_dev *dev, const struct pci_device_id *id) {

	int i, retval = 0;

	// allocate the memory for the struct alt_up_pci_dev
	struct alt_up_pci_dev *mydev = kmalloc( sizeof(struct alt_up_pci_dev), GFP_KERNEL );
	if (mydev == NULL){
		printk(KERN_DEBUG "kmalloc() memory for struct alt_up_pci_dev failed. \n");
		goto err_alloc_dev;
	}
	
	// save the pointers for the future usage
	pci_set_drvdata(dev, (void *)mydev);
	mydev->pci_dev = dev;
	
	// wake up the device             
	retval = pci_enable_device(dev);
	if (retval) {
		printk(KERN_DEBUG "pci_enable_device() failed. \n");
		goto err_enable_device;
	}

	// enables bus-mastering for device dev       
	pci_set_master(dev);
	
	// reserved PCI I/O and memory resources
	retval = pci_request_regions(dev, DRV_NAME);
	if (retval) {
		printk(KERN_DEBUG "pci_request_regions() failed. \n");
		goto err_request_regions;
	}
			
	// set the DMA addressing limitation
	retval = pci_set_dma_mask(dev, DMA_BIT_MASK( pci_dma_bit_range ));
	if (retval) {
		printk(KERN_DEBUG "pci_set_dma_mask() failed. \n");
		goto err_set_dma_mask;      
	}

	retval = pci_set_consistent_dma_mask(dev,DMA_BIT_MASK( pci_dma_bit_range ));
	if(retval) {
		printk(KERN_DEBUG "pci_set_consistent_dma_mask() failed. \n");
		goto err_set_dma_mask;
	}

	// set __iomem address, accessed by ioread, iowrite
	for (i = 0; i < MAX_NUM_OF_BARS; i ++) {
		if ( pci_resource_end(dev, i) != pci_resource_start(dev, i) ){

			/* create a virtual mapping cookie for a PCI BAR, 
			 * second arg is BAR, third is maxlen (0 means complete BAR) */
			mydev->bar[i] = pci_iomap(dev, i, 0); 
			if( !mydev->bar[i] ){
				printk(KERN_DEBUG "pci_iomap() failed. \n");
				goto err_iomap;
			}
			
			printk(KERN_DEBUG DRV_NAME " BAR%d initialized.\n", i);
			mydev->bar_size[i] = pci_resource_end(dev, i) - pci_resource_start(dev, i) + 1;
			
		} else  mydev->bar[i] = NULL;
	}

	// initialize the alt_up_pci_dev struct
	retval = alt_up_pci_dev_init(mydev);
	if(retval) {
		printk(KERN_DEBUG "alt_up_pci_dev_init() failed. \n");
		goto err_dev_init;
	}
	
	// have MSI enabled on its device function    
	retval = pci_enable_msi(dev);
	if (retval) {
		printk(KERN_DEBUG "pci_enable_msi() failed. \n");
		goto err_enable_msi;        
	}
			
	// request irq line for interrupt
	mydev->irq_line = dev->irq;
	retval = request_irq((int)mydev->irq_line, (void*)alt_up_pci_irqhandler, IRQF_SHARED, DRV_NAME, (void *)mydev);
	if (retval) {
		printk(KERN_DEBUG "pci_request_irq() failed. \n");
		goto err_request_irq;
	}

	// write irq_line to the PCI configuration space
	retval = pci_write_config_byte(dev, PCI_INTERRUPT_LINE, mydev->irq_line);
	if (retval) {
		printk(KERN_DEBUG "pci_read_config() failed. \n");
		goto err_write_config;       
	}  

	/* dynamically allocate a character device node
	 * 0 : requested minor
	 * 1 : count 
	 */
	retval = alloc_chrdev_region(&mydev->cdev_no, 0, 1, DRV_NAME);
	if(retval) {
		printk(KERN_DEBUG "alloc_chrdev_region() failed. \n");
		goto err_alloc_chrdev;
	}

	// init the cdev
	cdev_init(&mydev->cdev, &alt_up_pci_fops);
	mydev->cdev.owner = THIS_MODULE;
	mydev->cdev.ops = &alt_up_pci_fops;
	
	// add the cdev to kernel, from now on, the driver is alive
	retval = cdev_add(&mydev->cdev, mydev->cdev_no, 1);   /* 1: count */
	if(retval) {
		printk(KERN_DEBUG "cdev_add() failed. \n");
		goto err_cdev_add;
	}
	
	return 0;
	
	
	//cdev_del(&mydev->cdev);
err_cdev_add:
	unregister_chrdev_region(mydev->cdev_no, 1);  
err_alloc_chrdev:

err_write_config:
	free_irq(mydev->irq_line, (void *)mydev);
err_request_irq:
	pci_disable_msi(dev);
err_enable_msi:
	alt_up_pci_dev_exit(mydev);
err_dev_init:
	for (i = 0; i < MAX_NUM_OF_BARS; i ++) {
		if( mydev->bar[i] != NULL )
			pci_iounmap(dev, mydev->bar[i]);
	}
	goto err_set_dma_mask;
err_iomap:     
	for ( i = i - 1; i >= 0; i --){
		if( mydev->bar[i] != NULL)
			pci_iounmap(dev, mydev->bar[i]);
	}
err_set_dma_mask:
	pci_release_regions(dev);
err_request_regions:
	pci_disable_device(dev);
err_enable_device:
	kfree(mydev);
err_alloc_dev:
	printk("alt_up_pci_probe() failed with error: %d \n ", retval);

	return retval;        
}
Example #29
0
static int __init i2c_flash_dev_init(void)
{
	int res;

	printk(KERN_INFO "i2c /dev entries driver\n");

	//res = register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops);
	//if (res)
		//goto out;
	if (alloc_chrdev_region(&i2c_flash_dev_number, 0, 1, DEVICE_NAME)) {
		printk(KERN_DEBUG "Can't registed device \"%s\"\n", DEVICE_NAME);
	}

	i2c_flash_dev_class = class_create(THIS_MODULE, DEVICE_NAME);

	/* Bind to already existing adapters right away */
	//i2c_for_each_dev(NULL, i2cdev_attach_adapter);
	i2c_flash_devp = kmalloc(sizeof(struct i2c_flash_dev), GFP_KERNEL);

	if (!i2c_flash_devp) {
		printk("Bad kmalloc on device \"%s\"\n", DEVICE_NAME);
		return -ENOMEM;
	}

	//request I/O region
	sprintf(i2c_flash_devp->name, DEVICE_NAME);

	//connect fops with the cdev
	cdev_init(&i2c_flash_devp->cdev, &My_fops);
	i2c_flash_devp->cdev.owner = THIS_MODULE;

	//connect the major/minor num to the cdev
	res = cdev_add(&i2c_flash_devp->cdev, MKDEV(MAJOR(i2c_flash_dev_number), 0), 1);

	if (res < 0) {
		printk("Bad cdev on device \"%s\"\n", DEVICE_NAME);
		return res;
	}

	//send uevents to udev to create /dev nodes
	device_create(i2c_flash_dev_class, NULL, MKDEV(MAJOR(i2c_flash_dev_number), 0), NULL, DEVICE_NAME);

	//instantiate current page to 0
	currPage = 0;

	//need to initialize the work queue
	i2c_flash_wqp = kmalloc(sizeof(struct i2c_flash_wq), GFP_KERNEL);
	i2c_flash_wqp->wq = create_singlethread_workqueue(WQUEUE_NAME);
	i2c_flash_wqp->size = 0;

	i2c_flash_queue_status = 0;
	i2c_flash_page_count = 0;

	i2c_flash_rbuf = NULL;
	i2c_flash_wbuf = NULL;	//buffers for read and write
	client = NULL;
	adap = NULL;

	printk("\nInitializing work_write!\n");
	INIT_WORK(&work_write, NULL);
	printk("\nInitializing work_read!\n");
	INIT_WORK(&work_read, NULL);

	printk("%s initialized.\n", DEVICE_NAME);

	return 0;

}
static int __init diagchar_init(void)
{
	dev_t dev;
	int error;

	DIAG_INFO("diagfwd initializing ..\n");
	driver = kzalloc(sizeof(struct diagchar_dev) + 5, GFP_KERNEL);

	if (driver) {
		driver->used = 0;
		timer_in_progress = 0;
		driver->debug_flag = 1;
		setup_timer(&drain_timer, drain_timer_func, 1234);
		driver->itemsize = itemsize;
		driver->poolsize = poolsize;
		driver->itemsize_hdlc = itemsize_hdlc;
		driver->poolsize_hdlc = poolsize_hdlc;
		driver->itemsize_write_struct = itemsize_write_struct;
		driver->poolsize_write_struct = poolsize_write_struct;
		driver->num_clients = max_clients;
		driver->logging_mode = USB_MODE;
		mutex_init(&driver->diagchar_mutex);
		init_waitqueue_head(&driver->wait_q);
		wake_lock_init(&driver->wake_lock, WAKE_LOCK_SUSPEND, "diagchar");

		INIT_WORK(&(driver->diag_drain_work), diag_drain_work_fn);
		INIT_WORK(&(driver->diag_read_smd_work), diag_read_smd_work_fn);
		INIT_WORK(&(driver->diag_read_smd_cntl_work),
						 diag_read_smd_cntl_work_fn);
		INIT_WORK(&(driver->diag_read_smd_qdsp_work),
			   diag_read_smd_qdsp_work_fn);
		INIT_WORK(&(driver->diag_read_smd_qdsp_cntl_work),
			   diag_read_smd_qdsp_cntl_work_fn);
		INIT_WORK(&(driver->diag_read_smd_wcnss_work),
			diag_read_smd_wcnss_work_fn);
		INIT_WORK(&(driver->diag_read_smd_wcnss_cntl_work),
			diag_read_smd_wcnss_cntl_work_fn);
#ifdef CONFIG_DIAG_SDIO_PIPE
		driver->num_mdmclients = 1;
		init_waitqueue_head(&driver->mdmwait_q);
		spin_lock_init(&driver->diagchar_lock);
		mutex_init(&driver->diagcharmdm_mutex);

		driver->num = 2;
#else
		driver->num = 1;
#endif
		diagfwd_init();
		if (chk_config_get_id() == AO8960_TOOLS_ID) {
			diagfwd_cntl_init();
			DIAGFWD_INFO("CNTL channel was enabled in the platform\n");
		} else
			DIAGFWD_INFO("CNTL channel was not enabled in the platform\n");

		diag_sdio_fn(INIT);
		pr_debug("diagchar initializing ..\n");
		driver->name = ((void *)driver) + sizeof(struct diagchar_dev);
		strlcpy(driver->name, "diag", 4);

		/* Get major number from kernel and initialize */
		error = alloc_chrdev_region(&dev, driver->minor_start,
					    driver->num, driver->name);
		if (!error) {
			driver->major = MAJOR(dev);
			driver->minor_start = MINOR(dev);
		} else {
			printk(KERN_INFO "Major number not allocated\n");
			goto fail;
		}
		driver->cdev = cdev_alloc();

#ifdef CONFIG_DIAG_SDIO_PIPE
		driver->cdev_mdm = cdev_alloc();
#endif
		error = diagchar_setup_cdev(dev);
		if (error)
			goto fail;
	} else {
		printk(KERN_INFO "kzalloc failed\n");
		goto fail;
	}

	DIAG_INFO("diagchar initialized\n");
	return 0;

fail:
	diagchar_cleanup();
	diagfwd_exit();
	diagfwd_cntl_exit();
	diag_sdio_fn(EXIT);
	return -1;
}