Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2235231ybi; Thu, 18 Jul 2019 05:26:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwW3sVkQDKTWyVflPw6h2tndRMLTI03NZOHuvbpXQjYGSlCC+0f+BtiR+Rzla9F3fUYvwfO X-Received: by 2002:a17:902:42d:: with SMTP id 42mr47583761ple.228.1563452786184; Thu, 18 Jul 2019 05:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563452786; cv=none; d=google.com; s=arc-20160816; b=WG47hV92eVBzp2s24dTIDoKToI5AsTkYMPaFxZfZDfSPnjzYJLu+dJFF0u5OY89ZZL P6SgOeG/8QK5q333zwI2F3fLZHJZA6jAfxRXtkdC15Y/17L49cqsRshDxGuTkJYVAkbS ft/+HlUedF7gSwM24vPs4zAJk6d7ovzJRmMFafYYB/bTEjfuZXTcGLTI5x/GbGX+Y4Nb Onk5SWcKNSbrWu1/YwSdEugc0dfwpKITPQrja3UteszAZzn9BIRD3pww2hiOupp67iV1 5mecrkINU89+tMupAMgSi9MsnQooP3l2XDSHU7+y69uUo63bL1mPEigvc3Hl2IunF/z6 PIYQ== 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:references:cc:to:subject:from :dkim-signature; bh=x68xceUAF1yvMJBVzFE8A19VprQT/IEWuO3/oCnUXnk=; b=fC+sv3fF7KpURtCjMUSXIm3MN83jF8s9kPZhsZGqVsL8k50+nDqJ+70bnEafqGYffA wKDap4sXNtH0tBGy/OPYtLR4WrG5k53wK7yPaQPNG6fp8myXDprHLvwiq32pYN2muU4n laXOq2llcrHf/DSdSIOpzOWsY0OdaChH2K/xHeXeiO2JsAwDHC/CsUS9yIEBKXjqjzu5 4kc3D3u/uqw6yb0ZRVJ428doudF8MQZOe3jVAB8l5ZKbB96+tBlTTC3jcf9Zzfx1pOCu uwDXCTo9Tc5+wyDadzKKwHYxI8qMZ1PBGJcYvZpoCDbVfFG5FqqWxcTd6pix7p1162hr v36w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DNAImOfx; 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 i94si1884720plb.78.2019.07.18.05.26.08; Thu, 18 Jul 2019 05:26:26 -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=DNAImOfx; 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 S2390304AbfGRMY5 (ORCPT + 99 others); Thu, 18 Jul 2019 08:24:57 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35550 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727742AbfGRMY4 (ORCPT ); Thu, 18 Jul 2019 08:24:56 -0400 Received: by mail-wr1-f67.google.com with SMTP id y4so28498302wrm.2; Thu, 18 Jul 2019 05:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=x68xceUAF1yvMJBVzFE8A19VprQT/IEWuO3/oCnUXnk=; b=DNAImOfxbX3eNqb2HVNoudd7KQAOXr5inJI7OKDGAu9P/WB35RXydbF059QlmSzAId yrDzs9M+gtOHYDamVdA9oLP4Zdn0gFdZ9ONyulsmK+rvMkIfLPHhDvYZ+0LoumpN9MEJ JwfVhowDwLTbfiT82dAPEF4s02l9BniapaOw90MHWEExr3hB6a+TP18VNGixx9yXlycR 2fVwhC0XD25MMjWdUiF60l0um2tXO5FM3x6doXtIwUUWmvxHAuG17vxECzV6WXEsYDLL rSCVtvD2Ptmn7+WDn5N/GGAcYXnsjDY9t97l755jsm3CY3FzjLrvFn585YaFCK3QtAYC KMmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=x68xceUAF1yvMJBVzFE8A19VprQT/IEWuO3/oCnUXnk=; b=gAHCsU6Do+FfNxbMFXiSHYO/ETcfiyYmCsFIy02zD1zuuZAtLeWTc7BTE84IfaZluo fBsQMqodk1xI9JEl83T+5+E0nNEmoB8VM70rlucYDUmg6X8LZahOsNQIaHKqXAE0/UMO O/iX7MzRSNFN54fw16GlVxj/SbBE1mqbYIjzs/p+kWMM3muFciAUhm9UhKHziFdLRCnh 55giDWyi2/2O4CKjLznCDaDpU/vLWaP8P1Y7hr2+Cuuz1/mewE+CA/g1ZPcGMn4B8Dnv 4EH1xuCQodDfSzVOPqZpX1Z+hAX4b9JIxmzntcLQO3+K5eoNE04wqTnh3A3WIONWPaW8 2v3A== X-Gm-Message-State: APjAAAV3KlnLOPUxLELtcFgTWgF1PPBKRwJgalChZOVDZoKrI548ms4d Sk0A3yDq6BD7bDIfYTcowtcsVeX9 X-Received: by 2002:a5d:4cc5:: with SMTP id c5mr1521436wrt.278.1563452692450; Thu, 18 Jul 2019 05:24:52 -0700 (PDT) Received: from [192.168.1.19] (bkt159.neoplus.adsl.tpnet.pl. [83.28.187.159]) by smtp.gmail.com with ESMTPSA id r14sm25128966wrx.57.2019.07.18.05.24.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jul 2019 05:24:51 -0700 (PDT) From: Jacek Anaszewski 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> 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+Pp1tCw16BOaPjtlqSTcrlD2fo2IbaB5D21SUa IsdZ/XkD+V2S9jCrN1yyK2iKgxtDoUkWiqlfRgH2Ep1tZtb4NLF/S0oCr7r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zVpolaGQPd9E7xwOVHhhDcXRqqNjLzHUSe eGGiEQ== Message-ID: <4bd3b558-ea5b-0d2e-16b2-5b2e8bb484d2@gmail.com> Date: Thu, 18 Jul 2019 14:24:48 +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: <20190717135948.19340-3-jjhiblot@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 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: > Sometimes LEDs are powered by an external voltage/current regulator. Let > the LED core know about it. This allows the LED core to turn on or off > managed power supplies. > > Signed-off-by: Jean-Jacques Hiblot > Reviewed-by: Dan Murphy > --- > drivers/leds/led-class.c | 15 +++++++++++++ > drivers/leds/led-core.c | 47 +++++++++++++++++++++++++++++++++++++--- > drivers/leds/leds.h | 1 + > include/linux/leds.h | 4 ++++ > 4 files changed, 64 insertions(+), 3 deletions(-) > > diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c > index 4793e77808e2..cadd43c30d50 100644 > --- a/drivers/leds/led-class.c > +++ b/drivers/leds/led-class.c > @@ -253,6 +253,7 @@ int of_led_classdev_register(struct device *parent, struct device_node *np, > { > char name[LED_MAX_NAME_SIZE]; > int ret; > + struct regulator *regulator; > > ret = led_classdev_next_name(led_cdev->name, name, sizeof(name)); > if (ret < 0) > @@ -272,6 +273,20 @@ int of_led_classdev_register(struct device *parent, struct device_node *np, > dev_warn(parent, "Led %s renamed to %s due to name collision", > led_cdev->name, dev_name(led_cdev->dev)); > > + regulator = devm_regulator_get_optional(led_cdev->dev, "power"); > + if (IS_ERR(regulator)) { > + if (PTR_ERR(regulator) != -ENODEV) { > + dev_err(led_cdev->dev, "Cannot get the power supply for %s\n", > + led_cdev->name); > + device_unregister(led_cdev->dev); > + mutex_unlock(&led_cdev->led_access); > + return PTR_ERR(regulator); > + } > + led_cdev->regulator = NULL; > + } else { > + led_cdev->regulator = regulator; > + } > + > if (led_cdev->flags & LED_BRIGHT_HW_CHANGED) { > ret = led_add_brightness_hw_changed(led_cdev); > if (ret) { > diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c > index 7107cd7e87cf..dab32cf778f2 100644 > --- a/drivers/leds/led-core.c > +++ b/drivers/leds/led-core.c > @@ -23,6 +23,33 @@ EXPORT_SYMBOL_GPL(leds_list_lock); > LIST_HEAD(leds_list); > EXPORT_SYMBOL_GPL(leds_list); > > +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; > + > + 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. > 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 from __led_set_brightness_blocking() you wouldn't need this change here. > + > if (ret < 0 && > /* LED HW might have been unplugged, therefore don't warn */ > !(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) && > @@ -256,8 +285,14 @@ void led_set_brightness_nopm(struct led_classdev *led_cdev, > enum led_brightness value) > { > /* Use brightness_set op if available, it is guaranteed not to sleep */ > - if (!__led_set_brightness(led_cdev, value)) > - return; > + if (!__led_set_brightness(led_cdev, value)) { > + /* > + * if regulator state doesn't need to be changed, that is all/ > + * Otherwise delegate the change to a work queue > + */ > + if (!__led_need_regulator_update(led_cdev, value)) > + return; > + } This change should be also not needed then. > > /* If brightness setting can sleep, delegate it to a work queue task */ > led_cdev->delayed_set_value = value; > @@ -280,6 +315,8 @@ EXPORT_SYMBOL_GPL(led_set_brightness_nosleep); > int led_set_brightness_sync(struct led_classdev *led_cdev, > enum led_brightness value) > { > + int ret; > + > if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) > return -EBUSY; > > @@ -288,7 +325,11 @@ int led_set_brightness_sync(struct led_classdev *led_cdev, > if (led_cdev->flags & LED_SUSPENDED) > return 0; > > - return __led_set_brightness_blocking(led_cdev, led_cdev->brightness); > + ret = __led_set_brightness_blocking(led_cdev, led_cdev->brightness); > + if (ret) > + return ret; > + > + return __led_handle_regulator(led_cdev, led_cdev->brightness); As well as this one. > } > EXPORT_SYMBOL_GPL(led_set_brightness_sync); > > diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h > index 47b229469069..5aa5c038bd38 100644 > --- a/drivers/leds/leds.h > +++ b/drivers/leds/leds.h > @@ -11,6 +11,7 @@ > > #include > #include > +#include > > static inline int led_get_brightness(struct led_classdev *led_cdev) > { > diff --git a/include/linux/leds.h b/include/linux/leds.h > index 9b2bf574a17a..bee8e3f8dddd 100644 > --- a/include/linux/leds.h > +++ b/include/linux/leds.h > @@ -123,6 +123,10 @@ struct led_classdev { > > /* Ensures consistent access to the LED Flash Class device */ > struct mutex led_access; > + > + /* regulator */ > + struct regulator *regulator; > + bool regulator_state; > }; > > extern int of_led_classdev_register(struct device *parent, > -- Best regards, Jacek Anaszewski