Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1225383ybi; Fri, 12 Jul 2019 11:51:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOHVN2Op8APYFaT0tJuOIUuphE4h19Ge/aNDxtQ2RrB1Xle6UMuozECTyCNRqxSL41mFKF X-Received: by 2002:a63:e70f:: with SMTP id b15mr12791324pgi.152.1562957473939; Fri, 12 Jul 2019 11:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562957473; cv=none; d=google.com; s=arc-20160816; b=q3pVSjpdQgn7ezrYI60igZmJ2kzalpuFv+es5XNYhJV2qLs0b8G1RtimVHda7SM+DE ysHCziYe74wTqG3ORyRJ4cqxvk6D2Ueo5ywkMyE1/uZ9IOlz+UQhvX0j5DA3m8QIK0Wz P3kTKECLepwRK2ooo2ADYLqPyYPckLMjVu5DN77YhUR4SbaXLjtkxoT0xjZ2BWV/oCGF dcvoeO2nQnX8Aqte0CdCyqMkD48nWUtGHc03x52gzDYhgul92PBxLPmHmQElj+OiPJ3n NFSzbjL2Y2VFOkiW19zg6YVrdXKG5ejGchzE9RTBlO/yo4b0FrIozD2BjJwYNQMdrVcL 5+mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=zqQ58ER/KkKEyQXdg8uscL61M3xULXtOuGlfXPiC+0g=; b=seAdFJwXQE+zH473c9a8d4pNJNvXu+gpp+F/fBdBwgLSGKvB/f2dQe/chBdLUyojnt HsUKlS27JVShqd2kJSNy8TqGol/pCUJAgJZ0f2THh+nejrmG3LbMsIbgq23DWsOoetpP k75imv80iinZx+6MQUJ9JashNdJAkaH2FryWOs2yBymhCG99A+yV64Njhkz51cDjCmgE 9uMUlT1FMNyU/GaZv8NbNm0GTZajXuRXjA70Hyz9v+dKxQEjtzA1MxbxGsPT+XGbpAAO 23gH93B5pgGs7/PSHQn/iEbSzR56MSyyyOYSLk8VAdvx4gyplACSnnFfaNwNGgMjh/1N WP/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=dAaZQGHV; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18si9169359pgf.457.2019.07.12.11.50.53; Fri, 12 Jul 2019 11:51:13 -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=@ti.com header.s=ti-com-17Q1 header.b=dAaZQGHV; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727447AbfGLSuS (ORCPT + 99 others); Fri, 12 Jul 2019 14:50:18 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:44448 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726867AbfGLSuS (ORCPT ); Fri, 12 Jul 2019 14:50:18 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x6CIo9EC024168; Fri, 12 Jul 2019 13:50:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1562957409; bh=zqQ58ER/KkKEyQXdg8uscL61M3xULXtOuGlfXPiC+0g=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=dAaZQGHV1DwZdJc3UcxYwVwxsHGEIz6yobfLwkVrdJ8xlzPcRiFLnt5YhDoVz/jYR YZPUa6bJPksA7hRv5TVSbBcil3pf+rn+aSPgKKUNZEelUV6Jc2CmrBWF+ksF5YIdOL pLPtf1Lq32spU5PxbfkO8McmuC/BT5NJ6PdhBbsI= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x6CIo9B2120918 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 12 Jul 2019 13:50:09 -0500 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Fri, 12 Jul 2019 13:50:09 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Fri, 12 Jul 2019 13:50:09 -0500 Received: from [128.247.59.136] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id x6CIo9xY056447; Fri, 12 Jul 2019 13:50:09 -0500 Subject: Re: [PATCH 1/2] leds: Add control of the voltage/current regulator to the LED core To: Jean-Jacques Hiblot , , , , , CC: , , References: <20190708103547.23528-1-jjhiblot@ti.com> <20190708103547.23528-2-jjhiblot@ti.com> From: Dan Murphy Message-ID: <56d16260-ff82-3439-4c1f-2a3a1552bc7d@ti.com> Date: Fri, 12 Jul 2019 13:49:21 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190708103547.23528-2-jjhiblot@ti.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > + 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. 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. > + > + 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? 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,