示例#1
0
static int __init install(void)
{
    int i, result;
    dev_t dev=0;

    printk(KERN_ALERT "Initialisation driver touchscreen\n");

    if (result<0) {
        printk(KERN_ALERT "install driver : can't get major number\n");
        return result;
    }

    touchscreen = kmalloc(MAXDEVICES*sizeof(struct devInfo), GFP_KERNEL);
    if (!touchscreen) {
        result = -ENOMEM;
        goto fail;
    }
    memset(touchscreen, 0, MAXDEVICES*sizeof(struct devInfo));

    for (i=0; i < MAXDEVICES; i++) {
        setup_dev(&touchscreen[i], i);
    }
    printk(KERN_ALERT "installation OK, MAJOR NUMBER: %i\n",major);
    return 0;

fail:
    desinstall();
    return result;
}
示例#2
0
文件: genhd.c 项目: andreiw/mkunity
void device_setup(void)
{
	extern void console_map_init(void);
	struct gendisk *p;
	int nr=0;

	chr_dev_init();
	blk_dev_init();
	sti();
#ifdef CONFIG_SCSI
	scsi_dev_init();
#endif
#ifdef CONFIG_INET
	net_dev_init();
#endif
	console_map_init();

	for (p = gendisk_head ; p ; p=p->next) {
		setup_dev(p);
		nr += p->nr_real;
	}
#ifdef CONFIG_BLK_DEV_RAM
#ifdef CONFIG_BLK_DEV_INITRD
	if (initrd_start && mount_initrd) initrd_load();
	else
#endif
	rd_load();
#endif
}
示例#3
0
int main(int argc, char **argv)
{
	int rem = 0, c;
	char *pkt_device;
	char *device;

	if (argc == 1)
		return usage();

	while ((c = getopt(argc, argv, "ds?")) != EOF) {
		switch (c) {
			case 'd':
				rem = 1;
				break;
			case 's':
				show_mappings();
				return 0;
			default:
				return usage();
		}
	}
	pkt_device = argv[optind];
	device = argv[optind + 1];
	if (strchr(pkt_device, '/'))
		setup_dev(pkt_device, device, rem);
	else
		setup_dev_chardev(pkt_device, device, rem);
	return 0;
}
示例#4
0
文件: vfs.c 项目: szoftveres/avros
static void
do_mkdev (vfsmsg_t *msg) {
    int i;

    i = find_empty_devtab();
    if (i < 0) {
        msg->mkdev.ans.id = -1;
        return;
    }
    devtab[i] = setup_dev(msg);
    msg->mkdev.ans.id = i;
    return;
}
示例#5
0
static int __init list3_init(void)
{
	printk(KERN_INFO "list3: Initializing the list3 LKM\n",
		   communication_mode);

	if (strcmp(communication_mode, "sysfs") == 0)
		printk(KERN_INFO "list3: sysfs communication_mode. Ioctl will be unavailable\n");
	else
		if (strcmp(communication_mode, "ioctl") == 0)
			printk(KERN_INFO "list3: ioctl communication_mode. Sysfs will be unavailable\n");
	else
		printk(KERN_INFO "list3: Wrong communication mode\n");

	// Try to dynamically allocate a major number for the device
	major_number = register_chrdev(0, DEVICE_NAME, &fops);
	if (major_number < 0)
	{
		printk(KERN_ALERT "list3 failed to register a major number\n");
		return major_number;
	}
	printk(KERN_INFO "list3: registered correctly with major number %d\n", major_number);

	// Register the device class
	list3_class = class_create(THIS_MODULE, CLASS_NAME);
	if (IS_ERR(list3_class))
	{
		unregister_chrdev(major_number, DEVICE_NAME);
		printk(KERN_ALERT "Failed to register device class\n");
		return PTR_ERR(list3_class);          // Correct way to return an error on a pointer
	}
	printk(KERN_INFO "list3: device class registered correctly\n");

	// Register the device driver
	list3_device = device_create(list3_class, NULL, MKDEV(major_number, 0), NULL, DEVICE_NAME);
	if (IS_ERR(list3_device))
	{               // Clean up if there is an error
		class_destroy(list3_class);           // Repeated code but the alternative is goto statements
		unregister_chrdev(major_number, DEVICE_NAME);
		printk(KERN_ALERT "Failed to create the device\n");
		return PTR_ERR(list3_device);
	}

	setup_dev();
	if (strcmp(communication_mode, "sysfs") == 0)
		setup_sysfs();
	mutex_init(&list3_mutex);

	printk(KERN_INFO "list3: device class created correctly\n");
	return 0;
}
示例#6
0
文件: init.c 项目: Edwin-Edward/elks
void device_setup(void)
{
    register struct gendisk *p;

    chr_dev_init();
    blk_dev_init();

    set_irq();

    for (p = gendisk_head; p; p = p->next)
	setup_dev(p);

#ifdef CONFIG_BLK_DEV_RAM
    rd_load();
#endif

}