static enum hrtimer_restart flashlight_hrtimer_func(struct hrtimer *timer) { struct flashlight_struct *fl_str = container_of(timer, struct flashlight_struct, timer); spin_lock_irqsave(&fl_str->spin_lock, fl_str->spinlock_flags); flashlight_turn_off(); spin_unlock_irqrestore(&fl_str->spin_lock, fl_str->spinlock_flags); FLT_INFO_LOG("%s: turn off flash mode\n", __func__); return HRTIMER_NORESTART; }
static void flashlight_early_suspend(struct early_suspend *handler) { struct flashlight_struct *fl_str = container_of(handler, struct flashlight_struct, early_suspend_flashlight); if (fl_str != NULL && fl_str->mode_status) { spin_lock_irqsave(&fl_str->spin_lock, fl_str->spinlock_flags); flashlight_turn_off(); spin_unlock_irqrestore(&fl_str->spin_lock, fl_str->spinlock_flags); } }
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 ssize_t poweroff_store( struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int input; input = simple_strtoul(buf, NULL, 10); FLT_INFO_LOG("%s\n", __func__); if(input == 1){ flashlight_turn_off(); }else FLT_INFO_LOG("%s: Input out of range\n",__func__); return size; }
static ssize_t store_flash_adj(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { static int tmp, adj_tmp; if ((buf[0] == '0' || buf[0] == '1' || buf[0] == '2') && buf[1] == '\n') { spin_lock_irqsave(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); tmp = buf[0] - 0x30; if (tmp == this_fl_str->flash_adj_value) { spin_unlock_irqrestore(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); FLT_INFO_LOG("%s: status is same(%d)\n", __func__, this_fl_str->flash_adj_value); return count; } adj_tmp = this_fl_str->gpio_flash_adj; switch (tmp) { case 2: flashlight_turn_off(); break; case 1: /* if (this_fl_str->flash_adj_gpio_status) { gpio_set_value(adj_tmp, 0); this_fl_str->flash_adj_gpio_status = 0; } */ break; case 0: /* if (!this_fl_str->flash_adj_gpio_status) { gpio_set_value(adj_tmp, 1); this_fl_str->flash_adj_gpio_status = 1; } */ break; } this_fl_str->flash_adj_value = tmp; spin_unlock_irqrestore(&this_fl_str->spin_lock, this_fl_str->spinlock_flags); } return count; }
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; }
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 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) { printk(KERN_INFO "%s: mode is same: %d\n", FLASHLIGHT_NAME, mode); 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); wake_unlock(&this_fl_str->wake_lock); flashlight_turn_off(); } switch (mode) { case FL_MODE_OFF: flashlight_turn_off(); break; case FL_MODE_TORCH: flashlight_hw_command(3, 1); flashlight_hw_command(0, 15); 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); wake_lock(&this_fl_str->wake_lock); break; case FL_MODE_PRE_FLASH: flashlight_hw_command(3, 1); flashlight_hw_command(0, 9); 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: flashlight_hw_command(3, 8); 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: flashlight_hw_command(3, 4); flashlight_hw_command(0, 15); 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: printk(KERN_ERR "%s: unknown flash_light flags: %d\n", __func__, mode); ret = -EINVAL; break; } printk(KERN_DEBUG "%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; }