Exemplo n.º 1
0
static int hello_init(void)
{
//3.告诉内核
	dev_t devid;
#if 0
	register_chrdev(0, "hello", &hello_fops);
#else
	if (major) {
		devid = MKDEV(major, 0);
		register_chrdev_region(devid, HELLO_CNT, "hello");
		//(major, 0~1)对应hello_fops,其他的(major,1~255)都不对应
	} else {
		alloc_chrdev_region(&devid, 0, HELLO_CNT, "hello");
		major = MAJOR(devid);
	}
	cdev_init(&hello_cdev, &hello_fops);
	cdev_add(&hello_cdev, devid, HELLO_CNT);
#endif

	cls = class_create(THIS_MODULE, "hello");
	class_device_create(cls, NULL, MKDEV(major,0), NULL, "hello0");		//   /dev/hello0
	class_device_create(cls, NULL, MKDEV(major,1), NULL, "hello1");		//   /dev/hello1
	class_device_create(cls, NULL, MKDEV(major,2), NULL, "hello2");		//   /dev/hello2


	return 0;
}
Exemplo n.º 2
0
static int hello_init(void)
{
	dev_t devid;
	
	/* 3. 告诉内核 */
#if 0
	major = register_chrdev(0, "hello", &hello_fops); /* (major,  0), (major, 1), ..., (major, 255)都对应hello_fops */
#else
	if (major) {
		devid = MKDEV(major, 0);
		register_chrdev_region(devid, HELLO_CNT, "hello");  /* (major,0~1) 对应 hello_fops, (major, 2~255)都不对应hello_fops */
	} else {
		alloc_chrdev_region(&devid, 0, HELLO_CNT, "hello"); /* (major,0~1) 对应 hello_fops, (major, 2~255)都不对应hello_fops */
		major = MAJOR(devid);                     
	}
	
	cdev_init(&hello_cdev, &hello_fops);
	cdev_add(&hello_cdev, devid, HELLO_CNT);
#endif

	cls = class_create(THIS_MODULE, "hello");
	class_device_create(cls, NULL, MKDEV(major, 0), NULL, "hello0"); /* /dev/hello0 */
	class_device_create(cls, NULL, MKDEV(major, 1), NULL, "hello1"); /* /dev/hello1 */
	class_device_create(cls, NULL, MKDEV(major, 2), NULL, "hello2"); /* /dev/hello2 */
	
	
	return 0;
}
Exemplo n.º 3
0
static void mtd_notify_add(struct mtd_info* mtd)
{
	if (!mtd)
		return;

	class_device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
			    NULL, "mtd%d", mtd->index);

	class_device_create(mtd_class, NULL,
			    MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
			    NULL, "mtd%dro", mtd->index);
}
Exemplo n.º 4
0
static int at24cxx_detect(struct i2c_adapter *adapter, int address, int kind)
{
	
		
	printk("at24cxx_detect\n");

	at24cxx_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);

	at24cxx_client->addr = address;
	at24cxx_client->adapter = adapter;
	at24cxx_client->driver = &at24cxx_driver;


	/* Fill in the remaining client fields */
	strcpy(at24cxx_client->name, "at24cxx");

	i2c_attach_client(at24cxx_client);

	major = register_chrdev(0, "at24cxx", &at24cxx_fops);
	cls = class_create(THIS_MODULE, "at24cxx");

	class_device_create(cls, NULL, MKDEV(major, 0), NULL, "at24cxx"); 

	
	
	return 0;
}
Exemplo n.º 5
0
static int __init wixevent_init ( void ) {
	struct proc_dir_entry *entry;

	WixEventHead = WixEventTail = NULL;
	wixEventCount = 0;
	init_MUTEX_LOCKED( &wixevent_semaphore );
	up( &wixevent_semaphore );

	if ( (wixevent_devmajor = register_chrdev(EVENT_MAJOR, DRV_NAME,&wixevent_fops)) < 0 ) {
		WIXPRINT( "unable to get major %d for wixevent device\n", EVENT_MAJOR );
		return -1;
	}
	WIXDEBUG( "wixevent major %d for the wixevent devs\n", wixevent_devmajor );

	wixevent_class = class_create( THIS_MODULE, "wixevent" );
	//class_device_create( wixevent_class, MKDEV(wixevent_devmajor,0), NULL, DRV_NAME, 0 );
	class_device_create( wixevent_class, NULL, MKDEV(wixevent_devmajor,0), NULL, DRV_NAME );

	proc_wixevent = proc_mkdir( "wixevent", NULL );
	entry = create_proc_entry( "count", 0, proc_wixevent );
	if ( entry ) {
		entry->read_proc = proc_wixevent_count_read;
		entry->data = NULL;
	}

	return 0;
}
Exemplo n.º 6
0
/*!
 * This function implements the init function of the DAM device.
 * This function is called when the module is loaded.
 *
 * @return       This function returns 0.
 */
