Esempio n. 1
0
static int sound_insert_unit(struct sound_unit **list, struct file_operations *fops, int index, int low, int top, const char *name, umode_t mode)
{
	struct sound_unit *s = kmalloc(sizeof(*s), GFP_KERNEL);
	int r;

	if (!s)
		return -ENOMEM;
		
	spin_lock(&sound_loader_lock);
	r = __sound_insert_unit(s, list, fops, index, low, top);
	spin_unlock(&sound_loader_lock);
	
	if (r < 0)
		goto fail;
	else if (r < SOUND_STEP)
		sprintf(s->name, "sound/%s", name);
	else
		sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP);

	devfs_mk_cdev(MKDEV(SOUND_MAJOR, s->unit_minor),
			S_IFCHR | mode, s->name);
	class_simple_device_add(sound_class, MKDEV(SOUND_MAJOR, s->unit_minor),
				NULL, s->name+6);
	return r;

 fail:
	kfree(s);
	return r;
}
Esempio n. 2
0
int init_module(void)
{
	int ret;
	dev_t dev = MKDEV(DVB_MAJOR, 0);

	if ((ret = register_chrdev_region(dev, 64, DEVICE_NAME)) != 0) {
		printk(KERN_INFO "td-dvb-fe: unable to get major %d\n", DVB_MAJOR);
		goto error;
	}

	cdev_init(&device_cdev, &fops);
	if ((ret = cdev_add(&device_cdev, dev, 64)) != 0) {
		printk(KERN_INFO "td-dvb-fe: unable to get major %d\n", DVB_MAJOR);
		goto error;
	}

	devfs_mk_dir("dvb");
	my_class = class_simple_create(THIS_MODULE, DEVICE_NAME);

	if (IS_ERR(my_class)) {
		ret = PTR_ERR(my_class);
		goto error;
	}

	devfs_mk_cdev(MKDEV(DVB_MAJOR, 3), S_IFCHR | S_IRUSR | S_IWUSR, "dvb/adapter0/frontend0");
	class_simple_device_add(my_class, MKDEV(DVB_MAJOR, 3), NULL, "dvb0.frontend0");

	printk(KERN_INFO "[td-dvb-fe] loaded\n");
	return 0;
error:
	cdev_del(&device_cdev);
	unregister_chrdev_region(dev, 64);
	return ret;
}
Esempio n. 3
0
static int init_kb(void)
{
	unsigned int ret;
	kb_file_ops.owner = THIS_MODULE,
	kb_file_ops.read = kb_read;
	kb_file_ops.open = kb_open;
	kb_file_ops.release = kb_release;
     	/*kb_drv.driver.name = "mykb";
	kb_drv.interrupt   =  kb_interrupt;
	kb_drv.connect	   =  kb_connect; 	 */
	
        ret=alloc_chrdev_region(&mydev,0,1,"mykb");

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

        /* Let's Start Udev stuff */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
        veda_class = class_simple_create(THIS_MODULE,"Veda");
        if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }

        class_simple_device_add(veda_class,mydev,NULL,"mykb");
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
        veda_class = class_create(THIS_MODULE,"Veda");
        if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }

        device_create(veda_class,NULL,mydev,NULL,"mykb");
#endif

        /*Register our character Device*/
        veda_cdev= cdev_alloc();


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

        ret=cdev_add(veda_cdev,mydev,1);
        if( ret < 0 ) {
                printk("Error registering device driver\n");
                return ret;
        }
        printk("Device Registered with MAJOR NO[%d]\n",kb_id);
	
      if(request_irq(KB_INT,kb_interrupt,IRQF_SHARED, "mykb",(void *)&some_data)){
                printk(KERN_ERR "mykb: cannot register IRQ %d\n", 8);
                return -EIO;
        }
	init_waitqueue_head( &mykb_queue );

        printk("mykb interrupt registered\n");

	return 0;
}
Esempio n. 4
0
int kb_init(void)
{	
	unsigned int ret;
	inuse = 0;
	 kb_file_ops.owner = THIS_MODULE,
        kb_file_ops.read = kb_read;
        kb_file_ops.open = kb_open;
        kb_file_ops.release = kb_release;

	ret = alloc_chrdev_region(&mydev,0,1,"mykb");
	char_device_id = MAJOR(mydev);

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
        veda_class = class_simple_create(THIS_MODULE,"Veda");
        if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }

        class_simple_device_add(veda_class,mydev,NULL,"mykb");
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
        veda_class = class_create(THIS_MODULE,"Veda");
        if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }

        device_create(veda_class,NULL,mydev,"mykb");
