Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4008323ybi; Mon, 15 Jul 2019 02:25:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqysDUfBBpesFTeWnmM/tHD9EIj0hpH9gz4AXCQY++eE+Pg6pXQ7DZVM4xAhuorLyV0ae5gv X-Received: by 2002:a17:90a:30aa:: with SMTP id h39mr28323858pjb.32.1563182747988; Mon, 15 Jul 2019 02:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563182747; cv=none; d=google.com; s=arc-20160816; b=Jvs/8CL3xpwYhHhjP7lns0oUc9254YhXAzHGbYZFTwA7bJQ+t1xfzPDEJonmpZ0Cqz zSbuV6JC85hTc7oEbBtNjveHngcFuv8a9t6mKt8n3QZoiEO3Ex6YUwUSC60fagCI+pnL u6gfNWOyoZPT65YybsKjMb1l2RtWD7NGMLaoX/3UmN9NfqsIZwOIK22U2YEwr8vB//3k kPg3UFTQmBT7rLrnnRttt3u95MQSgojN66RGQUTv1aDgYAuL1Cg8LRTaOcGkzYNQqcob yH2MhnE51tKFgEbgySFrDOgnelOB1i8xJU5vnLCH7CmhKY2NvyaDDGfx67MmpmCqD9UX 4FAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nfm6Ua4RrGb4WspYU/6CGmVhaLbOHYoHSE5D469nkM4=; b=U/iZ0CNigFnEqDxS50+dLjhVFQ5Ww8ZtOmsSL/zz/j6IuA4cTUdfPO3Bozq/ql0nEy K/y8jA9uwIlkAGQlg+EOqwodfgPyo2boettOqsg4W8h/w8pQ6A9q3MqZzsp5TEnse8p0 0rCduErr7LwoREOwuqfhyPc/8w9u1JuHWMy3KG7X/5zWnSnMcKWO8KrUan+VIVe0XI3l 8YMo/ItN8V7TSH8wo5IJzWdX1yeivkTM+Ig11XPcWJ0nll+KNqUVOdtO8vcbTWweGnnf +R9b3vvHDIuhkpgO98cYhPQTxhUMe8esOv/kTBR3POCFu0WY1nFwcbXetq4fFHjIUoiv vV7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nUxlRHFE; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i32si15219547pje.44.2019.07.15.02.25.26; Mon, 15 Jul 2019 02:25:47 -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=@linaro.org header.s=google header.b=nUxlRHFE; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729646AbfGOJYM (ORCPT + 99 others); Mon, 15 Jul 2019 05:24:12 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45239 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729426AbfGOJYG (ORCPT ); Mon, 15 Jul 2019 05:24:06 -0400 Received: by mail-wr1-f66.google.com with SMTP id f9so16206421wre.12 for ; Mon, 15 Jul 2019 02:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=nfm6Ua4RrGb4WspYU/6CGmVhaLbOHYoHSE5D469nkM4=; b=nUxlRHFEmdE//fmjfkSwYbzIynIsAnyHZUwgu6k0FB6rJdmYLn1JuaKI7GL+Or08qm /HGIxW0JUuNh1P87D362eX4UINwyRltQtIAdPWZ5jzdhOvPEoYsdbm19qyy9LSa4BYMj 19mBueDluvMxyxuhKPDWjd5WxBAPDUSCsWMXuJDuuVK6xPYOEshMZsyOq6oIQEagQ5Bx Xz74JAvKgmaa9W2rGpL8v3ORmqBOLPrK9+yQdLuKN9ziL/7AUbq5GKY5bZ4enS+ztBW1 VjjE3L5Rj/aaNY8X9f3BiuYpolJhC9Nn+pRwVw3CzhorEC/HiPOlfVNUgETAa0t4Xk6V x3Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=nfm6Ua4RrGb4WspYU/6CGmVhaLbOHYoHSE5D469nkM4=; b=atQ9R9DJAxcId6HqzCKycCPwMDuB7plwes6tiBeXUULNBkkv59YOJc4tPHEUw20ZvT eD4Bz4BSJ7QDCVx4P2MdA/KFXnXQK6XUIGVl0DlBFwSuT+qtgBqGdA2emYja4FS0/kJt MtnrKr/6fDB9MJv97IH6jAty0GIHTuP1mvFK+DNPThAsBDctMSwhlASdAEpiZCLMv9AQ REaQ+QDQGP+/uue99X2dV3sZW8y2F6z4F0uN9/wfFfJgXmANZbmivxHbvo5gXNs3WxDv 66meuNPcBvnHp6/S9ZMDA0uj5bZQF8iNJdbmeap3wSRiSO9qjVer68duBPaKagpfc3VF 9OYA== X-Gm-Message-State: APjAAAU5z+IrVhZUsnbjf9EzVkcTHws4H9H7PYNnFjbmnxzRlZJCLr8t lGmwtk/ACJMF/6g8T2y7xxbr9A== X-Received: by 2002:a5d:518c:: with SMTP id k12mr26872647wrv.116.1563182643036; Mon, 15 Jul 2019 02:24:03 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id n1sm13156524wrx.39.2019.07.15.02.24.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 02:24:02 -0700 (PDT) Date: Mon, 15 Jul 2019 10:24:00 +0100 From: Daniel Thompson To: Jean-Jacques Hiblot Cc: Dan Murphy , jacek.anaszewski@gmail.com, pavel@ucw.cz, robh+dt@kernel.org, mark.rutland@arm.com, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH 1/2] leds: Add control of the voltage/current regulator to the LED core Message-ID: <20190715092400.sedjumqkecglheyu@holly.lan> References: <20190708103547.23528-1-jjhiblot@ti.com> <20190708103547.23528-2-jjhiblot@ti.com> <56d16260-ff82-3439-4c1f-2a3a1552bc7d@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 15, 2019 at 11:01:29AM +0200, Jean-Jacques Hiblot wrote: > Hi Dan, > > On 12/07/2019 20:49, Dan Murphy wrote: > > JJ > > > > On 7/8/19 5:35 AM, Jean-Jacques Hiblot wrote: > > > A LED is usually powered by a voltage/current regulator. Let the LED > > > core > > Let the LED core know > > > about it. This allows the LED core to turn on or off the power supply > > > as needed. > > > > > > > > Signed-off-by: Jean-Jacques Hiblot > > > --- > > > ? drivers/leds/led-class.c | 10 ++++++++ > > > ? drivers/leds/led-core.c? | 53 +++++++++++++++++++++++++++++++++++++--- > > > ? include/linux/leds.h???? |? 4 +++ > > > ? 3 files changed, 64 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c > > > index 4793e77808e2..e01b2d982564 100644 > > > --- a/drivers/leds/led-class.c > > > +++ b/drivers/leds/led-class.c > > > @@ -17,6 +17,7 @@ > > > ? #include > > > ? #include > > > ? #include > > > +#include > > > > What if you move this to leds.h so core and class can both include it. > > > > > > > ? #include > > > ? #include "leds.h" > > > ? @@ -272,6 +273,15 @@ 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)); > > > ? +??? led_cdev->regulator = devm_regulator_get(led_cdev->dev, "power"); > > > > Is the regulator always going to be called power? > > Actually in the dts, that will be "power-supply". I lacked the imagination > to come up with a better name. > > > > > > > > +??? if (IS_ERR(led_cdev->regulator)) { > > > +??????? 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(led_cdev->regulator); > > > > This is listed as optional in the DT doc.? This appears to be required. > > The regulator core will provide a dummy regulator if none is given in the > device tree. I would rather have an error in that case, but that is not how > it works. If you actively wanted to get -ENODEV back when there is no regulator then you can use devm_regulator_get_optional() for that. However perhaps be careful what you wish for. If you use get_optional() then you will have to sprinkle NULL or IS_ERR() checks everywhere. I'd favour using the current approach! Daniel. > > > > > > I prefer to keep it optional.? Many LED drivers are connected to fixed > > non-managed supplies. > > > > > +??? } > > > + > > > ????? 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..139de6b08cad 100644 > > > --- a/drivers/leds/led-core.c > > > +++ b/drivers/leds/led-core.c > > > @@ -16,6 +16,7 @@ > > > ? #include > > > ? #include > > > ? #include "leds.h" > > > +#include > > > ? ? DECLARE_RWSEM(leds_list_lock); > > > ? EXPORT_SYMBOL_GPL(leds_list_lock); > > > @@ -23,6 +24,31 @@ 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_regulator_state = (brightness != LED_OFF); > > > + > > > +??? return led_cdev->regulator_state != new_regulator_state; > > > +} > > > + > > > +static int __led_handle_regulator(struct led_classdev *led_cdev, > > > +??????????????? int brightness) > > > +{ > > > +??? if (__led_need_regulator_update(led_cdev, brightness)) { > > > +??????? int ret; > > > > Prefer to this to be moved up. > ok > > > > > + > > > +??????? if (brightness != LED_OFF) > > > +??????????? ret = regulator_enable(led_cdev->regulator); > > > +??????? else > > > +??????????? ret = regulator_disable(led_cdev->regulator); > > > +??????? if (ret) > > > +??????????? return ret; > > new line > > > +??????? led_cdev->regulator_state = (brightness != LED_OFF); > > > +??? } > > > +??? return 0; > > > +} > > > + > > > ? static int __led_set_brightness(struct led_classdev *led_cdev, > > > ????????????????? enum led_brightness value) > > > ? { > > > @@ -80,6 +106,7 @@ static void led_timer_function(struct timer_list *t) > > > ????? } > > > ? ????? led_set_brightness_nosleep(led_cdev, brightness); > > > +??? __led_handle_regulator(led_cdev, brightness); > > > > Again this seems to indicate that the regulator is a required property > > for the LEDs > > > > This needs to be made optional.? And the same comment through out for > > every call. > > > > > > > ? ????? /* Return in next iteration if led is in one-shot mode and > > > we are in > > > ?????? * the final blink state so that the led is toggled each > > > delay_on + > > > @@ -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 (ret < 0 && > > > ????????? /* LED HW might have been unplugged, therefore don't warn */ > > > ????????? !(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) && > > > @@ -141,6 +170,7 @@ static void led_set_software_blink(struct > > > led_classdev *led_cdev, > > > ????? /* never on - just set to off */ > > > ????? if (!delay_on) { > > > ????????? led_set_brightness_nosleep(led_cdev, LED_OFF); > > > +??????? __led_handle_regulator(led_cdev, LED_OFF); > > > ????????? return; > > > ????? } > > > ? @@ -148,6 +178,7 @@ static void led_set_software_blink(struct > > > led_classdev *led_cdev, > > > ????? if (!delay_off) { > > > ????????? led_set_brightness_nosleep(led_cdev, > > > ???????????????????????? led_cdev->blink_brightness); > > > +??????? __led_handle_regulator(led_cdev, led_cdev->blink_brightness); > > > ????????? return; > > > ????? } > > > ? @@ -256,8 +287,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; > > > +??? } > > > ? ????? /* If brightness setting can sleep, delegate it to a work > > > queue task */ > > > ????? led_cdev->delayed_set_value = value; > > > @@ -280,6 +317,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 +327,15 @@ 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; > > > + > > > +??? ret = __led_handle_regulator(led_cdev, led_cdev->brightness); > > > > Can't you just return here? > > ok > > > thanks for the review > > JJ > > > > > Dan > > > > > +??? if (ret) > > > +??????? return ret; > > > + > > > +??? return 0; > > > ? } > > > ? EXPORT_SYMBOL_GPL(led_set_brightness_sync); > > > ? 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,