static int __init dam_init(void)
{
#ifdef TEST_DAM
	struct class_device *temp_class;

	major_dam = register_chrdev(0, DAM_NAME, &dam_fops);
	if (major_dam < 0) {
		printk(KERN_WARNING "Unable to get a major for dam");
		return major_dam;
	}

	mxc_dam_class = class_create(THIS_MODULE, DAM_NAME);
	if (IS_ERR(mxc_dam_class)) {
		goto err_out;
	}

	temp_class = class_device_create(mxc_dam_class, NULL,
					 MKDEV(major_dam, 0), NULL, DAM_NAME);
	if (IS_ERR(temp_class)) {
		goto err_out;
	}
#endif
	printk(KERN_DEBUG "dam : successfully loaded\n");
	return 0;

      err_out:
	printk(KERN_ERR "Error creating dam class device.\n");
	class_device_destroy(mxc_dam_class, MKDEV(major_dam, 0));
	class_destroy(mxc_dam_class);
	unregister_chrdev(major_dam, DAM_NAME);
	return -1;
}
Exemplo n.º 7
0
static int s3c_dma_init(void)
{
	/* 分配SRC, DST对应的缓冲区 */
	src = dma_alloc_writecombine(NULL, BUF_SIZE, &src_phys, GFP_KERNEL);
	if (NULL == src)
	{
		printk("can't alloc buffer for src\n");
		return -ENOMEM;
	}
	
	dst = dma_alloc_writecombine(NULL, BUF_SIZE, &dst_phys, GFP_KERNEL);
	if (NULL == dst)
	{
		dma_free_writecombine(NULL, BUF_SIZE, src, src_phys);
		printk("can't alloc buffer for dst\n");
		return -ENOMEM;
	}

	major = register_chrdev(0, "s3c_dma", &dma_fops);

	/* 为了自动创建设备节点 */
	cls = class_create(THIS_MODULE, "s3c_dma");
	class_device_create(cls, NULL, MKDEV(major, 0), NULL, "dma"); /* /dev/dma */
		
	return 0;
}
Exemplo n.º 8
0
/**
 * hwmon_device_register - register w/ hwmon sysfs class
 * @dev: the device to register
 *
 * hwmon_device_unregister() must be called when the class device is no
 * longer needed.
 *
 * Returns the pointer to the new struct class device.
 */
struct class_device *hwmon_device_register(struct device *dev)
{
	struct class_device *cdev;
	int id, err;

again:
	if (unlikely(idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0))
		return ERR_PTR(-ENOMEM);

	spin_lock(&idr_lock);
	err = idr_get_new(&hwmon_idr, NULL, &id);
	spin_unlock(&idr_lock);

	if (unlikely(err == -EAGAIN))
		goto again;
	else if (unlikely(err))
		return ERR_PTR(err);

	id = id & MAX_ID_MASK;
	cdev = class_device_create(hwmon_class, NULL, MKDEV(0,0), dev,
					HWMON_ID_FORMAT, id);

	if (IS_ERR(cdev)) {
		spin_lock(&idr_lock);
		idr_remove(&hwmon_idr, id);
		spin_unlock(&idr_lock);
	}