#endif


 /*Register our character Device*/
	veda_cdev = cdev_alloc();

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

	ret = cdev_add(veda_cdev, mydev, 1);

	init_waitqueue_head(&kb_queue);	


	 if( ret < 0 ) {
	 printk("Error registering device driver\n");
	  return ret;
 }
    

	printk("\n Device Regitered with id : %d",char_device_id);	

if(request_irq(KB_INT,kb_interrupt,IRQF_SHARED, "mykb",(void *)&some_data)){
		printk(KERN_ERR "mykb: cannot register IRQ %d\n", 8);
		return -EIO;
	}
	printk("\n mykb interrupt registered\n");
	return 0;
}
Esempio n. 5
0
int init_char_device(void)
{
	int i,ret;
	char_device_file_ops.owner = THIS_MODULE;
	char_device_file_ops.read = char_device_read;
	char_device_file_ops.write = char_device_write;
	char_device_file_ops.open = char_device_open;
	char_device_file_ops.release = char_device_release;
	char_device_file_ops.llseek = char_device_lseek;
	char_device_file_ops.aio_read = char_device_aio_read;
	char_device_file_ops.aio_write = char_device_aio_write;
 
	ret=alloc_chrdev_region(&mydev,0,1,"veda_cdrv");

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


#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
        veda_class = class_simple_create(THIS_MODULE,"Veda");
        if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }

        class_simple_device_add(veda_class,mydev,NULL,"veda_cdrv");
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
        veda_class=class_create(THIS_MODULE,"Veda");

        if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }

        device_create(veda_class,NULL,mydev,NULL,"veda_cdrv");
