Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1934876pxb; Thu, 7 Oct 2021 19:15:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydTiRvPbqtPcL+xRdb/YluDsEZFlTXYW+JbhyPFskvNn5WE2YxMNOXGf/LslR7yZofKQLd X-Received: by 2002:a17:906:3745:: with SMTP id e5mr716639ejc.400.1633659339258; Thu, 07 Oct 2021 19:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633659339; cv=none; d=google.com; s=arc-20160816; b=WZEUZNpfgjswMvGW/jDZmT5DeHJGBM4liCiqJNjuarSjztWAzZ8rJwYK6W0sZn906V F0t+4SCUWSuG3F8ZQbERys8B+p4P4nMARqN1g3yxwOc6FZX3axt6IaI74BahGHXDw03A amy0bg7IDW2X0+44YAx9GHWCWM1DKO+655/LOK5fr72OSwyqtaagTd29OlA0PjPaGAeJ F6qVoednBCNQA1n/NSdxjJgh29JWhvh/5yH5jKb2POUztDDMPdfcTW7bIMYgvlBStSRr DJTl+u9oLO7D/ZbNfyux2tl16FkhdHEcRHmPiGAX92irpK1+KZqpiB3NuM7EWHdiCBuk YD3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=8zjqR4d40OrfZQChcnPYfxufF2MVkRD2Tr6gUlIKqF0=; b=SZO5h0ibjdp+ZsF4uJvjj+JB2KSzml77ZjWGWGe4iTzaOXE9XU0UTq6bZc26EA7as0 Uxr/VbLytaCTHwipDl2Qw8A/PuTwSKayp4FRs9vjqobo56RGSrkG0t4Q7vzCYYtsOqRz DcqgW3g4Zw/ZnhO3kXQov4ZEzgbbcYOfpd0Vdkp25h5Dz8CIWdi1BqSmehCFwfq60Qes /v512YquvaUgFpXh7+krWAdYHBts3SoRJGYwDbtrFplBY4fXrVZdDSXETFV/6N9dSN6c EKquaZkYnc91VslPvfS4bO8lv/JUMRQu/53QKR7uFvA1U9YngVMkaMgQ5pxxrVNq6zEA njKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 5si1271515eji.628.2021.10.07.19.15.13; Thu, 07 Oct 2021 19:15:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232411AbhJHCOv (ORCPT + 99 others); Thu, 7 Oct 2021 22:14:51 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:41774 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbhJHCOu (ORCPT ); Thu, 7 Oct 2021 22:14:50 -0400 Received: from notapiano (unknown [IPv6:2806:105e:7:9ede::6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: nfraprado) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 027D21F45416; Fri, 8 Oct 2021 03:12:49 +0100 (BST) Date: Thu, 7 Oct 2021 21:12:45 -0500 From: =?utf-8?B?TsOtY29sYXMgRi4gUi4gQS4=?= Prado To: Jacek Anaszewski Cc: Pavel Machek , Dan Murphy , Bjorn Andersson , Andy Gross , Rob Herring , linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, Brian Masney , Luca Weiss , Russell King , Georgi Djakov , linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, ~lkcamp/patches@lists.sr.ht, =?utf-8?B?QW5kcsOp?= Almeida , kernel@collabora.com Subject: Re: [PATCH v3 2/5] leds: Add driver for QCOM SPMI Flash LEDs Message-ID: <20211008021245.barkpi4fd4lakt36@notapiano> References: <20210803162641.1525980-1-nfraprado@collabora.com> <20210803162641.1525980-3-nfraprado@collabora.com> <20210824214515.ekjpvaymkgxltlzp@notapiano> <278ea1e8-8b21-457d-78d7-fbb32544fe0a@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <278ea1e8-8b21-457d-78d7-fbb32544fe0a@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jacek, > > > > +static int qcom_flash_flcdev_strobe_set(struct led_classdev_flash *fled_cdev, > > > > + bool state) > > > > +{ > > > > + struct qcom_flash_led *led = flcdev_to_led(fled_cdev); > > > > + struct qcom_flash_device *leds_dev = led_to_leds_dev(led); > > > > + unsigned int bright; > > > > + unsigned int i; > > > > + int rc; > > > > + > > > > + /* Can't operate on flash if torch is on */ > > > > + if (leds_dev->torch_enabled) > > > > + return -EBUSY; > > > > + > > > > + mutex_lock(&leds_dev->lock); > > > > + if (!state) { > > > > + rc = qcom_flash_fled_off(led); > > > > + } else { > > > > + /* > > > > + * Turn off flash LEDs from previous strobe > > > > + */ > > > > + rc = qcom_flash_check_timedout(leds_dev); > > > > + if (rc > 0) { > > > > + for (i = 0; i < leds_dev->num_leds; i++) { > > > > + rc = qcom_flash_fled_off(&leds_dev->leds[i]); > > > > + if (rc) > > > > + goto unlock; > > > > + } > > > > + } else if (rc < 0) { > > > > + goto unlock; > > > > + } > > > > > > What if flash gets timed out after this check here? Why do you need to > > > call qcom_flash_fled_off() if it has already timed out? > > > > The issue is that after the flash times out, the hardware is not ready for > > another strobe. > > > > When I strobe LED0 for example, the STATUS register, 0x10, gets set to 0x08 > > indicating the LED0 is on. After the timeout, it changes to 0x04. At that point > > if I try to strobe LED0 again, it doesn't work. When I turn the LED0 off (write > > 0x00 to either the ENABLE or STROBE register), the STATUS is reset to 0x00. Now > > I'm able to strobe the LED0 again. > > > > I'm not sure if this is the normal behavior on other flash LED controllers, and > > maybe there's even some configuration of this PMIC that resets the LED status > > automatically after the strobe timeout, but I have not been able to do that. So > > that's why I reset the status manually everytime it's needed. > > My point was that the flash may time out after reading STATUS register > and before writing QCOM_FLASH_ADDR_LED_STROBE_CTRL. > You can't be 100% sure that you know the exact STATUS state just > a moment before strobing. That's true, but that scenario only happens if there's an ongoing flash strobe happening and userspace triggers another strobe. Is that a scenario that really needs to be taken care of, and if so, what would be the correct behavior? Does the timeout need to be reset for this new strobe, possibly using updated brightness and timeout values? (Currently none of this happens) The purpose of this check is not to know if an ongoing flash strobe has timed out, but rather to differentiate if the previous time the LED was strobed was as a flash (with timeout) or torch (no timeout), because the flash case needs an extra reset step that can be ommited in the torch case. For this purpose there's no race condition. > > To alleviate that I propose to avoid checking the status and always > calling qcom_flash_fled_off() before initiating a new strobe. Thanks, Nicolas