	return cdev;
}
Exemplo n.º 9
0
int switch_dev_register(struct switch_dev *sdev)
{
	int ret;

	if (!switch_class) {
		ret = create_switch_class();
		if (ret < 0)
			return ret;
	}

	sdev->index = atomic_inc_return(&device_count);
	sdev->cdev = class_device_create(switch_class, NULL,
		MKDEV(0, sdev->index), NULL, sdev->name);
	if (IS_ERR(sdev->cdev))
		return PTR_ERR(sdev->cdev);

	ret = class_device_create_file(sdev->cdev, &class_device_attr_state);
	if (ret < 0)
		goto err_create_file_1;
	ret = class_device_create_file(sdev->cdev, &class_device_attr_name);
	if (ret < 0)
		goto err_create_file_2;

	class_set_devdata(sdev->cdev, sdev);
	sdev->state = 0;
	return 0;

err_create_file_2:
	class_device_remove_file(sdev->cdev, &class_device_attr_state);
err_create_file_1:
	class_device_destroy(switch_class, MKDEV(0, sdev->index));
	printk(KERN_ERR "switch: Failed to register driver %s\n", sdev->name);

	return ret;
}
Exemplo n.º 10
0
/**
 * led_classdev_register - register a new object of led_classdev class.
 * @dev: The device to register.
 * @led_cdev: the led_classdev structure for this device.
 */
