/* To avoid device shutdown when timeout, * 0x01 and 0x02 bits need to be refreshed within less than 13.0s * use timer to do it */ static void flash_on(struct work_struct *work) { printk("flash_on!\n"); tps61310_i2c_write(tps61310_client, 0x01, 0x40 ); tps61310_i2c_write(tps61310_client, 0x02, 0x40 ); /* Restart timer ,so it can be recurrent */ hrtimer_start(&flash_timer, ktime_set(FLASH_REFRESHED_TIME, 0), HRTIMER_MODE_REL); }
/*different handlings of different flash's states*/ int tps61310_set_flash(unsigned led_state) { int rc = 0; hw_camera_flash_number led_num = get_hw_camera_flash_number(); printk("tps61310_set_flash: led_state = %d\n", led_state); /* timer should be cancel,when Led_state possible changed */ if(timer_is_run) { hrtimer_cancel(&flash_timer); timer_is_run = false; } switch (led_state) { case MSM_CAMERA_LED_LOW: case MSM_CAMERA_LED_TORCH: case MSM_CAMERA_LED_TORCH_MIDDLE: //use for flashlight tps61310_i2c_write( tps61310_client,0x00, 0x0A ); tps61310_i2c_write( tps61310_client,0x05, 0x6F ); tps61310_i2c_write( tps61310_client,0x01, 0x40 ); tps61310_i2c_write( tps61310_client,0x02, 0x40 ); INIT_WORK(&flash_work, flash_on); hrtimer_init(&flash_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); flash_timer.function= flash_timer_func; timer_is_run = true; hrtimer_start(&flash_timer, ktime_set(FLASH_REFRESHED_TIME, 0), HRTIMER_MODE_REL); break; case MSM_CAMERA_LED_HIGH: gpio_set_value(tps61310_strb0, 1); tps61310_i2c_write( tps61310_client, 0x03, 0xE7 ); tps61310_i2c_write( tps61310_client, 0x05, 0x6F ); if(CAMERA_FLASH_LED_DOUBLE == led_num) { tps61310_i2c_write( tps61310_client, 0x01, 0x94 ); tps61310_i2c_write( tps61310_client, 0x02, 0x8a ); } else { tps61310_i2c_write( tps61310_client, 0x01, 0x88 ); tps61310_i2c_write( tps61310_client, 0x02, 0x88 ); } break; case MSM_CAMERA_LED_TORCH_HIGH: //use for flashlight tps61310_i2c_write( tps61310_client, 0x00, 0x12 ); tps61310_i2c_write( tps61310_client, 0x05, 0x6F ); tps61310_i2c_write( tps61310_client, 0x01, 0x40 ); tps61310_i2c_write( tps61310_client, 0x02, 0x40 ); INIT_WORK(&flash_work, flash_on); hrtimer_init(&flash_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); flash_timer.function= flash_timer_func; timer_is_run = true; hrtimer_start(&flash_timer, ktime_set(FLASH_REFRESHED_TIME, 0), HRTIMER_MODE_REL); break; case MSM_CAMERA_LED_TORCH_LOW: //use for flashlight tps61310_i2c_write( tps61310_client,0x00, 0x08); tps61310_i2c_write( tps61310_client,0x05, 0x6F ); tps61310_i2c_write( tps61310_client,0x01, 0x40 ); tps61310_i2c_write( tps61310_client,0x02, 0x40 ); INIT_WORK(&flash_work, flash_on); hrtimer_init(&flash_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); flash_timer.function= flash_timer_func; timer_is_run = true; hrtimer_start(&flash_timer, ktime_set(FLASH_REFRESHED_TIME, 0), HRTIMER_MODE_REL); break; case MSM_CAMERA_LED_OFF: tps61310_i2c_write( tps61310_client, 0x00, 0x80 ); gpio_set_value(tps61310_strb0, 0); break; case MSM_CAMERA_LED_FIRST_MMI: printk("MSM_CAMERA_LED_FIRST_MMI\n"); tps61310_i2c_write( tps61310_client,0x00, 0x08 );/*turn on led and then delay*/ tps61310_i2c_write( tps61310_client,0x05, 0x6F ); tps61310_i2c_write( tps61310_client,0x01, 0x40 ); tps61310_i2c_write( tps61310_client,0x02, 0x40 ); usleep(1000*200); tps61310_i2c_write( tps61310_client, 0x00, 0x80 );/*turn off*/ gpio_set_value(tps61310_strb0, 0); break; case MSM_CAMERA_LED_SECOND_MMI: printk("MSM_CAMERA_LED_SECOND_MMI\n"); tps61310_i2c_write( tps61310_client,0x00, 0x02 );/*switch to the other led*/ tps61310_i2c_write( tps61310_client,0x05, 0x6F ); tps61310_i2c_write( tps61310_client,0x01, 0x40 ); tps61310_i2c_write( tps61310_client,0x02, 0x40 ); usleep(1000*200); tps61310_i2c_write( tps61310_client, 0x00, 0x80 );/*turn off*/ gpio_set_value(tps61310_strb0, 0); break; default: tps61310_i2c_write( tps61310_client, 0x00, 0x80 ); gpio_set_value(tps61310_strb0, 0); break; } return rc; }
/*different handlings of different flash's states*/ int tps61310_set_flash(unsigned led_state) { int rc = 0; printk("tps61310_set_flash: led_state = %d\n", led_state); /* timer should be cancel,when Led_state possible changed */ if(timer_is_run) { hrtimer_cancel(&flash_timer); timer_is_run = false; } switch (led_state) { case MSM_CAMERA_LED_LOW: #ifdef CONFIG_ARCH_MSM7X30 pm8xxx_gpio_set_value(PMIC_GPIO_FLASH_EN, 1); pm8xxx_gpio_set_value(PMIC_GPIO_TORCH_FLASH, 1); mdelay(1); #endif tps61310_i2c_write( tps61310_client,0x00, 0x0A ); tps61310_i2c_write( tps61310_client,0x05, 0x6F ); tps61310_i2c_write( tps61310_client,0x01, 0x40 ); tps61310_i2c_write( tps61310_client,0x02, 0x40 ); INIT_WORK(&flash_work, flash_on); hrtimer_init(&flash_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); flash_timer.function= flash_timer_func; timer_is_run = true; hrtimer_start(&flash_timer, ktime_set(FLASH_REFRESHED_TIME, 0), HRTIMER_MODE_REL); break; case MSM_CAMERA_LED_HIGH: #ifdef CONFIG_ARCH_MSM7X27A gpio_set_value(tps61310_strb0, 1); #else pm8xxx_gpio_set_value(PMIC_GPIO_FLASH_EN, 1); pm8xxx_gpio_set_value(PMIC_GPIO_TORCH_FLASH, 1); mdelay(1); #endif tps61310_i2c_write( tps61310_client, 0x03, 0xE7 ); tps61310_i2c_write( tps61310_client, 0x05, 0x6F ); tps61310_i2c_write( tps61310_client, 0x01, 0x88 ); tps61310_i2c_write( tps61310_client, 0x02, 0x88 ); break; case MSM_CAMERA_LED_TORCH: #ifdef CONFIG_ARCH_MSM7X30 pm8xxx_gpio_set_value(PMIC_GPIO_FLASH_EN, 1); pm8xxx_gpio_set_value(PMIC_GPIO_TORCH_FLASH, 1); mdelay(1); #endif tps61310_i2c_write( tps61310_client,0x00, 0x0A ); tps61310_i2c_write( tps61310_client,0x05, 0x6F ); tps61310_i2c_write( tps61310_client,0x01, 0x40 ); tps61310_i2c_write( tps61310_client,0x02, 0x40 ); INIT_WORK(&flash_work, flash_on); hrtimer_init(&flash_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); flash_timer.function= flash_timer_func; timer_is_run = true; hrtimer_start(&flash_timer, ktime_set(FLASH_REFRESHED_TIME, 0), HRTIMER_MODE_REL); break; case MSM_CAMERA_LED_OFF: tps61310_i2c_write( tps61310_client, 0x00, 0x80 ); #ifdef CONFIG_ARCH_MSM7X27A gpio_set_value(tps61310_strb0, 0); #else mdelay(1); pm8xxx_gpio_set_value(PMIC_GPIO_FLASH_EN, 0); pm8xxx_gpio_set_value(PMIC_GPIO_TORCH_FLASH, 0); #endif break; default: tps61310_i2c_write( tps61310_client, 0x00, 0x80 ); #ifdef CONFIG_ARCH_MSM7X27A gpio_set_value(tps61310_strb0, 0); #else mdelay(1); pm8xxx_gpio_set_value(PMIC_GPIO_FLASH_EN, 0); pm8xxx_gpio_set_value(PMIC_GPIO_TORCH_FLASH, 0); #endif break; } return rc; }