static int platform_led_probe(struct platform_device *pdev) { int result; dev_t devno; devno = MKDEV(major,minor); if(major) result = register_chrdev_region(devno,1,"led-dyf"); else{ result = alloc_chrdev_region(&devno,0,1,"led-dyf"); major = MAJOR(devno); } if(result < 0){ printk("driver init unsuccess!\n"); return result; } gpbcon = (volatile unsigned long *)ioremap(0x56000010,16); gpbdat = gpbcon + 1; cdev_setup(); dyf_led_init(); led_all_off(); printk("platform_led_driver is init successfull!\n"); return 0; }
static int __init cdev_vir_init(void) { int ret=0; dev_t dev; int i; char node_name[NAME_LEN]; printk(KERN_ERR "cdev ringbuffer world!\n"); ret = alloc_chrdev_region(&dev, 0, DEV_NUM, device_name); if (ret) { CL_ERR("cdev: alloc_chardev_region failed!\n"); ret = -1; return ret; } vir_cdev_class = class_create(THIS_MODULE,device_name); if(IS_ERR(vir_cdev_class)) { CL_ERR(" failed in creating class.\n"); ret = -1; goto err_class_create; } CL_PRINT("class_create\n"); vir_devices = kzalloc(sizeof(struct vir_device)*DEV_NUM,GFP_KERNEL); if(vir_devices == NULL) { CL_ERR("kmalloc vir_device \n"); ret = -1; goto err_kzalloc_err; } for(i=0;i<DEV_NUM;i++) { sprintf(node_name,"%s%d",device_name,i); cdev_setup(&vir_devices[i],dev+i,node_name); } goto err_chrdev_region; err_kzalloc_err: class_destroy(vir_cdev_class); err_class_create: unregister_chrdev_region(dev, DEV_NUM); err_chrdev_region: return ret; }