#endif


	/*Register our character Device*/
	veda_cdev= cdev_alloc();

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


	ret=cdev_add(veda_cdev,mydev,1);

	
	if( ret < 0 ) {
		printk("Error registering device driver\n");
		return ret;
	}
	printk("Device Registered with MAJOR NO[%d]\n",char_device_id); 
	
	for(i=0; i<MAX_LENGTH; i++) char_device_buf[i] = 0;
	char_device_buf[MAX_LENGTH] = '\0';
	return 0;
}
Esempio n. 6
0
static int cpuid_class_simple_device_add(int i) 
{
	int err = 0;
	struct class_device *class_err;

	class_err = class_simple_device_add(cpuid_class, MKDEV(CPUID_MAJOR, i), NULL, "cpu%d",i);
	if (IS_ERR(class_err))
		err = PTR_ERR(class_err);
	return err;
}
Esempio n. 7
0
int __init gbshm_init(void)
{
	int err = 0;

	/* cut-and-paste above as part of adding support for more than 2 blocks */

	gbshm_major = register_chrdev(0, "vidctl", &gbshm_fxns);

	if (gbshm_major < 0) {
		__E("Failed to allocate major number.\n");
		return -ENODEV;
	}

	__D("Allocated major number: %d\n", gbshm_major);

#if (USE_UDEV==1)
#ifdef USE_CLASS_SIMPLE
	gbshm_class = class_simple_create(THIS_MODULE, "gbshm");
#else
	gbshm_class = class_create(THIS_MODULE, "gbshm");
#endif
	if (IS_ERR(gbshm_class)) {
		__E("Error creating cmem device class.\n");
		err = -EIO;
		return err;
	}

#ifdef USE_CLASS_SIMPLE
	class_simple_device_add(gbshm_class, MKDEV(gbshm_major, 0), NULL, "gbshm");
#else
#ifdef USE_CLASS_DEVICE
	class_device_create(gbshm_class, NULL, MKDEV(gbshm_major, 0), NULL, "gbshm");
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
	device_create(gbshm_class, NULL, MKDEV(gbshm_major, 0), NULL, "gbshm");
#else
	device_create(gbshm_class, NULL, MKDEV(gbshm_major, 0), "gbshm");
#endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
#endif // USE_CLASS_DEVICE
#endif // USE_CLASS_SIMPLE
#endif // USE_UDEV

	/* Create the /proc entry */

	printk(KERN_INFO "vidctl initialized\n");


	//set_reg();
	//printk_reg();
	//tvp5150_set_input_mux(0);

	return 0;

}
Esempio n. 8
0
 int init_char_device(void)
{
	int i,ret;
	char_device_file_ops.owner = THIS_MODULE;
	char_device_file_ops.read = char_device_read;
	char_device_file_ops.write = char_device_write;
	char_device_file_ops.open = char_device_open;
	char_device_file_ops.release = char_device_release;
	char_device_file_ops.llseek = char_device_lseek;
 
	ret=alloc_chrdev_region(&mydev,0,1,CHAR_DEVICE_NAME);/* allocating major number and no. of minor numbers (in mydev) to my char driver name sc CHAR_DEVICE_NAME */

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

	/* Let's Start Udev stuff */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
	veda_class = class_simple_create(THIS_MODULE,"Veda");
	if(IS_ERR(veda_class)){
		printk(KERN_ERR "Error registering veda class\n");
	}
	
	class_simple_device_add(veda_class,mydev,NULL,"veda_cdrv");
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
	veda_class=class_create(THIS_MODULE,"Veda");

	if(IS_ERR(veda_class)){
                printk(KERN_ERR "Error registering veda class\n");
        }
      
	device_create(veda_class,NULL,mydev,"veda_cdrv");/*This function args are changed after 2.6.18 kernel (ref:drivers/base/class.c" 914L)*/
#endif	
	/*Register our character Device*/
	veda_cdev= cdev_alloc();

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

	ret=cdev_add(veda_cdev,mydev,1);
	if( ret < 0 ) {
		printk("Error registering device driver\n");
		return ret;
	}
	printk("Device Registered with MAJOR NO[%d]\n",char_device_id); 
	
	for(i=0; i<MAX_LENGTH; i++) char_device_buf[i] = 0;
	char_device_buf[MAX_LENGTH] = '\0';
	return 0;
}
Esempio n. 9
0
static void
adbdev_init(void)
{
	if (register_chrdev(ADB_MAJOR, "adb", &adb_fops)) {
		printk(KERN_ERR "adb: unable to get major %d\n", ADB_MAJOR);
		return;
	}

	devfs_mk_cdev(MKDEV(ADB_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR, "adb");

	adb_dev_class = class_simple_create(THIS_MODULE, "adb");
	if (IS_ERR(adb_dev_class)) {
		return;
	}
	class_simple_device_add(adb_dev_class, MKDEV(ADB_MAJOR, 0), NULL, "adb");
}
Esempio n. 10
0
static int __init chr_dev_init(void)
{
	int i;

	if (register_chrdev(MEM_MAJOR,"mem",&memory_fops))
		printk("unable to get major %d for memory devs\n", MEM_MAJOR);

	mem_class = class_simple_create(THIS_MODULE, "mem");
	for (i = 0; i < ARRAY_SIZE(devlist); i++) {
		class_simple_device_add(mem_class,
					MKDEV(MEM_MAJOR, devlist[i].minor),
					NULL, devlist[i].name);
		devfs_mk_cdev(MKDEV(MEM_MAJOR, devlist[i].minor),
				S_IFCHR | devlist[i].mode, devlist[i].name);
	}
	
	return 0;
}
Esempio n. 11
0
static int __init mod_init(void)
{
    int i;

    banner();

    major = register_chrdev(0, "edma", &fops);

    __D("edma registered major = %d\n", major);

#ifdef USE_CLASS_SIMPLE
    dma_class = class_simple_create(THIS_MODULE, "edma");
    class_simple_device_add(dma_class, MKDEV(major, 0), NULL, "edma");
#else
#ifdef USE_CLASS_DEVICE
    dma_class = class_create(THIS_MODULE, "edma");
    class_device_create(dma_class, NULL, MKDEV(major, 0), NULL, "edma");
#else
    dma_class = class_create(THIS_MODULE, "edma");
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
    device_create(dma_class, NULL, MKDEV(major, 0), NULL, "edma");
#else
    device_create(dma_class, NULL, MKDEV(major, 0), "edma");
#endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
#endif // USE_CLASS_DEVICE
#endif // USE_CLASS_SIMPLE

    __D("initializing channel owner array...\n");

    for (i = 0; i < NCHAN; i++) {
        INIT_LIST_HEAD(&channels[i].users);
        channels[i].nParam = 0;
        channels[i].isParam = 0;
    }

    mutex_init(&edma_mutex);

    return 0;
}
Esempio n. 12
0
static int __init dsp56k_init_driver(void)
{
	int err = 0;

	if(!MACH_IS_ATARI || !ATARIHW_PRESENT(DSP56K)) {
		printk("DSP56k driver: Hardware not present\n");
		return -ENODEV;
	}

	if(register_chrdev(DSP56K_MAJOR, "dsp56k", &dsp56k_fops)) {
		printk("DSP56k driver: Unable to register driver\n");
		return -ENODEV;
	}
	dsp56k_class = class_simple_create(THIS_MODULE, "dsp56k");
	if (IS_ERR(dsp56k_class)) {
		err = PTR_ERR(dsp56k_class);
		goto out_chrdev;
	}
	class_simple_device_add(dsp56k_class, MKDEV(DSP56K_MAJOR, 0), NULL, "dsp56k");

	err = devfs_mk_cdev(MKDEV(DSP56K_MAJOR, 0),
		      S_IFCHR | S_IRUSR | S_IWUSR, "dsp56k");
	if(err)
		goto out_class;

	printk(banner);
	goto out;

out_class:
	class_simple_device_remove(MKDEV(DSP56K_MAJOR, 0));
	class_simple_destroy(dsp56k_class);
out_chrdev:
	unregister_chrdev(DSP56K_MAJOR, "dsp56k");
out:
	return err;
}
Esempio n. 13
0
/*
 * scdrv_init
 *
 * Called at boot time to initialize the system controller communication
 * facility.
 */
int __init
scdrv_init(void)
{
	geoid_t geoid;
	cmoduleid_t cmod;
	int i;
	char devname[32];
	char *devnamep;
	module_t *m;
	struct sysctl_data_s *scd;
	void *salbuf;
	struct class_simple *snsc_class;
	dev_t first_dev, dev;

	if (alloc_chrdev_region(&first_dev, 0, (MAX_SLABS*nummodules),
				SYSCTL_BASENAME) < 0) {
		printk("%s: failed to register SN system controller device\n",
		       __FUNCTION__);
		return -ENODEV;
	}
	snsc_class = class_simple_create(THIS_MODULE, SYSCTL_BASENAME);

	for (cmod = 0; cmod < nummodules; cmod++) {
		m = sn_modules[cmod];
		for (i = 0; i <= MAX_SLABS; i++) {

			if (m->nodes[i] == -1) {
				/* node is not alive in module */
				continue;
			}

			geoid = m->geoid[i];
			devnamep = devname;
			format_module_id(devnamep, geo_module(geoid),
					 MODULE_FORMAT_BRIEF);
			devnamep = devname + strlen(devname);
			sprintf(devnamep, "#%d", geo_slab(geoid));

			/* allocate sysctl device data */
			scd = kmalloc(sizeof (struct sysctl_data_s),
				      GFP_KERNEL);
			if (!scd) {
				printk("%s: failed to allocate device info"
				       "for %s/%s\n", __FUNCTION__,
				       SYSCTL_BASENAME, devname);
				continue;
			}
			memset(scd, 0, sizeof (struct sysctl_data_s));

			/* initialize sysctl device data fields */
			scd->scd_nasid = cnodeid_to_nasid(m->nodes[i]);
			if (!(salbuf = kmalloc(SCDRV_BUFSZ, GFP_KERNEL))) {
				printk("%s: failed to allocate driver buffer"
				       "(%s%s)\n", __FUNCTION__,
				       SYSCTL_BASENAME, devname);
				kfree(scd);
				continue;
			}

			if (ia64_sn_irtr_init(scd->scd_nasid, salbuf,
					      SCDRV_BUFSZ) < 0) {
				printk
				    ("%s: failed to initialize SAL for"
				     " system controller communication"
				     " (%s/%s): outdated PROM?\n",
				     __FUNCTION__, SYSCTL_BASENAME, devname);
				kfree(scd);
				kfree(salbuf);
				continue;
			}

			dev = first_dev + m->nodes[i];
			cdev_init(&scd->scd_cdev, &scdrv_fops);
			if (cdev_add(&scd->scd_cdev, dev, 1)) {
				printk("%s: failed to register system"
				       " controller device (%s%s)\n",
				       __FUNCTION__, SYSCTL_BASENAME, devname);
				kfree(scd);
				kfree(salbuf);
				continue;
			}

			class_simple_device_add(snsc_class, dev, NULL,
						"%s", devname);

			ia64_sn_irtr_intr_enable(scd->scd_nasid,
						 0 /*ignored */ ,
						 SAL_IROUTER_INTR_RECV);
		}
	}
	return 0;
}
Esempio n. 14
0
int ndas_ctrldev_init(void)
{
	int ret = 0;

#ifdef NDAS_DEVFS
        // Create control device file
	devfs_control_handle = devfs_register(NULL, "ndas",
		DEVFS_FL_DEFAULT, NDAS_CHR_DEV_MAJOR, 0,
		S_IFCHR | S_IRUGO | S_IWUGO,
		&ndasctrl_fops, NULL);

	if (!devfs_control_handle) {
		printk(KERN_ERR "Failed to register control device file\n");
		return -EBUSY;
	}
#else
    ret = register_chrdev(NDAS_CHR_DEV_MAJOR, "ndas", &ndasctrl_fops);
    if (ret < 0) { 
        printk(KERN_ERR "ndas: can't register char device\n");
        return ret;
    }
#endif

#if LINUX_VERSION_25_ABOVE 
#if LINUX_VERSION_HAS_CLASS_CREATE 
    ndas_ctrldev_class = class_create(THIS_MODULE, "ndas");
    if (IS_ERR(ndas_ctrldev_class)) {
#ifdef NDAS_DEVFS
		devfs_unregister(devfs_control_handle);
#else
		unregister_chrdev(NDAS_CHR_DEV_MAJOR, "ndas");
#endif
        return PTR_ERR(ndas_ctrldev_class);
    }

#if LINUX_VERSION_HAS_DEVICE_CREATE
#if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28) )
	device_create(
#else
    device_create_drvdata(
#endif // Linux 2.6.28 (device_create_drvdata deprecated, now removed)
		ndas_ctrldev_class, NULL,
        MKDEV(NDAS_CHR_DEV_MAJOR, NDAS_CHR_DEV_MINOR),
        NULL, "ndas");
#else
    class_device_create(ndas_ctrldev_class, NULL,
        MKDEV(NDAS_CHR_DEV_MAJOR, NDAS_CHR_DEV_MINOR),
        NULL, "ndas");
#endif //#if LINUX_VERSION_HAS_DEVICE_CREATE

#else 
    ndas_ctrldev_class = class_simple_create(THIS_MODULE, "ndas");
    if (IS_ERR(ndas_ctrldev_class)) {
#ifdef NDAS_DEVFS
		devfs_unregister(devfs_control_handle);
#else
		unregister_chrdev(NDAS_CHR_DEV_MAJOR, "ndas");
#endif
        return PTR_ERR(ndas_ctrldev_class);
    }
    class_simple_device_add(ndas_ctrldev_class,
        MKDEV(NDAS_CHR_DEV_MAJOR, NDAS_CHR_DEV_MINOR),
        NULL, "ndas");
#endif  /* LINUX_VERSION_HAS_CLASS_CREATE */
#endif /* LINUX_VERSION_25_ABOVE  */

    return ret;
}
Esempio n. 15
0
/**
 * usb_register_dev - register a USB device, and ask for a minor number
 * @intf: pointer to the usb_interface that is being registered
 * @class_driver: pointer to the usb_class_driver for this device
 *
 * This should be called by all USB drivers that use the USB major number.
 * If CONFIG_USB_DYNAMIC_MINORS is enabled, the minor number will be
 * dynamically allocated out of the list of available ones.  If it is not
 * enabled, the minor number will be based on the next available free minor,
 * starting at the class_driver->minor_base.
 *
 * This function also creates the devfs file for the usb device, if devfs
 * is enabled, and creates a usb class device in the sysfs tree.
 *
 * usb_deregister_dev() must be called when the driver is done with
 * the minor numbers given out by this function.
 *
 * Returns -EINVAL if something bad happens with trying to register a
 * device, and 0 on success.
 */
int usb_register_dev(struct usb_interface *intf,
		     struct usb_class_driver *class_driver)
{
	int retval = -EINVAL;
	int minor_base = class_driver->minor_base;
	int minor = 0;
	char name[BUS_ID_SIZE];
	char *temp;

#ifdef CONFIG_USB_DYNAMIC_MINORS
	/* 
	 * We don't care what the device tries to start at, we want to start
	 * at zero to pack the devices into the smallest available space with
	 * no holes in the minor range.
	 */
	minor_base = 0;
#endif
	intf->minor = -1;

	dbg ("looking for a minor, starting at %d", minor_base);

	if (class_driver->fops == NULL)
		goto exit;

	spin_lock (&minor_lock);
	for (minor = minor_base; minor < MAX_USB_MINORS; ++minor) {
		if (usb_minors[minor])
			continue;

		usb_minors[minor] = class_driver->fops;

		retval = 0;
		break;
	}
	spin_unlock (&minor_lock);

	if (retval)
		goto exit;

	intf->minor = minor;

	/* handle the devfs registration */
	snprintf(name, BUS_ID_SIZE, class_driver->name, minor - minor_base);
	devfs_mk_cdev(MKDEV(USB_MAJOR, minor), class_driver->mode, name);

	/* create a usb class device for this usb interface */
	temp = strrchr(name, '/');
	if (temp && (temp[1] != 0x00))
		++temp;
	else
		temp = name;
	intf->class_dev = class_simple_device_add(usb_class, MKDEV(USB_MAJOR, minor), &intf->dev, "%s", temp);
	if (IS_ERR(intf->class_dev)) {
		spin_lock (&minor_lock);
		usb_minors[intf->minor] = NULL;
		spin_unlock (&minor_lock);
		devfs_remove (name);
		retval = PTR_ERR(intf->class_dev);
	}
exit:
	return retval;
}
Esempio n. 16
0
/*
 * scdrv_init
 *
 * Called at boot time to initialize the system controller communication
 * facility.
 */
int __init
scdrv_init(void)
{
	geoid_t geoid;
	cnodeid_t cnode;
	char devname[32];
	char *devnamep;
	struct sysctl_data_s *scd;
	void *salbuf;
	struct class_simple *snsc_class;
	dev_t first_dev, dev;
	nasid_t event_nasid = ia64_sn_get_console_nasid();

	if (alloc_chrdev_region(&first_dev, 0, numionodes,
				SYSCTL_BASENAME) < 0) {
		printk("%s: failed to register SN system controller device\n",
		       __FUNCTION__);
		return -ENODEV;
	}
	snsc_class = class_simple_create(THIS_MODULE, SYSCTL_BASENAME);

	for (cnode = 0; cnode < numionodes; cnode++) {
			geoid = cnodeid_get_geoid(cnode);
			devnamep = devname;
			format_module_id(devnamep, geo_module(geoid),
					 MODULE_FORMAT_BRIEF);
			devnamep = devname + strlen(devname);
			sprintf(devnamep, "#%d", geo_slab(geoid));

			/* allocate sysctl device data */
			scd = kmalloc(sizeof (struct sysctl_data_s),
				      GFP_KERNEL);
			if (!scd) {
				printk("%s: failed to allocate device info"
				       "for %s/%s\n", __FUNCTION__,
				       SYSCTL_BASENAME, devname);
				continue;
			}
			memset(scd, 0, sizeof (struct sysctl_data_s));

			/* initialize sysctl device data fields */
			scd->scd_nasid = cnodeid_to_nasid(cnode);
			if (!(salbuf = kmalloc(SCDRV_BUFSZ, GFP_KERNEL))) {
				printk("%s: failed to allocate driver buffer"
				       "(%s%s)\n", __FUNCTION__,
				       SYSCTL_BASENAME, devname);
				kfree(scd);
				continue;
			}

			if (ia64_sn_irtr_init(scd->scd_nasid, salbuf,
					      SCDRV_BUFSZ) < 0) {
				printk
				    ("%s: failed to initialize SAL for"
				     " system controller communication"
				     " (%s/%s): outdated PROM?\n",
				     __FUNCTION__, SYSCTL_BASENAME, devname);
				kfree(scd);
				kfree(salbuf);
				continue;
			}

			dev = first_dev + cnode;
			cdev_init(&scd->scd_cdev, &scdrv_fops);
			if (cdev_add(&scd->scd_cdev, dev, 1)) {
				printk("%s: failed to register system"
				       " controller device (%s%s)\n",
				       __FUNCTION__, SYSCTL_BASENAME, devname);
				kfree(scd);
				kfree(salbuf);
				continue;
			}

			class_simple_device_add(snsc_class, dev, NULL,
						"%s", devname);

			ia64_sn_irtr_intr_enable(scd->scd_nasid,
						 0 /*ignored */ ,
						 SAL_IROUTER_INTR_RECV);

                        /* on the console nasid, prepare to receive
                         * system controller environmental events
                         */
                        if(scd->scd_nasid == event_nasid) {
                                scdrv_event_init(scd);
                        }
	}
	return 0;
}
Esempio n. 17
0
static int dvblo_chardev_init(struct dvblo_chardev *chardev, struct dvblo_chardev_config *cfg)
{
	int rv = SUCCESS, i;
	
	if(chardev->used != 0) {
		rv = -EINVAL;
	} else {
		chardev->used = 1;
		chardev->initlev = 0;
		chardev->initdone = 0;
		do {
			dprintk(DBGLEV_ALL, "initializing char device with minor device number %u\n", chardev->minor);
			i = snprintf(chardev->name, sizeof(chardev->name), DVBLO_NAME "%d", chardev->minor);
			if(i < 0 || i >= sizeof(chardev->name)) {
				if(i < 0)
					rv = i;
				else
					rv = -ENOBUFS;
				break;
			}
			
			chardev->hcount = 0;
			chardev->cfg.ts_sz = DVBLO_TS_SZ;
			chardev->cfg.hwrbuf_sz = 20 * chardev->cfg.ts_sz;
			
			i = dvblo_adap_create(chardev->minor, cfg ? &cfg->dvbcfg : NULL, &chardev->dvblo);
			if(i < 0) {
				mprintk(KERN_ALERT, "failed to create virtual DVB adapter: %d\n", i);
				rv = i;
				break;
			}
			chardev->initlev++;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
			/* In 2.6.15, class_device_create() got a pointer to the parent device (if any) as its second param */ 
			chardev->clsdev = class_device_create(dvblo_class, NULL, MKDEV(dvblo_char_major, chardev->minor), NULL, chardev->name);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
			/* class_device_create() first appeared in 2.6.13 */
			chardev->clsdev = class_device_create(dvblo_class, MKDEV(dvblo_char_major, chardev->minor), NULL, chardev->name);
#else
			/* The old-style "simple" class API */
			chardev->clsdev = class_simple_device_add(dvblo_class, MKDEV(dvblo_char_major, chardev->minor), NULL, chardev->name);
#endif
			if(IS_ERR(chardev->clsdev)) {
				rv = PTR_ERR(chardev->clsdev);
				mprintk(KERN_ALERT, "failed to create device class \"%s\": %d\n", chardev->name, rv);
				break;
			}
			chardev->initlev++;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
			for(i=0; i<(sizeof(clsdev_attrs)/sizeof(clsdev_attrs[0])) && rv == SUCCESS; i++)
				rv = class_device_create_file(chardev->clsdev, &clsdev_attrs[i]);
			if(rv != SUCCESS)
				break;
#endif
			chardev->initlev++;
			mprintk(KERN_INFO, "added character device %s\n", chardev->name);
		} while(0);
		if(rv != 0)
			dvblo_chardev_release(chardev); // error cleanup
	}
	return rv;
}
Esempio n. 18
0
static int init_char_device(void)
{
	unsigned int i,ret;

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

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

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

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

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

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


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


	for(i=0;i<3;i++)
        	ret=cdev_add(veda_cdev,MKDEV(char_device_id,i),3);
        if( ret < 0 ) {
                printk("Error registering device driver\n");
                return ret;
        }
        printk("Device Registered with MAJOR NO[%d]\n",char_device_id);
	
	for(i=0; i<MAX_LENGTH; i++) char_device_buf_minor0[i] = 0;
	for(i=0; i<MAX_LENGTH; i++) char_device_buf_minor1[i] = 0;
	for(i=0; i<MAX_LENGTH; i++) char_device_buf_minor2[i] = 0;
	init_waitqueue_head( &veda_queue0 );
	init_waitqueue_head( &veda_queue1 );
	init_waitqueue_head( &veda_queue2 );
	mutex_init(&vmut0);
	mutex_init(&vmut1);
	mutex_init(&vmut2);
	return 0;
}