/** * @brief ドライバ初期化関数 * * @param[in] なし * @retval D_SHDMA_RET_OK : 正常終了 * @retval EIO : ドライバ初期化エラー * @retval D_SHDMA_RET_NG : ドライバ名取得失敗 * @exception なし * @see なし */ int shdma_init_module(void) { int ret = 0; /** <ol><li>処理開始*/ SHDMA_DEBUG_MSG_ENTER(0, 0, 0); /** <li>ドライバのアサイン */ ret = register_chrdev(0, /* auto asign mode */ D_SHDMA_DRV_NAME, &shdma_fops); /** <ol><li>アサイン失敗時はエラー終了 */ if( ret < 0 ){ printk("***ERROR: asign falut.\n" ); return -1; } /** </ol> */ shdma_major = ret; /** <li>クラス作成 */ shdma_dev_class = class_create(THIS_MODULE, D_SHDMA_DRV_NAME); /** <ol><li>クラス作成失敗時はエラー終了 */ if (IS_ERR(shdma_dev_class)) { unregister_chrdev( shdma_major, D_SHDMA_DRV_NAME ); printk("***ERROR: fault class create.\n" ); return -EIO; } /** </ol> */ /** <li>ドライバ作成 */ shdma_dev_device = device_create(shdma_dev_class, NULL, MKDEV(shdma_major, 0), NULL, D_SHDMA_DRV_NAME); /** <ol><li>ドライバ作成失敗時はエラー終了 */ if(IS_ERR(shdma_dev_device)) { class_destroy( shdma_dev_class ); unregister_chrdev( shdma_major, D_SHDMA_DRV_NAME ); printk("***ERROR: fault device create.\n" ); return -EIO; } /** </ol> */ /** <li>ドライバファイル作成 */ ret = device_create_file(shdma_dev_device, &dev_attr_name); /** <ol><li>ドライバファイル作成失敗時はエラー終了 */ if( ret ) { device_destroy( shdma_dev_class, MKDEV(shdma_major, 0)); class_destroy( shdma_dev_class ); unregister_chrdev( shdma_major, D_SHDMA_DRV_NAME ); printk("***ERROR: fault device create file.\n" ); return -EIO; } /** </ol>*/ /** <li>セマフォ初期化 */ sema_init( &open_sem, 1 ); sema_init( &write_sem, 1 ); SHDMA_DEBUG_MSG_EXIT(); /** <li>処理終了</ol>*/ return 0; }
/** * platform driver * */ static int __devinit dsps_probe(struct platform_device *pdev) { int ret; pr_debug("%s.\n", __func__); if (pdev->dev.platform_data == NULL) { pr_err("%s: platform data is NULL.\n", __func__); return -ENODEV; } drv = kzalloc(sizeof(*drv), GFP_KERNEL); if (drv == NULL) { pr_err("%s: kzalloc fail.\n", __func__); goto alloc_err; } drv->pdata = pdev->dev.platform_data; ret = dsps_alloc_resources(pdev); if (ret) { pr_err("%s: failed to allocate dsps resources.\n", __func__); goto res_err; } drv->dev_class = class_create(THIS_MODULE, DRV_NAME); if (drv->dev_class == NULL) { pr_err("%s: class_create fail.\n", __func__); goto res_err; } ret = alloc_chrdev_region(&drv->dev_num, 0, 1, DRV_NAME); if (ret) { pr_err("%s: alloc_chrdev_region fail.\n", __func__); goto alloc_chrdev_region_err; } drv->dev = device_create(drv->dev_class, NULL, drv->dev_num, drv, DRV_NAME); if (IS_ERR(drv->dev)) { pr_err("%s: device_create fail.\n", __func__); goto device_create_err; } drv->cdev = cdev_alloc(); if (drv->cdev == NULL) { pr_err("%s: cdev_alloc fail.\n", __func__); goto cdev_alloc_err; } cdev_init(drv->cdev, &dsps_fops); drv->cdev->owner = THIS_MODULE; ret = cdev_add(drv->cdev, drv->dev_num, 1); if (ret) { pr_err("%s: cdev_add fail.\n", __func__); goto cdev_add_err; } return 0; cdev_add_err: kfree(drv->cdev); cdev_alloc_err: device_destroy(drv->dev_class, drv->dev_num); device_create_err: unregister_chrdev_region(drv->dev_num, 1); alloc_chrdev_region_err: class_destroy(drv->dev_class); res_err: kfree(drv); drv = NULL; alloc_err: return -ENODEV; }
static void __exit leds_exit(void) { class_destroy(leds_class); }
/** * genwqe_exit_module() - Driver exit */ static void __exit genwqe_exit_module(void) { pci_unregister_driver(&genwqe_driver); debugfs_remove(debugfs_genwqe); class_destroy(class_genwqe); }
static int __init ofcd_init(void) /* Constructor */ { int err; printk(KERN_INFO DRV_NAME " : Registered\n"); test_data.irq_pin = 46; test_data.gpio_pin = 38; test_data.led_pin = 54; if (alloc_chrdev_region(&first, 0, 1, "JON") < 0) { goto err_return; } if ((cl = class_create(THIS_MODULE, "gpio-irq-test")) == NULL) { goto err_unregister_chrdev_return; } if (device_create(cl, NULL, first, NULL, "gpio-irq-test") == NULL) { goto err_class_destroy_return; } cdev_init(&c_dev, &pugs_fops); if (cdev_add(&c_dev, first, 1) == -1) { goto err_device_destroy_return; } /* Confiure GPIO Pins*/ if (gpio_request(test_data.gpio_pin, "out pin")) { printk(KERN_ALERT DRV_NAME " : Unable to register output pin %d\n", test_data.gpio_pin); goto err_device_destroy_return; } if(gpio_request(test_data.led_pin, "led pin")) { printk(KERN_ALERT DRV_NAME " : Unable to register led pin %d\n", test_data.led_pin); goto err_free_outpin_return; } if (gpio_request(test_data.irq_pin, "irq pin")) { printk(KERN_ALERT DRV_NAME " : Unable to register irq pin %d\n", test_data.led_pin); goto err_free_ledpin_return; } gpio_direction_output(test_data.led_pin, 0); gpio_direction_output(test_data.gpio_pin, 0); gpio_direction_input(test_data.irq_pin); /* Confiure IRQ*/ err = gpio_to_irq(test_data.irq_pin); if (err < 0) { printk(KERN_ALERT DRV_NAME " : failed to get IRQ for pin %d.\n", test_data.irq_pin); goto err_free_irqpin_return; } else { test_data.irq = (u16)err; err = 0; } err = request_any_context_irq(test_data.irq, gpio_test_irq_interrupt_handler, IRQF_TRIGGER_RISING | IRQF_DISABLED, DRV_NAME, (void*)&test_data); if (err < 0) { printk(KERN_ALERT DRV_NAME " : failed to enable IRQ %d for pin %d.\n", test_data.irq, test_data.irq_pin); goto err_free_irqpin_return; } else test_data.irq_enabled = 1; return 0; /* Cleanup of registers */ err_free_irqpin_return: gpio_free(test_data.irq_pin); err_free_ledpin_return: gpio_free(test_data.led_pin); err_free_outpin_return: gpio_free(test_data.gpio_pin); err_device_destroy_return: device_destroy(cl, first); err_class_destroy_return: class_destroy(cl); err_unregister_chrdev_return: unregister_chrdev_region(first, 1); err_return: return -1; }
static void __exit ilo_exit(void) { pci_unregister_driver(&ilo_driver); unregister_chrdev_region(MKDEV(ilo_major, 0), MAX_OPEN); class_destroy(ilo_class); }
/* ******************************* */ int main(int argc, char *argv[]) { /* ******************************* */ // standard counter int32 i; // check if the parameter exist otherwise print help and exit if(argc < 2) { printf("no class file name given\n"); return -1; } // check if the given filename exist char * filename = argv[1]; if(!fopen(filename,"r")) { printf("no class file found\n"); return -1; } // bootstrap class loader bootstrap_cache_load(); // should be threaded // NCC = native class count STACK * ncl_list; ncl_list = (STACK *) mmalloc(sizeof(STACK)); stack_init(ncl_list, sizeof(CLASS)); for(i = 0; i < NCC; i++) { CLASS * clc = load_class(ncs[i].name); STACK_ELEM * stack_elem; stack_elem = (STACK_ELEM *) mmalloc(sizeof(STACK_ELEM)); stack_elem->data = clc; stack_push(ncl_list,stack_elem); } // user defined class loader CLASS * cl = load_class(argv[1]); // link class file /** * Verification: ensures the correctness of the imported type * Preparation: allocates memory for class variables and initializing the memory to default values * Resolution: transforms symbolic references from the type into direct references. */ linker(cl); /* cache the result of parsing and linking */ //cache(); // starting the main interprer process MACHINE * vm; vm = (MACHINE *) mmalloc(sizeof(MACHINE)); virtual_machine_init(vm); stack_init(vm->native_ms, sizeof(CLASS)); virtual_machine_exec(vm,cl); /* memory cleanup */ virtual_machine_destroy(vm); stack_destroy(ncl_list); class_destroy(cl); /* always return zero at the end */ return 0; }
/****************************************************************************** * devinfo_exit * * DESCRIPTION: * Free the device driver ! * * PARAMETERS: * None * * RETURNS: * None * * NOTES: * None * ******************************************************************************/ static void __exit devinfo_exit(void) { cdev_del(&devinfo_cdev); class_destroy(devinfo_class); unregister_chrdev_region(devinfo_dev, 1); }
static int __init S3C_BC_ModInit(void) { #if defined(LDM_PLATFORM) || defined(LDM_PCI) struct device *psDev; #endif #if defined(LMA) struct pci_dev *psPCIDev; int error; #endif #if defined(LMA) psPCIDev = pci_get_device(VENDOR_ID_PVR, DEVICE_ID_PVR, NULL); if (psPCIDev == NULL) { printk(KERN_ERR DRVNAME ": S3C_BC_ModInit: pci_get_device failed\n"); goto ExitError; } if ((error = pci_enable_device(psPCIDev)) != 0) { printk(KERN_ERR DRVNAME ": S3C_BC_ModInit: pci_enable_device failed (%d)\n", error); goto ExitError; } #endif AssignedMajorNumber = register_chrdev(0, DEVNAME, &S3C_BC_fops); if (AssignedMajorNumber <= 0) { printk(KERN_ERR DRVNAME ": S3C_BC_ModInit: unable to get major number\n"); goto ExitDisable; } #if defined(DEBUG) printk(KERN_DEBUG DRVNAME ": S3C_BC_ModInit: major device %d\n", AssignedMajorNumber); #endif #if defined(LDM_PLATFORM) || defined(LDM_PCI) psPvrClass = class_create(THIS_MODULE, DEVNAME); if (IS_ERR(psPvrClass)) { printk(KERN_ERR DRVNAME ": S3C_BC_ModInit: unable to create class (%ld)", PTR_ERR(psPvrClass)); goto ExitUnregister; } psDev = device_create(psPvrClass, NULL, MKDEV(AssignedMajorNumber, 0), #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) NULL, #endif DEVNAME); if (IS_ERR(psDev)) { printk(KERN_ERR DRVNAME ": S3C_BC_ModInit: unable to create device (%ld)", PTR_ERR(psDev)); goto ExitDestroyClass; } #endif if(S3C_BC_Register() != S3C_BC_OK) { printk (KERN_ERR DRVNAME ": S3C_BC_ModInit: can't init device\n"); goto ExitUnregister; } //printk("s3c_bc: physical base addres = 0x%x\n", S3C_BC_DEVICE_PHYS_ADDR_START); #if defined(LMA) pci_disable_device(psPCIDev); #endif return 0; #if defined(LDM_PLATFORM) || defined(LDM_PCI) ExitDestroyClass: class_destroy(psPvrClass); #endif ExitUnregister: unregister_chrdev(AssignedMajorNumber, DEVNAME); ExitDisable: #if defined(LMA) pci_disable_device(psPCIDev); ExitError: #endif return -EBUSY; }
static void __exit switch_class_exit(void) { class_destroy(switch_class); }
static int __init shm_driver_init(void) { int res, i; /* Figure out our device number. */ res = register_chrdev_region(MKDEV(GALOIS_SHM_MAJOR, 0), GALOIS_SHM_MINORS, SHM_DEVICE_NAME); if (res < 0) { shm_error("unable to get shm device major [%d]\n", GALOIS_SHM_MAJOR); goto err_reg_device; } shm_debug("register cdev device major [%d]\n", GALOIS_SHM_MAJOR); /* Now setup cdevs. */ for (i = 0; i < ARRAY_SIZE(shm_driver_dev_list); i++) { res = shm_driver_setup_cdev(shm_driver_dev_list[i].cdev, GALOIS_SHM_MAJOR, shm_driver_dev_list[i].minor, shm_driver_dev_list[i].fops); if (res) { shm_error("shm_driver_setup_cdev failed in [%d].\n", i); goto err_add_device; } shm_debug("setup cdevs device minor [%d]\n", shm_driver_dev_list[i].minor); } /* add shm devices to sysfs */ shm_dev_class = class_create(THIS_MODULE, SHM_DEVICE_NAME); if (IS_ERR(shm_dev_class)) { shm_error("class_create failed.\n"); res = -ENODEV; goto err_add_device; } for (i = 0; i < ARRAY_SIZE(shm_driver_dev_list); i++) { device_create(shm_dev_class, NULL, MKDEV(GALOIS_SHM_MAJOR, shm_driver_dev_list[i].minor), NULL, shm_driver_dev_list[i].name); shm_debug("create device sysfs [%s]\n", shm_driver_dev_list[i].name); } /* create shm device*/ res = shm_device_create(&shm_device, shm_base, shm_size, SHM_DEVICE_THRESHOLD); if (res != 0) { shm_error("shm_device_create failed.\n"); goto err_add_device; } /* create shm kernel API */ res = MV_SHM_Init(shm_device); if (res != 0) { shm_error("MV_SHM_Init failed !!!\n"); goto err_SHM_Init; } /* create shm device proc file*/ shm_driver_procdir = proc_mkdir(SHM_DEVICE_NAME, NULL); shm_driver_procdir->owner = THIS_MODULE; create_proc_read_entry(SHM_DEVICE_PROCFILE_MEMINFO, 0, shm_driver_procdir, read_proc_meminfo, NULL); create_proc_read_entry(SHM_DEVICE_PROCFILE_BASEINFO, 0, shm_driver_procdir, read_proc_baseinfo, NULL); create_proc_read_entry(SHM_DEVICE_PROCFILE_DETAIL, 0, shm_driver_procdir, read_proc_detail, NULL); shm_trace("shm_driver_init OK\n"); return 0; err_SHM_Init: shm_trace("shm_driver_init Undo ...\n"); shm_device_destroy(&shm_device); /* del sysfs entries */ for (i = 0; i < ARRAY_SIZE(shm_driver_dev_list); i++) { device_destroy(shm_dev_class, MKDEV(GALOIS_SHM_MAJOR, shm_driver_dev_list[i].minor)); shm_debug("delete device sysfs [%s]\n", shm_driver_dev_list[i].name); } class_destroy(shm_dev_class); err_add_device: for (i = 0; i < ARRAY_SIZE(shm_driver_dev_list); i++) { cdev_del(shm_driver_dev_list[i].cdev); } unregister_chrdev_region(MKDEV(GALOIS_SHM_MAJOR, 0), GALOIS_SHM_MINORS); err_reg_device: shm_trace("shm_driver_init failed !!! (%d)\n", res); return res; }
void usb_major_cleanup(void) { class_destroy(usb_class); unregister_chrdev(USB_MAJOR, "usb"); }
static int drv_init(void) #endif { int ret, i; int result = -EINVAL; gceSTATUS status = gcvSTATUS_OK; gckGALDEVICE device = gcvNULL; struct class* device_class = gcvNULL; gcmkHEADER(); #if ENABLE_GPU_CLOCK_BY_DRIVER && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)) gcmkONERROR(gckOS_GpuPowerEnable(gcvNULL, gcvCORE_MAJOR, gcvTRUE, gcvTRUE, coreClock*1000*1000)); #if MRVL_PLATFORM_PXA1088 /* PXA1088: 2D power is shared with 3D */ gcmkONERROR(gckOS_GpuPowerEnable(gcvNULL, gcvCORE_2D, gcvTRUE, gcvFALSE, coreClock*1000*1000)); #endif #endif #if MRVL_PLATFORM_NEVO if (cpu_is_pxa978_Dx()) { baseAddress = 0x0; } else { baseAddress = 0x80000000; } #endif if (showArgs) { printk("galcore options:\n"); printk(" irqLine = %d\n", irqLine); printk(" registerMemBase = 0x%08lX\n", registerMemBase); printk(" registerMemSize = 0x%08lX\n", registerMemSize); if (irqLine2D != -1) { printk(" irqLine2D = %d\n", irqLine2D); printk(" registerMemBase2D = 0x%08lX\n", registerMemBase2D); printk(" registerMemSize2D = 0x%08lX\n", registerMemSize2D); } if (irqLineVG != -1) { printk(" irqLineVG = %d\n", irqLineVG); printk(" registerMemBaseVG = 0x%08lX\n", registerMemBaseVG); printk(" registerMemSizeVG = 0x%08lX\n", registerMemSizeVG); } printk(" contiguousSize = %ld\n", contiguousSize); printk(" contiguousBase = 0x%08lX\n", contiguousBase); printk(" bankSize = 0x%08lX\n", bankSize); #if (MRVL_VIDEO_MEMORY_USE_TYPE != gcdMEM_TYPE_NONE) printk(" pmemSize = %ld\n", pmemSize); #endif printk(" fastClear = %d\n", fastClear); printk(" compression = %d\n", compression); printk(" signal = %d\n", signal); printk(" baseAddress = 0x%08lX\n", baseAddress); printk(" physSize = 0x%08lX\n", physSize); printk(" logFileSize = %d KB \n", logFileSize); #if ENABLE_GPU_CLOCK_BY_DRIVER printk(" coreClock = %lu\n", coreClock); #endif } physSize = 0x80000000; #ifndef CONFIG_CPU_PXA988 pmemSize = 0x0; #endif printk(" physSize modified to = 0x%08lX\n", physSize); if(logFileSize != 0) { gckDebugFileSystemInitialize(); } /* Create the GAL device. */ gcmkONERROR(gckGALDEVICE_Construct( irqLine, registerMemBase, registerMemSize, irqLine2D, registerMemBase2D, registerMemSize2D, irqLineVG, registerMemBaseVG, registerMemSizeVG, contiguousBase, contiguousSize, #if (MRVL_VIDEO_MEMORY_USE_TYPE != gcdMEM_TYPE_NONE) pmemSize, #endif bankSize, fastClear, compression, baseAddress, physSize, signal, logFileSize, &device )); /* Start the GAL device. */ gcmkONERROR(gckGALDEVICE_Start(device)); if ((physSize != 0) && (device->kernels[gcvCORE_MAJOR] != gcvNULL) && (device->kernels[gcvCORE_MAJOR]->hardware->mmuVersion != 0)) { status = gckMMU_Enable(device->kernels[gcvCORE_MAJOR]->mmu, mmuBaseAddress, physSize); //status = gckMMU_Enable(device->kernels[gcvCORE_MAJOR]->mmu, (gctUINT32)device->contiguousStart, contiguousSize); gcmkTRACE_ZONE(gcvLEVEL_INFO, gcvZONE_DRIVER, "Enable new MMU: status=%d\n", status); if ((device->kernels[gcvCORE_2D] != gcvNULL) && (device->kernels[gcvCORE_2D]->hardware->mmuVersion != 0)) { status = gckMMU_Enable(device->kernels[gcvCORE_2D]->mmu, mmuBaseAddress, physSize); gcmkTRACE_ZONE(gcvLEVEL_INFO, gcvZONE_DRIVER, "Enable new MMU for 2D: status=%d\n", status); } /* Reset the base address */ device->baseAddress = 0; } for (i = 0; i < gcdMAX_GPU_COUNT; i++) { if(device->kernels[i] != gcvNULL) { device->kernels[i]->bTryIdleGPUEnable = gcvTRUE; } } /* Register the character device. */ ret = register_chrdev(major, DRV_NAME, &driver_fops); if (ret < 0) { gcmkTRACE_ZONE( gcvLEVEL_ERROR, gcvZONE_DRIVER, "%s(%d): Could not allocate major number for mmap.\n", __FUNCTION__, __LINE__ ); gcmkONERROR(gcvSTATUS_OUT_OF_MEMORY); } if (major == 0) { major = ret; } /* Create the device class. */ device_class = class_create(THIS_MODULE, "graphics_class"); if (IS_ERR(device_class)) { gcmkTRACE_ZONE( gcvLEVEL_ERROR, gcvZONE_DRIVER, "%s(%d): Failed to create the class.\n", __FUNCTION__, __LINE__ ); gcmkONERROR(gcvSTATUS_OUT_OF_RESOURCES); } if (pdevice == gcvNULL) gcmkONERROR(gcvSTATUS_DEVICE); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) device_create(device_class, pdevice, MKDEV(major, 0), NULL, "galcore"); #else device_create(device_class, pdevice, MKDEV(major, 0), "galcore"); #endif galDevice = device; gpuClass = device_class; gcmkTRACE_ZONE( gcvLEVEL_INFO, gcvZONE_DRIVER, "%s(%d): irqLine=%d, contiguousSize=%lu, memBase=0x%lX\n", __FUNCTION__, __LINE__, irqLine, contiguousSize, registerMemBase ); /* Success. */ gcmkFOOTER_NO(); return 0; OnError: /* Roll back. */ if (device_class != gcvNULL) { device_destroy(device_class, MKDEV(major, 0)); class_destroy(device_class); } if (device != gcvNULL) { gcmkVERIFY_OK(gckGALDEVICE_Stop(device)); gcmkVERIFY_OK(gckGALDEVICE_Destroy(device)); } gcmkFOOTER(); return result; }
static void __exit typec_exit(void) { class_destroy(typec_class); sysfs_remove_group(&typec_dev->kobj, &typec_attr_group); }
static int register_attributes(void) { int ret = 0; hi->htc_accessory_class = class_create(THIS_MODULE, "htc_accessory"); if (IS_ERR(hi->htc_accessory_class)) { ret = PTR_ERR(hi->htc_accessory_class); hi->htc_accessory_class = NULL; goto err_create_class; } /* Register TTY attributes */ hi->tty_dev = device_create(hi->htc_accessory_class, NULL, 0, "%s", "tty"); if (unlikely(IS_ERR(hi->tty_dev))) { ret = PTR_ERR(hi->tty_dev); hi->tty_dev = NULL; goto err_create_tty_device; } ret = device_create_file(hi->tty_dev, &dev_attr_tty); if (ret) goto err_create_tty_device_file; /* Register FM attributes */ hi->fm_dev = device_create(hi->htc_accessory_class, NULL, 0, "%s", "fm"); if (unlikely(IS_ERR(hi->fm_dev))) { ret = PTR_ERR(hi->fm_dev); hi->fm_dev = NULL; goto err_create_fm_device; } ret = device_create_file(hi->fm_dev, &dev_attr_fm); if (ret) goto err_create_fm_device_file; /* Register debug attributes */ hi->debug_dev = device_create(hi->htc_accessory_class, NULL, 0, "%s", "debug"); if (unlikely(IS_ERR(hi->debug_dev))) { ret = PTR_ERR(hi->debug_dev); hi->debug_dev = NULL; goto err_create_debug_device; } /* register the attributes */ ret = device_create_file(hi->debug_dev, &dev_attr_debug); if (ret) goto err_create_debug_device_file; return 0; err_create_debug_device_file: device_unregister(hi->debug_dev); err_create_debug_device: device_remove_file(hi->fm_dev, &dev_attr_fm); err_create_fm_device_file: device_unregister(hi->fm_dev); err_create_fm_device: device_remove_file(hi->tty_dev, &dev_attr_tty); err_create_tty_device_file: device_unregister(hi->tty_dev); err_create_tty_device: class_destroy(hi->htc_accessory_class); err_create_class: return ret; }
static int mdnie_probe(struct platform_device *pdev) { #if defined(CONFIG_FB_MDNIE_PWM) struct platform_mdnie_data *pdata = pdev->dev.platform_data; #endif struct mdnie_info *mdnie; int ret = 0; mdnie_class = class_create(THIS_MODULE, dev_name(&pdev->dev)); if (IS_ERR_OR_NULL(mdnie_class)) { pr_err("failed to create mdnie class\n"); ret = -EINVAL; goto error0; } mdnie_class->dev_attrs = mdnie_attributes; mdnie = kzalloc(sizeof(struct mdnie_info), GFP_KERNEL); if (!mdnie) { pr_err("failed to allocate mdnie\n"); ret = -ENOMEM; goto error1; } mdnie->dev = device_create(mdnie_class, &pdev->dev, 0, &mdnie, "mdnie"); if (IS_ERR_OR_NULL(mdnie->dev)) { pr_err("failed to create mdnie device\n"); ret = -EINVAL; goto error2; } #if defined(CONFIG_FB_MDNIE_PWM) if (!pdata) { pr_err("no platform data specified\n"); ret = -EINVAL; goto error2; } mdnie->bd = backlight_device_register("panel", mdnie->dev, mdnie, &mdnie_backlight_ops, NULL); mdnie->bd->props.max_brightness = MAX_BRIGHTNESS_LEVEL; mdnie->bd->props.brightness = DEFAULT_BRIGHTNESS; mdnie->bd_enable = TRUE; mdnie->lcd_pd = pdata->lcd_pd; ret = device_create_file(&mdnie->bd->dev, &dev_attr_auto_brightness); if (ret < 0) dev_err(&mdnie->bd->dev, "failed to add sysfs entries, %d\n", __LINE__); #endif mdnie->scenario = UI_MODE; mdnie->mode = STANDARD; mdnie->tone = TONE_NORMAL; mdnie->outdoor = OUTDOOR_OFF; #if defined(CONFIG_FB_MDNIE_PWM) mdnie->cabc = CABC_ON; mdnie->power_lut_idx = LUT_LEVEL_MANUAL_AND_INDOOR; mdnie->auto_brightness = 0; #else mdnie->cabc = CABC_OFF; #endif #if defined(CONFIG_FB_S5P_S6C1372) mdnie->cabc = CABC_OFF; #endif mdnie->enable = TRUE; mdnie->tunning = FALSE; mdnie->negative = NEGATIVE_OFF; mutex_init(&mdnie->lock); mutex_init(&mdnie->dev_lock); platform_set_drvdata(pdev, mdnie); dev_set_drvdata(mdnie->dev, mdnie); #ifdef CONFIG_HAS_WAKELOCK #ifdef CONFIG_HAS_EARLYSUSPEND #if 1 /* defined(CONFIG_FB_MDNIE_PWM) */ mdnie->early_suspend.suspend = mdnie_early_suspend; mdnie->early_suspend.resume = mdnie_late_resume; mdnie->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN; //EARLY_SUSPEND_LEVEL_DISABLE_FB - 1; register_early_suspend(&mdnie->early_suspend); #endif #endif #endif #if defined(CONFIG_FB_S5P_S6C1372) check_lcd_type(); dev_info(mdnie->dev, "lcdtype = %d\n", pdata->display_type); if (pdata->display_type == 1) { b_value.max = 1441; b_value.mid = 784; b_value.low = 16; b_value.dim = 16; } else { b_value.max = 1216; /* 76% */ b_value.mid = 679; /* 39% */ b_value.low = 16; /* 1% */ b_value.dim = 16; /* 1% */ } #endif #if defined(CONFIG_FB_S5P_S6F1202A) if (pdata->display_type == 0) { memcpy(tunning_table, tunning_table_hydis, sizeof(tunning_table)); memcpy(etc_table, etc_table_hydis, sizeof(etc_table)); memcpy(camera_table, camera_table_hydis, sizeof(camera_table)); } else if (pdata->display_type == 1) { memcpy(tunning_table, tunning_table_sec, sizeof(tunning_table)); memcpy(etc_table, etc_table_sec, sizeof(etc_table)); memcpy(camera_table, camera_table_sec, sizeof(camera_table)); } else if (pdata->display_type == 2) { memcpy(tunning_table, tunning_table_boe, sizeof(tunning_table)); memcpy(etc_table, etc_table_boe, sizeof(etc_table)); memcpy(camera_table, camera_table_boe, sizeof(camera_table)); } #endif g_mdnie = mdnie; set_mdnie_value(mdnie, 0); dev_info(mdnie->dev, "registered successfully\n"); return 0; error2: kfree(mdnie); error1: class_destroy(mdnie_class); error0: return ret; }
static int WMT_init(void) { dev_t devID = MKDEV(gWmtMajor, 0); INT32 cdevErr = -1; INT32 ret = -1; #if REMOVE_MK_NODE struct device *wmt_dev = NULL; #endif WMT_INFO_FUNC("WMT Version= %s DATE=%s\n", MTK_WMT_VERSION, MTK_WMT_DATE); WMT_INFO_FUNC("COMBO Driver Version= %s\n", MTK_COMBO_DRIVER_VERSION); /* Prepare a UCHAR device */ /*static allocate chrdev */ gWmtInitDone = 0; init_waitqueue_head((wait_queue_head_t *) &gWmtInitWq); stp_drv_init(); ret = register_chrdev_region(devID, WMT_DEV_NUM, WMT_DRIVER_NAME); if (ret) { WMT_ERR_FUNC("fail to register chrdev\n"); return ret; } cdev_init(&gWmtCdev, &gWmtFops); gWmtCdev.owner = THIS_MODULE; cdevErr = cdev_add(&gWmtCdev, devID, WMT_DEV_NUM); if (cdevErr) { WMT_ERR_FUNC("cdev_add() fails (%d)\n", cdevErr); goto error; } WMT_INFO_FUNC("driver(major %d) installed\n", gWmtMajor); #if REMOVE_MK_NODE wmt_class = class_create(THIS_MODULE, "stpwmt"); if (IS_ERR(wmt_class)) goto error; wmt_dev = device_create(wmt_class, NULL, devID, NULL, "stpwmt"); if (IS_ERR(wmt_dev)) goto error; #endif #if 0 pWmtDevCtx = wmt_drv_create(); if (!pWmtDevCtx) { WMT_ERR_FUNC("wmt_drv_create() fails\n"); goto error; } ret = wmt_drv_init(pWmtDevCtx); if (ret) { WMT_ERR_FUNC("wmt_drv_init() fails (%d)\n", ret); goto error; } WMT_INFO_FUNC("stp_btmcb_reg\n"); wmt_cdev_btmcb_reg(); ret = wmt_drv_start(pWmtDevCtx); if (ret) { WMT_ERR_FUNC("wmt_drv_start() fails (%d)\n", ret); goto error; } #endif ret = wmt_lib_init(); if (ret) { WMT_ERR_FUNC("wmt_lib_init() fails (%d)\n", ret); goto error; } #if CFG_WMT_DBG_SUPPORT wmt_dev_dbg_setup(); #endif #if CFG_WMT_PROC_FOR_AEE wmt_dev_proc_for_aee_setup(); #endif mtk_wcn_hif_sdio_update_cb_reg(wmt_dev_tra_sdio_update); #if CONSYS_WMT_REG_SUSPEND_CB_ENABLE ret = register_pm_notifier(&wmt_pm_notifier_block); if (ret) WMT_ERR_FUNC("WMT failed to register PM notifier failed(%d)\n", ret); #endif gWmtInitDone = 1; wake_up(&gWmtInitWq); #if CONSYS_EARLYSUSPEND_ENABLE osal_sleepable_lock_init(&g_es_lr_lock); register_early_suspend(&wmt_early_suspend_handler); WMT_INFO_FUNC("register_early_suspend finished\n"); #endif WMT_INFO_FUNC("success \n"); return 0; error: wmt_lib_deinit(); #if CFG_WMT_DBG_SUPPORT wmt_dev_dbg_remove(); #endif #if REMOVE_MK_NODE if (!IS_ERR(wmt_dev)) device_destroy(wmt_class, devID); if (!IS_ERR(wmt_class)) { class_destroy(wmt_class); wmt_class = NULL; } #endif if (cdevErr == 0) { cdev_del(&gWmtCdev); } if (ret == 0) { unregister_chrdev_region(devID, WMT_DEV_NUM); gWmtMajor = -1; } WMT_ERR_FUNC("fail\n"); return -1; }
/** * gpio_pmodoled_of_probe - Probe method for PmodOLED device (over GPIO). * @pdev: pointer to platform devices * * This function probes the OLED device in the device tree. It initializes the * OLED driver data structure. It returns 0, if the driver is bound to the OLED * device, or a negative value if there is an error. */ static int gpio_pmodoled_of_probe(struct platform_device *pdev) { struct gpio_pmodoled_device *gpio_pmodoled_dev; struct platform_device *gpio_pmodoled_pdev; struct spi_gpio_platform_data *gpio_pmodoled_pdata; struct device_node *np = pdev->dev.of_node; const u32 *tree_info; int status = 0; /* Alloc Space for platform device structure */ gpio_pmodoled_dev = kzalloc(sizeof(*gpio_pmodoled_dev), GFP_KERNEL); if (!gpio_pmodoled_dev) { status = -ENOMEM; goto dev_alloc_err; } /* Alloc Graphic Buffer for device */ gpio_pmodoled_dev->disp_buf = kmalloc(DISPLAY_BUF_SZ, GFP_KERNEL); if (!gpio_pmodoled_dev->disp_buf) { status = -ENOMEM; dev_err(&pdev->dev, "Device Display data buffer allocation failed: %d\n", status); goto disp_buf_alloc_err; } /* Get the GPIO Pins */ gpio_pmodoled_dev->iVBAT = of_get_named_gpio(np, "vbat-gpio", 0); gpio_pmodoled_dev->iVDD = of_get_named_gpio(np, "vdd-gpio", 0); gpio_pmodoled_dev->iRES = of_get_named_gpio(np, "res-gpio", 0); gpio_pmodoled_dev->iDC = of_get_named_gpio(np, "dc-gpio", 0); gpio_pmodoled_dev->iSCLK = of_get_named_gpio(np, "spi-sclk-gpio", 0); gpio_pmodoled_dev->iSDIN = of_get_named_gpio(np, "spi-sdin-gpio", 0); status = of_get_named_gpio(np, "spi-cs-gpio", 0); gpio_pmodoled_dev->iCS = (status < 0) ? SPI_GPIO_NO_CHIPSELECT : status; #ifdef CONFIG_PMODS_DEBUG pr_info(DRIVER_NAME " %s: iVBAT: 0x%lx\n", np->name, gpio_pmodoled_dev->iVBAT); pr_info(DRIVER_NAME " %s: iVDD : 0x%lx\n", np->name, gpio_pmodoled_dev->iVDD); pr_info(DRIVER_NAME " %s: iRES : 0x%lx\n", np->name, gpio_pmodoled_dev->iRES); pr_info(DRIVER_NAME " %s: iDC : 0x%lx\n", np->name, gpio_pmodoled_dev->iDC); pr_info(DRIVER_NAME " %s: iSCLK: 0x%lx\n", np->name, gpio_pmodoled_dev->iSCLK); pr_info(DRIVER_NAME " %s: iSDIN: 0x%lx\n", np->name, gpio_pmodoled_dev->iSDIN); pr_info(DRIVER_NAME " %s: iCS : 0x%lx\n", np->name, gpio_pmodoled_dev->iCS); #endif /* Get SPI Related Params */ tree_info = of_get_property(np, "spi-bus-num", NULL); if (tree_info) { gpio_pmodoled_dev->spi_id = be32_to_cpup((tree_info)); #ifdef CONFIG_PMODS_DEBUG pr_info(DRIVER_NAME " %s: BUS_ID\t%x\n", np->name, gpio_pmodoled_dev->spi_id); #endif } /* Alloc Space for platform data structure */ gpio_pmodoled_pdata = kzalloc(sizeof(*gpio_pmodoled_pdata), GFP_KERNEL); if (!gpio_pmodoled_pdata) { status = -ENOMEM; goto pdata_alloc_err; } /* Fill up Platform Data Structure */ gpio_pmodoled_pdata->sck = gpio_pmodoled_dev->iSCLK; gpio_pmodoled_pdata->miso = SPI_GPIO_NO_MISO; gpio_pmodoled_pdata->mosi = gpio_pmodoled_dev->iSDIN; gpio_pmodoled_pdata->num_chipselect = 1; /* Alloc Space for platform data structure */ gpio_pmodoled_pdev = kzalloc(sizeof(*gpio_pmodoled_pdev), GFP_KERNEL); if (!gpio_pmodoled_pdev) { status = -ENOMEM; goto pdev_alloc_err; } /* Fill up Platform Device Structure */ gpio_pmodoled_pdev->name = "spi_gpio"; gpio_pmodoled_pdev->id = gpio_pmodoled_dev->spi_id; gpio_pmodoled_pdev->dev.platform_data = gpio_pmodoled_pdata; gpio_pmodoled_dev->pdev = gpio_pmodoled_pdev; /* Register spi_gpio master */ status = platform_device_register(gpio_pmodoled_dev->pdev); if (status < 0) { dev_err(&pdev->dev, "platform_device_register failed: %d\n", status); goto pdev_reg_err; } #ifdef CONFIG_PMODS_DEBUG pr_info(DRIVER_NAME " %s: spi_gpio platform device registered.\n", np->name); #endif gpio_pmodoled_dev->name = np->name; /* Fill up Board Info for SPI device */ status = add_gpio_pmodoled_device_to_bus(gpio_pmodoled_dev); if (status < 0) { dev_err(&pdev->dev, "add_gpio_pmodoled_device_to_bus failed: %d\n", status); goto spi_add_err; } #ifdef CONFIG_PMODS_DEBUG pr_info(DRIVER_NAME " %s: spi device registered.\n", np->name); #endif /* Point device node data to gpio_pmodoled_device structure */ if (np->data == NULL) np->data = gpio_pmodoled_dev; if (gpio_pmodoled_dev_id == 0) { /* Alloc Major & Minor number for char device */ status = alloc_chrdev_region(&gpio_pmodoled_dev_id, 0, MAX_PMODOLED_GPIO_DEV_NUM, DRIVER_NAME); if (status) { dev_err(&pdev->dev, "Character device region not allocated correctly: %d\n", status); goto err_alloc_chrdev_region; } #ifdef CONFIG_PMODS_DEBUG pr_info(DRIVER_NAME " : Char Device Region Registered, with Major: %d.\n", MAJOR(gpio_pmodoled_dev_id)); #endif } if (gpio_pmodoled_class == NULL) { /* Create Pmodoled-gpio Device Class */ gpio_pmodoled_class = class_create(THIS_MODULE, DRIVER_NAME); if (IS_ERR(gpio_pmodoled_class)) { status = PTR_ERR(gpio_pmodoled_class); goto err_create_class; } #ifdef CONFIG_PMODS_DEBUG pr_info(DRIVER_NAME " : pmodoled_gpio device class registered.\n"); #endif } if (spi_drv_registered == 0) { /* Register SPI Driver for Pmodoled Device */ status = spi_register_driver(&gpio_pmodoled_spi_driver); if (status < 0) { dev_err(&pdev->dev, "gpio_pmodoled_spi_driver register failed: %d\n", status); goto err_spi_register; } spi_drv_registered = 1; } device_num++; return status; err_spi_register: class_destroy(gpio_pmodoled_class); gpio_pmodoled_class = NULL; err_create_class: unregister_chrdev_region(gpio_pmodoled_dev_id, MAX_PMODOLED_GPIO_DEV_NUM); gpio_pmodoled_dev_id = 0; err_alloc_chrdev_region: spi_unregister_device(gpio_pmodoled_dev->spi); spi_add_err: platform_device_unregister(gpio_pmodoled_dev->pdev); pdev_reg_err: kfree(gpio_pmodoled_pdev); pdev_alloc_err: kfree(gpio_pmodoled_pdata); pdata_alloc_err: kfree(gpio_pmodoled_dev->disp_buf); disp_buf_alloc_err: kfree(gpio_pmodoled_dev); dev_alloc_err: return status; }
static void __exit tape_exit(void) { class_destroy(tape_class); tape_class = NULL; }
static void __exit lg_fw_diag_class_exit(void) { class_destroy(lg_fw_diag_class); }
static void __exit notify_class_exit(void) { class_destroy(host_notify.host_notify_class); }
int mali_sysfs_register(struct mali_dev *device, dev_t dev, const char *mali_dev_name) { int err = 0; struct device * mdev; device->mali_class = class_create(THIS_MODULE, mali_dev_name); if (IS_ERR(device->mali_class)) { err = PTR_ERR(device->mali_class); goto init_class_err; } mdev = device_create(device->mali_class, NULL, dev, NULL, mali_dev_name); if (IS_ERR(mdev)) { err = PTR_ERR(mdev); goto init_mdev_err; } mali_debugfs_dir = debugfs_create_dir(mali_dev_name, NULL); if(ERR_PTR(-ENODEV) == mali_debugfs_dir) { /* Debugfs not supported. */ mali_debugfs_dir = NULL; } else { if(NULL != mali_debugfs_dir) { /* Debugfs directory created successfully; create files now */ #if MALI_TIMELINE_PROFILING_ENABLED struct dentry *mali_profiling_dir = debugfs_create_dir("profiling", mali_debugfs_dir); if (mali_profiling_dir != NULL) { struct dentry *mali_profiling_proc_dir = debugfs_create_dir("proc", mali_profiling_dir); if (mali_profiling_proc_dir != NULL) { struct dentry *mali_profiling_proc_default_dir = debugfs_create_dir("default", mali_profiling_proc_dir); if (mali_profiling_proc_default_dir != NULL) { debugfs_create_file("enable", 0600, mali_profiling_proc_default_dir, NULL, &profiling_proc_default_enable_fops); } } debugfs_create_file("record", 0600, mali_profiling_dir, NULL, &profiling_record_fops); debugfs_create_file("events", 0400, mali_profiling_dir, NULL, &profiling_events_fops); } #endif #if MALI_STATE_TRACKING debugfs_create_file("state_dump", 0400, mali_debugfs_dir, NULL, &mali_seq_internal_state_fops); #endif debugfs_create_file("memory_usage", 0400, mali_debugfs_dir, NULL, &memory_usage_fops); } } /* Success! */ return 0; /* Error handling */ init_mdev_err: class_destroy(device->mali_class); init_class_err: return err; }
static int amhdmitx_probe(struct platform_device *pdev) { int r; HDMI_DEBUG(); pr_dbg("amhdmitx_probe\n"); r = alloc_chrdev_region(&hdmitx_id, 0, HDMI_TX_COUNT, DEVICE_NAME); if (r < 0) { pr_error("Can't register major for amhdmitx device\n"); return r; } hdmitx_class = class_create(THIS_MODULE, DEVICE_NAME); if (IS_ERR(hdmitx_class)) { unregister_chrdev_region(hdmitx_id, HDMI_TX_COUNT); return -1; //return PTR_ERR(aoe_class); } hdmitx_device.unplug_powerdown=0; hdmitx_device.vic_count=0; hdmitx_device.auth_process_timer=0; hdmitx_device.force_audio_flag=0; if(init_flag&INIT_FLAG_CEC_FUNC){ hdmitx_device.cec_func_flag = 1; } else{ hdmitx_device.cec_func_flag = 0; } if((init_flag&INIT_FLAG_POWERDOWN)&&(hpdmode==2)){ hdmitx_device.mux_hpd_if_pin_high_flag=0; } else{ hdmitx_device.mux_hpd_if_pin_high_flag=1; } hdmitx_device.audio_param_update_flag=0; cdev_init(&(hdmitx_device.cdev), &amhdmitx_fops); hdmitx_device.cdev.owner = THIS_MODULE; cdev_add(&(hdmitx_device.cdev), hdmitx_id, HDMI_TX_COUNT); //hdmitx_dev = device_create(hdmitx_class, NULL, hdmitx_id, "amhdmitx%d", 0); hdmitx_dev = device_create(hdmitx_class, NULL, hdmitx_id, NULL, "amhdmitx%d", 0); //kernel>=2.6.27 device_create_file(hdmitx_dev, &dev_attr_disp_mode); device_create_file(hdmitx_dev, &dev_attr_aud_mode); device_create_file(hdmitx_dev, &dev_attr_edid); device_create_file(hdmitx_dev, &dev_attr_config); device_create_file(hdmitx_dev, &dev_attr_debug); device_create_file(hdmitx_dev, &dev_attr_disp_cap); device_create_file(hdmitx_dev, &dev_attr_hpd_state); device_create_file(hdmitx_dev, &dev_attr_log); device_create_file(hdmitx_dev, &dev_attr_cec); if (hdmitx_dev == NULL) { pr_error("device_create create error\n"); class_destroy(hdmitx_class); r = -EEXIST; return r; } vout_register_client(&hdmitx_notifier_nb_v); #ifndef DISABLE_AUDIO aout_register_client(&hdmitx_notifier_nb_a); #endif hdmitx_device.task = kthread_run(hdmi_task_handle, &hdmitx_device, "kthread_hdmi"); switch_dev_register(&sdev); if (r < 0){ printk(KERN_ERR "hdmitx: register switch dev failed\n"); return r; } return r; }
static void __exit tzic_exit(void) { device_destroy(driver_class, tzic_device_no); class_destroy(driver_class); unregister_chrdev_region(tzic_device_no, 1); }
static void __exit mod_exit(void) { tsif_exit_one(&the_devices[0]); class_destroy(tsif_class); unregister_chrdev_region(tsif_dev, TSIF_NUM_DEVS); }
static void __exit dram_sys_exit(void) { platform_driver_unregister(&dram_driver); platform_device_unregister(&dram_device); class_destroy(dram_class); }
static void __exit display_class_exit(void) { class_destroy(display_class); }
static void __exit pps_exit(void) { class_destroy(pps_class); unregister_chrdev_region(pps_devt, PPS_MAX_SOURCES); }
static void __exit rmidev_exit(void) { pr_debug("%s: exiting.\n", __func__); rmi_unregister_character_driver(&rmidev_driver); class_destroy(rmidev_device_class); }
static int wmt_detect_init(void) { dev_t devID = MKDEV(gWmtDetectMajor, 0); int cdevErr = -1; int ret = -1; ret = register_chrdev_region(devID, WMT_DETECT_DEV_NUM, WMT_DETECT_DRVIER_NAME); if (ret) { WMT_DETECT_ERR_FUNC("fail to register chrdev\n"); return ret; } cdev_init(&gWmtDetectCdev, &gWmtDetectFops); gWmtDetectCdev.owner = THIS_MODULE; cdevErr = cdev_add(&gWmtDetectCdev, devID, WMT_DETECT_DEV_NUM); if (cdevErr) { WMT_DETECT_ERR_FUNC("cdev_add() fails (%d) \n", cdevErr); goto err1; } pDetectClass = class_create(THIS_MODULE, WMT_DETECT_DEVICE_NAME); if(IS_ERR(pDetectClass)) { WMT_DETECT_ERR_FUNC("class create fail, error code(%ld)\n",PTR_ERR(pDetectClass)); goto err1; } pDetectDev = device_create(pDetectClass,NULL,devID,NULL,WMT_DETECT_DEVICE_NAME); if(IS_ERR(pDetectDev)) { WMT_DETECT_ERR_FUNC("device create fail, error code(%ld)\n",PTR_ERR(pDetectDev)); goto err2; } WMT_DETECT_INFO_FUNC("driver(major %d) installed success\n", gWmtDetectMajor); /*init SDIO-DETECT module*/ sdio_detect_init(); return 0; err2: if(pDetectClass) { class_destroy(pDetectClass); pDetectClass = NULL; } err1: if (cdevErr == 0) { cdev_del(&gWmtDetectCdev); } if (ret == 0) { unregister_chrdev_region(devID, WMT_DETECT_DEV_NUM); gWmtDetectMajor = -1; } WMT_DETECT_ERR_FUNC("fail \n"); return -1; }