From 24ca52d06d445006481357cedc7cae4727cf440c Mon Sep 17 00:00:00 2001 From: Anjelique Melendez Date: Mon, 18 Oct 2021 10:00:57 -0700 Subject: [PATCH] leds: qti-flash: Skip configuring a LED channel if it's configured already Currently, brightness for a torch/flash device can be set on a channel that's already configured for a flash/torch device that shared the same LED channel. Though the target current configured at the end for that channel is correct, there is a transitional behavior where the channel can be disabled and enabled again. Fix this by not allowing the brightness to be set if it's attempted for the same channel id but another type (flash or torch) is configured before. Change-Id: I3ae5990121af1302e14dc2bd14f9baa178dd0cd2 Signed-off-by: Anjelique Melendez --- drivers/leds/leds-qti-flash.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/leds/leds-qti-flash.c b/drivers/leds/leds-qti-flash.c index 3e5eeade377a..ec1672bd3bf3 100644 --- a/drivers/leds/leds-qti-flash.c +++ b/drivers/leds/leds-qti-flash.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "qti-flash: %s: " fmt, __func__ @@ -239,6 +239,22 @@ static int current_to_code(u32 target_curr_ma, u32 ires_ua) return DIV_ROUND_CLOSEST(target_curr_ma * 1000, ires_ua) - 1; } +static bool is_channel_configured(struct flash_node_data *fnode) +{ + int i; + + for (i = 0; i < fnode->led->num_fnodes; i++) { + if (fnode->led->fnode[i].id == fnode->id && + fnode->led->fnode[i].type != fnode->type && + fnode->led->fnode[i].configured) { + pr_debug("Channel %d for %s is already configured by %s\n", fnode->id, + fnode->fdev.led_cdev.name, fnode->led->fnode[i].fdev.led_cdev.name); + return true; + } + } + return false; +} + static int qti_flash_led_read(struct qti_flash_led *led, u16 offset, u8 *data, u8 len) { @@ -640,6 +656,9 @@ static void qti_flash_led_brightness_set(struct led_classdev *led_cdev, fnode = container_of(fdev, struct flash_node_data, fdev); led = fnode->led; + if (is_channel_configured(fnode)) + return; + rc = __qti_flash_led_brightness_set(led_cdev, brightness); if (!rc) fnode->user_current_ma = brightness;