int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
{
	led_cdev->class_dev = class_device_create(leds_class, NULL, 0,
						parent, "%s", led_cdev->name);
	if (unlikely(IS_ERR(led_cdev->class_dev)))
		return PTR_ERR(led_cdev->class_dev);

	class_set_devdata(led_cdev->class_dev, led_cdev);

	/* register the attributes */
	class_device_create_file(led_cdev->class_dev,
				&class_device_attr_brightness);

	/* add to the list of leds */
	write_lock(&leds_list_lock);
	list_add_tail(&led_cdev->node, &leds_list);
	write_unlock(&leds_list_lock);

#ifdef CONFIG_LEDS_TRIGGERS
	rwlock_init(&led_cdev->trigger_lock);

	led_trigger_set_default(led_cdev);

	class_device_create_file(led_cdev->class_dev,
				&class_device_attr_trigger);
#endif

	printk(KERN_INFO "Registered led device: %s\n",
			led_cdev->class_dev->class_id);

	return 0;
}
Exemplo n.º 11
0
static int __init hdshm_init(void) 
{
        int retval;
#ifdef IS_HD        
	retval=hdshm_init_struct_hd();
#else
        retval=hdshm_init_struct_host();
#endif	
	if (retval)
		return retval;

        retval= register_chrdev(HDSHM_MAJOR, "hdshm", &hdshm_fops);

#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))	
        devfs_mk_cdev(MKDEV(HDSHM_MAJOR, 0),
                        S_IFCHR | S_IRUSR | S_IWUSR,
                        "hdshm", 0);
#else
	hdshm_class = class_create(THIS_MODULE, "hdshm");
	// FIXME error checking
	class_device_create(hdshm_class, NULL, MKDEV(HDSHM_MAJOR, 0),
			    NULL, "hdshm");

#endif
	if (retval)
		return retval;
#ifdef HAS_HD_FB
	retval = hdfb_init();
#endif
	return retval;
}
Exemplo n.º 12
0
static int __init
gpio_init(void)
{
	if (!(gpio_sih = si_kattach(SI_OSH)))
		return -ENODEV;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
	if ((gpio_major = register_chrdev(0, "gpio", &gpio_fops)) < 0)
#else
	if ((gpio_major = devfs_register_chrdev(0, "gpio", &gpio_fops)) < 0)
#endif
		return gpio_major;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
	gpiodev_class = class_create(THIS_MODULE, "gpio");
	if (IS_ERR(gpiodev_class)) {
		printk("Error creating gpio class\n");
		return -1;
	}

	/* Add the device gpio0 */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
	device_create(gpiodev_class, NULL, MKDEV(gpio_major, 0), NULL, "gpio", 0);
#else
	class_device_create(gpiodev_class, NULL, MKDEV(gpio_major, 0), NULL, "gpio");
#endif /* linux-2.6.36 */
#else
	gpiodev_handle = devfs_register(NULL, "gpio", DEVFS_FL_DEFAULT,
	                                gpio_major, 0, S_IFCHR | S_IRUGO | S_IWUGO,
	                                &gpio_fops, NULL);
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */

	return 0;
}
Exemplo n.º 13
0
static int __init cir_dm6446_init(void)
{
	s8 retval = 0;

	cir_dm6446_major_number = 0;
	cir_dm6446_minor_number = 0;
	cir_class = NULL;

	retval = alloc_chrdev_region(&cir_dm6446_dev, cir_dm6446_minor_number,
			CIR_DM6446_DEV_COUNT, "/dev/cir");
	if (retval < 0) {
		printk(KERN_ERR "Unable to register the CIR device\n");
		retval = -ENODEV;
		goto failure;
	}

	cir_dm6446_major_number = MAJOR(cir_dm6446_dev);

	cdev_init(&cir_dm6446_cdev, &cir_dm6446_fops);
	cir_dm6446_cdev.owner = THIS_MODULE;
	cir_dm6446_cdev.ops = &cir_dm6446_fops;

	retval = cdev_add(&cir_dm6446_cdev, cir_dm6446_dev,
			CIR_DM6446_DEV_COUNT);
	if (retval) {
		unregister_chrdev_region(cir_dm6446_dev, CIR_DM6446_DEV_COUNT);
		printk(KERN_ERR "Error %d adding CIR device\n", retval);
		goto failure;
	}

	cir_class = class_create(THIS_MODULE, "cir");

	if (!cir_class) {
		unregister_chrdev_region(cir_dm6446_dev, CIR_DM6446_DEV_COUNT);
		cdev_del(&cir_dm6446_cdev);
		goto failure;
	}

	if (driver_register(&cir_dm6446_driver) != 0) {
		unregister_chrdev_region(cir_dm6446_dev, CIR_DM6446_DEV_COUNT);
		cdev_del(&cir_dm6446_cdev);
		class_destroy(cir_class);
		goto failure;
	}
	/* Register the drive as a platform device */
	if (platform_device_register(&cir_dm6446_device) != 0) {
		driver_unregister(&cir_dm6446_driver);
		unregister_chrdev_region(cir_dm6446_dev, CIR_DM6446_DEV_COUNT);
		cdev_del(&cir_dm6446_cdev);
		class_destroy(cir_class);
		goto failure;
	}

	cir_dm6446_dev = MKDEV(cir_dm6446_major_number, 0);

	class_device_create(cir_class, NULL, cir_dm6446_dev, NULL, "cir");

 failure:
	return retval;
}
Exemplo n.º 14
0
static int __init irrtc_init(void)
{
    int status = 0;
    init_timer(&learning_key_timer);
    init_waitqueue_head (&wait);

    printk(KERN_INFO "\t" MOD_DESC "\n");

    sysfs_class = class_create(THIS_MODULE, "neuros_ir_blaster");
    if (IS_ERR(sysfs_class)) 
    {
        return PTR_ERR(sysfs_class);
    }
    status = register_chrdev(NEUROS_IR_BLASTER_MAJOR, "neuros_ir_blaster", &irrtc_fops);
    if (status != 0)
    {
        if (status == -EINVAL) printk(KERN_ERR "%s Couldn't register device: invalid major number %d.\n", pname, NEUROS_IR_BLASTER_MAJOR);
        else if (status == -EBUSY) printk(KERN_ERR "%s Couldn't register device: major number %d already busy.\n", pname, NEUROS_IR_BLASTER_MAJOR);
        else printk(KERN_ERR "%s Couldn't register device: error %d.\n", pname, status);
        status = -1;
        goto out;
    }
	class_device_create(sysfs_class, NULL,
			    MKDEV(NEUROS_IR_BLASTER_MAJOR, 0),
			    NULL, "neuros_ir_blaster");

    blaster_init();

out:
    return status;
}
Exemplo 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 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;

	/* create a usb class device for this usb interface */
	snprintf(name, BUS_ID_SIZE, class_driver->name, minor - minor_base);
	temp = strrchr(name, '/');
	if (temp && (temp[1] != 0x00))
		++temp;
	else
		temp = name;
	intf->class_dev = class_device_create(usb_class, NULL,
					      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);
		retval = PTR_ERR(intf->class_dev);
	}
