From a16e0056dc6a40251e0bdc912e0d2fee0095d449 Mon Sep 17 00:00:00 2001 From: Kavya Nunna Date: Thu, 20 Aug 2020 17:33:35 +0530 Subject: [PATCH] leds: qti-flash: Enable the torch mode after enabling the led module Currently, we are enabling the torch mode before enabling led module. This causes large USB current spike after the torch event. To avoid such undesired behaviour enable the torch mode after enabling the led module. Change-Id: I1d867b07d05c3d745220c33a941680aa7d70f1f5 Signed-off-by: Kavya Nunna --- drivers/leds/leds-qti-flash.c | 37 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/leds/leds-qti-flash.c b/drivers/leds/leds-qti-flash.c index 78f5fd97ba32..a4608db7cc09 100644 --- a/drivers/leds/leds-qti-flash.c +++ b/drivers/leds/leds-qti-flash.c @@ -364,6 +364,18 @@ static int qti_flash_led_strobe(struct qti_flash_led *led, if (rc < 0) goto error; + for (i = 0; i < led->num_fnodes; i++) { + if ((mask & BIT(led->fnode[i].id)) && + led->fnode[i].configured && + led->fnode[i].type == FLASH_LED_TYPE_TORCH && + led->subtype == 0x6) { + rc = qti_flash_led_masked_write(led, + FORCE_TORCH_MODE, + FORCE_TORCH, FORCE_TORCH); + if (rc < 0) + goto error; + } + } rc = qti_flash_led_masked_write(led, FLASH_EN_LED_CTRL, mask, value); if (rc < 0) @@ -379,6 +391,17 @@ static int qti_flash_led_strobe(struct qti_flash_led *led, if (rc < 0) goto error; + for (i = 0; i < led->num_fnodes; i++) { + if ((mask & BIT(led->fnode[i].id)) && + led->fnode[i].configured && + led->fnode[i].type == FLASH_LED_TYPE_TORCH && + led->subtype == 0x6) { + rc = qti_flash_led_masked_write(led, + FORCE_TORCH_MODE, FORCE_TORCH, 0); + if (rc < 0) + goto error; + } + } rc = qti_flash_led_module_control(led, enable); if (rc < 0) goto error; @@ -434,13 +457,6 @@ static int qti_flash_led_enable(struct flash_node_data *fnode) goto out; } - if (fnode->type == FLASH_LED_TYPE_TORCH && led->subtype == 0x6) { - rc = qti_flash_led_masked_write(led, FORCE_TORCH_MODE, - FORCE_TORCH, FORCE_TORCH); - if (rc < 0) - goto out; - } - fnode->configured = true; if ((fnode->strobe_sel == HW_STROBE) && @@ -476,13 +492,6 @@ static int qti_flash_led_disable(struct flash_node_data *fnode) if (rc < 0) goto out; - if (fnode->type == FLASH_LED_TYPE_TORCH && led->subtype == 0x6) { - rc = qti_flash_led_masked_write(led, FORCE_TORCH_MODE, - FORCE_TORCH, 0); - if (rc < 0) - goto out; - } - fnode->configured = false; fnode->current_ma = 0;