static int __init drm_core_init(void) { int ret = -ENOMEM; drm_global_init(); drm_connector_ida_init(); idr_init(&drm_minors_idr); if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops)) goto err_p1; drm_class = drm_sysfs_create(THIS_MODULE, "drm"); if (IS_ERR(drm_class)) { printk(KERN_ERR "DRM: Error creating drm class.\n"); ret = PTR_ERR(drm_class); goto err_p2; } drm_debugfs_root = debugfs_create_dir("dri", NULL); if (!drm_debugfs_root) { DRM_ERROR("Cannot create /sys/kernel/debug/dri\n"); ret = -1; goto err_p3; } DRM_INFO("Initialized %s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE); return 0; err_p3: drm_sysfs_destroy(); err_p2: unregister_chrdev(DRM_MAJOR, "drm"); idr_destroy(&drm_minors_idr); err_p1: return ret; }
int init_module(void) { int result, i; /* * Register your major, and accept a dynamic number */ result = register_chrdev(scullp_major, "scullp", &scullp_fops); if (result < 0) return result; if (scullp_major == 0) scullp_major = result; /* dynamic */ /* * allocate the devices -- we can't have them static, as the number * can be specified at load time */ scullp_devices = kmalloc(scullp_devs * sizeof (ScullP_Dev), GFP_KERNEL); if (!scullp_devices) { result = -ENOMEM; goto fail_malloc; } memset(scullp_devices, 0, scullp_devs * sizeof (ScullP_Dev)); for (i=0; i < scullp_devs; i++) { scullp_devices[i].order = scullp_order; scullp_devices[i].qset = scullp_qset; sema_init (&scullp_devices[i].sem, 1); } #ifdef SCULLP_USE_PROC /* only when available */ create_proc_read_entry("scullpmem", 0, NULL, scullp_read_procmem, NULL); #endif return 0; /* succeed */ fail_malloc: unregister_chrdev(scullp_major, "scullp"); return result; }
static int __init msr_init(void) { int i, err = 0; i = 0; if (register_chrdev(MSR_MAJOR, "cpu/msr", &msr_fops)) { printk(KERN_ERR "msr: unable to get major %d for msr\n", MSR_MAJOR); err = -EBUSY; goto out; } msr_class = class_create(THIS_MODULE, "msr"); if (IS_ERR(msr_class)) { err = PTR_ERR(msr_class); goto out_chrdev; } msr_class->devnode = msr_devnode; for_each_online_cpu(i) { err = msr_device_create(i); if (err != 0) goto out_class; } register_hotcpu_notifier(&msr_class_cpu_notifier); err = 0; goto out; out_class: i = 0; for_each_online_cpu(i) msr_device_destroy(i); class_destroy(msr_class); out_chrdev: unregister_chrdev(MSR_MAJOR, "cpu/msr"); out: return err; }
static __init int example_init(void) { int result; /* * Register your major, and accept a dynamic number */ result = register_chrdev(example_major, "example", &example_fops); if (result < 0) { printk(KERN_WARNING "example: can't get major %d\n",example_major); return result; } if (example_major == 0) example_major = result; /* dynamic */ printk("<1> example device driver version 4: loaded at major number %d\n", example_major); example_device_stats = (example_stats *) kmalloc(sizeof(example_stats),GFP_KERNEL); if (!example_device_stats) { result = -ENOMEM; goto fail_malloc; } init_example_device_stats(); /* We assume that the /proc/driver exists. Otherwise we need to use proc_mkdir to * create it as follows: proc_mkdir("driver", NULL); */ example_proc_file = proc_create("driver/example", 0, NULL, &example_proc_fops); if (!example_proc_file) { result = -ENOMEM; goto fail_malloc; } return 0; fail_malloc: unregister_chrdev(example_major, "example"); return result; }
int register_ipu_device() { int ret = 0; struct device *temp; mxc_ipu_major = register_chrdev(0, "mxc_ipu", &mxc_ipu_fops); if (mxc_ipu_major < 0) { printk(KERN_ERR "Unable to register Mxc Ipu as a char device\n"); return mxc_ipu_major; } mxc_ipu_class = class_create(THIS_MODULE, "mxc_ipu"); if (IS_ERR(mxc_ipu_class)) { printk(KERN_ERR "Unable to create class for Mxc Ipu\n"); ret = PTR_ERR(mxc_ipu_class); goto err1; } temp = device_create(mxc_ipu_class, NULL, MKDEV(mxc_ipu_major, 0), NULL, "mxc_ipu"); if (IS_ERR(temp)) { printk(KERN_ERR "Unable to create class device for Mxc Ipu\n"); ret = PTR_ERR(temp); goto err2; } spin_lock_init(&queue_lock); init_waitqueue_head(&waitq); return ret; err2: class_destroy(mxc_ipu_class); err1: unregister_chrdev(mxc_ipu_major, "mxc_ipu"); return ret; }
int bano_init(void) { int b; /* Registering device */ b = register_chrdev(bano_major, "bano", &bano_fops); if (b < 0) { printk("<1>Bano: cannot obtain major number %d\n", bano_major); return b; } damas = 0; varones = 0; curr_size_d = 0; curr_size_v = 0; damas_pos = 0; varones_pos = 0; m_init(&mutex); c_init(&cond); /* Allocating syncread_buffer */ buffer_d = kmalloc(MAX_SIZE, GFP_KERNEL); if (buffer_d == NULL) { bano_exit(); return -ENOMEM; } memset(buffer_d, 0, MAX_SIZE); buffer_v = kmalloc(MAX_SIZE, GFP_KERNEL); if (buffer_v == NULL) { bano_exit(); return -ENOMEM; } memset(buffer_v, 0, MAX_SIZE); printk("<1>Inserting bano module varones y damas\n"); return 0; }
static int __init cpuid_init(void) { int i, err = 0; i = 0; if (register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) { printk(KERN_ERR "cpuid: unable to get major %d for cpuid\n", CPUID_MAJOR); err = -EBUSY; goto out; } cpuid_class = class_create(THIS_MODULE, "cpuid"); if (IS_ERR(cpuid_class)) { err = PTR_ERR(cpuid_class); goto out_chrdev; } for_each_online_cpu(i) { err = cpuid_device_create(i); if (err != 0) goto out_class; } register_hotcpu_notifier(&cpuid_class_cpu_notifier); err = 0; goto out; out_class: i = 0; for_each_online_cpu(i) { device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, i)); } class_destroy(cpuid_class); out_chrdev: unregister_chrdev(CPUID_MAJOR, "cpu/cpuid"); out: return err; }
static int __init load_module(void) { int ret_val; ret_val = register_chrdev(MAJOR_NUMBER, DEVICE_NAME, &Fops); if(ret_val < 0){ printk(KERN_ALERT "%s failed with %d\n", "Sorry, registering the character device ", ret_val); return ret_val; } printk(KERN_INFO "%s The major device number is %d.\n", "Registeration is a success", MAJOR_NUMBER); printk(KERN_INFO "If you want to talk to the device driver,\n"); printk(KERN_INFO "you'll have to create a device file. \n"); printk(KERN_INFO "We suggest you use:\n"); printk(KERN_INFO "mknod %s c %d 0\n", DEVICE_FILE_NAME, MAJOR_NUMBER); printk(KERN_INFO "The device file name is important, because\n"); printk(KERN_INFO "the ioctl program assumes that's the\n"); printk(KERN_INFO "file you'll use.\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 int xordev_init_module(void) { int result, i; /* clear structures */ for(i = 0; i < MAX_DEVICES; i++) xordev_data[i].devno = 0; /* Registering character device */ major = register_chrdev(0, DRVNAME, &xordev_fops); if (major < 0) { printk(KERN_NOTICE "Can't register a character device"); result = major; goto fail; } xordev_class = class_create(THIS_MODULE, DRVNAME); if (IS_ERR(xordev_class)) { printk(KERN_NOTICE "Can't create device class"); result = PTR_ERR(xordev_class); goto fail; } /* PCI probing */ DBG printk(KERN_DEBUG "Probing PCI devices"); result = pci_register_driver(&xordev_pci_driver); if (result < 0) { printk(KERN_NOTICE "Can't register pci driver"); goto fail; } return 0; /* success */ fail: xordev_cleanup_module(); return result; }
int ethinit_module(void) { int res; printk(KERN_INFO "init module called \n"); init_module2_2(); spin_lock_init(ð_lock); schar_name = "schar2"; /* register device with kernel */ res = register_chrdev(SCHAR_MAJOR_2, schar_name, &schar_fops); if (res) { printk(KERN_INFO "can't register device with kernel\n"); return res; } /* register proc entry */ schar_root_header_2 = register_sysctl_table(schar_root_dir_2, 0); return 0; }
static int pmic_rtc_probe(struct platform_device *pdev) { int ret = 0; struct device *temp_class; pmic_rtc_major = register_chrdev(0, "pmic_rtc", &pmic_rtc_fops); if (pmic_rtc_major < 0) { printk(KERN_ERR "Unable to get a major for pmic_rtc\n"); return pmic_rtc_major; } pmic_rtc_class = class_create(THIS_MODULE, "pmic_rtc"); if (IS_ERR(pmic_rtc_class)) { printk(KERN_ERR "Error creating pmic rtc class.\n"); ret = PTR_ERR(pmic_rtc_class); goto err_out1; } temp_class = device_create(pmic_rtc_class, NULL, MKDEV(pmic_rtc_major, 0), NULL, "pmic_rtc"); if (IS_ERR(temp_class)) { printk(KERN_ERR "Error creating pmic rtc class device.\n"); ret = PTR_ERR(temp_class); goto err_out2; } printk(KERN_INFO "PMIC RTC successfully probed\n"); return ret; err_out2: class_destroy(pmic_rtc_class); err_out1: unregister_chrdev(pmic_rtc_major, "pmic_rtc"); return ret; }
static int s3c_dma_init(void) { //分配src,dst对应的缓冲区 src = dma_alloc_writecombine(NULL, BUF_SIZE, &src_phys, GFP_KERNEL); if(NULL == src) { printk("can not alloc buf for src"); 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 not alloc buf for dst"); 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"); return 0; }
/** gpsdrv_init Function * This function Initializes the gps driver parametes and exposes * /dev/gps node to user space * * Parameters : NULL * Returns GPS_SUCCESS on success * else suitable error code */ static int __init gpsdrv_init(void) { GPSDRV_DBG(" Inside %s", __func__); /* Expose the device DEVICE_NAME to user space * And obtain the major number for the device */ gpsdrv_major = register_chrdev(0, DEVICE_NAME, \ &gpsdrv_chrdev_ops); if (0 > gpsdrv_major) { GPSDRV_ERR("Error when registering to char dev"); return GPS_ERR_FAILURE; } GPSDRV_VER("allocated %d, %d", gpsdrv_major, 0); /* udev */ gpsdrv_class = class_create(THIS_MODULE, DEVICE_NAME); if (IS_ERR(gpsdrv_class)) { GPSDRV_ERR(" Something went wrong in class_create"); unregister_chrdev(gpsdrv_major, DEVICE_NAME); return GPS_ERR_CLASS; } gpsdrv_dev = device_create(gpsdrv_class, NULL, MKDEV(gpsdrv_major, 0), NULL, DEVICE_NAME); if (IS_ERR(gpsdrv_dev)) { GPSDRV_ERR(" Error in class_create"); unregister_chrdev(gpsdrv_major, DEVICE_NAME); class_destroy(gpsdrv_class); return GPS_ERR_CLASS; } return GPS_SUCCESS; }
static int __init dummy_init(void) { int ret; printk(KERN_INFO "Dummy is loading\n"); memory_buffer = kmalloc(1, GFP_KERNEL); if (!memory_buffer) return -ENOMEM; memset(memory_buffer, 0, 1); ret = register_chrdev(memory_major, "dummy", &memory_fops); if (ret < 0) goto fail; printk(KERN_INFO "Dummy initialized\n"); return 0; fail: printk(KERN_INFO "dummy: cannot obtain major number %d\n", memory_major); kfree(memory_buffer); return ret; }
/* * This function is called when the module is loaded and registers a * device for the driver to use. */ static int __init my_init(void) { /* Note that as soon as the device is registered we might get access to the functions pointed to by fops, hence the ordering. */ // Linux kernel's version of printf printk(KERN_INFO "Mapping virtual address...\n"); // map virtual address to multiplier physical address // use ioremap virt_addr = ioremap(PHY_ADDR, MEMSIZE); // might need to convert inputs to unsigned long printk(KERN_INFO "Multiplication physical address: %h \n", PHY_ADDR); // might need to change %p printk(KERN_INFO "Multiplication virtual address: %h \n", virt_addr); /* This function call registers a device and returns a major number associated with it. Be wary, the device file could be accessed as soon as you register it, make sure anything you need (ie buffers ect) are setup _BEFORE_ you register the device.*/ Major = register_chrdev(0, DEVICE_NAME, &fops); /* Negative values indicate a problem */ if (Major < 0) { /* Make sure you release any other resources you've already grabbed if you get here so you don't leave the kernel in a broken state. */ printk(KERN_ALERT "Registering char device failed with %d\n", Major); return Major; } printk(KERN_INFO "Registered a device with dynamic Major number of %d\n", Major); //printk(KERN_INFO "Create a device file for this device with this command:\n'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major); return 0; /* success */ }
int __init load_module(void) { _major = register_chrdev (0,"brightnessMajor",&mod_fops); if (_major < 0) { printk("Registering the character device failed with (Major)- %d\n", _major); return _major; } if (_major > 0) { printk("Registering the character device success with (Major)- %d\n", _major); } _minor=misc_register(&mod_misc); if (_minor){ printk("Registering the character device failed with (Minor) - %d\n", _minor); return -EIO; } printk("Registering the character device success with (Minor) - %d\n", _minor); initPin(); printk(KERN_ALERT "brightness Module Load Successfuly\n"); return 0; }
/* Driver initialization */ static int sg_init() { static int sg_registered = 0; if (sg_template.dev_noticed == 0) return 0; if(!sg_registered) { if (register_chrdev(SCSI_GENERIC_MAJOR,"sg",&sg_fops)) { printk("Unable to get major %d for generic SCSI device\n", SCSI_GENERIC_MAJOR); return 1; } sg_registered++; } /* If we have already been through here, return */ if(scsi_generics) return 0; #ifdef DEBUG printk("sg: Init generic device.\n"); #endif #ifdef SG_BIG_BUFF big_buff= (char *) scsi_init_malloc(SG_BIG_BUFF, GFP_ATOMIC | GFP_DMA); #endif scsi_generics = (struct scsi_generic *) scsi_init_malloc((sg_template.dev_noticed + SG_EXTRA_DEVS) * sizeof(struct scsi_generic), GFP_ATOMIC); memset(scsi_generics, 0, (sg_template.dev_noticed + SG_EXTRA_DEVS) * sizeof(struct scsi_generic)); sg_template.dev_max = sg_template.dev_noticed + SG_EXTRA_DEVS; return 0; }
// tb_init(): invoked as part of the kernel bootup process static int tb_init(void) { int err=0; Message("tb_init() invoked"); tb_major = register_chrdev (240, "xlr_tracebuffer", &tb_fops); if (tb_major < 0) { ErrorMsg("tb_init() register_chrdev() failed"); return tb_major; } // the handler too gets registered in the following call err = request_irq(PIC_BRIDGE_TB_IRQ(), tb_int_handler, TB_INT_FLAGS, "trace buffer", NULL); if (err) { unregister_chrdev (tb_major, "trace buffer"); ErrorMsg("tb_init(): request_irq() failed"); return err; } tb_dev.data = (unsigned char *)kmalloc(TB_SIZE,GFP_KERNEL); Message("tb_init() request_irq() succeeded"); printk("Registered tracebuffer driver with Major No. [%d]\n", 240); return 0; }
int __init simple_init(void) { int result; /* Register an entry in /proc */ proc_entry = proc_create("simple", 0, NULL, &proc_fops); /* Register a device with the given major number */ result = register_chrdev(simple_major, "simple", &simple_fops); if (result < 0) { printk(KERN_WARNING "Cannot register the /dev/simple device with major number: %d\n", simple_major); return result; } mybuf = kmalloc(mybuf_size, GFP_KERNEL); if (!mybuf) { result = -ENOMEM; simple_exit(); return result; } else { memset(mybuf, 0, 1); printk(KERN_INFO "The SIMPLE module has been inserted.\n"); return 0; } }
static int __init chardev_example_init(void) { major_number = register_chrdev(0, "Chardev_Device", &fops);\ if (major_number < 0) { return -1; } sysfs_class = class_create(THIS_MODULE, "Sysfs_class"); if (IS_ERR(sysfs_class)) { unregister_chrdev(major_number, "Sysfs_Device"); return -1; } sysfs_device = device_create(sysfs_class, NULL, MKDEV(major_number, 0), NULL, "sysfs_class" "_" "sysfs_Device"); if (IS_ERR(sysfs_device)) { class_destroy(sysfs_class); unregister_chrdev(major_number, "Sysfs_Device"); return -1; } return 0; }
/* * This function is called when the module is loaded and registers a * device for the driver to use. */ int my_init(void) { /* This function call registers a device and returns a major number associated with it. Be wary, the device file could be accessed as soon as you register it, make sure anything you need (ie buffers ect) are setup _BEFORE_ you register the device.*/ Major = register_chrdev(0, DEVICE_NAME, &fops); /* Negative values indicate a problem */ if (Major < 0) { /* Make sure you release any other resources you've already grabbed if you get here so you don't leave the kernel in a broken state. */ printk(KERN_ALERT "Registering char device failed with %d\n", Major); return Major; } printk(KERN_INFO "Registered a device with dynamic Major number of %d\n", Major); printk(KERN_INFO "Create a device file for this device with this command:\n'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major); return 0; /* success */ }
static int led_probe(struct platform_device *pdev) { struct resource *res; /* 根据platform_device的资源进行ioremap */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); gpio_con = ioremap(res->start, res->end - res->start + 1); gpio_dat = gpio_con + 1; res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); pin = res->start; /* 注册字符设备驱动程序 */ printk("led_probe, found led\n"); major = register_chrdev(0, "myled", &led_fops); cls = class_create(THIS_MODULE, "myled"); device_create(cls, NULL, MKDEV(major, 0), NULL, "led"); /* /dev/led */ return 0; }
static int __init zt_key_init(void) { int ret; struct device *dev; printk("zt_key_init\r\n"); /* create motor dev */ // ZT_KEY_MAJOR ret = register_chrdev(ZT_KEY_MAJOR, "zt_key", &zt_key_fops); if ( ret < 0) { printk("zt_key_init register_chrdev error = 0x%x\n",ret); return -EFAULT; } zt_key_class = class_create(THIS_MODULE, "zt_key"); dev = device_create(zt_key_class, NULL, MKDEV(ZT_KEY_MAJOR, 0), NULL, "zt_key"); return 0; }
static int gpio_pwm_init(void) { int i; printk(KERN_ALERT "Initializing the kernel module for GPIO and PWM ports...\n"); register_chrdev(GPIO_PWM_MAJOR, "gpio_pwm_module", &fops); for (i = FIRST_GPIO_PORT; i <= LAST_GPIO_PORT; i++) gpio_direction_output(i,1); init_timer(& timer_period); timer_period.function = period_function; timer_period.data = 0; // non utilise timer_period.expires = jiffies+ time_period; printk("init timer period"); add_timer(& timer_period); init_timer(& timer_duty); timer_duty.function = duty_function; timer_duty.data = 0; // non utilise timer_duty.expires = jiffies+ time_duty; printk("init duty period"); add_timer(& timer_duty); return 0; }
static int __init init_mtdchar(void) { #ifdef CONFIG_DEVFS_FS if (devfs_register_chrdev(MTD_CHAR_MAJOR, "mtd", &mtd_fops)) { printk(KERN_NOTICE "Can't allocate major number %d for Memory Technology Devices.\n", MTD_CHAR_MAJOR); return -EAGAIN; } devfs_dir_handle = devfs_mk_dir(NULL, "mtd", NULL); register_mtd_user(¬ifier); #else if (register_chrdev(MTD_CHAR_MAJOR, "mtd", &mtd_fops)) { printk(KERN_NOTICE "Can't allocate major number %d for Memory Technology Devices.\n", MTD_CHAR_MAJOR); return -EAGAIN; } #endif return 0; }
static int __init htc_msgservice_init(void) { int32_t ret; htc_rmt_msg = kzalloc(sizeof(htc_remote_msg_t), GFP_KERNEL); if (htc_rmt_msg == NULL) { PERR("allocate the space for remote message failed"); return -1; } ret = register_chrdev(0, DEVICE_NAME, &htc_msgservice_fops); if (ret < 0) { kfree(htc_rmt_msg); PERR("register module fail\n"); return ret; } htc_msgservice_major = ret; htc_msgservice_class = class_create(THIS_MODULE, "htc_msgservice"); device_create(htc_msgservice_class, NULL, MKDEV(htc_msgservice_major, 0), NULL, DEVICE_NAME); PDEBUG("register module ok\n"); return 0; }
int init_module(void) { int result, i; /* * Register your major, and accept a dynamic number */ result = register_chrdev(scullv_major, "scullv", &scullv_fops); if (result < 0) return result; if (scullv_major == 0) scullv_major = result; /* dynamic */ /* * allocate the devices -- we can't have them static, as the number * can be specified at load time */ scullv_devices = kmalloc(scullv_devs * sizeof (ScullV_Dev), GFP_KERNEL); if (!scullv_devices) { result = -ENOMEM; goto fail_malloc; } memset(scullv_devices, 0, scullv_devs * sizeof (ScullV_Dev)); for (i=0; i < scullv_devs; i++) { scullv_devices[i].order = scullv_order; scullv_devices[i].qset = scullv_qset; } #ifdef SCULLV_USE_PROC /* only when available */ /* this is the last line in init_module */ proc_register_dynamic(&proc_root, &scullv_proc_entry); #endif return 0; /* succeed */ fail_malloc: unregister_chrdev(scullv_major, "scullv"); return result; }
static int __init my_led_init(void) { int ret; int error,devno; printk("Hello led module\n"); //// /* //// PortJ = ioremap(PORTJ_BASE_ADDR,sizeof(GPIO_PORT)); //// if (PortJ == NULL) { //// printk("Failed to remap register block\n"); //// return -1; //// } //// */ //// //Init GPIOJ output //// //PortJ->con = 0x00001111; #if 0 ret = register_chrdev(DEVICE_MIJOR, DEVICE_NAME, &fops); if (ret < 0) { printk( "Registering char device %s failed with\n",DEVICE_NAME); return ret; } printk( "Registering char device %s ok with Major number %d \n",DEVICE_NAME,DEVICE_MIJOR); #endif //// #if 0 //// dev = MKDEV (hello_major, hello_minor); //// ret = register_chrdev_region (dev, number_of_devices, "hello"); //// if (ret<0) { //// printk (KERN_WARNING "hello: can't get major number %d\n", hello_major); //// return ret; //// } //// devno = MKDEV (hello_major, hello_minor); //// cdev_init (&cdev, &fops); //// cdev.owner = THIS_MODULE; //// cdev.ops = &fops; //// error = cdev_add (&cdev, devno , 1); //// if (error) //// printk (KERN_NOTICE "Error adding char_reg_setup_cdev"); //// //// /* create your own class under /sysfs */ //// my_class = class_create(THIS_MODULE, "my_class"); //// if(IS_ERR(my_class)) //// { //// printk("Err: failed in creating class.\n"); //// return -1; //// } //// //// /* register your own device in sysfs, and this will cause udev to create corresponding device node */ //// device_create( my_class, NULL, MKDEV(hello_major,hello_minor), NULL,"hello%d",0); //// printk (KERN_INFO "Registered character driver by register_chrdev_region ok\n"); //// #endif //// #if 1 //// if (alloc_chrdev_region(&first, 0, 1, DEVICE_NAME) < 0) //$cat /proc/devices //// { //// return -1; //// } //// //// cdev_init(&c_dev, &fops); //// if (cdev_add(&c_dev, first, 1) == -1) //// { //// device_destroy(cl, first); //// class_destroy(cl); //// unregister_chrdev_region(first, 1); //// return -1; //// } //// //// if ((cl = class_create(THIS_MODULE, "leddrv")) == NULL) //$ls /sys/class //// { //// unregister_chrdev_region(first, 1); //// return -1; //// } //// //// if (device_create(cl, NULL, first, NULL, "myled") == NULL) //$ls /dev/ //// { //// class_destroy(cl); //// unregister_chrdev_region(first, 1); //// return -1; //// } //// //// //// printk ("Registered character driver by alloc_chrdev_region wiht major %d minor %d ok\n",MAJOR(first),MINOR(first)); //// #endif #if 1 printk("sample misc init\n"); ret = misc_register(&sample_misc_device); if(ret<0) { printk("Registered misc character driver error\n"); misc_deregister(&sample_misc_device); } printk("Registered misc character driver ok\n"); #endif //iounmap(PorJ_Con); return 0; }
STATIC int balong_compose_probe(struct platform_device *pdev) { int ret = 0; struct ade_compose_data_type *ade_pri_data; struct balong_fb_data_type *fb_data; BUG_ON(pdev == NULL); balongfb_logi("enter succ!"); if (IS_ERR(compose_class)) { balongfb_loge("compose_class is NULL"); return -EINVAL; } ade_pri_data = (struct ade_compose_data_type *)platform_get_drvdata(pdev); fb_data = (struct balong_fb_data_type *)platform_get_drvdata(ade_pri_data->parent); ret = register_chrdev(major, DEV_ADE_COMPOSE_NAME, &compose_driver_fops); if (ret < 0) { balongfb_loge("register_chrdev is error %d", ret); return ret; } if (major == 0) { major = ret; } device_create(compose_class, NULL, MKDEV(major, 0), NULL, DEV_ADE_COMPOSE_NAME); /*************init private data********************************************/ mutex_init(&ade_pri_data->ade_lock); ade_pri_data->have_refresh = false; ade_pri_data->res_switch_cmpl = 0; init_waitqueue_head(&ade_pri_data->wait_res_cmpl); ade_pri_data->ovly1_cmpl = 0; init_waitqueue_head(&ade_pri_data->wait_ovly1_cmpl); ade_pri_data->wdma1_cmpl = 0; init_waitqueue_head(&ade_pri_data->wait_wdma1_cmpl); ade_pri_data->cmdq1_cmpl = 0; init_waitqueue_head(&ade_pri_data->wait_cmdq1_cmpl); ade_pri_data->cmdq2_cmpl = 0; init_waitqueue_head(&ade_pri_data->wait_cmdq2_cmpl); #ifdef CONFIG_HAS_EARLYSUSPEND ade_pri_data->early_suspend.suspend = balong_compose_early_suspend; ade_pri_data->early_suspend.resume = balong_compose_late_resume; ade_pri_data->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB - 2; register_early_suspend(&ade_pri_data->early_suspend); #endif /* init ade overlay, only intialize one time */ ade_overlay_init(&ade_pri_data->overlay_ctl); ade_cmdq_cmdfile_buff_init(fb_data->fb_ion_client, ade_pri_data->cmdq_list); ade_overlay_init_wdma2_buff(fb_data->fb_ion_client, ade_pri_data); #if ADE_DEBUG_LOG_ENABLE g_debug_balongfd = fb_data; #endif balongfb_logi("exit succ!"); return 0; }