exit:
	return retval;
}
Exemplo n.º 16
0
static int i2cdev_attach_adapter(struct i2c_adapter *adap)
{
	struct i2c_dev *i2c_dev;
	struct device *dev;

	i2c_dev = get_free_i2c_dev(adap);
	if (IS_ERR(i2c_dev))
		return PTR_ERR(i2c_dev);

	pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
		 adap->name, i2c_dev->minor);

	/* register this i2c device with the driver core */
	i2c_dev->adap = adap;
	if (adap->dev.parent == &platform_bus)
		dev = &adap->dev;
	else
		dev = adap->dev.parent;
	i2c_dev->class_dev = class_device_create(i2c_dev_class, NULL,
						 MKDEV(I2C_MAJOR, i2c_dev->minor),
						 dev, "i2c-%d", i2c_dev->minor);
	if (!i2c_dev->class_dev)
		goto error;
	class_device_create_file(i2c_dev->class_dev, &class_device_attr_name);
	return 0;
error:
	return_i2c_dev(i2c_dev);
	kfree(i2c_dev);
	return -ENODEV;
}
Exemplo n.º 17
0
/*
 * Register a tape device and return a pointer to the cdev structure.
 *
 * device
 *	The pointer to the struct device of the physical (base) device.
 * drivername
 *	The pointer to the drivers name for it's character devices.
 * dev
 *	The intended major/minor number. The major number may be 0 to
 *	get a dynamic major number.
 * fops
 *	The pointer to the drivers file operations for the tape device.
 * devname
 *	The pointer to the name of the character device.
 */
