static void mtd_notify_add(struct mtd_info* mtd) { if (!mtd) return; 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); }
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; }
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; }
int init_vfc_device(struct sbus_dev *sdev,struct vfc_dev *dev, int instance) { if(dev == NULL) { printk(KERN_ERR "VFC: Bogus pointer passed\n"); return -ENOMEM; } printk("Initializing vfc%d\n",instance); dev->regs = NULL; dev->regs = (volatile struct vfc_regs *) sbus_ioremap(&sdev->resource[0], 0, sizeof(struct vfc_regs), vfcstr); dev->which_io = sdev->reg_addrs[0].which_io; dev->phys_regs = (struct vfc_regs *) sdev->reg_addrs[0].phys_addr; if (dev->regs == NULL) return -EIO; printk("vfc%d: registers mapped at phys_addr: 0x%lx\n virt_addr: 0x%lx\n", instance,(unsigned long)sdev->reg_addrs[0].phys_addr,(unsigned long)dev->regs); if (init_vfc_devstruct(dev, instance)) return -EINVAL; if (init_vfc_hw(dev)) return -EIO; devfs_mk_cdev(MKDEV(VFC_MAJOR, instance), S_IFCHR | S_IRUSR | S_IWUSR, "vfc/%d", instance); return 0; }
static int __init bpp_init(void) { int rc; unsigned idx; rc = collectLptPorts(); if (rc == 0) return -ENODEV; rc = register_chrdev(BPP_MAJOR, dev_name, &bpp_fops); if (rc < 0) return rc; for (idx = 0; idx < BPP_NO; idx++) { instances[idx].opened = 0; probeLptPort(idx); } devfs_mk_dir("bpp"); for (idx = 0; idx < BPP_NO; idx++) { devfs_mk_cdev(MKDEV(BPP_MAJOR, idx), S_IFCHR | S_IRUSR | S_IWUSR, "bpp/%d", idx); } return 0; }
/*------------------------------------------------------------------ * Func : mcp_init * * Desc : mcp module init function * * Parm : N/A * * Retn : N/A *------------------------------------------------------------------*/ static int __init mcp_module_init(void) { if (mcp_init()<0) return -ENODEV; cdev_init(&mcp_dev, &mcp_ops); if (alloc_chrdev_region(&devno, 0, 1, MCP_DEV_FILE_NAME)!=0) { cdev_del(&mcp_dev); return -EFAULT; } if (cdev_add(&mcp_dev, devno, 1)<0) return -EFAULT; devfs_mk_cdev(devno, S_IFCHR|S_IRUSR|S_IWUSR, MCP_DEV_FILE_NAME); mcp_device = platform_device_register_simple("MCP", 0, NULL, 0); //MCP_AES_128_ECB_DataEncrypt(); //MCP_AES_H_DataHashTest(); //MCP_SHA1_DataHashTest(); return 0; }
inline int xp_sys_hook() { /* Called insmod when inserting the module. */ /* register the dazuko device */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) dev_major = register_chrdev(CONFIG_RSBAC_DAZ_DEV_MAJOR, DEVICE_NAME, &fops); devfs_mk_cdev(MKDEV(dev_major, CONFIG_RSBAC_DAZ_DEV_MAJOR), S_IFCHR | S_IRUSR | S_IWUSR, DEVICE_NAME); #else #ifdef CONFIG_DEVFS_FS dev_major = devfs_register_chrdev(CONFIG_RSBAC_DAZ_DEV_MAJOR, DEVICE_NAME, &fops); devfs_register(NULL, DEVICE_NAME, DEVFS_FL_DEFAULT, dev_major, 0, S_IFCHR | S_IRUSR | S_IWUSR, &fops, NULL); #else dev_major = register_chrdev(CONFIG_RSBAC_DAZ_DEV_MAJOR, DEVICE_NAME, &fops); #endif #endif if (dev_major < 0) { xp_print("dazuko: unable to register device chrdev, err=%d\n", dev_major); return dev_major; } /* initialization complete */ return 0; }
static int sound_insert_unit(struct sound_unit **list, const struct file_operations *fops, int index, int low, int top, const char *name, umode_t mode, struct device *dev) { 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); device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor), s->name+6); return r; fail: kfree(s); return r; }
/* * Initialization and Exit */ static int __init mc13783_rtc_init(void) { int ret = 0; if (mc13783_core_loaded() == 0) { printk(KERN_INFO MC13783_LOAD_ERROR_MSG); return -1; } mc13783_rtc_major = register_chrdev(0, "mc13783_rtc", &mc13783_rtc_fops); if (mc13783_rtc_major < 0) { TRACEMSG_RTC(_K_D("Unable to get a major for mc13783_rtc")); return -1; } devfs_mk_cdev(MKDEV(mc13783_rtc_major, 0), S_IFCHR | S_IRUGO | S_IWUSR, "mc13783_rtc"); ret = driver_register(&mc13783_rtc_driver_ldm); if (ret == 0) { ret = platform_device_register(&mc13783_rtc_ldm); if (ret != 0) { driver_unregister(&mc13783_rtc_driver_ldm); } else { mc13783_rtc_detected = 1; printk(KERN_INFO "mc13783 RTC loaded\n"); } } return ret; }
/* Init and cleanup functions for module */ static int __init ixp400_sw_init_module(void) { /* Add initialization code here */ #ifdef DEBUG printk("\n\n"__FUNCTION__": addr=%p\n\n", ixp400_sw_init_module); #endif /* * If livelock prevention dispatcher is requested - enable in FeatureCtrl */ if (livelock_dispatcher != 0) { ixFeatureCtrlSwConfigurationWrite (IX_FEATURECTRL_ORIGB0_DISPATCHER, IX_FEATURE_CTRL_SWCONFIG_DISABLED); } #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE /* Register driver for /dev/ixNpe */ if (register_chrdev(DEV_IXNPE_MAJOR_NUMBER, "ixNpe", &ixNpe_dev_fops)) printk (KERN_ERR "Failed to register driver for /dev/ixNpe\n"); #ifdef CONFIG_DEVFS_FS devfs_mk_cdev(MKDEV(DEV_IXNPE_MAJOR_NUMBER, DEV_IXNPE_MAJOR_NUMBER), S_IFCHR | S_IWUGO, DEV_IXNPE_DEVFS_NAME); #endif /* CONFIG_DEVFS_FS */ #endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */ printk(KERN_DEBUG "ixp400: Module init.\n"); return 0; }
static int __init mc13783_battery_init(void) { int ret = 0; if (mc13783_core_loaded() == 0) { printk(KERN_INFO MC13783_LOAD_ERROR_MSG); return -1; } mc13783_battery_major = register_chrdev(0, MC13783_BATTERY_STRING, &mc13783_battery_fops); if (mc13783_battery_major < 0) { TRACEMSG_BATTERY(_K_D ("Unable to get a major for mc13783_battery")); return -1; } init_waitqueue_head(&suspendq); devfs_mk_cdev(MKDEV(mc13783_battery_major, 0), S_IFCHR | S_IRUGO | S_IWUSR, MC13783_BATTERY_STRING); ret = driver_register(&mc13783_battery_driver_ldm); if (ret == 0) { ret = platform_device_register(&mc13783_battery_ldm); if (ret != 0) { driver_unregister(&mc13783_battery_driver_ldm); } else { mc13783_battery_detected = 1; printk(KERN_INFO "mc13783 Battery loaded\n"); } } return ret; }
/* * Module init/exit */ static int __init venus_ir_wo_init_module(void) { int result; /* MKDEV */ dev_venus_ir_wo = MKDEV(VENUS_IR_WO_MAJOR, VENUS_IR_WO_MINOR_RP); /* Request Device Number */ result = register_chrdev_region(dev_venus_ir_wo, VENUS_IR_WO_DEVICE_NUM, "venus_ir_wo"); if (result < 0) { printk(KERN_WARNING "venus_ir_wo: can't register device number.\n"); goto fail_alloc_dev; } venus_ir_wo_devs = platform_device_register_simple("VenusIR_W", -1, NULL, 0); if (driver_register(&venus_ir_wo_driver) != 0) goto fail_device_register; /* create sysfs files */ device_create_file(&venus_ir_wo_devs->dev, &dev_attr_fakekey); /* Char Device Registration */ venus_ir_wo_cdev = cdev_alloc(); if (venus_ir_wo_cdev == NULL) { printk(KERN_ERR "venus_ir_wo: can't allocate cdev\n"); result = -ENOMEM; goto fail_cdev_alloc; } venus_ir_wo_cdev->ops = &venus_ir_wo_fops; if (cdev_add(venus_ir_wo_cdev, MKDEV(VENUS_IR_WO_MAJOR, VENUS_IR_WO_MINOR_RP), 1)) { printk(KERN_ERR "venus_ir_wo: can't add character device\n"); result = -ENOMEM; goto fail_cdev_add; } /* use devfs to create device file */ devfs_mk_cdev(MKDEV(VENUS_IR_WO_MAJOR, VENUS_IR_WO_MINOR_RP), S_IFCHR|S_IRUSR|S_IWUSR, VENUS_IR_WO_DEVICE_FILE); /* rest of the init */ result = venus_ir_wo_init(); if (result) goto fail_init; printk(KERN_INFO "venus_ir_wo: driver loaded\n"); return 0; /* success */ fail_init: devfs_remove(VENUS_IR_WO_DEVICE_FILE); fail_cdev_add: cdev_del(venus_ir_wo_cdev); fail_cdev_alloc: driver_unregister(&venus_ir_wo_driver); device_remove_file(&venus_ir_wo_devs->dev, &dev_attr_fakekey); fail_device_register: if (!IS_ERR(venus_ir_wo_devs)) platform_device_unregister(venus_ir_wo_devs); unregister_chrdev_region(dev_venus_ir_wo, VENUS_IR_WO_DEVICE_NUM); fail_alloc_dev: return result; }
static void ipmi_new_smi(int if_num) { if (if_num <= MAX_DEVICES) { devfs_mk_cdev(MKDEV(ipmi_major, if_num), S_IFCHR | S_IRUSR | S_IWUSR, "ipmidev/%d", if_num); } }
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 }
static int DIVA_INIT_FUNCTION divas_maint_register_chrdev(void) { if ((major = register_chrdev(0, DEVNAME, &divas_maint_fops)) < 0) { printk(KERN_ERR "%s: failed to create /dev entry.\n", DRIVERLNAME); return (0); } devfs_mk_cdev(MKDEV(major, 0), S_IFCHR|S_IRUSR|S_IWUSR, DEVNAME); return (1); }
static void devfs_register_card(struct em84xx *card) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,70) char devname[64]; sprintf(devname, "%s%d", REALMAGIC_DEVICE_NAME, 0); em8300_handle[0] = devfs_register(NULL, devname, DEVFS_FL_DEFAULT, REALMAGIC_MAJOR, 0, S_IFCHR | S_IRUGO | S_IWUGO, &em8300_fops, NULL); sprintf(devname, "%s%d", REALMAGIC_DEVICE_NAME, 1); em8300_handle[0] = devfs_register(NULL, devname, DEVFS_FL_DEFAULT, REALMAGIC_MAJOR, 1, S_IFCHR | S_IRUGO | S_IWUGO, &em8300_fops, NULL); sprintf(devname, "%s%d", REALMAGIC_DEVICE_NAME, 2); em8300_handle[0] = devfs_register(NULL, devname, DEVFS_FL_DEFAULT, REALMAGIC_MAJOR, 2, S_IFCHR | S_IRUGO | S_IWUGO, &em8300_fops, NULL); sprintf(devname, "%s%d", REALMAGIC_DEVICE_NAME, 3); em8300_handle[0] = devfs_register(NULL, devname, DEVFS_FL_DEFAULT, REALMAGIC_MAJOR, 3, S_IFCHR | S_IRUGO | S_IWUGO, &em8300_fops, NULL); #else devfs_mk_cdev(MKDEV(REALMAGIC_MAJOR, 0), S_IFCHR | S_IRUGO | S_IWUGO, "%s%d", REALMAGIC_DEVICE_NAME, 0); devfs_mk_cdev(MKDEV(REALMAGIC_MAJOR, 1), S_IFCHR | S_IRUGO | S_IWUGO, "%s%d", REALMAGIC_DEVICE_NAME, 1); devfs_mk_cdev(MKDEV(REALMAGIC_MAJOR, 2), S_IFCHR | S_IRUGO | S_IWUGO, "%s%d", REALMAGIC_DEVICE_NAME, 2); devfs_mk_cdev(MKDEV(REALMAGIC_MAJOR, 3), S_IFCHR | S_IRUGO | S_IWUGO, "%s%d", REALMAGIC_DEVICE_NAME, 3); #endif }
static int __init viadev_init(void) { // Find the device di.pcidev = pci_find_device(PCI_VENDOR_ID_VIA, _PCI_DEVICE_ID_VIA_CLE3122, NULL); MY_ASSERT(di.pcidev, MODULE_NAME ": VIA CLE266 graphics device not found.", -ENODEV); MY_ASSERT(!di.pcidev->driver, MODULE_NAME ": There is already a driver installed.", -EBUSY); // Map physical IO memory address into kernel space. di.io_base_phy = pci_resource_start(di.pcidev, 1); di.size = pci_resource_len(di.pcidev, 1); MY_ASSERT(request_mem_region(di.io_base_phy, di.size, MODULE_NAME), MODULE_NAME ": Memory mapping failed (1).", -EBUSY); di.iobase = ioremap(di.io_base_phy, di.size); MY_ASSERT(di.iobase, MODULE_NAME ": Memory mapping failed (2).", -EBUSY); // TODO: Register PCI device driver. Or not. We don't really need to. // Register a character device. Uses devfs #if CLE266_STATIC_DEVNUM int result; result = register_chrdev(VIADEV_MAJOR, MODULE_NAME, &viadev_fops); MY_ASSERT(!result, MODULE_NAME " Unable to register driver\n", result); #else #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0) int result; result = register_chrdev(VIADEV_MAJOR, MODULE_NAME, &viadev_fops); MY_ASSERT(!result, MODULE_NAME " Unable to register driver\n", result); devfs_mk_cdev(MKDEV(VIADEV_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR, MODULE_NAME); #else di.devhnd = devfs_register(NULL, MODULE_NAME, DEVFS_FL_AUTO_DEVNUM, 0, 0, S_IFCHR | S_IRUGO | S_IWUGO, &viadev_fops, &di); MY_ASSERT(di.devhnd, MODULE_NAME ": Could not register a /dev entry.", -EAGAIN); #endif #endif // CLE266_STATIC_DEVNUM printk(MODULE_NAME " installed. Hardware rev %d detected.\n", via_get_revision()); via_enable_mmio(); return 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_create(THIS_MODULE, "adb"); if (IS_ERR(adb_dev_class)) return; class_device_create(adb_dev_class, MKDEV(ADB_MAJOR, 0), NULL, "adb"); }
static int __init mcp_cipher_init(void) { cdev_init(&mcp_cdev, &mcp_ops); if (alloc_chrdev_region(&devno, 0, 1, MCP_CIPHER_FILE_NAME)!=0) { cdev_del(&mcp_cdev); return -EFAULT; } if (cdev_add(&mcp_cdev, devno, 1)<0) return -EFAULT; devfs_mk_cdev(devno, S_IFCHR|S_IRUSR|S_IWUSR, MCP_CIPHER_FILE_NAME); return 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; }
/*! * Post-processing driver module initialization function. */ int mxc_pp_dev_init(void) { FUNC_START; mxc_pp_major = register_chrdev(0, "mxc_ipu_pp", &mxc_pp_fops); if(mxc_pp_major < 0) { printk(KERN_INFO "Unable to get a major for mxc_ipu_pp"); return mxc_pp_major; } devfs_mk_cdev(MKDEV(mxc_pp_major, 0), S_IFCHR | S_IRUGO | S_IWUGO, "mxc_ipu_pp"); printk(KERN_INFO "IPU Post-processing loading\n"); FUNC_END; return 0; }
static int __init qq2440_leds_init(void) { int ret; int i; ret = register_chrdev(LED_MAJOR, DEVICE_NAME, &qq2440_leds_fops); if (ret < 0) { printk(DEVICE_NAME " can't register major number\n"); return ret; } devfs_mk_cdev(MKDEV(LED_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, DEVICE_NAME); for (i = 0; i < 4; i++) { s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]); s3c2410_gpio_setpin(led_table[i], 1); } printk(DEVICE_NAME " initialized\n"); return 0; }
static int __init adc_init(void) { int ret; ret = register_chrdev(0,DEVICE_NAME,&adc_fops); if(ret < 0) { printk("adc: can't get major number\n"); return ret; } adc_major = ret; peter_base_addr= ioremap(S3C2410_PA_ADC,0x20); #ifdef CONFIG_DEVFS_FS devfs_mk_dir("adc"); devfs_mk_cdev(MKDEV(adc_major, 0), S_IFCHR|S_IRUGO|S_IWUSR, "adc/%d", 0); #endif printk("s3c2410_adc driver initial\n"); return 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; }
static ssize_t raw_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos) { struct iovec local_iov = { .iov_base = (void *)buf, .iov_len = count }; return generic_file_write_nolock(file, &local_iov, 1, ppos); } static ssize_t raw_file_aio_write(struct kiocb *iocb, const char *buf, size_t count, loff_t pos) { struct iovec local_iov = { .iov_base = (void *)buf, .iov_len = count }; return generic_file_aio_write_nolock(iocb, &local_iov, 1, &iocb->ki_pos); } static struct file_operations raw_fops = { .read = generic_file_read, .aio_read = generic_file_aio_read, .write = raw_file_write, .aio_write = raw_file_aio_write, .open = raw_open, .release= raw_release, .ioctl = raw_ioctl, .readv = generic_file_readv, .writev = generic_file_writev, .owner = THIS_MODULE, }; static struct file_operations raw_ctl_fops = { .ioctl = raw_ctl_ioctl, .open = raw_open, .owner = THIS_MODULE, }; static int __init raw_init(void) { int i; register_chrdev(RAW_MAJOR, "raw", &raw_fops); devfs_mk_cdev(MKDEV(RAW_MAJOR, 0), S_IFCHR | S_IRUGO | S_IWUGO, "raw/rawctl"); for (i = 1; i < MAX_RAW_MINORS; i++) devfs_mk_cdev(MKDEV(RAW_MAJOR, i), S_IFCHR | S_IRUGO | S_IWUGO, "raw/raw%d", i); return 0; } static void __exit raw_exit(void) { int i; for (i = 1; i < MAX_RAW_MINORS; i++) devfs_remove("raw/raw%d", i); devfs_remove("raw/rawctl"); devfs_remove("raw"); unregister_chrdev(RAW_MAJOR, "raw"); }
/* int init_module(void) */ static int __init can_init(void) { int i; #if LDDK_USE_BLKREQUEST extern int Can_request (); #endif DBGin("init_module"); #ifdef CONFIG_DEVFS_FS devfs_mk_cdev (MKDEV(Can_MAJOR, 0), S_IRUSR | S_IWUSR | S_IFCHR, "can0", 0); #endif #if LDDK_USE_REGISTER if( register_chrdev(Can_major, "can", &can_fops) ) { printk("can't get Major %d\n", Can_major); return(-EIO); } #endif { printk(__CAN_TYPE__ "CAN Driver " VERSION " (c) " __DATE__ " " __TIME__ "\n"); } /* initialize the variables layed down in /proc/sys/Can */ for (i = 0; i < MAX_CHANNELS; i++) { IOModel[i] = IO_MODEL; Baud[i] = 125; AccCode[i] = AccMask[i] = STD_MASK; Timeout[i] = 100; Outc[i] = CAN_OUTC_VAL; IRQ_requested[i] = 0; Can_minors[i] = i; /* used as IRQ dev_id */ #if defined(CONFIG_FIRE_ENGINE) /* we have a really fixed address here */ Base[i] = (MCF_MBAR + 0xa000 + CAN_MODULE*(0x0800)); /* Because the MCF FlexCAN is using more then 1 Interrupt vector, * what should be specified here ? * For information purpose let's only specify the first used here */ IRQ[i] = 64 + ISC_CANn_MBOR(CAN_MODULE); #endif #if defined(CONFIG_M528x) Base[i] = (MCF_MBAR + 0x1c0000); IRQ[i] = 136; #endif #if defined(CONFIG_M532x) /* we have a really fixed address here */ Base[i] = MCF_FLEXCAN_BASEADDR(CAN_MODULE); /* Because the MCF FlexCAN is using more then 1 Interrupt vector, * what should be specified here ? * For information purpose let's only specify the first used here */ IRQ[i] = 128; /* Enable GPIO pins for CANTX, CANRX */ #if defined(CONFIG_M5329EVB) /* On Freescale 5329 EVB CAN pins are muxed with I2C pins */ MCF_GPIO_PAR_FECI2C &= 0xF0; MCF_GPIO_PAR_FECI2C |= MCF_GPIO_PAR_FECI2C_PAR_SDA(0x2) | MCF_GPIO_PAR_FECI2C_PAR_SCL(0x2); #elif defined(CONFIG_UC532X) || defined(CONFIG_UC53281EVM) #ifdef CONFIG_PAR_LCDDATA_FOR_CAN /* we may use these pins for CAN signal */ MCF_GPIO_PAR_LCDDATA &= 0x0F; MCF_GPIO_PAR_LCDDATA |= MCF_GPIO_PAR_LCDDATA_PAR_LD17(0x2) | MCF_GPIO_PAR_LCDDATA_PAR_LD16(0x2); #else MCF_GPIO_PAR_FECI2C &= 0xF0; MCF_GPIO_PAR_FECI2C |= MCF_GPIO_PAR_FECI2C_PAR_SDA(0x2) | MCF_GPIO_PAR_FECI2C_PAR_SCL(0x2); #endif #else /* Could be changed for other boards. Depends on board design */ MCF_GPIO_PDDR_SSI = 0; MCF_GPIO_PAR_SSI = MCF_GPIO_PAR_SSI_PAR_RXD(0x1) | MCF_GPIO_PAR_SSI_PAR_TXD(0x1); #endif #endif #if defined(CONFIG_M5253EVB) /* we have a really fixed address here */ Base[i] = MCF_FLEXCAN_BASEADDR(i); /* Because the MCF FlexCAN is using more then 1 Interrupt vector, * what should be specified here ? * For information purpose let's only specify the first used here */ IRQ[i] = 128 + i; #endif #if defined(CCPC104) pc104_irqsetup(); IRQ[i] = 67; /* The only possible vector on CTRLink's 5282 CPU */ Base[i] = 0x40000280; #endif } /* after initializing channel based parameters * finisch some entries * and do drivers specific initialization */ IOModel[i] = '\0'; /* CAN_register_dump(); */ #if CAN4LINUX_PCI /* make some sysctl entries read only * IRQ number * Base address * and access mode * are fixed and provided by the PCI BIOS */ Can_sysctl_table[SYSCTL_IRQ - 1].mode = 0444; Can_sysctl_table[SYSCTL_BASE - 1].mode = 0444; /* printk("CAN pci test loaded\n"); */ /* dbgMask = 0; */ pcimod_scan(); #endif #if defined(CCPC104) /* The only possible interrupt could be IRQ4 on the PC104 Board */ Can_sysctl_table[SYSCTL_IRQ - 1].mode = 0444; #endif #if defined(CONFIG_FIRE_ENGINE) Can_sysctl_table[SYSCTL_BASE - 1].mode = 0444; #endif #if defined(CONFIG_M532x) || defined(CONFIG_M5253) || defined(CONFIG_M528x) Can_sysctl_table[SYSCTL_BASE - 1].mode = 0444; #endif #if LDDK_USE_PROCINFO /* #error procinfo */ register_procinfo(); #endif #if LDDK_USE_SYSCTL register_systables(); #endif #if LDDK_USE_BLKREQUEST blk_dev[Can_major].request_fn = Can_request; #endif DBGout(); return 0; }
static int __init EplLinInit(void) { tEplKernel EplRet; int iErr; int iRet; #ifdef CONFIG_DEVFS_FS int nMinorNumber; #endif TRACE0("EPL: + EplLinInit...\n"); TRACE2("EPL: Driver build: %s / %s\n", __DATE__, __TIME__); iRet = 0; // initialize global variables atomic_set(&AtomicEventState_g, EVENT_STATE_INIT); sema_init(&SemaphoreCbEvent_g, 1); init_waitqueue_head(&WaitQueueCbEvent_g); init_waitqueue_head(&WaitQueueProcess_g); init_waitqueue_head(&WaitQueueRelease_g); #ifdef CONFIG_DEVFS_FS // register character device handler TRACE2("EPL: Installing Driver '%s', Version %s...\n", EPLLIN_DRV_NAME, EPL_PRODUCT_VERSION); TRACE0("EPL: (using dynamic major number assignment)\n"); nDrvMajorNumber_g = register_chrdev(0, EPLLIN_DRV_NAME, &EplLinFileOps_g); if (nDrvMajorNumber_g != 0) { TRACE2 ("EPL: Driver '%s' installed successful, assigned MajorNumber=%d\n", EPLLIN_DRV_NAME, nDrvMajorNumber_g); } else { TRACE1 ("EPL: ERROR: Driver '%s' is unable to get a free MajorNumber!\n", EPLLIN_DRV_NAME); iRet = -EIO; goto Exit; } // create device node in DEVFS nMinorNumber = 0; TRACE1("EPL: Creating device node '/dev/%s'...\n", EPLLIN_DEV_NAME); iErr = devfs_mk_cdev(MKDEV(nDrvMajorNumber_g, nMinorNumber), S_IFCHR | S_IRUGO | S_IWUGO, EPLLIN_DEV_NAME); if (iErr == 0) { TRACE1("EPL: Device node '/dev/%s' created successful.\n", EPLLIN_DEV_NAME); } else { TRACE1("EPL: ERROR: unable to create device node '/dev/%s'\n", EPLLIN_DEV_NAME); iRet = -EIO; goto Exit; } #else // register character device handler // only one Minor required TRACE2("EPL: Installing Driver '%s', Version %s...\n", EPLLIN_DRV_NAME, EPL_PRODUCT_VERSION); iRet = alloc_chrdev_region(&nDevNum_g, 0, 1, EPLLIN_DRV_NAME); if (iRet == 0) { TRACE2 ("EPL: Driver '%s' installed successful, assigned MajorNumber=%d\n", EPLLIN_DRV_NAME, MAJOR(nDevNum_g)); } else { TRACE1 ("EPL: ERROR: Driver '%s' is unable to get a free MajorNumber!\n", EPLLIN_DRV_NAME); iRet = -EIO; goto Exit; } // register cdev structure pEpl_cdev_g = cdev_alloc(); pEpl_cdev_g->ops = &EplLinFileOps_g; pEpl_cdev_g->owner = THIS_MODULE; iErr = cdev_add(pEpl_cdev_g, nDevNum_g, 1); if (iErr) { TRACE2("EPL: ERROR %d: Driver '%s' could not be added!\n", iErr, EPLLIN_DRV_NAME); iRet = -EIO; goto Exit; } #endif // create device node in PROCFS EplRet = EplLinProcInit(); if (EplRet != kEplSuccessful) { goto Exit; } Exit: TRACE1("EPL: - EplLinInit (iRet=%d)\n", iRet); return (iRet); }
/** * Initialize module. * * @returns appropriate status code. */ static int __init VBoxDrvLinuxInit(void) { int rc; /* * Check for synchronous/asynchronous TSC mode. */ printk(KERN_DEBUG DEVICE_NAME ": Found %u processor cores.\n", (unsigned)RTMpGetOnlineCount()); #ifdef CONFIG_VBOXDRV_AS_MISC rc = misc_register(&gMiscDevice); if (rc) { printk(KERN_ERR DEVICE_NAME ": Can't register misc device! rc=%d\n", rc); return rc; } #else /* !CONFIG_VBOXDRV_AS_MISC */ /* * Register character device. */ g_iModuleMajor = DEVICE_MAJOR; rc = register_chrdev((dev_t)g_iModuleMajor, DEVICE_NAME, &gFileOpsVBoxDrv); if (rc < 0) { Log(("register_chrdev() failed with rc=%#x!\n", rc)); return rc; } /* * Save returned module major number */ if (DEVICE_MAJOR != 0) g_iModuleMajor = DEVICE_MAJOR; else g_iModuleMajor = rc; rc = 0; # ifdef CONFIG_DEVFS_FS /* * Register a device entry */ if (devfs_mk_cdev(MKDEV(DEVICE_MAJOR, 0), S_IFCHR | VBOX_DEV_FMASK, DEVICE_NAME) != 0) { Log(("devfs_register failed!\n")); rc = -EINVAL; } # endif #endif /* !CONFIG_VBOXDRV_AS_MISC */ if (!rc) { /* * Initialize the runtime. * On AMD64 we'll have to donate the high rwx memory block to the exec allocator. */ rc = RTR0Init(0); if (RT_SUCCESS(rc)) { #if defined(RT_ARCH_AMD64) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) rc = RTR0MemExecDonate(&g_abExecMemory[0], sizeof(g_abExecMemory)); printk(KERN_DEBUG "VBoxDrv: dbg - g_abExecMemory=%p\n", (void *)&g_abExecMemory[0]); #endif Log(("VBoxDrv::ModuleInit\n")); /* * Initialize the device extension. */ if (RT_SUCCESS(rc)) rc = supdrvInitDevExt(&g_DevExt, sizeof(SUPDRVSESSION)); if (RT_SUCCESS(rc)) { #ifdef VBOX_WITH_SUSPEND_NOTIFICATION rc = platform_driver_register(&gPlatformDriver); if (rc == 0) { rc = platform_device_register(&gPlatformDevice); if (rc == 0) #endif { printk(KERN_INFO DEVICE_NAME ": TSC mode is %s, kernel timer mode is 'normal'.\n", g_DevExt.pGip->u32Mode == SUPGIPMODE_SYNC_TSC ? "'synchronous'" : "'asynchronous'"); LogFlow(("VBoxDrv::ModuleInit returning %#x\n", rc)); printk(KERN_DEBUG DEVICE_NAME ": Successfully loaded version " VBOX_VERSION_STRING " (interface " RT_XSTR(SUPDRV_IOC_VERSION) ").\n"); return rc; } #ifdef VBOX_WITH_SUSPEND_NOTIFICATION else platform_driver_unregister(&gPlatformDriver); } #endif } rc = -EINVAL; RTR0TermForced(); } else rc = -EINVAL; /* * Failed, cleanup and return the error code. */ #if defined(CONFIG_DEVFS_FS) && !defined(CONFIG_VBOXDRV_AS_MISC) devfs_remove(DEVICE_NAME); #endif } #ifdef CONFIG_VBOXDRV_AS_MISC misc_deregister(&gMiscDevice); Log(("VBoxDrv::ModuleInit returning %#x (minor:%d)\n", rc, gMiscDevice.minor)); #else unregister_chrdev(g_iModuleMajor, DEVICE_NAME); Log(("VBoxDrv::ModuleInit returning %#x (major:%d)\n", rc, g_iModuleMajor)); #endif return rc; }
/** * Initialize module. * * @returns appropriate status code. */ static int __init VBoxDrvLinuxInit(void) { int rc; /* * Check for synchronous/asynchronous TSC mode. */ printk(KERN_DEBUG "vboxdrv: Found %u processor cores\n", (unsigned)RTMpGetOnlineCount()); #ifdef CONFIG_VBOXDRV_AS_MISC rc = misc_register(&gMiscDeviceSys); if (rc) { printk(KERN_ERR "vboxdrv: Can't register system misc device! rc=%d\n", rc); return rc; } rc = misc_register(&gMiscDeviceUsr); if (rc) { printk(KERN_ERR "vboxdrv: Can't register user misc device! rc=%d\n", rc); misc_deregister(&gMiscDeviceSys); return rc; } #else /* !CONFIG_VBOXDRV_AS_MISC */ /* * Register character devices and save the returned major numbers. */ /* /dev/vboxdrv */ g_iModuleMajorSys = DEVICE_MAJOR_SYS; rc = register_chrdev((dev_t)g_iModuleMajorSys, DEVICE_NAME_SYS, &gFileOpsVBoxDrvSys); if (rc < 0) { Log(("register_chrdev() failed with rc=%#x for vboxdrv!\n", rc)); return rc; } if (DEVICE_MAJOR_SYS != 0) g_iModuleMajorSys = DEVICE_MAJOR_SYS; else g_iModuleMajorSys = rc; /* /dev/vboxdrvu */ /** @todo Use a minor number of this bugger (not sure if this code is used * though, so not bothering right now.) */ g_iModuleMajorUsr = DEVICE_MAJOR_USR; rc = register_chrdev((dev_t)g_iModuleMajorUsr, DEVICE_NAME_USR, &gFileOpsVBoxDrvUsr); if (rc < 0) { Log(("register_chrdev() failed with rc=%#x for vboxdrv!\n", rc)); return rc; } if (DEVICE_MAJOR_USR != 0) g_iModuleMajorUsr = DEVICE_MAJOR_USR; else g_iModuleMajorUsr = rc; rc = 0; # ifdef CONFIG_DEVFS_FS /* * Register a device entry */ if ( devfs_mk_cdev(MKDEV(DEVICE_MAJOR_SYS, 0), S_IFCHR | VBOX_DEV_FMASK, DEVICE_NAME_SYS) != 0 || devfs_mk_cdev(MKDEV(DEVICE_MAJOR_USR, 0), S_IFCHR | VBOX_DEV_FMASK, DEVICE_NAME_USR) != 0) { Log(("devfs_register failed!\n")); rc = -EINVAL; } # endif #endif /* !CONFIG_VBOXDRV_AS_MISC */ if (!rc) { /* * Initialize the runtime. * On AMD64 we'll have to donate the high rwx memory block to the exec allocator. */ rc = RTR0Init(0); if (RT_SUCCESS(rc)) { #if (defined(RT_ARCH_AMD64) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)) || defined(VBOX_WITH_TEXT_MODMEM_HACK) # ifdef VBOX_WITH_TEXT_MODMEM_HACK set_memory_x(&g_abExecMemory[0], sizeof(g_abExecMemory) / PAGE_SIZE); set_memory_rw(&g_abExecMemory[0], sizeof(g_abExecMemory) / PAGE_SIZE); # endif rc = RTR0MemExecDonate(&g_abExecMemory[0], sizeof(g_abExecMemory)); printk(KERN_DEBUG "VBoxDrv: dbg - g_abExecMemory=%p\n", (void *)&g_abExecMemory[0]); #endif Log(("VBoxDrv::ModuleInit\n")); /* * Initialize the device extension. */ if (RT_SUCCESS(rc)) rc = supdrvInitDevExt(&g_DevExt, sizeof(SUPDRVSESSION)); if (RT_SUCCESS(rc)) { #ifdef VBOX_WITH_SUSPEND_NOTIFICATION rc = platform_driver_register(&gPlatformDriver); if (rc == 0) { rc = platform_device_register(&gPlatformDevice); if (rc == 0) #endif { printk(KERN_INFO "vboxdrv: TSC mode is %s, tentative frequency %llu Hz\n", SUPGetGIPModeName(g_DevExt.pGip), g_DevExt.pGip->u64CpuHz); LogFlow(("VBoxDrv::ModuleInit returning %#x\n", rc)); printk(KERN_DEBUG "vboxdrv: Successfully loaded version " VBOX_VERSION_STRING " (interface " RT_XSTR(SUPDRV_IOC_VERSION) ")\n"); return rc; } #ifdef VBOX_WITH_SUSPEND_NOTIFICATION else platform_driver_unregister(&gPlatformDriver); } #endif } rc = -EINVAL; RTR0TermForced(); } else rc = -EINVAL; /* * Failed, cleanup and return the error code. */ #if defined(CONFIG_DEVFS_FS) && !defined(CONFIG_VBOXDRV_AS_MISC) devfs_remove(DEVICE_NAME_SYS); devfs_remove(DEVICE_NAME_USR); #endif } #ifdef CONFIG_VBOXDRV_AS_MISC misc_deregister(&gMiscDeviceSys); misc_deregister(&gMiscDeviceUsr); Log(("VBoxDrv::ModuleInit returning %#x (minor:%d & %d)\n", rc, gMiscDeviceSys.minor, gMiscDeviceUsr.minor)); #else unregister_chrdev(g_iModuleMajorUsr, DEVICE_NAME_USR); unregister_chrdev(g_iModuleMajorSys, DEVICE_NAME_SYS); Log(("VBoxDrv::ModuleInit returning %#x (major:%d & %d)\n", rc, g_iModuleMajorSys, g_iModuleMajorUsr)); #endif return rc; }
/** * 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_device_create(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; }