Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2593536ybi; Thu, 18 Jul 2019 10:51:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEb8gP9nbC14eFF264jxskxyJM+VcAqVhrUEQSGlWtMMPvK0xyLSo8C9QaBnuywoCaKnEq X-Received: by 2002:a17:90a:bc0c:: with SMTP id w12mr22072726pjr.111.1563472283181; Thu, 18 Jul 2019 10:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563472283; cv=none; d=google.com; s=arc-20160816; b=TmRr2bxm49QI0NQD+AtcxbzCOuw/8D2gMgPGpUz7MFUbLlCsz73twR+IGyxGua6mHV iGVXEkWqFhDPS46E6P1fG4dEcQvBOobL4Fz0bDaxe267BSsXHzuGenwzFLHXP4LmHgVo d/pfD2Hs5bfeIIIFNctWgAR+sTAJ6LEBOrUmBVLN7VnzYkxhu96Q3zLeIRDXMkvQFlfK FpNkurBM07qalDUCzIbgHy9bFpC9verQMg+BogJ6NGaotmT8WOgW5cu3q23HXhGrwB0N +RfHktju4V2t8UHHU8l/QkrdNAWRSqRWh26S2ndvh39OGXWcq3cem2WU0rVBwDtE2bMY WSCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=pgafvxZ2WNWOqgq4j6/+Wz8LCOx0VkOfOwXK6KTHB34=; b=WkGUx9sCQ6qPY7cAwmj+DuehuOsi+H0Y3HFsLEr6kmlJvjO0PzNffAISSehzwgoGfs JbeXSJhkdQBGJ62V+ugygr1/g0P7ctTFPqMSLBnZQHPMV0nhn3/guaBijvmIevEPfJGC SHXL3RTJPUi5oXbqEe7Mdx/rbEUbgJAFcmHHSP5pmMiInNaiLTbTIqZfnoO+nrusmOxp 2Ja0Yz904EpCyxg0S2dpGiU6+bfVK4x92XjXBBRDtTEi/jfgGSPZLAuwN2UW4sEHP2p0 jzymtkCihrrDy4odu3swgCfvGWP0W6KVI230RtkHytv9GS0trybVS0VcN23X5aYjz/Zx JQKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VAxlwSVp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l97si165545pje.6.2019.07.18.10.51.07; Thu, 18 Jul 2019 10:51:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VAxlwSVp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390494AbfGRRtV (ORCPT + 99 others); Thu, 18 Jul 2019 13:49:21 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41311 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727685AbfGRRtV (ORCPT ); Thu, 18 Jul 2019 13:49:21 -0400 Received: by mail-wr1-f67.google.com with SMTP id c2so26435604wrm.8; Thu, 18 Jul 2019 10:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=pgafvxZ2WNWOqgq4j6/+Wz8LCOx0VkOfOwXK6KTHB34=; b=VAxlwSVpmVGpT9xS2WTQl3NmzWZ20jUxLMaYhEhhFTBnQJ0smUNnpUv0E/+apDK+hY DWKMVRrbqlhgT7uKkSv4S1xXRXNLsmwv+oOnjBZZyOSp89NpwsU0lSBiSeT0oTF6TcZ4 yOPeL4CzjUljTXllLsRszWlPsrWrtG2zBbfuX0BeHVO3MkjkAjPnC4MxTHS3fZEsPwMM w2ohrzgn8v7/HX9TY1UMlDH3Nl+14RaLI39kzW61ULL0Tc7xv0aSFc/tjuYcIiNtRtg/ YZblwpMroF1o4LdvaaPUS4cq8aXDuQt2ULSnAQb/KMArm0J5WnyIqIl9DUPLHkpJBVRn 1tMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=pgafvxZ2WNWOqgq4j6/+Wz8LCOx0VkOfOwXK6KTHB34=; b=p4yHfiwsc680RFi65MYBsVNCuy5U44r7seRHAgCn9oVirAoTYuaC0EC03TBk79iVLj Ok1Xgqgw+a+x3Z0LqRguSf25to+AoPEKp6X4feTU32Bthq1D1t5aEdCSLfMN09p0yUY+ kWpSvzU3T3V194ofPrJbKBb3tNYppWgkoo2I2Sv7ssdBN/+cyMYF84eXA87349wlepkF rbv527xFzhASDeRA4Vxc45ctXRLIrfxOZNqivjUUtuKHbclK/5tRX1zbhpzKX7pwBClE CKjf7SFfskiZDQDRffMAb7oEikNxcjHvTtcZX09XeEemLkvxrMU82JMiiXL1RRSLVRph OBaA== X-Gm-Message-State: APjAAAW2rW0k9GKbZ/ot7bnG8v7L5v53zyA4PAIl2oeAf7UTKspcuVic 6Zc8kNu+jPFNhEvhBAZlcJTGpL// X-Received: by 2002:a5d:518f:: with SMTP id k15mr10642655wrv.321.1563472157706; Thu, 18 Jul 2019 10:49:17 -0700 (PDT) Received: from [192.168.1.19] (bkt159.neoplus.adsl.tpnet.pl. [83.28.187.159]) by smtp.gmail.com with ESMTPSA id t3sm20585948wmi.6.2019.07.18.10.49.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jul 2019 10:49:17 -0700 (PDT) Subject: Re: [PATCH v3 2/3] leds: Add control of the voltage/current regulator to the LED core To: Jean-Jacques Hiblot , pavel@ucw.cz, robh+dt@kernel.org, mark.rutland@arm.com, daniel.thompson@linaro.org Cc: dmurphy@ti.com, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org References: <20190717135948.19340-1-jjhiblot@ti.com> <20190717135948.19340-3-jjhiblot@ti.com> <4bd3b558-ea5b-0d2e-16b2-5b2e8bb484d2@gmail.com> <49152281-059c-6006-4c0f-a6be96a12707@ti.com> From: Jacek Anaszewski Openpgp: preference=signencrypt Autocrypt: addr=jacek.anaszewski@gmail.com; prefer-encrypt=mutual; keydata= mQINBFWjfaEBEADd66EQbd6yd8YjG0kbEDT2QIkx8C7BqMXR8AdmA1OMApbfSvEZFT1D/ECR eWFBS8XtApKQx1xAs1j5z70k3zebk2eeNs5ahxi6vM4Qh89vBM46biSKeeX5fLcv7asmGb/a FnHPAfQaKFyG/Bj9V+//ef67hpjJWR3s74C6LZCFLcbZM0z/wTH+baA5Jwcnqr4h/ygosvhP X3gkRzJLSFYekmEv+WHieeKXLrJdsUPUvPJTZtvi3ELUxHNOZwX2oRJStWpmL2QGMwPokRNQ 29GvnueQdQrIl2ylhul6TSrClMrKZqOajDFng7TLgvNfyVZE8WQwmrkTrdzBLfu3kScjE14Q Volq8OtQpTsw5570D4plVKh2ahlhrwXdneSot0STk9Dh1grEB/Jfw8dknvqkdjALUrrM45eF FM4FSMxIlNV8WxueHDss9vXRbCUxzGw37Ck9JWYo0EpcpcvwPf33yntYCbnt+RQRjv7vy3w5 osVwRR4hpbL/fWt1AnZ+RvbP4kYSptOCPQ+Pp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V4f8q0V0MW3KWfkD9/07bbGxXSnImeLt7bPuVMGK2tAUbr2+dUYmUdsETZ 1HgZ11moCVU5Ru0RwTv9oyThOsK3HQjI7NCIsDzVpolaGQPd9E7xwOVHhhDcXRqqNjLzHUSe eGGiEQ== Message-ID: <928fd71b-d1d3-cbf3-1aed-ae7fa97f6cf0@gmail.com> Date: Thu, 18 Jul 2019 19:49:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <49152281-059c-6006-4c0f-a6be96a12707@ti.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/18/19 3:31 PM, Jean-Jacques Hiblot wrote: > > On 18/07/2019 14:24, Jacek Anaszewski wrote: >> Hi Jean, >> >> Thank you for the updated patch set. >> >> I have some more comments below. >> >> On 7/17/19 3:59 PM, Jean-Jacques Hiblot wrote: >>>   +static bool __led_need_regulator_update(struct led_classdev >>> *led_cdev, >>> +                    int brightness) >>> +{ >>> +    bool new_state = (brightness != LED_OFF); >> How about: >> >> bool new_state = !!brightness; > > Throughout the code LED_OFF is used when the LED is turned off. I think > it would be more consistent to use it there too. Basically brightness is a scalar and 0 always means off. We treat enum led_brightness as a legacy type - it is no longer valid on the whole its span since LED_FULL = 255 was depreciated with addition of max_brightness property. IMHO use of reverse logic here only hinders code analysis. >>> + >>> +    return led_cdev->regulator && led_cdev->regulator_state != >>> new_state; >>> +} >>> +static int __led_handle_regulator(struct led_classdev *led_cdev, >>> +                int brightness) >>> +{ >>> +    int rc; >>> + >>> +    if (__led_need_regulator_update(led_cdev, brightness)) { >>> + >>> +        if (brightness != LED_OFF) >>> +            rc = regulator_enable(led_cdev->regulator); >>> +        else >>> +            rc = regulator_disable(led_cdev->regulator); >>> +        if (rc) >>> +            return rc; >>> + >>> +        led_cdev->regulator_state = (brightness != LED_OFF); >>> +    } >>> +    return 0; >>> +} >> Let's have these function names without leading underscores. > OK. >> >>>   static int __led_set_brightness(struct led_classdev *led_cdev, >>>                   enum led_brightness value) >>>   { >>> @@ -115,6 +142,8 @@ static void set_brightness_delayed(struct >>> work_struct *ws) >>>       if (ret == -ENOTSUPP) >>>           ret = __led_set_brightness_blocking(led_cdev, >>>                       led_cdev->delayed_set_value); >>> +    __led_handle_regulator(led_cdev, led_cdev->delayed_set_value) >> If you called it from __led_set_brightness() and > > We cannot call it from __led_set_brightness() because it is supposed not > to block. You're right. The problematic part is that with regulator handling we cannot treat the whole brightness setting operation uniformly for brightness_set op case, i.e. without mediation of a workqueue. Now you have to fire workqueue in led_set_brightness_nopm() even for brightness_set() op path, if regulator state needs update. This is ugly and can be misleading. Can be also error prone and have non-obvious implications for software blink state transitions. I think we would first need to improve locking between the workqueue and led_timer_function(). I proposed a patch [0] over a year ago. Only then we could think of adding another asynchronous dependency to the brightness setting chain. [0] https://lkml.org/lkml/2018/1/17/1144 -- Best regards, Jacek Anaszewski