static int flashlight_setup_gpio(struct flashlight_platform_data *flashlight, struct flashlight_struct *fl_str) { int ret = 0; if (flashlight->gpio_init) flashlight->gpio_init(); if (flashlight->torch) { ret = gpio_request(flashlight->torch, "fl_torch"); if (ret < 0) { FLT_ERR_LOG("%s: gpio_request(torch) failed\n", __func__); return ret; } fl_str->gpio_torch = flashlight->torch; } if (flashlight->flash) { ret = gpio_request(flashlight->flash, "fl_flash"); if (ret < 0) { FLT_ERR_LOG("%s: gpio_request(flash) failed\n", __func__); return ret; } fl_str->gpio_flash = flashlight->flash; } return ret; }
static int flashlight_setup_gpio(struct flashlight_platform_data *flashlight, struct flashlight_struct *fl_str) { int ret = 0; if (flashlight->gpio_init) flashlight->gpio_init(); if (flashlight->torch) { ret = gpio_request(flashlight->torch, "fl_torch"); if (ret < 0) { FLT_ERR_LOG("%s: gpio_request(torch) failed\n", __func__); return ret; } fl_str->gpio_torch = flashlight->torch; } if (flashlight->flash) { ret = gpio_request(flashlight->flash, "fl_flash"); if (ret < 0) { FLT_ERR_LOG("%s: gpio_request(flash) failed\n", __func__); return ret; } fl_str->gpio_flash = flashlight->flash; } if (flashlight->torch_set1) { ret = gpio_request(flashlight->torch_set1, "fl_torch_set1"); if (ret < 0) { FLT_ERR_LOG("%s: gpio_request(fl_torch_set1) failed\n", __func__); return ret; } fl_str->torch_set1 = flashlight->torch_set1; } if (flashlight->torch_set2) { ret = gpio_request(flashlight->torch_set2, "fl_torch_set2"); if (ret < 0) { FLT_ERR_LOG("%s: gpio_request(fl_torch_set2) failed\n", __func__); return ret; } fl_str->torch_set2 = flashlight->torch_set2; } if (flashlight->flash_adj) { ret = gpio_request(flashlight->flash_adj, "fl_flash_adj"); if (ret < 0) { FLT_ERR_LOG("%s: gpio_request(flash_adj) failed\n", __func__); return ret; } fl_str->gpio_flash_adj = flashlight->flash_adj; gpio_set_value(fl_str->gpio_flash_adj, 0); fl_str->flash_adj_gpio_status = 0; FLT_INFO_LOG("%s: enable flash_adj function\n", FLASHLIGHT_NAME); } 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; return ret; }
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->chip_model = flashlight->chip_model; 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) { FLT_ERR_LOG("%s: failed on led_classdev_register\n", __func__); goto fail_free_gpio; } #ifdef FLASHLIGHT_ADJ_FUNC if (fl_str->gpio_flash_adj) { FLT_INFO_LOG("%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) FLT_ERR_LOG("%s: dev_attr_flash_adj failed\n", __func__); } #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; FLT_INFO_LOG("%s: led_count = %d\n", __func__, fl_str->led_count); 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); FLT_ERR_LOG("make %s: The Flashlight driver is Failure\n", __func__); return err; }
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; }
static void flashlight_hw_command(uint8_t addr, uint8_t data) { uint8_t loop_i, loop_j; const uint8_t fl_addr_to_rising_count[4] = { 17, 18, 19, 20 }; uint8_t loop_tmp; if (!this_fl_str->gpio_torch && !this_fl_str->gpio_flash) { FLT_ERR_LOG("%s: not setup GPIO??? torch: %d, flash: %d\n", __func__, this_fl_str->gpio_torch, this_fl_str->gpio_flash); return; } for (loop_j = 0; loop_j < 2; loop_j++) { if (!loop_j) loop_tmp = fl_addr_to_rising_count[addr]; else loop_tmp = data; for (loop_i = 0; loop_i < loop_tmp; loop_i++) { gpio_direction_output(this_fl_str->gpio_torch, 0); udelay(2); gpio_direction_output(this_fl_str->gpio_torch, 1); udelay(2); } udelay(500); } }
int aat1271_flashlight_control(int mode) { int ret = 0; uint32_t flash_ns = ktime_to_ns(ktime_get()); #if 0 /* disable flash_adj_value check now */ if (this_fl_str->flash_adj_value == 2) { printk(KERN_WARNING "%s: force disable function!\n", __func__); return -EIO; } #endif if (this_fl_str->mode_status == mode) { FLT_INFO_LOG("%s: mode is same: %d\n", FLASHLIGHT_NAME, mode); if (!hrtimer_active(&this_fl_str->timer) && this_fl_str->mode_status == FL_MODE_OFF) { FLT_INFO_LOG("flashlight hasn't been enable or" \ " has already reset to 0 due to timeout\n"); return ret; } else return -EINVAL; } spin_lock_irqsave(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); if (this_fl_str->mode_status == FL_MODE_FLASH) { hrtimer_cancel(&this_fl_str->timer); flashlight_turn_off(); } switch (mode) { case FL_MODE_OFF: flashlight_turn_off(); break; case FL_MODE_TORCH: if (this_fl_str->led_count) flashlight_hw_command(3, 4); else flashlight_hw_command(3, 3); flashlight_hw_command(0, 6); flashlight_hw_command(2, 4); this_fl_str->mode_status = FL_MODE_TORCH; this_fl_str->fl_lcdev.brightness = LED_HALF; break; case FL_MODE_TORCH_LED_A: flashlight_hw_command(3, 1); flashlight_hw_command(0, 15); flashlight_hw_command(2, 3); this_fl_str->mode_status = FL_MODE_TORCH_LED_A; this_fl_str->fl_lcdev.brightness = 1; break; case FL_MODE_TORCH_LED_B: flashlight_hw_command(3, 1); flashlight_hw_command(0, 15); flashlight_hw_command(2, 2); this_fl_str->mode_status = FL_MODE_TORCH_LED_B; this_fl_str->fl_lcdev.brightness = 2; break; case FL_MODE_FLASH: flashlight_hw_command(2, 4); gpio_direction_output(this_fl_str->gpio_flash, 1); this_fl_str->mode_status = FL_MODE_FLASH; this_fl_str->fl_lcdev.brightness = LED_FULL; hrtimer_start(&this_fl_str->timer, ktime_set(this_fl_str->flash_sw_timeout_ms / 1000, (this_fl_str->flash_sw_timeout_ms % 1000) * NSEC_PER_MSEC), HRTIMER_MODE_REL); break; case FL_MODE_PRE_FLASH: flashlight_hw_command(3, 3); flashlight_hw_command(0, 6); flashlight_hw_command(2, 4); this_fl_str->mode_status = FL_MODE_PRE_FLASH; this_fl_str->fl_lcdev.brightness = LED_HALF + 1; break; case FL_MODE_TORCH_LEVEL_1: if (this_fl_str->led_count) flashlight_hw_command(3, 4); else flashlight_hw_command(3, 3); flashlight_hw_command(0, 15); flashlight_hw_command(2, 4); this_fl_str->mode_status = FL_MODE_TORCH_LEVEL_1; this_fl_str->fl_lcdev.brightness = LED_HALF - 2; break; case FL_MODE_TORCH_LEVEL_2: if (this_fl_str->led_count) flashlight_hw_command(3, 4); else flashlight_hw_command(3, 3); flashlight_hw_command(0, 10); flashlight_hw_command(2, 4); this_fl_str->mode_status = FL_MODE_TORCH_LEVEL_2; this_fl_str->fl_lcdev.brightness = LED_HALF - 1; break; default: FLT_ERR_LOG("%s: unknown flash_light flags: %d\n", __func__, mode); ret = -EINVAL; break; } FLT_INFO_LOG("%s: mode: %d, %u\n", FLASHLIGHT_NAME, mode, flash_ns/(1000*1000)); spin_unlock_irqrestore(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); return ret; }
int aat1277_flashlight_control(int mode) { int ret = 0; uint32_t flash_ns = ktime_to_ns(ktime_get()); #if 0 /* disable flash_adj_value check now */ if (this_fl_str->flash_adj_value == 2) { printk(KERN_WARNING "%s: force disable function!\n", __func__); return -EIO; } #endif #ifndef CONFIG_ARCH_MSM_FLASHLIGHT_DEATH_RAY if (this_fl_str->mode_status == mode) { FLT_INFO_LOG("%s: mode is same: %d\n", FLASHLIGHT_NAME, mode); if (!hrtimer_active(&this_fl_str->timer) && this_fl_str->mode_status == FL_MODE_OFF) { FLT_INFO_LOG("flashlight hasn't been enable or" \ " has already reset to 0 due to timeout\n"); return ret; } else return -EINVAL; } #endif spin_lock_irqsave(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); if (this_fl_str->mode_status == FL_MODE_FLASH) { hrtimer_cancel(&this_fl_str->timer); flashlight_turn_off(); } switch (mode) { case FL_MODE_OFF: flashlight_turn_off(); break; case FL_MODE_TORCH: gpio_direction_output(this_fl_str->gpio_torch, 0); gpio_set_value(this_fl_str->torch_set1, 1); gpio_set_value(this_fl_str->torch_set2, 1); gpio_direction_output(this_fl_str->gpio_torch, 1); this_fl_str->mode_status = FL_MODE_TORCH; this_fl_str->fl_lcdev.brightness = LED_HALF; break; case FL_MODE_FLASH: gpio_direction_output(this_fl_str->gpio_flash, 1); this_fl_str->mode_status = FL_MODE_FLASH; this_fl_str->fl_lcdev.brightness = LED_FULL; hrtimer_start(&this_fl_str->timer, ktime_set(this_fl_str->flash_sw_timeout_ms / 1000, (this_fl_str->flash_sw_timeout_ms % 1000) * NSEC_PER_MSEC), HRTIMER_MODE_REL); break; case FL_MODE_PRE_FLASH: gpio_direction_output(this_fl_str->gpio_torch, 0); gpio_set_value(this_fl_str->torch_set1, 1); gpio_set_value(this_fl_str->torch_set2, 1); gpio_direction_output(this_fl_str->gpio_torch, 1); this_fl_str->mode_status = FL_MODE_PRE_FLASH; this_fl_str->fl_lcdev.brightness = LED_HALF + 1; break; case FL_MODE_TORCH_LEVEL_1: gpio_direction_output(this_fl_str->gpio_torch, 0); gpio_set_value(this_fl_str->torch_set1, 0); gpio_set_value(this_fl_str->torch_set2, 0); gpio_direction_output(this_fl_str->gpio_torch, 1); this_fl_str->mode_status = FL_MODE_TORCH_LEVEL_1; this_fl_str->fl_lcdev.brightness = LED_HALF - 2; break; case FL_MODE_TORCH_LEVEL_2: gpio_direction_output(this_fl_str->gpio_torch, 0); gpio_set_value(this_fl_str->torch_set1, 0); gpio_set_value(this_fl_str->torch_set2, 1); gpio_direction_output(this_fl_str->gpio_torch, 1); this_fl_str->mode_status = FL_MODE_TORCH_LEVEL_2; this_fl_str->fl_lcdev.brightness = LED_HALF - 1; break; #ifdef CONFIG_ARCH_MSM_FLASHLIGHT_DEATH_RAY case FL_MODE_DEATH_RAY: pr_info("%s: death ray\n", __func__); hrtimer_cancel(&this_fl_str->timer); gpio_direction_output(this_fl_str->gpio_flash, 0); udelay(40); gpio_direction_output(this_fl_str->gpio_flash, 1); this_fl_str->mode_status = 0; this_fl_str->fl_lcdev.brightness = 3; break; #endif default: FLT_ERR_LOG("%s: unknown flash_light flags: %d\n", __func__, mode); ret = -EINVAL; break; } FLT_INFO_LOG("%s: mode: %d, %u\n", FLASHLIGHT_NAME, mode, flash_ns/(1000*1000)); spin_unlock_irqrestore(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); return ret; }
int aat1277_flashlight_control(int mode) { int ret = 0; uint32_t flash_ns = ktime_to_ns(ktime_get()); if (this_fl_str->mode_status == mode) { FLT_INFO_LOG("%s: mode is same: %d\n", "aat1277_flashlight", mode); if (!hrtimer_active(&this_fl_str->timer) && this_fl_str->mode_status == FL_MODE_OFF) { FLT_INFO_LOG("flashlight hasn't been enable or" \ " has already reset to 0 due to timeout\n"); return ret; } else return -EINVAL; } spin_lock_irqsave(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); if (this_fl_str->mode_status == FL_MODE_FLASH) { hrtimer_cancel(&this_fl_str->timer); flashlight_turn_off(); } switch (mode) { case FL_MODE_OFF: flashlight_turn_off(); break; case FL_MODE_TORCH: gpio_direction_output(this_fl_str->gpio_torch, 0); gpio_set_value(this_fl_str->torch_set1, 1); gpio_set_value(this_fl_str->torch_set2, 1); gpio_direction_output(this_fl_str->gpio_torch, 1); this_fl_str->mode_status = FL_MODE_TORCH; this_fl_str->fl_lcdev.brightness = LED_HALF; break; case FL_MODE_FLASH: gpio_direction_output(this_fl_str->gpio_flash, 1); this_fl_str->mode_status = FL_MODE_FLASH; this_fl_str->fl_lcdev.brightness = LED_FULL; hrtimer_start(&this_fl_str->timer, ktime_set(this_fl_str->flash_sw_timeout_ms / 1000, (this_fl_str->flash_sw_timeout_ms % 1000) * NSEC_PER_MSEC), HRTIMER_MODE_REL); break; case FL_MODE_PRE_FLASH: gpio_direction_output(this_fl_str->gpio_torch, 0); gpio_set_value(this_fl_str->torch_set1, 1); gpio_set_value(this_fl_str->torch_set2, 1); gpio_direction_output(this_fl_str->gpio_torch, 1); this_fl_str->mode_status = FL_MODE_PRE_FLASH; this_fl_str->fl_lcdev.brightness = LED_HALF + 1; break; case FL_MODE_TORCH_LEVEL_1: gpio_direction_output(this_fl_str->gpio_torch, 0); gpio_set_value(this_fl_str->torch_set1, 0); gpio_set_value(this_fl_str->torch_set2, 0); gpio_direction_output(this_fl_str->gpio_torch, 1); this_fl_str->mode_status = FL_MODE_TORCH_LEVEL_1; this_fl_str->fl_lcdev.brightness = LED_HALF - 2; break; case FL_MODE_TORCH_LEVEL_2: gpio_direction_output(this_fl_str->gpio_torch, 0); gpio_set_value(this_fl_str->torch_set1, 0); gpio_set_value(this_fl_str->torch_set2, 1); gpio_direction_output(this_fl_str->gpio_torch, 1); this_fl_str->mode_status = FL_MODE_TORCH_LEVEL_2; this_fl_str->fl_lcdev.brightness = LED_HALF - 1; break; default: FLT_ERR_LOG("%s: unknown flash_light flags: %d\n", __func__, mode); ret = -EINVAL; break; } FLT_INFO_LOG("%s: mode: %d, %u\n", "aat1277_flashlight", mode, flash_ns/(1000*1000)); spin_unlock_irqrestore(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); return ret; }