struct tape_class_device *register_tape_dev(
	struct device *		device,
	dev_t			dev,
	struct file_operations *fops,
	char *			device_name,
	char *			mode_name)
{
	struct tape_class_device *	tcd;
	int		rc;
	char *		s;

	tcd = kmalloc(sizeof(struct tape_class_device), GFP_KERNEL);
	if (!tcd)
		return ERR_PTR(-ENOMEM);

	memset(tcd, 0, sizeof(struct tape_class_device));
	strncpy(tcd->device_name, device_name, TAPECLASS_NAME_LEN);
	for (s = strchr(tcd->device_name, '/'); s; s = strchr(s, '/'))
		*s = '!';
	strncpy(tcd->mode_name, mode_name, TAPECLASS_NAME_LEN);
	for (s = strchr(tcd->mode_name, '/'); s; s = strchr(s, '/'))
		*s = '!';

	tcd->char_device = cdev_alloc();
	if (!tcd->char_device) {
		rc = -ENOMEM;
		goto fail_with_tcd;
	}

	tcd->char_device->owner = fops->owner;
	tcd->char_device->ops   = fops;
	tcd->char_device->dev   = dev;

	rc = cdev_add(tcd->char_device, tcd->char_device->dev, 1);
	if (rc)
		goto fail_with_cdev;

	tcd->class_device = class_device_create(
				tape_class,
				NULL,
				tcd->char_device->dev,
				device,
				"%s", tcd->device_name
			);
	sysfs_create_link(
		&device->kobj,
		&tcd->class_device->kobj,
		tcd->mode_name
	);

	return tcd;

fail_with_cdev:
	cdev_del(tcd->char_device);

fail_with_tcd:
	kfree(tcd);

	return ERR_PTR(rc);
}
Exemplo n.º 18
0
Arquivo: bar.c Projeto: knaka/src
static int
bar_init (void) {
  dev_t bar_dev = MKDEV(bar_major, bar_minor_base);
  int alloc_chrdev_region_error = -1;
  int cdev_add_error = -1;
  int class_create_error = -1;
  int i;
    alloc_chrdev_region_error = alloc_chrdev_region(
     & bar_dev, /* dev_t * dev */
     bar_minor_base, /* unsigned baseminor */
     bar_minor_num, /* unsigned count */
     driver_name ); /* const char * name */
    if (alloc_chrdev_region_error != 0) {
        goto error;
    }
    bar_major = MAJOR(bar_dev);
    cdev_init(& bar_cdev, & bar_fops);
    bar_cdev.owner = THIS_MODULE; /* struct module * */
    cdev_add_error = cdev_add(& bar_cdev, bar_dev, bar_minor_num);
    if (cdev_add_error != 0) {
        goto error;
    }
    /* class registration */
    bar_class = class_create(THIS_MODULE, "bar");
    class_create_error = IS_ERR(bar_class);
    if (class_create_error) {
        goto error;
    }
    for (i = 0; i < bar_minor_num; i ++) {
      dev_t bar_dev_tmp = MKDEV(bar_major, bar_minor_base + i);
        class_device_create(
         bar_class,
         NULL,
         bar_dev_tmp,
         NULL,
         "bar%d",
         bar_minor_base + i );
    }
    printk(KERN_ALERT "driver %s (major: %d) installed.\n",
     driver_name, bar_major );
    return (0);
error:
    if (class_create_error == 0) {
        for (i = 0; i < bar_minor_num; i ++) {
          dev_t bar_dev_tmp = MKDEV(bar_major, bar_minor_base + i);
            class_device_destroy(bar_class, bar_dev_tmp);
        }
        class_destroy(bar_class);
    }
    if (cdev_add_error == 0) {
        cdev_del(& bar_cdev);
    }
    if (alloc_chrdev_region_error == 0) {
        unregister_chrdev_region(bar_dev, bar_minor_num);
    }
    return (-1);
}
Exemplo n.º 19
0
static int msr_class_device_create(int i)
{
	int err = 0;
	struct class_device *class_err;

	class_err = class_device_create(msr_class, NULL, MKDEV(MSR_MAJOR, i), NULL, "msr%d",i);
	if (IS_ERR(class_err)) 
		err = PTR_ERR(class_err);
	return err;
}
Exemplo n.º 20
0
static int cpuid_class_device_create(int i)
{
    int err = 0;
    struct class_device *class_err;

    class_err = class_device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, i), NULL, "cpu%d",i);
    if (IS_ERR(class_err))
        err = PTR_ERR(class_err);
    return err;
}
Exemplo n.º 21
0
static void mtd_notify_add(struct mtd_info* mtd)
{
	if (!mtd)
		return;

#ifdef CONFIG_DEVFS_FS
	devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
			S_IFCHR | S_IRUGO | S_IWUGO, "mtd/%d", mtd->index);

	devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
			S_IFCHR | S_IRUGO, "mtd/%dro", mtd->index);
#else
	class_device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
			    NULL, "mtd%d", mtd->index);

	class_device_create(mtd_class, NULL,
			    MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
			    NULL, "mtd%dro", mtd->index);
#endif
}
Exemplo n.º 22
0
static int first_drv_init(void)
{
	major = register_chrdev(0, "first_drv", &first_drv_fops);
	firstdrv_class = class_create(THIS_MODULE,"firstdrv");
	firstdrv_class_dev = class_device_create(firstdrv_class,NULL,MKDEV(major,0),NULL,"xyz");
	
	gpfcon = (volatile unsigned long *)ioremap(0x56000050,16);
	gpfdat = gpfcon + 1;

	return 0;
}
Exemplo n.º 23
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;

}
Exemplo n.º 24
0
static  int first_drv_init(void)  //entrance 
{
	major = register_chrdev(0, "first_drv",&first_drv_fops);

	firstdrv_class = class_create(THIS_MODULE, "firstdrv");  //生成系统信息,建立一个类,在这个类下面生成设备MKV
	
	firstdrv_class_devs[0] = class_device_create(firstdrv_class, NULL, MKDEV(major, 0), NULL, "zyz");
	
	return ;

}
Exemplo n.º 25
0
int i2c_slave_device_register(i2c_slave_device_t *device)
{
	device->dev =
	    class_device_create(i2c_slave_class, NULL,
				(dev_t) MKDEV(i2c_slave_major, device->id),
				NULL, "slave-i2c-%d", device->id);
	if (!device->dev) {
		return -1;
	}
	i2c_slave_devices[device->id] = device;
	return 0;
}
Exemplo n.º 26
0
/*!
 * This function implements the init function of the PMIC char device.
 * This function is called when the module is loaded. It registers 
 * the character device for PMIC to be used by user-space programs.
 *
 * @return       This function returns 0.
 */
