Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1148157ybg; Fri, 18 Oct 2019 12:49:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFnaKefw7glgIFglX3xBQrnvk9rIK6PQQ+Gu2fGYelV59xUu10dfbHJre8EeHuXmCrAkzA X-Received: by 2002:a17:906:3c4:: with SMTP id c4mr10480856eja.302.1571428176124; Fri, 18 Oct 2019 12:49:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571428176; cv=none; d=google.com; s=arc-20160816; b=pW0nedHztliAE2fSzGBjbKfL5m41I8ixRQ9yZUtMo/8xHT8ptu0vNu9pdnkN7rQUVP SEyoaqsrhCI080aUTcEPT279eHojgQz2PTKm+Ht/cSZVueGTgjlFy21QihF6izw9ve8z s2xHamOxShFZuip7t4fShZ/e+29t6jhqwofYFtibV6SPeF0s9xzS48vpBizrXnK9KPAO tq9tTrl8rFQshLA7tPu9L2Iqbdvi1jeaXmVcnSGvJ3OmLDl2Jwa29F7lCwz+mhR256ij WkkvMiimO3a0tuWiwIajsO0/au6arW8tMcrxlaBmIs8AxV7vH73U1y6L8M0OcdlwRnLb HWog== 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; bh=tGg6bsc8S9rTK+HZ8UXl1BTXEpDabPFyCJjzUliwgn8=; b=uQk8kJVAMZdbEUYa0g0ZfF9BHyCOcNlcXxTxHUnXBM0sEu66C3JfL9isGHfCbT2R9O yVh2Rb2O47hSaAwbDTh1my+Ag+tEMWDi+wbWHOh1OVZArry9JKO7qlTeMkC50ijcLAap Jq9VzKNp4Hkjznz8c6R/HDoebOM8HWSyc0dKkLdc9qeaRaB+fN2lSXtmurOaO9td7K7D s8I7u682KEHJ6u+ZbDsjC7/exDaDysGcCWg8qx/Kfu6oQIRpcBT17RvpYeUU9h31ZeX8 nwnTqGInc/r4Vx0ju/VvnzZXLNkaFS6mK/t3CoXrnnc9s3b7u0quQrfl77oQ4fJxwASy u5yw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j18si4037787ejv.201.2019.10.18.12.49.13; Fri, 18 Oct 2019 12:49:36 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440299AbfJQO2d (ORCPT + 99 others); Thu, 17 Oct 2019 10:28:33 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:32847 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731664AbfJQO2c (ORCPT ); Thu, 17 Oct 2019 10:28:32 -0400 X-Originating-IP: 86.207.98.53 Received: from localhost (aclermont-ferrand-651-1-259-53.w86-207.abo.wanadoo.fr [86.207.98.53]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 02998E0006; Thu, 17 Oct 2019 14:28:26 +0000 (UTC) Date: Thu, 17 Oct 2019 16:28:23 +0200 From: Alexandre Belloni To: Dan Murphy Cc: Matti Vaittinen , mazziesaccount@gmail.com, Lee Jones , Rob Herring , Mark Rutland , Liam Girdwood , Mark Brown , Michael Turquette , Stephen Boyd , Linus Walleij , Bartosz Golaszewski , Jacek Anaszewski , Pavel Machek , Alessandro Zummo , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org, linux-leds@vger.kernel.org, linux-rtc@vger.kernel.org Subject: Re: [RFC PATCH 11/13] led: bd71828: Support LED outputs on ROHM BD71828 PMIC Message-ID: <20191017142823.GF3125@piout.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/10/2019 09:04:48-0500, Dan Murphy wrote: > Matt > > On 10/17/19 4:53 AM, Matti Vaittinen wrote: > > ROHM BD71828 power management IC has two LED outputs for charge status > > and button pressing indications. The LED outputs can also be forced > > bs SW so add driver allowing to use these LEDs for other indications > s/bs/by > > as well. > > > > Leds are controlled by SW using 'Force ON' bits. Please note the > > constrains mentioned in data-sheet: > > 1. If one LED is forced ON - then also the other LED is forced. > > => You can't use SW control to force ON one LED and allow HW > > to control the other. > > 2. You can't force both LEDs OFF. If the FORCE bit for both LED's is > > zero, then LEDs are controlled by HW and indicate button/charger > > states as explained in data-sheet. > > > > Signed-off-by: Matti Vaittinen > > --- > > drivers/leds/Kconfig | 10 ++++ > > drivers/leds/Makefile | 1 + > > drivers/leds/leds-bd71828.c | 97 +++++++++++++++++++++++++++++++++++++ > > 3 files changed, 108 insertions(+) > > create mode 100644 drivers/leds/leds-bd71828.c > > > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > > index b0fdeef10bd9..ec59f28bcb39 100644 > > --- a/drivers/leds/Kconfig > > +++ b/drivers/leds/Kconfig > > @@ -529,6 +529,16 @@ config LEDS_BD2802 > > This option enables support for BD2802GU RGB LED driver chips > > accessed via the I2C bus. > > +config LEDS_BD71828 > > + tristate "LED driver for LED pins on ROHM BD71828 PMIC" > > + depends on LEDS_CLASS > doesn't this have a dependency on MFD_ROHM_BD71828 > > + depends on I2C > > + help > > + This option enables support for LED outputs located on ROHM > > + BD71828 power management IC. ROHM BD71828 has two led output pins > > + which can be left to indicate HW states or controlled by SW. Say > > + yes here if you want to enable SW control for these LEDs. > > + > > Add module statement > > > > config LEDS_INTEL_SS4200 > > tristate "LED driver for Intel NAS SS4200 series" > > depends on LEDS_CLASS > > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > > index 41fb073a39c1..2a8f6a8e4c7c 100644 > > --- a/drivers/leds/Makefile > > +++ b/drivers/leds/Makefile > > @@ -15,6 +15,7 @@ obj-$(CONFIG_LEDS_AN30259A) += leds-an30259a.o > > obj-$(CONFIG_LEDS_BCM6328) += leds-bcm6328.o > > obj-$(CONFIG_LEDS_BCM6358) += leds-bcm6358.o > > obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o > > +obj-$(CONFIG_LEDS_BD71828) += leds-bd71828.o > > obj-$(CONFIG_LEDS_CPCAP) += leds-cpcap.o > > obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o > > obj-$(CONFIG_LEDS_LM3530) += leds-lm3530.o > > diff --git a/drivers/leds/leds-bd71828.c b/drivers/leds/leds-bd71828.c > > new file mode 100644 > > index 000000000000..2427619444f5 > > --- /dev/null > > +++ b/drivers/leds/leds-bd71828.c > > @@ -0,0 +1,97 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +// Copyright (C) 2019 ROHM Semiconductors > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#define BD71828_LED_TO_DATA(l) ((l)->id == ID_GREEN_LED ? \ > > + container_of((l), struct bd71828_leds, green) : \ > > + container_of((l), struct bd71828_leds, amber)) > > I don't think we should be defining the color as the variable. The outputs > can drive any color LED. > > > > + > > +enum { > > + ID_GREEN_LED, > > + ID_AMBER_LED, > > + ID_NMBR_OF, > > +}; > > + > > Please use the color_id in linux/include/dt-bindings/leds/common.h > > > > +struct bd71828_led { > > + int id; > > + struct led_classdev l; > > + u8 force_mask; > > +}; > > + > > +struct bd71828_leds { > > + struct rohm_regmap_dev *bd71828; > > + struct bd71828_led green; > > + struct bd71828_led amber; > > +}; > > + > > +static int bd71828_led_brightness_set(struct led_classdev *led_cdev, > > + enum led_brightness value) > > +{ > > + struct bd71828_led *l = container_of(led_cdev, struct bd71828_led, l); > > + struct bd71828_leds *data; > > + unsigned int val = BD71828_LED_OFF; > > + > > + data = BD71828_LED_TO_DATA(l); > > + if (value != LED_OFF) > > + val = BD71828_LED_ON; > > + > > + return regmap_update_bits(data->bd71828->regmap, BD71828_REG_LED_CTRL, > > + l->force_mask, val); > > +} > > + > > +static int bd71828_led_probe(struct platform_device *pdev) > > +{ > > + struct rohm_regmap_dev *bd71828; > > + struct bd71828_leds *l; > > + struct bd71828_led *g, *a; > > + static const char *GNAME = "bd71828-green-led"; > > + static const char *ANAME = "bd71828-amber-led"; > The LED class creates the name it can get it from the DT. > > + int ret; > > + > > + pr_info("bd71828 LED driver probed\n"); > > + > > + bd71828 = dev_get_drvdata(pdev->dev.parent); > > + l = devm_kzalloc(&pdev->dev, sizeof(*l), GFP_KERNEL); > > + if (!l) > > + return -ENOMEM; > > + l->bd71828 = bd71828; > > + a = &l->amber; > > + g = &l->green; > > + a->id = ID_AMBER_LED; > > + g->id = ID_GREEN_LED; > > + a->force_mask = BD71828_MASK_LED_AMBER; > > + g->force_mask = BD71828_MASK_LED_GREEN; > > + > > + a->l.name = ANAME; > > + g->l.name = GNAME; > > + a->l.brightness_set_blocking = bd71828_led_brightness_set; > > + g->l.brightness_set_blocking = bd71828_led_brightness_set; > > + > > + ret = devm_led_classdev_register(&pdev->dev, &g->l); > > + if (ret) > > + return ret; > > + > > + return devm_led_classdev_register(&pdev->dev, &a->l); > > +} > > + > > This looks different.? Not sure why you register both LEDs in this probe. > > You can use the DT to define both LEDs and then each will be probed and > registered separately. > > This is how it is commonly done. > > You can reference the LM36274 led driver as this is a MFD device to the > ti-lmu.c in the MFD directory. > > > > +static struct platform_driver bd71828_led_driver = { > > + .driver = { > > + .name = "bd71828-led", > > + }, > > + .probe = bd71828_led_probe, > > +}; > > + > > +module_platform_driver(bd71828_led_driver); > > + > > +MODULE_AUTHOR("Matti Vaittinen "); > > +MODULE_DESCRIPTION("ROHM BD71828 LED driver"); > > +MODULE_LICENSE("GPL"); > GPL v2 GPL is fine, see bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity") -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com