static int flashlight_probe(struct platform_device *pdev)
{

	struct flashlight_platform_data *flashlight = pdev->dev.platform_data;
	struct flashlight_struct *fl_str;
	int err = 0;

	fl_str = kzalloc(sizeof(struct flashlight_struct), GFP_KERNEL);
	if (!fl_str) {
		printk(KERN_ERR "%s: kzalloc fail !!!\n", __func__);
		return -ENOMEM;
	}

	err = flashlight_setup_gpio(flashlight, fl_str);
	if (err < 0) {
		printk(KERN_ERR "%s: setup GPIO fail !!!\n", __func__);
		goto fail_free_mem;
	}
	spin_lock_init(&fl_str->spin_lock);
	wake_lock_init(&fl_str->wake_lock, WAKE_LOCK_SUSPEND, pdev->name);
	fl_str->fl_lcdev.name = pdev->name;
	fl_str->fl_lcdev.brightness_set = fl_lcdev_brightness_set;
	fl_str->fl_lcdev.brightness = 0;
	err = led_classdev_register(&pdev->dev, &fl_str->fl_lcdev);
	if (err < 0) {
		printk(KERN_ERR "failed on led_classdev_register\n");
		goto fail_free_gpio;
	}
#ifdef FLASHLIGHT_ADJ_FUNC
	if (fl_str->gpio_flash_adj) {
		printk(KERN_DEBUG "%s: flash_adj exist, create attr file\n",
								__func__);
		err = device_create_file(fl_str->fl_lcdev.dev,
							&dev_attr_flash_adj);
		if (err != 0)
			printk(KERN_WARNING "dev_attr_flash_adj failed\n");
	}
#endif
#ifdef CONFIG_HAS_EARLYSUSPEND
	fl_str->early_suspend_flashlight.suspend = flashlight_early_suspend;
	fl_str->early_suspend_flashlight.resume = flashlight_late_resume;
	register_early_suspend(&fl_str->early_suspend_flashlight);
#endif
	hrtimer_init(&fl_str->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	fl_str->timer.function = flashlight_hrtimer_func;
	fl_str->led_count = flashlight->led_count;
	pr_info("%s: led_count = %d\n", __func__, fl_str->led_count);

	this_fl_str = fl_str;
	printk(KERN_INFO "%s: The Flashlight Driver is ready\n", __func__);
	return 0;

fail_free_gpio:
	wake_lock_destroy(&fl_str->wake_lock);
	flashlight_free_gpio(flashlight, fl_str);
fail_free_mem:
	kfree(fl_str);
	printk(KERN_ERR "%s: The Flashlight driver is Failure\n", __func__);
	return err;
}
static int flashlight_remove(struct platform_device *pdev)
{
	struct flashlight_platform_data *flashlight = pdev->dev.platform_data;

	flashlight_turn_off();
	hrtimer_cancel(&this_fl_str->timer);
	unregister_early_suspend(&this_fl_str->early_suspend_flashlight);
	led_classdev_unregister(&this_fl_str->fl_lcdev);
	flashlight_free_gpio(flashlight, this_fl_str);

	kfree(this_fl_str);
	return 0;
}
static int flashlight_probe(struct platform_device *pdev)
{
	struct flashlight_platform_data *flashlight = pdev->dev.platform_data;
	struct flashlight_struct *fl_str;
	int err = 0;

	fl_str = kzalloc(sizeof(struct flashlight_struct), GFP_KERNEL);
	if (!fl_str) {
		FLT_ERR_LOG("%s: kzalloc fail !!!\n", __func__);
		return -ENOMEM;
	}

	err = flashlight_setup_gpio(flashlight, fl_str);
	if (err < 0) {
		FLT_ERR_LOG("%s: setup GPIO fail !!!\n", __func__);
		goto fail_free_mem;
	}
	spin_lock_init(&fl_str->spin_lock);

	fl_str->fl_lcdev.name = FLASHLIGHT_NAME;
	fl_str->fl_lcdev.brightness_set = fl_lcdev_brightness_set;
	fl_str->fl_lcdev.brightness = 0;
	if (flashlight->flash_duration_ms)
		fl_str->flash_sw_timeout_ms = flashlight->flash_duration_ms;
	else /* load default value */
		fl_str->flash_sw_timeout_ms = 600;
	err = led_classdev_register(&pdev->dev, &fl_str->fl_lcdev);
	if (err < 0) {
		FLT_ERR_LOG("%s: failed on led_classdev_register\n", __func__);
		goto fail_free_gpio;
	}
#ifdef CONFIG_HAS_EARLYSUSPEND
	fl_str->early_suspend_flashlight.suspend = flashlight_early_suspend;
	fl_str->early_suspend_flashlight.resume = flashlight_late_resume;
	register_early_suspend(&fl_str->early_suspend_flashlight);
#endif
	hrtimer_init(&fl_str->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	fl_str->timer.function = flashlight_hrtimer_func;

	this_fl_str = fl_str;
	FLT_INFO_LOG("%s: The Flashlight Driver is ready\n", __func__);
	return 0;

fail_free_gpio:
	flashlight_free_gpio(flashlight, fl_str);
fail_free_mem:
	kfree(fl_str);
	return err;
}
Esempio n. 4
0
static int flashlight_remove(struct platform_device *pdev)
{
	struct flashlight_platform_data *flashlight = pdev->dev.platform_data;

	flashlight_turn_off();
	hrtimer_cancel(&this_fl_str->timer);
	unregister_early_suspend(&this_fl_str->early_suspend_flashlight);
#ifdef FLASHLIGHT_ADJ_FUNC
	if (this_fl_str->gpio_flash_adj) {
		device_remove_file(this_fl_str->fl_lcdev.dev,
							&dev_attr_flash_adj);
	}
#endif
	led_classdev_unregister(&this_fl_str->fl_lcdev);
	flashlight_free_gpio(flashlight, this_fl_str);

	kfree(this_fl_str);
	return 0;
}