static int __init pmic_dev_init(void)
{
	int ret = 0;
	struct class_device *pmic_device;
	pmic_version_t pmic_ver;

	pmic_ver = pmic_get_version();
	if (pmic_ver.revision < 0) {
		printk(KERN_ERR "No PMIC device found\n");
		return -ENODEV;
	}

	pmic_major = register_chrdev(0, PMIC_NAME, &pmic_fops);
	if (pmic_major < 0) {
		printk(KERN_ERR "unable to get a major for pmic\n");
		return pmic_major;
	}

	pmic_class = class_create(THIS_MODULE, PMIC_NAME);
	if (IS_ERR(pmic_class)) {
		printk(KERN_ERR "Error creating pmic class.\n");
		ret = PMIC_ERROR;
		goto err;
	}

	pmic_device =
	    class_device_create(pmic_class, NULL, MKDEV(pmic_major, 0),
				NULL, PMIC_NAME);
	if (IS_ERR(pmic_device)) {
		printk(KERN_ERR "Error creating pmic class device.\n");
		ret = PMIC_ERROR;
		goto err1;
	}

	pmic_events.buf = kmalloc(CIRC_BUF_MAX * sizeof(char), GFP_KERNEL);
	if (NULL == pmic_events.buf) {
		ret = -ENOMEM;
		goto err2;
	}
	pmic_events.head = pmic_events.tail = 0;

	printk(KERN_INFO "PMIC Character device: successfully loaded\n");
	return ret;
      err2:
	class_device_destroy(pmic_class, MKDEV(pmic_major, 0));
      err1:
	class_destroy(pmic_class);
      err:
	unregister_chrdev(pmic_major, PMIC_NAME);
	return ret;

}
Exemplo n.º 27
0
static int key_int_drv_init(void)
{
	major = register_chrdev(0, "key_int_drv", &key_int_drv_fops);

	key_int_drv_class = class_create(THIS_MODULE, "key");
	key_int_drv_class_dev = class_device_create(key_int_drv_class, NULL, MKDEV(major, 0), NULL, "key");

	gpfcon = (volatile unsigned long *)ioremap(0x56000050, 16);
	gpfdat = gpfcon + 1;
	gpgcon = (volatile unsigned long *)ioremap(0x56000060, 16);
	gpgdat = gpgcon + 1;
	return 0;
}
Exemplo n.º 28
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;
	}

	adb_dev_class = class_create(THIS_MODULE, "adb");
	if (IS_ERR(adb_dev_class))
		return;
	class_device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");
}
Exemplo n.º 29
0
static int sixth_drv_init(void)
{
	major = register_chrdev(0, "sixth_drv", &sencod_drv_fops);

	sixthdrv_class = class_create(THIS_MODULE, "sixth_drv");

	sixthdrv_class_dev = class_device_create(sixthdrv_class, NULL, MKDEV(major, 0), NULL, "buttons"); /* /dev/buttons */

//	gpfcon = (volatile unsigned long *)ioremap(0x56000050, 16);
//	gpfdat = gpfcon + 1;

	return 0;
}
Exemplo n.º 30
0
static int third_drv_init(void)
{
	major = register_chrdev(0 ,"third_drv", &third_drv_fops);

	thirddrv_class = class_create(THIS_MODULE, "third_drv");

	thirddrv_class_dev = class_device_create(thirddrv_class, NULL, MKDEV(major, 0), NULL, "bottons");  /*  /dev/buttom */

	gpfcon = (volatile unsigned long *)ioremap(0x56000050, 16);
	gpfdat = gpfcon + 1;

	gpgcon = (volatile unsigned long *)ioremap(0x56000060, 16);
	gpgdat = gpgcon + 1;

	return 0;
}