From patchwork Mon Jan 21 21:56:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 156252 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6848694jaa; Mon, 21 Jan 2019 13:57:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN5o9EPGzlGK8OO9OLdqmcp04oRQMaXdkvd65VnItdnfDtYH9jEJwDSB3agSbll1/Qy1dpvn X-Received: by 2002:a17:902:28c1:: with SMTP id f59mr31745147plb.37.1548107828667; Mon, 21 Jan 2019 13:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548107828; cv=none; d=google.com; s=arc-20160816; b=P7j2PZIcs6FB188ay7a8GK/vyMb9yeSigsVGSDfRtj6n1BxJN56HuUIBkANGmKpQHE XkINmQEOcN96wN/iE96MsFF/0eD6/2EAYie5JqxQZ1tjjVG2NeTU6+A0TwGwMH+ixm2e eDrH9IpSTHXD0HWosLxpzv3uc/Uwioti/H0rUhCP1BgRv/ghIFF2sUXxjTbtIMA+dDI7 4zI7AzWn3pu1X77wV7fvFsY36CJYCaSSzJFydciPVqq2cmIAUNXeh4kg52qKULEzdXwj ueIeMqo/kkS3R4UwIEMSkmgHnsv88pbVXvXLvDdqnPl69q8oQcfwgJc6hJkp9Qox64cz 927g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=gVbHm6NjtR0uqlq38Ijt0M1g1n0Ufx4QUl0hap9n3Wc=; b=F/wRgpcXGXxkmPeQH9+LS3CUDukXT6yPlOpxCMUw8OHjUm9+eiclt52m/YmYY1riC9 rJ2gubwgkWAm/x80dXrrd/4LDrgF3WK2FvYkuO22yXU49e3JPiIVer2heBTs/2Bs7Go0 4paaxqv205E4YFGGao+4q/cBTJ+BGl8xZRrMTTwuqRfp0/XNgkWBUh0x36B5HqXSVcjV g0Nqbx8lF3DkwdrrFJ2wOcui56DNFqo89Zx2pdXPIfCzVU67XRELnTh5FJWq96J7plBt 7urYCIiwUEsI1SQlr26qbnaF3JqJT4tvFL2+jTHNLx4nJnPQAau1lDSpaAoxbD+iE3Wx 3yoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=HkBquUu5; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 9si14124932plc.40.2019.01.21.13.57.08; Mon, 21 Jan 2019 13:57:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-leds-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=HkBquUu5; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 S1727798AbfAUV5H (ORCPT + 1 other); Mon, 21 Jan 2019 16:57:07 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:58852 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727457AbfAUV5H (ORCPT ); Mon, 21 Jan 2019 16:57:07 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0LLv3LV114961; Mon, 21 Jan 2019 15:57:03 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548107823; bh=gVbHm6NjtR0uqlq38Ijt0M1g1n0Ufx4QUl0hap9n3Wc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=HkBquUu5sJ7kBIAmY6uwKaeR6Pzlz4eOGCqvEFVkNdbOETR2W7qkm2bu7lIVnxNEm zKC81iUL6VJVyXwfax0GOj5gkNROBJgtWnKr8YeJRjJB3Ict1HJVdyAzZp9QDZtjV5 CPaTHMV6bkXQvs/AnrApE4cnG0Vl4HoGfmFNmsfQ= Received: from DFLE108.ent.ti.com (dfle108.ent.ti.com [10.64.6.29]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0LLv3QB081619 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 21 Jan 2019 15:57:03 -0600 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 21 Jan 2019 15:57:02 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 21 Jan 2019 15:57:02 -0600 Received: from legion.dal.desgin.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0LLv2R8009410; Mon, 21 Jan 2019 15:57:02 -0600 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.78.123]) by legion.dal.desgin.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id x0LLv2U20724; Mon, 21 Jan 2019 15:57:02 -0600 (CST) From: Dan Murphy To: CC: , , , Dan Murphy Subject: [RFC PATCH 1/6] DO NOT MERGE:dt and defconfig Date: Mon, 21 Jan 2019 15:56:54 -0600 Message-ID: <20190121215659.31125-2-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20190121215659.31125-1-dmurphy@ti.com> References: <20190121215659.31125-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Signed-off-by: Dan Murphy --- arch/arm/boot/dts/am335x-bone-common.dtsi | 58 ++++++++++++++++++- .../arm/boot/dts/motorola-cpcap-mapphone.dtsi | 8 ++- arch/arm/configs/omap2plus_defconfig | 7 ++- 3 files changed, 68 insertions(+), 5 deletions(-) -- 2.20.1.98.gecbdaf0899 diff --git a/arch/arm/boot/dts/am335x-bone-common.dtsi b/arch/arm/boot/dts/am335x-bone-common.dtsi index 456eef57ef89..c36f623375f3 100644 --- a/arch/arm/boot/dts/am335x-bone-common.dtsi +++ b/arch/arm/boot/dts/am335x-bone-common.dtsi @@ -255,8 +255,62 @@ status = "okay"; clock-frequency = <100000>; + led-controller@29 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "ti,lp5024"; + reg = <0x29>; + enable-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>; + vled-supply = <&vmmcsd_fixed>; + + led@0 { + reg = <0>; + label = "led1_mod"; + ti,led-module = <1>; + }; + }; + + led-controller@30 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "rgb,framework_test"; + reg = <0x30>; + + led@0 { + reg = <0>; + label = "rgb_test1"; + rgb-sources = < 0xff 1 2 >; + rgb-white = < 0xd4 0x01 0x16 >; + }; +/* + led@1 { + reg = <1>; + label = "rgb_test2"; + rgb-sources = < 0xff 3 5 >; + };*/ + }; - cape_eeprom0: cape_eeprom0@54 { + led-controller@30 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "rgb,framework_test"; + reg = <0x30>; + + led@0 { + reg = <0>; + label = "rgb_test1"; + rgb-sources = < 0xff 1 2 >; + rgb-white = < 0xd4 0x01 0x16 >; + }; +/* + led@1 { + reg = <1>; + label = "rgb_test2"; + rgb-sources = < 0xff 3 5 >; + };*/ + }; + +/* cape_eeprom0: cape_eeprom0@54 { compatible = "atmel,24c256"; reg = <0x54>; #address-cells = <1>; @@ -294,7 +348,7 @@ cape3_data: cape_data@0 { reg = <0 0x100>; }; - }; + };*/ }; diff --git a/arch/arm/boot/dts/motorola-cpcap-mapphone.dtsi b/arch/arm/boot/dts/motorola-cpcap-mapphone.dtsi index ddc7a7bb33c0..42aafffcb3e4 100644 --- a/arch/arm/boot/dts/motorola-cpcap-mapphone.dtsi +++ b/arch/arm/boot/dts/motorola-cpcap-mapphone.dtsi @@ -117,6 +117,12 @@ vusb-supply = <&vusb>; }; + led_rgb: led-rgb { + compatible = "motorola,cpcap-led-rgb"; + vdd-supply = <&sw5>; + label = "status-led:rgb"; + }; +/* led_red: led-red { compatible = "motorola,cpcap-led-red"; vdd-supply = <&sw5>; @@ -134,7 +140,7 @@ vdd-supply = <&sw5>; label = "status-led:blue"; }; - +*/ led_adl: led-adl { compatible = "motorola,cpcap-led-adl"; vdd-supply = <&sw5>; diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig index 9c6f436d1b12..a4e7159325ae 100644 --- a/arch/arm/configs/omap2plus_defconfig +++ b/arch/arm/configs/omap2plus_defconfig @@ -453,8 +453,11 @@ CONFIG_MMC_OMAP=y CONFIG_MMC_OMAP_HS=y CONFIG_MMC_SDHCI_OMAP=y CONFIG_NEW_LEDS=y -CONFIG_LEDS_CLASS=m -CONFIG_LEDS_CPCAP=m +CONFIG_LEDS_CLASS=y +CONFIG_LEDS_CLASS_RGB=y +CONFIG_LEDS_RGB_TEST=y +CONFIG_LEDS_LP50XX=y +CONFIG_LEDS_CPCAP=y CONFIG_LEDS_GPIO=m CONFIG_LEDS_PCA963X=m CONFIG_LEDS_PWM=m From patchwork Mon Jan 21 21:56:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 156256 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6848713jaa; Mon, 21 Jan 2019 13:57:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN6ha1zaZT+bSuE7J9tn0YPFEeh0qms8WMRNBl+cfKpRhEfNmFOKgNh1RtoGSgxqoRAQuTCq X-Received: by 2002:a62:fc52:: with SMTP id e79mr31598097pfh.8.1548107829953; Mon, 21 Jan 2019 13:57:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548107829; cv=none; d=google.com; s=arc-20160816; b=yjHa0jagEQhnkCGzRkPuqrBWrPtx8wflO1HQ1igg7bH0nZkotIKm8BwhAIApVlZbDg YdjNvqtPt7AAz7ON/lI+q0+e0IPb5BUzM+PuqHAWClx4OaccjgbVqp6aRjHMlGr66x3c jRthrksK73Mq3JVZuAfpCCJYaag32t/BrYGxMbXWNlUOd7yLq7rlQNhqGetk1MmZOtk7 5IHiNXS9jO3f8VxKdVdi1VlgLkkIMUwitfckrtBzuQNTQKJ47Ilgf08V+CrubFxvVk/M nQdnGj9CfLyDQun2Ks/yqjNlLcPgzMIUCOhfoHh9wHpQsVucnLVTAEd+60S33bbJ9Z0t vnww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=uJqCWvpeCGTDa+/5qaviaWDSzoXdFFvyHIka7+9IYp0=; b=nkto0jTxiXJF8CI4mMW2Nd/4r9X5UQKqAAbYGYmD4ZI/LcHmV8e2M98zFBcwLPWW01 cofwSIesNLkAARW9bdlmmnoeRRWYfhdPnF/w5B7rwsEmhRcPKHl92YV61E7rStRBuLrK 5xhZSZK+jNA8fBx09ygdD9t5fPlmNzli5hbTf3rYzljkQ14E3Tt+D/O83fDPjWCcsyV2 VjAIDVDwxDV1M9XjNIZCnQHjni0r3gHjXOpt2ib7bksNkj/bcUR1QLYkRxr0engFpVQ7 q1ui2O7kk6eXZCf3LrDxgOksEpKN7S4v5GZNbLa2Aq7/Ujvv3+EH3xKnX9iifZ2UQhwf wcAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=FccCE0W8; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 9si14124932plc.40.2019.01.21.13.57.09; Mon, 21 Jan 2019 13:57:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-leds-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=FccCE0W8; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 S1727761AbfAUV5J (ORCPT + 1 other); Mon, 21 Jan 2019 16:57:09 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:58854 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727791AbfAUV5I (ORCPT ); Mon, 21 Jan 2019 16:57:08 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0LLv3eC114957; Mon, 21 Jan 2019 15:57:03 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548107823; bh=uJqCWvpeCGTDa+/5qaviaWDSzoXdFFvyHIka7+9IYp0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=FccCE0W8FZNgDozGWGz5at6lo5/7P/0/hQHLBFEgea3kecnl2dN/fWPIZuFcZHTw8 zJOg/MZxWCHfoAdj8TqnDK1mphuzYRvlew13J886CvCfKltJUA0wee8Vb+cJqmBBRZ YhEENTT90q0nmQ0NrPlPmGj9lbKXh7TjHeBhOoKg= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0LLv3KB125677 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 21 Jan 2019 15:57:03 -0600 Received: from DFLE100.ent.ti.com (10.64.6.21) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 21 Jan 2019 15:57:03 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 21 Jan 2019 15:57:03 -0600 Received: from legion.dal.desgin.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0LLv3fi020797; Mon, 21 Jan 2019 15:57:03 -0600 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.78.123]) by legion.dal.desgin.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id x0LLv2U20728; Mon, 21 Jan 2019 15:57:02 -0600 (CST) From: Dan Murphy To: CC: , , , Dan Murphy Subject: [RFC PATCH 2/6] leds: RGB Framework: Introduce a simple RGB framework Date: Mon, 21 Jan 2019 15:56:55 -0600 Message-ID: <20190121215659.31125-3-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20190121215659.31125-1-dmurphy@ti.com> References: <20190121215659.31125-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Introduce a simple RGB framework that will allow devices to cluster and control RGB LEDs as a single LED. This simple framework exposes 4 files for control. color - This will set all RGB values to obtain a certain color red - This will set the red LED brightness green - This will set the green LED brightness blue - This will set the blue LED brightness Signed-off-by: Dan Murphy --- drivers/leds/Kconfig | 9 + drivers/leds/Makefile | 1 + drivers/leds/led-class-rgb.c | 313 ++++++++++++++++++++++++++++++++++ include/linux/led-class-rgb.h | 89 ++++++++++ 4 files changed, 412 insertions(+) create mode 100644 drivers/leds/led-class-rgb.c create mode 100644 include/linux/led-class-rgb.h -- 2.20.1.98.gecbdaf0899 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index a72f97fca57b..f2d8bb7f4a6d 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -29,6 +29,15 @@ config LEDS_CLASS_FLASH for the flash related features of a LED device. It can be built as a module. +config LEDS_CLASS_RGB + tristate "LED RGB Class Support" + depends on LEDS_CLASS + help + This option enables the RGB led sysfs class in /sys/class/leds. + It wrapps LED Class and adds RGB LEDs specific sysfs attributes + and kernel internal API to it. You'll need this to provide support + for the clustered RGB LED devices. It can be built as a module. + config LEDS_BRIGHTNESS_HW_CHANGED bool "LED Class brightness_hw_changed attribute support" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 4c1b0054f379..5806760f00cb 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -4,6 +4,7 @@ obj-$(CONFIG_NEW_LEDS) += led-core.o obj-$(CONFIG_LEDS_CLASS) += led-class.o obj-$(CONFIG_LEDS_CLASS_FLASH) += led-class-flash.o +obj-$(CONFIG_LEDS_CLASS_RGB) += led-class-rgb.o obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o # LED Platform Drivers diff --git a/drivers/leds/led-class-rgb.c b/drivers/leds/led-class-rgb.c new file mode 100644 index 000000000000..a50beafbbd21 --- /dev/null +++ b/drivers/leds/led-class-rgb.c @@ -0,0 +1,313 @@ +// SPDX-License-Identifier: GPL-2.0 +/* LED RGB class interface + * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + */ + +#include +#include +#include +#include +#include +#include +#include "leds.h" + +static ssize_t color_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + const struct led_rgb_ops *ops = rgbled_cdev->ops; + int red, green, blue; + ssize_t ret = -EINVAL; + + mutex_lock(&led_cdev->led_access); + + if (led_sysfs_is_disabled(led_cdev)) { + ret = -EBUSY; + goto unlock; + } + + if (sscanf(buf, "%d %d %d", &red, &green, &blue) != 3) { + pr_err("%s:unable to parse input\n", __func__); + return -1; + } + + /* Should these values be retainable if the ops fails should the old + * values be restored? + */ + colors->red = red; + colors->green = green; + colors->blue = blue; + + ret = ops->set_color(rgbled_cdev); + if (ret < 0) + goto unlock; + + ret = size; +unlock: + mutex_unlock(&led_cdev->led_access); + return ret; +} + +static ssize_t color_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + u8 red, green, blue; + + red = rgbled_cdev->rgb_colors.red; + green = rgbled_cdev->rgb_colors.green; + blue = rgbled_cdev->rgb_colors.blue; + + return sprintf(buf, "%d %d %d\n", red, green, blue); +} +static DEVICE_ATTR_RW(color); + +static struct attribute *led_set_color_attrs[] = { + &dev_attr_color.attr, + NULL, +}; + +static const struct attribute_group led_color_group = { + .attrs = led_set_color_attrs, +}; + +static ssize_t red_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t size) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + const struct led_rgb_ops *ops = rgbled_cdev->ops; + unsigned long state; + ssize_t ret = -EINVAL; + + mutex_lock(&led_cdev->led_access); + + if (led_sysfs_is_disabled(led_cdev)) { + ret = -EBUSY; + goto unlock; + } + + ret = kstrtoul(buf, 10, &state); + if (ret) + goto unlock; + + if (state > LED_FULL) { + ret = -EINVAL; + goto unlock; + } + + ret = ops->set_red_brightness(rgbled_cdev, state); + if (ret < 0) + goto unlock; + + colors->red = state; + + ret = size; +unlock: + mutex_unlock(&led_cdev->led_access); + return ret; +} + +static ssize_t red_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + + if (rgbled_cdev->ops->get_red_brightness) + colors->red = rgbled_cdev->ops->get_red_brightness(rgbled_cdev); + + return sprintf(buf, "%d\n", colors->red); +} +static DEVICE_ATTR_RW(red); + +static struct attribute *led_color_red_attrs[] = { + &dev_attr_red.attr, + NULL, +}; + +static const struct attribute_group led_set_red_group = { + .attrs = led_color_red_attrs, +}; +static ssize_t green_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t size) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + const struct led_rgb_ops *ops = rgbled_cdev->ops; + unsigned long state; + ssize_t ret = -EINVAL; + + mutex_lock(&led_cdev->led_access); + + if (led_sysfs_is_disabled(led_cdev)) { + ret = -EBUSY; + goto unlock; + } + + ret = kstrtoul(buf, 10, &state); + if (ret) + goto unlock; + + if (state > LED_FULL) { + ret = -EINVAL; + goto unlock; + } + + ret = ops->set_green_brightness(rgbled_cdev, state); + if (ret < 0) + goto unlock; + + colors->green = state; + ret = size; +unlock: + mutex_unlock(&led_cdev->led_access); + return ret; +} + +static ssize_t green_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + + if (rgbled_cdev->ops->get_green_brightness) + colors->green = rgbled_cdev->ops->get_green_brightness(rgbled_cdev); + + return sprintf(buf, "%d\n", colors->green); +} +static DEVICE_ATTR_RW(green); + +static struct attribute *led_color_green_attrs[] = { + &dev_attr_green.attr, + NULL, +}; + +static const struct attribute_group led_set_green_group = { + .attrs = led_color_green_attrs, +}; + +static ssize_t blue_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + const struct led_rgb_ops *ops = rgbled_cdev->ops; + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + unsigned long state; + ssize_t ret = -EINVAL; + + mutex_lock(&led_cdev->led_access); + + if (led_sysfs_is_disabled(led_cdev)) { + ret = -EBUSY; + goto unlock; + } + + ret = kstrtoul(buf, 10, &state); + if (ret) + goto unlock; + + if (state > LED_FULL) { + ret = -EINVAL; + goto unlock; + } + + ret = ops->set_blue_brightness(rgbled_cdev, state); + if (ret < 0) + goto unlock; + + colors->blue = state; + ret = size; +unlock: + mutex_unlock(&led_cdev->led_access); + return ret; +} + +static ssize_t blue_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct led_classdev *led_cdev = dev_get_drvdata(dev); + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + + if (rgbled_cdev->ops->get_blue_brightness) + colors->blue = rgbled_cdev->ops->get_blue_brightness(rgbled_cdev); + + return sprintf(buf, "%d\n", colors->blue); +} +static DEVICE_ATTR_RW(blue); + +static struct attribute *led_color_blue_attrs[] = { + &dev_attr_blue.attr, + NULL, +}; + +static const struct attribute_group led_set_blue_group = { + .attrs = led_color_blue_attrs, +}; + +static void led_rgb_init_sysfs_groups(struct led_classdev_rgb *rgbled_cdev) +{ + struct led_classdev *led_cdev = &rgbled_cdev->led_cdev; + const struct led_rgb_ops *ops = rgbled_cdev->ops; + const struct attribute_group **rgb_groups = rgbled_cdev->sysfs_groups; + + int num_sysfs_groups = 0; + + rgb_groups[num_sysfs_groups++] = &led_color_group; + + if (ops->set_red_brightness) + rgb_groups[num_sysfs_groups++] = &led_set_red_group; + + if (ops->set_green_brightness) + rgb_groups[num_sysfs_groups++] = &led_set_green_group; + + if (ops->set_blue_brightness) + rgb_groups[num_sysfs_groups++] = &led_set_blue_group; + + led_cdev->groups = rgb_groups; +} + +int led_classdev_rgb_register(struct device *parent, + struct led_classdev_rgb *rgbled_cdev) +{ + struct led_classdev *led_cdev; + struct led_rgb_ops *ops; + + if (!rgbled_cdev) + return -EINVAL; + + ops = rgbled_cdev->ops; + if (!ops || !ops->set_color) + return -EINVAL; + + led_cdev = &rgbled_cdev->led_cdev; + + /* Select the sysfs attributes to be created for the device */ + led_rgb_init_sysfs_groups(rgbled_cdev); + + /* Register led class device */ + return led_classdev_register(parent, led_cdev); +} +EXPORT_SYMBOL_GPL(led_classdev_rgb_register); + +void led_classdev_rgb_unregister(struct led_classdev_rgb *rgbled_cdev) +{ + if (!rgbled_cdev) + return; + + led_classdev_unregister(&rgbled_cdev->led_cdev); +} +EXPORT_SYMBOL_GPL(led_classdev_rgb_unregister); + +MODULE_AUTHOR("Dan Murphy "); +MODULE_DESCRIPTION("RGB LED class interface"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/led-class-rgb.h b/include/linux/led-class-rgb.h new file mode 100644 index 000000000000..b5bc607a6b25 --- /dev/null +++ b/include/linux/led-class-rgb.h @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +/* LED RGB class interface + * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + */ + +#ifndef __LINUX_RGB_LEDS_H_INCLUDED +#define __LINUX_RGB_LEDS_H_INCLUDED + +#include + +struct led_classdev_rgb; + +#define LED_RGB_RED BIT(0) +#define LED_RGB_GREEN BIT(1) +#define LED_RGB_BLUE BIT(2) +#define LED_RGB_WHITE BIT(3) +#define LED_RGB_ALL (LED_RGB_RED | LED_RGB_GREEN | LED_RGB_BLUE | \ + LED_RGB_WHITE) + +#define LED_RGB_SYSFS_GROUPS_SIZE 5 + +struct led_rgb_ops { + /* set RGB color */ + int (*set_color)(struct led_classdev_rgb *rgbled_cdev); + /* get RGB color */ + int (*get_color)(struct led_classdev_rgb *rgbled_cdev, u32 *color); + + /* set Red color */ + int (*set_red_brightness)(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness); + enum led_brightness (*get_red_brightness)(struct led_classdev_rgb *rgbled_cdev); + /* set green color */ + int (*set_green_brightness)(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness); + enum led_brightness (*get_green_brightness)(struct led_classdev_rgb *rgbled_cdev); + + /* set blue color */ + int (*set_blue_brightness)(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness); + enum led_brightness (*get_blue_brightness)(struct led_classdev_rgb *rgbled_cdev); + +}; + +struct led_rgb_colors { + u8 red; + u8 green; + u8 blue; +}; + +struct led_classdev_rgb { + /* led class device */ + struct led_classdev led_cdev; + + /* rgb led specific ops */ + struct led_rgb_ops *ops; + + /* RGB colors to set intensity per LED */ + struct led_rgb_colors rgb_colors; + + const struct attribute_group *sysfs_groups[LED_RGB_SYSFS_GROUPS_SIZE]; +}; + +static inline struct led_classdev_rgb *lcdev_to_rgbcdev( + struct led_classdev *lcdev) +{ + return container_of(lcdev, struct led_classdev_rgb, led_cdev); +} + +/** + * led_classdev_rgb_register - register a new object of led_classdev class + * with support for rgb LEDs + * @parent: the rgb LED to register + * @fled_cdev: the led_classdev_rgb structure for this device + * + * Returns: 0 on success or negative error value on failure + */ +extern int led_classdev_rgb_register(struct device *parent, + struct led_classdev_rgb *rgbled_cdev); + +/** + * led_classdev_rgb_unregister - unregisters an object of led_classdev class + * with support for rgb LEDs + * @rgbled_cdev: the rgb LED to unregister + * + * Unregister a previously registered via led_classdev_rgb_register object + */ +extern void led_classdev_rgb_unregister(struct led_classdev_rgb *rgbled_cdev); + +#endif /* __LINUX_RGB_LEDS_H_INCLUDED */ From patchwork Mon Jan 21 21:56:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 156255 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6848706jaa; Mon, 21 Jan 2019 13:57:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN4fK/yeJdk+wQbZUPWnX8o/hxfWqmhLDE1rVVIgyjoOOitjcKZanJgHhRb5BKNTN+9GHM5W X-Received: by 2002:a17:902:82c2:: with SMTP id u2mr31684271plz.110.1548107829673; Mon, 21 Jan 2019 13:57:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548107829; cv=none; d=google.com; s=arc-20160816; b=wlgtbox4HwYKKP0wwHULMRKukiHjehrARs1s3Sn+EU2CnC05mJdqBdYcgqWAQTAWD1 oludySnxPX+pwtzKCqbm0rupGviG3LLpNKipDxiuWujGoCuHxIjOYJFMWwCSFPEDV9ZK mTjhcZjJgE6CBqsBh+lOI/jS2JDhW14ZNqitC+iE3B+rBQwUqjuQPPWTqjs+uylv+dqQ 6ZW+pldDFPRaZ86E5erwk74+jWBiZ1bSTgqwBx9xd6seS/YMPziLQNvgxANBSHiAwsXC /n2nHQ0xl8b3K29a60Jn8Ign9MIJiXRxTsa+KBkiQe58bKTiQtG3pxVPcX3sDxk+8aev fyyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=IuIpqXWRHwXTk1fmAHaVMVRJZ83QSYHuTBY9toToh1Q=; b=xmmcTc01oskJqY2gPu8UDig4WgJfNHZrYSOTETpgXx3dDXdyIXNWW3s+jP0TZYQOTP oXmknYJbPPSlMpq1hYjFme1Sifhi5DhkvDTxFJx2+Ks7Y9M0qOVlnYE5/7O6wndlq2fr lTeLtB9U+n5uD1dsj+pkZumygKXBvuiEXgLDDFJa2q5eRHhw7uDtFhgzp/JBpimKM+sk dk+TDZo+See4Ji64TIOUnp2siJwQRRjh1/PRCOKv8CR/xdxfQlj94miyAZemi3jaN8Q+ beLrgq054Fph7+kfegYpM64OcTRK5RKm59QwWXX4oqxJbgdssmfein+O4bOAVaJMAHKL XIaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Cl5IMrgM; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 9si14124932plc.40.2019.01.21.13.57.09; Mon, 21 Jan 2019 13:57:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-leds-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=Cl5IMrgM; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 S1727785AbfAUV5I (ORCPT + 1 other); Mon, 21 Jan 2019 16:57:08 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:39652 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727761AbfAUV5I (ORCPT ); Mon, 21 Jan 2019 16:57:08 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0LLv4Ok089726; Mon, 21 Jan 2019 15:57:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548107824; bh=IuIpqXWRHwXTk1fmAHaVMVRJZ83QSYHuTBY9toToh1Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Cl5IMrgMdGtHKj95q0KnVxBLfMcbb8ZKuswwiZu4gVHVwcKybXlCKHGIZKFpP33ac gq8/AExxlbXbjpLl6/xxctQKpGOSG82AH5Qa0DnpdodxLb9HCz1ksZvvLEFGoRqpJg oK24WZmsqUUZUxPgzW29Aeo5Sdncfr8hfYCZtNbk= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0LLv3Tf081620 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 21 Jan 2019 15:57:04 -0600 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 21 Jan 2019 15:57:03 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 21 Jan 2019 15:57:03 -0600 Received: from legion.dal.desgin.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0LLv3cN002274; Mon, 21 Jan 2019 15:57:03 -0600 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.78.123]) by legion.dal.desgin.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id x0LLv3U20732; Mon, 21 Jan 2019 15:57:03 -0600 (CST) From: Dan Murphy To: CC: , , , Dan Murphy Subject: [RFC PATCH 3/6] leds: rgb: Add a dummy test file to test the RGB framework Date: Mon, 21 Jan 2019 15:56:56 -0600 Message-ID: <20190121215659.31125-4-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20190121215659.31125-1-dmurphy@ti.com> References: <20190121215659.31125-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Signed-off-by: Dan Murphy --- drivers/leds/Kconfig | 4 + drivers/leds/Makefile | 1 + drivers/leds/leds-rgb-fw-test.c | 177 ++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 drivers/leds/leds-rgb-fw-test.c -- 2.20.1.98.gecbdaf0899 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index f2d8bb7f4a6d..4369f287ec32 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -775,6 +775,10 @@ config LEDS_NIC78BX To compile this driver as a module, choose M here: the module will be called leds-nic78bx. +config LEDS_RGB_TEST + tristate "RGB Class Test file" + depends on LEDS_CLASS_RGB + comment "LED Triggers" source "drivers/leds/trigger/Kconfig" diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 5806760f00cb..4ec8f2c6e1f3 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -80,6 +80,7 @@ obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o obj-$(CONFIG_LEDS_LM3692X) += leds-lm3692x.o obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o obj-$(CONFIG_LEDS_LM3601X) += leds-lm3601x.o +obj-$(CONFIG_LEDS_RGB_TEST) += leds-rgb-fw-test.o # LED SPI Drivers obj-$(CONFIG_LEDS_CR0014114) += leds-cr0014114.o diff --git a/drivers/leds/leds-rgb-fw-test.c b/drivers/leds/leds-rgb-fw-test.c new file mode 100644 index 000000000000..d9f8335372d5 --- /dev/null +++ b/drivers/leds/leds-rgb-fw-test.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0 +// LED RGB class interface +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct rgb_fw_test_led { + struct led_classdev_rgb rgbled_cdev; + struct i2c_client *client; + + u32 white_setting[3]; + + u32 led_strings[3]; + + char led_name[LED_MAX_NAME_SIZE]; + u8 available_rgbs; +}; + +static struct rgb_fw_test_led *rgbled_cdev_to_led(struct led_classdev_rgb *rgbled_cdev) +{ + return container_of(rgbled_cdev, struct rgb_fw_test_led, rgbled_cdev); +} + +static int rgb_fw_set_red(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + printk("%s: Brightness is 0x%X\n", __func__, brightness); + return 0; +} + +static int rgb_fw_set_green(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + + printk("%s: Brightness is 0x%X\n", __func__, brightness); + return 0; +} + +static int rgb_fw_set_blue(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + + printk("%s: Brightness is 0x%X\n", __func__, brightness); + return 0; +} + +static int rgb_fw_set_color(struct led_classdev_rgb *rgbled_cdev) +{ +// struct rgb_fw_test_led *led = rgbled_cdev_to_led(rgbled_cdev); + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + + printk("%s: Would set red to %d\n", __func__, colors->red); + printk("%s: Would set green to %d\n", __func__, colors->green); + printk("%s: Would set blue to %d\n", __func__, colors->blue); + + return 0; +} + +static struct led_rgb_ops rgb_test_ops = { + .set_color = rgb_fw_set_color, +/* Need to do get functions */ +// .get_color = rgb_fw_get_color, +}; +static int rgb_fw_test_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + + printk("%s: Brightness is 0x%X\n", __func__, brightness); + return 0; +} + +static int rgb_fw_test_register_leds(struct rgb_fw_test_led *led) +{ + struct led_classdev *led_cdev; + + led->rgbled_cdev.ops = &rgb_test_ops; + + if (led->led_strings[0] != 0xff) + led->rgbled_cdev.ops->set_red_brightness = rgb_fw_set_red; + if (led->led_strings[1] != 0xff) + led->rgbled_cdev.ops->set_green_brightness = rgb_fw_set_green; + if (led->led_strings[2] != 0xff) + led->rgbled_cdev.ops->set_blue_brightness = rgb_fw_set_blue; + + led_cdev = &led->rgbled_cdev.led_cdev; + led_cdev->brightness_set_blocking = rgb_fw_test_brightness_set; + led_cdev->name = led->led_name; + + return led_classdev_rgb_register(&led->client->dev, &led->rgbled_cdev); +} + +static int rgb_fw_test_probe_node(struct rgb_fw_test_led *led) +{ + + struct fwnode_handle *child = NULL; + const char *name; + int ret; + +/* Need to set this up for multiple nodes this is not working since we reuse +the same led node. Need to fix that to continue */ + device_for_each_child_node(&led->client->dev, child) { + ret = fwnode_property_read_string(child, "label", &name); + + snprintf(led->led_name, sizeof(led->led_name), + "%s:%s", led->client->name, name); + + ret = fwnode_property_read_u32_array(child, "rgb-sources", + NULL, 0); + ret = fwnode_property_read_u32_array(child, "rgb-sources", + led->led_strings, ret); + + ret = rgb_fw_test_register_leds(led); + } + return 0; +} + +static int rgb_fw_test_probe(struct i2c_client *client) +{ + struct rgb_fw_test_led *led; + int ret; + + led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL); + if (!led) + return -ENOMEM; + + led->client = client; + i2c_set_clientdata(client, led); + + ret = rgb_fw_test_probe_node(led); + if (ret) + return -ENODEV; + + return ret; +} + +static int rgb_fw_test_remove(struct i2c_client *client) +{ + struct rgb_fw_test_led *led = i2c_get_clientdata(client); + + led_classdev_rgb_unregister(&led->rgbled_cdev); + + return 0; +} + +static const struct i2c_device_id rgb_fw_test_id[] = { + { "RGBNONE", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, lm3601x_id); + +static const struct of_device_id of_rgb_fw_test_leds_match[] = { + { .compatible = "rgb,framework_test", }, + { } +}; +MODULE_DEVICE_TABLE(of, of_rgb_fw_test_leds_match); + +static struct i2c_driver rgb_fw_test_i2c_driver = { + .driver = { + .name = "rgb_framework_test", + .of_match_table = of_rgb_fw_test_leds_match, + }, + .probe_new = rgb_fw_test_probe, + .remove = rgb_fw_test_remove, + .id_table = rgb_fw_test_id, +}; +module_i2c_driver(rgb_fw_test_i2c_driver); + +MODULE_AUTHOR("Dan Murphy "); +MODULE_DESCRIPTION("RGB LED class interface"); +MODULE_LICENSE("GPL v2"); From patchwork Mon Jan 21 21:56:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 156254 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6848703jaa; Mon, 21 Jan 2019 13:57:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN4YsZZL1BHhxo2K869RrxynWoXDTDHkxZymYKRABgqCNTjDmpekDlWfyRL9kzHblV6RaIBO X-Received: by 2002:a17:902:6bc7:: with SMTP id m7mr32221501plt.106.1548107829198; Mon, 21 Jan 2019 13:57:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548107829; cv=none; d=google.com; s=arc-20160816; b=ulWRVZOaawFQWPxrTEUqSAWMqlGrMzscp/W38aP8E4cUD9bBkSyi1G7LTUPjlthRve n5OYZ1vrbUsTwyOR0TWCrMjQWtDcxM4HseW3nvTPGlDPMh72uVj8c21p6IAI0rfuAZ6P Tgoe9pLkuMoZMXYjQY1fSETA1t5e4ydp6Z0Dw2NM98aCN/gTf3VJ2w4w4HI6/jE2LPXk n0/psKHCS6ChTgBcloER4qkc878WMffBKEBFhP3YKetuHGjpj2crp1+tHnzvuWO/Qw+g SJW9thRIpJeL283XbmqTFWHg3nFuwN7bVnWkC1IhVNHlvVse9kwujXFuvQoBbTeJ6lfs vvfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=vZUVgoZnmxxbuVK8nJx5ZZH3vCBG764r6kHxrHVlZzU=; b=rUR3plqxiAzOFz0/B3sQn/xL1iONpfO1sdjq/ou0Ql4IZ9lucMRLidpwBbZSHU1RNx ZJy38mPPbtG8YT0MeckGAnjaXV3GwW2nC5UUqK+Kw2OnpDqbS0Oep5spBvPHoLgKaYga pILNkQAEkxBrW+IiaAW3Mbug5rrVJAEuR/UKg0T9vYCnme33/1nloVS+QAY2NGIB6PTo SWT9av98l95HAe2Xr/IF5QhFLq/7c+mZ6nvzMu+hcI8KvoGlRrY7jKd5W5xUOOesFnNq /7gQT3/zmC7ywCAT89Y7u7JR5SrBcFBnZ0+0bROLf1lDW/SoSXE2Ig2Rf2h9n+FEtyeY KI0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="ar/3MbbM"; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 9si14124932plc.40.2019.01.21.13.57.09; Mon, 21 Jan 2019 13:57:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-leds-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="ar/3MbbM"; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 S1727803AbfAUV5I (ORCPT + 1 other); Mon, 21 Jan 2019 16:57:08 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:59158 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727785AbfAUV5I (ORCPT ); Mon, 21 Jan 2019 16:57:08 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0LLv4W0095345; Mon, 21 Jan 2019 15:57:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548107824; bh=vZUVgoZnmxxbuVK8nJx5ZZH3vCBG764r6kHxrHVlZzU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ar/3MbbMl5nOxILTHchBY+KFxPrxK93Hf7TdYPsN1geZ91bAbok3Wl6ZLO6yxQEOm JyLRhE1DfuUNsGgBx0ZBKuDxun/MXMvihIjytIpB1cEUvxVWSxxbGSnx2wb7QVZeFa oaIyanxNscj7LYmOM3gWTp+ZMTfuBdEfrmMxVkVQ= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0LLv4Ib125698 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 21 Jan 2019 15:57:04 -0600 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 21 Jan 2019 15:57:04 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 21 Jan 2019 15:57:04 -0600 Received: from legion.dal.desgin.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0LLv4XW002298; Mon, 21 Jan 2019 15:57:04 -0600 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.78.123]) by legion.dal.desgin.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id x0LLv3U20736; Mon, 21 Jan 2019 15:57:03 -0600 (CST) From: Dan Murphy To: CC: , , , Dan Murphy Subject: [RFC PATCH 4/6] dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers Date: Mon, 21 Jan 2019 15:56:57 -0600 Message-ID: <20190121215659.31125-5-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20190121215659.31125-1-dmurphy@ti.com> References: <20190121215659.31125-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Introduce the bindings for the Texas Instruments LP5036, LP5030, LP5024 and the LP5018 RGB LED device driver. The LP5036/3024/18 can control RGB LEDs individually or as part of a control bank group. These devices have the ability to adjust the mixing control for the RGB LEDs to obtain different colors independent of the overall brightness of the LED grouping. Datasheet: http://www.ti.com/lit/ds/symlink/lp5024.pdf http://www.ti.com/lit/ds/symlink/lp5036.pdf Signed-off-by: Dan Murphy --- .../devicetree/bindings/leds/leds-lp50xx.txt | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-lp50xx.txt -- 2.20.1.98.gecbdaf0899 diff --git a/Documentation/devicetree/bindings/leds/leds-lp50xx.txt b/Documentation/devicetree/bindings/leds/leds-lp50xx.txt new file mode 100644 index 000000000000..7bc6843ddba4 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-lp50xx.txt @@ -0,0 +1,143 @@ +* Texas Instruments - LP5018/24/30/36 RGB LED driver + +The LP50XX is multi-channel, I2C RGB LED Drivers that can group RGB LEDs into +a LED group or control them individually. + +The difference in these RGB LED drivers is the number of supported RGB strings. + +Required properties: + - compatible: + "ti,lp5018" + "ti,lp5024" + "ti,lp5030" + "ti,lp5036" + - reg : I2C slave address + lp5018/24 - 0x28 + lp5030/36 - 0x30 + - #address-cells : 1 + - #size-cells : 0 + +Optional properties: + - enable-gpios : gpio pin to enable/disable the device. + - vled-supply : LED supply + +Required child properties: + - reg : Is the child node iteration. + +Required Child properties but only one should be defined per child: +Either one of these two properties are required for each node. The +property ti,led-bank takes precedence over the ti,led-module within the same +node. + + - ti,led-module : This property denotes the single LED module number + that will be controlled in the LED class instance. + - ti,led-bank : This property denotes the LED module numbers that will + be controlled as a single RGB cluster. Each LED module + number will be controlled by a single LED class instance. + There can only be one instance of the ti,led-bank + property for each device node. + +The LED outpus associated with the LED modules are defined in Table 1 of the +corresponding data sheets. + +LP5018 - 6 Total RGB cluster LED outputs 0-5 +LP5024 - 8 Total RGB cluster LED outputs 0-7 +LP5030 - 10 Total RGB cluster LED outputs 0-9 +LP5036 - 12 Total RGB cluster LED outputs 0-11 + +Optional child properties: + - label : see Documentation/devicetree/bindings/leds/common.txt + - linux,default-trigger : + see Documentation/devicetree/bindings/leds/common.txt + +Examples: +LP5018 and LP5024 example: +led-controller@29 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "ti,lp5024"; + reg = <0x29>; + enable-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>; + vled-supply = <&vmmcsd_fixed>; + + led@0 { + reg = <0>; + label = "led1_mod"; + ti,led-module = <1>; + }; + + led@1 { + reg = <1>; + label = "banked_leds"; + ti,led-bank = <0 2 5 3 >; + }; + + led@2 { + reg = <2>; + label = "led4_mod"; + ti,led-module = <4>; + }; + + led@3 { + reg = <3>; + label = "led7_mod"; + ti,led-module = <7>; + }; + + led@4 { + reg = <4>; + label = "led6_mod"; + ti,led-module = <6>; + }; +}; + +LP5030 and LP5036 example: +led-controller@30 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "ti,lp5036"; + reg = <0x30>; + enable-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>; + vled-supply = <&vmmcsd_fixed>; + + led@0 { + reg = <0>; + label = "led1_mod"; + ti,led-module = <1>; + }; + + led@1 { + reg = <1>; + label = "led_banked"; + ti,led-bank = <0 2 5 3 9 10 >; + }; + + led@2 { + reg = <2>; + label = "led4_mod"; + ti,led-module = <4>; + }; + + led@3 { + reg = <3>; + label = "led7_mod"; + ti,led-module = <7>; + }; + + led@4 { + reg = <4>; + label = "led6_mod"; + ti,led-module = <6>; + }; + + led@5 { + reg = <5>; + label = "led8_mod"; + ti,led-module = <8>; + }; +}; + + +For more product information please see the link below: +http://www.ti.com/lit/ds/symlink/lp5024.pdf +http://www.ti.com/lit/ds/symlink/lp5036.pdf From patchwork Mon Jan 21 21:56:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 156257 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6848719jaa; Mon, 21 Jan 2019 13:57:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN7QUIELtmotgIVs6SQGb10B+tEI4XixZgu5rdmnmNopfa8zHj3FGYpF8LWZjBEtz4b8dx66 X-Received: by 2002:a63:ce08:: with SMTP id y8mr29345000pgf.388.1548107830292; Mon, 21 Jan 2019 13:57:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548107830; cv=none; d=google.com; s=arc-20160816; b=jCW7Gn24yjYNpdyAiLV4qcBkksEBjTKjnzwskHWkbUVjHVEXE/2tP+iQtnfgMIp5nK ZvGBPYRw4XfBhCX4R4dAFsKaobRUgSAtdf4geKbxlMpE8J0MJr5SZ8fsMnXsCayfscIJ DBsbp0k2icNZkXYOooRDvtu939uoTuAAaoRy1tAsNQ222NF04WHWXXWI1hO/EV8F5y5Q LsvFg6x6b54tjvBmOuNwkgUo5sW36T8BYY/NsDcJQUWqbLMSV+1da7e1aLtyFV5r59Bg KZeLCLCLqttRQpBX5jMQIc1WNt+bIFUji1w3tuj1wNidrM5DogAr7V8IZtNefwdxh5ef HFFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=D6UbX82iF2AzGxgyNoXJI/3R+2L7SDWeb28T9XfVI60=; b=SrwxbRD5s0jJ1GJwOQIMXsPrAeDODrxHyC7xgnmlx09K7wq2Esfd8epPpaGHpMZDhS D5cZh2ZbOQXZhOksCRj8MxgynSZSs6XVVCJlkXBb7Ra/VMrnJt8AVb86SYeFPKgxrl+H 4m+WQRyEw4bA6ZaRorHRv6EJhLZ4pi6qBzhLZSqm08zOPuSl7JiwtWfcT1lMVVvgdzeT ++JcFwEOjHXPGI0Bng2PLkV+0jrg+Y0LU4xTpT/Chtn8mfzfvlReLKiVUMq7ZeXuVVFo jJ1x3BFAgXKSsIV+GhS0ObNuncULVtNjvmqUQ78AyZ8RNsnHEXlswTa7qhsSkWn9aB6h PzkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=c2aorAM+; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 9si14124932plc.40.2019.01.21.13.57.10; Mon, 21 Jan 2019 13:57:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-leds-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=c2aorAM+; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 S1727791AbfAUV5J (ORCPT + 1 other); Mon, 21 Jan 2019 16:57:09 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:59160 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbfAUV5I (ORCPT ); Mon, 21 Jan 2019 16:57:08 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0LLv5Wg095350; Mon, 21 Jan 2019 15:57:05 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548107825; bh=D6UbX82iF2AzGxgyNoXJI/3R+2L7SDWeb28T9XfVI60=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=c2aorAM+T3gYRcDdA0QxpA9qAFBgQtnRPyVhHYMkkwunK44QIpGeZkrfU0+9iHL6F jIyTj5CMno53obB7Y1clOFSfqlXDDOILXDm60EfyYFBs18RGH5HolF7hBzxnbs4LnJ 7Oj81LhHHA9LB7l2yFK1zTFPRX7FfyyxMDoA1ZRc= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0LLv5Y4081806 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 21 Jan 2019 15:57:05 -0600 Received: from DFLE115.ent.ti.com (10.64.6.36) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 21 Jan 2019 15:57:04 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 21 Jan 2019 15:57:04 -0600 Received: from legion.dal.desgin.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0LLv4ja020852; Mon, 21 Jan 2019 15:57:04 -0600 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.78.123]) by legion.dal.desgin.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id x0LLv4U20740; Mon, 21 Jan 2019 15:57:04 -0600 (CST) From: Dan Murphy To: CC: , , , Dan Murphy Subject: [RFC PATCH 5/6] leds: lp50xx: Add the LP50XX family of the RGB LED driver Date: Mon, 21 Jan 2019 15:56:58 -0600 Message-ID: <20190121215659.31125-6-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20190121215659.31125-1-dmurphy@ti.com> References: <20190121215659.31125-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Introduce the LP5036/30/24/18 RGB LED driver. The difference in these parts are the number of LED outputs where the: LP5036 can control 36 LEDs LP5030 can control 30 LEDs LP5024 can control 24 LEDs LP5018 can control 18 LEDs The device has the ability to group LED output into control banks so that multiple LED banks can be controlled with the same mixing and brightness. Inversely the LEDs can also be controlled independently. Signed-off-by: Dan Murphy --- Documentation/leds/leds-lp50xx.txt | 36 ++ drivers/leds/Kconfig | 7 + drivers/leds/Makefile | 1 + drivers/leds/leds-lp50xx.c | 769 +++++++++++++++++++++++++++++ 4 files changed, 813 insertions(+) create mode 100644 Documentation/leds/leds-lp50xx.txt create mode 100644 drivers/leds/leds-lp50xx.c -- 2.20.1.98.gecbdaf0899 diff --git a/Documentation/leds/leds-lp50xx.txt b/Documentation/leds/leds-lp50xx.txt new file mode 100644 index 000000000000..8b1b01dfdd22 --- /dev/null +++ b/Documentation/leds/leds-lp50xx.txt @@ -0,0 +1,36 @@ +LP5018/LP5024/LP5030/LP5036 Common Driver +================================================= + +Authors: Dan Murphy + +Description +----------- +The LP50XX RGB LED drivers have the ability to group multiple RGB cluster +LEDs into a single group for simultaneous control or expose single RGB cluster +for control. This device exposes different register interfaces to control +the cluster brightness as well as the individual RGB LEDs color intensity. + +RGB Cluster Color Control +------------------------- +The LP50xx driver will expose a file called "color" for each LED class instance +defined. This file will accept a 24-bit RGB value in which the the color of the +RGB LEDs will be set. + +The 24-bit RGB value passed in follows the pattern 0xXXRRGGBB +XX - Do not care ignored by the driver +RR - is the 8 bit Red LED value +GG - is the 8 bit Green LED value +BB - is the 8 bit Blue LED value + +Example: +LED module output 4 of the LP5024 will be a yellow color: +echo 0xe6de00 > /sys/class/leds/lp5024\:led4_mod/color + +LED module output 4 of the LP5024 will be dimmed 50%: +echo 0x80 > /sys/class/leds/lp5024\:led4_mod/brightness + +LED banked RGBs of the LP5036 will be a white color: +echo 0xffffff > /sys/class/leds/lp5036\:led_banked/color + +LED banked RGBs of the LP50364 will be dimmed 50%: +echo 0x80 > /sys/class/leds/lp5036\:led_banked/brightness diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 4369f287ec32..e3a1101ee8c2 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -335,6 +335,13 @@ config LEDS_LP3952 To compile this driver as a module, choose M here: the module will be called leds-lp3952. +config LEDS_LP50XX + tristate "LED Support for TI LP5036/30/24/18 LED driver chip" + depends on LEDS_CLASS && REGMAP_I2C + help + If you say yes here you get support for the Texas Instruments + LP5036, LP5030, LP5024 and LP5018 LED driver. + config LEDS_LP55XX_COMMON tristate "Common Driver for TI/National LP5521/5523/55231/5562/8501" depends on LEDS_LP5521 || LEDS_LP5523 || LEDS_LP5562 || LEDS_LP8501 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 4ec8f2c6e1f3..8dd4676038d0 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_LEDS_GPIO_REGISTER) += leds-gpio-register.o obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o obj-$(CONFIG_LEDS_LP3952) += leds-lp3952.o +obj-$(CONFIG_LEDS_LP50XX) += leds-lp50xx.o obj-$(CONFIG_LEDS_LP55XX_COMMON) += leds-lp55xx-common.o obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o obj-$(CONFIG_LEDS_LP5523) += leds-lp5523.o diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c new file mode 100644 index 000000000000..97ac05464acd --- /dev/null +++ b/drivers/leds/leds-lp50xx.c @@ -0,0 +1,769 @@ +// SPDX-License-Identifier: GPL-2.0 +/* TI LP50XX LED chip family driver + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LP50XX_DEV_CFG0 0x00 +#define LP50XX_DEV_CFG1 0x01 +#define LP50XX_LED_CFG0 0x02 + +/* LP5018 and LP5024 registers */ +#define LP5024_BNK_BRT 0x03 +#define LP5024_BNKA_CLR 0x04 +#define LP5024_BNKB_CLR 0x05 +#define LP5024_BNKC_CLR 0x06 +#define LP5024_LED0_BRT 0x07 +#define LP5024_LED1_BRT 0x08 +#define LP5024_LED2_BRT 0x09 +#define LP5024_LED3_BRT 0x0a +#define LP5024_LED4_BRT 0x0b +#define LP5024_LED5_BRT 0x0c +#define LP5024_LED6_BRT 0x0d +#define LP5024_LED7_BRT 0x0e + +#define LP5024_OUT0_CLR 0x0f +#define LP5024_OUT1_CLR 0x10 +#define LP5024_OUT2_CLR 0x11 +#define LP5024_OUT3_CLR 0x12 +#define LP5024_OUT4_CLR 0x13 +#define LP5024_OUT5_CLR 0x14 +#define LP5024_OUT6_CLR 0x15 +#define LP5024_OUT7_CLR 0x16 +#define LP5024_OUT8_CLR 0x17 +#define LP5024_OUT9_CLR 0x18 +#define LP5024_OUT10_CLR 0x19 +#define LP5024_OUT11_CLR 0x1a +#define LP5024_OUT12_CLR 0x1b +#define LP5024_OUT13_CLR 0x1c +#define LP5024_OUT14_CLR 0x1d +#define LP5024_OUT15_CLR 0x1e +#define LP5024_OUT16_CLR 0x1f +#define LP5024_OUT17_CLR 0x20 +#define LP5024_OUT18_CLR 0x21 +#define LP5024_OUT19_CLR 0x22 +#define LP5024_OUT20_CLR 0x23 +#define LP5024_OUT21_CLR 0x24 +#define LP5024_OUT22_CLR 0x25 +#define LP5024_OUT23_CLR 0x26 +#define LP5024_RESET 0x27 + +/* LP5030 and LP5036 registers */ +#define LP5036_LED_CFG1 0x03 +#define LP5036_BNK_BRT 0x04 +#define LP5036_BNKA_CLR 0x05 +#define LP5036_BNKB_CLR 0x06 +#define LP5036_BNKC_CLR 0x07 +#define LP5036_LED0_BRT 0x08 +#define LP5036_LED1_BRT 0x09 +#define LP5036_LED2_BRT 0x0a +#define LP5036_LED3_BRT 0x0b +#define LP5036_LED4_BRT 0x0c +#define LP5036_LED5_BRT 0x0d +#define LP5036_LED6_BRT 0x0e +#define LP5036_LED7_BRT 0x0f +#define LP5036_LED8_BRT 0x10 +#define LP5036_LED9_BRT 0x11 +#define LP5036_LED10_BRT 0x12 +#define LP5036_LED11_BRT 0x13 + +#define LP5036_OUT0_CLR 0x14 +#define LP5036_OUT1_CLR 0x15 +#define LP5036_OUT2_CLR 0x16 +#define LP5036_OUT3_CLR 0x17 +#define LP5036_OUT4_CLR 0x18 +#define LP5036_OUT5_CLR 0x19 +#define LP5036_OUT6_CLR 0x1a +#define LP5036_OUT7_CLR 0x1b +#define LP5036_OUT8_CLR 0x1c +#define LP5036_OUT9_CLR 0x1d +#define LP5036_OUT10_CLR 0x1e +#define LP5036_OUT11_CLR 0x1f +#define LP5036_OUT12_CLR 0x20 +#define LP5036_OUT13_CLR 0x21 +#define LP5036_OUT14_CLR 0x22 +#define LP5036_OUT15_CLR 0x23 +#define LP5036_OUT16_CLR 0x24 +#define LP5036_OUT17_CLR 0x25 +#define LP5036_OUT18_CLR 0x26 +#define LP5036_OUT19_CLR 0x27 +#define LP5036_OUT20_CLR 0x28 +#define LP5036_OUT21_CLR 0x29 +#define LP5036_OUT22_CLR 0x2a +#define LP5036_OUT23_CLR 0x2b +#define LP5036_OUT24_CLR 0x2c +#define LP5036_OUT25_CLR 0x2d +#define LP5036_OUT26_CLR 0x2e +#define LP5036_OUT27_CLR 0x2f +#define LP5036_OUT28_CLR 0x30 +#define LP5036_OUT29_CLR 0x31 +#define LP5036_OUT30_CLR 0x32 +#define LP5036_OUT31_CLR 0x33 +#define LP5036_OUT32_CLR 0x34 +#define LP5036_OUT33_CLR 0x35 +#define LP5036_OUT34_CLR 0x36 +#define LP5036_OUT35_CLR 0x37 +#define LP5036_RESET 0x38 + +#define LP50XX_SW_RESET 0xff + +#define LP50XX_CHIP_EN BIT(6) + +#define LP5018_MAX_LED_STRINGS 6 +#define LP5024_MAX_LED_STRINGS 8 +#define LP5030_MAX_LED_STRINGS 10 +#define LP5036_MAX_LED_STRINGS 12 + +enum lp50xx_model { + LP5018, + LP5024, + LP5030, + LP5036, +}; + +struct lp50xx_led { + u32 led_strings[LP5036_MAX_LED_STRINGS]; + char label[LED_MAX_NAME_SIZE]; + struct led_classdev led_dev; + struct led_classdev_rgb rgb_cdev; + struct lp50xx *priv; + int led_number; + u8 ctrl_bank_enabled; +}; + +/** + * struct lp50xx - + * @enable_gpio: Hardware enable gpio + * @regulator: LED supply regulator pointer + * @client: Pointer to the I2C client + * @regmap: Devices register map + * @dev: Pointer to the devices device struct + * @lock: Lock for reading/writing the device + * @model_id: ID of the device + * @leds: Array of LED strings + */ +struct lp50xx { + struct gpio_desc *enable_gpio; + struct regulator *regulator; + struct i2c_client *client; + struct regmap *regmap; + struct device *dev; + struct mutex lock; + enum lp50xx_model model_id; + int max_leds; + int num_of_leds; + + u8 led_brightness0_reg; + u8 mix_out0_reg; + u8 bank_brt_reg; + u8 bank_mix_reg; + u8 reset_reg; + + /* This needs to be at the end of the struct */ + struct lp50xx_led leds[]; +}; + +static const struct reg_default lp5024_reg_defs[] = { + {LP50XX_DEV_CFG0, 0x0}, + {LP50XX_DEV_CFG1, 0x3c}, + {LP50XX_LED_CFG0, 0x0}, + {LP5024_BNK_BRT, 0xff}, + {LP5024_BNKA_CLR, 0x0f}, + {LP5024_BNKB_CLR, 0x0f}, + {LP5024_BNKC_CLR, 0x0f}, + {LP5024_LED0_BRT, 0x0f}, + {LP5024_LED1_BRT, 0xff}, + {LP5024_LED2_BRT, 0xff}, + {LP5024_LED3_BRT, 0xff}, + {LP5024_LED4_BRT, 0xff}, + {LP5024_LED5_BRT, 0xff}, + {LP5024_LED6_BRT, 0xff}, + {LP5024_LED7_BRT, 0xff}, + {LP5024_OUT0_CLR, 0x0f}, + {LP5024_OUT1_CLR, 0x00}, + {LP5024_OUT2_CLR, 0x00}, + {LP5024_OUT3_CLR, 0x00}, + {LP5024_OUT4_CLR, 0x00}, + {LP5024_OUT5_CLR, 0x00}, + {LP5024_OUT6_CLR, 0x00}, + {LP5024_OUT7_CLR, 0x00}, + {LP5024_OUT8_CLR, 0x00}, + {LP5024_OUT9_CLR, 0x00}, + {LP5024_OUT10_CLR, 0x00}, + {LP5024_OUT11_CLR, 0x00}, + {LP5024_OUT12_CLR, 0x00}, + {LP5024_OUT13_CLR, 0x00}, + {LP5024_OUT14_CLR, 0x00}, + {LP5024_OUT15_CLR, 0x00}, + {LP5024_OUT16_CLR, 0x00}, + {LP5024_OUT17_CLR, 0x00}, + {LP5024_OUT18_CLR, 0x00}, + {LP5024_OUT19_CLR, 0x00}, + {LP5024_OUT20_CLR, 0x00}, + {LP5024_OUT21_CLR, 0x00}, + {LP5024_OUT22_CLR, 0x00}, + {LP5024_OUT23_CLR, 0x00}, + {LP5024_RESET, 0x00} +}; + +static const struct reg_default lp5036_reg_defs[] = { + {LP50XX_DEV_CFG0, 0x0}, + {LP50XX_DEV_CFG1, 0x3c}, + {LP50XX_LED_CFG0, 0x0}, + {LP5036_LED_CFG1, 0x0}, + {LP5036_BNK_BRT, 0xff}, + {LP5036_BNKA_CLR, 0x0f}, + {LP5036_BNKB_CLR, 0x0f}, + {LP5036_BNKC_CLR, 0x0f}, + {LP5036_LED0_BRT, 0x0f}, + {LP5036_LED1_BRT, 0xff}, + {LP5036_LED2_BRT, 0xff}, + {LP5036_LED3_BRT, 0xff}, + {LP5036_LED4_BRT, 0xff}, + {LP5036_LED5_BRT, 0xff}, + {LP5036_LED6_BRT, 0xff}, + {LP5036_LED7_BRT, 0xff}, + {LP5036_OUT0_CLR, 0x0f}, + {LP5036_OUT1_CLR, 0x00}, + {LP5036_OUT2_CLR, 0x00}, + {LP5036_OUT3_CLR, 0x00}, + {LP5036_OUT4_CLR, 0x00}, + {LP5036_OUT5_CLR, 0x00}, + {LP5036_OUT6_CLR, 0x00}, + {LP5036_OUT7_CLR, 0x00}, + {LP5036_OUT8_CLR, 0x00}, + {LP5036_OUT9_CLR, 0x00}, + {LP5036_OUT10_CLR, 0x00}, + {LP5036_OUT11_CLR, 0x00}, + {LP5036_OUT12_CLR, 0x00}, + {LP5036_OUT13_CLR, 0x00}, + {LP5036_OUT14_CLR, 0x00}, + {LP5036_OUT15_CLR, 0x00}, + {LP5036_OUT16_CLR, 0x00}, + {LP5036_OUT17_CLR, 0x00}, + {LP5036_OUT18_CLR, 0x00}, + {LP5036_OUT19_CLR, 0x00}, + {LP5036_OUT20_CLR, 0x00}, + {LP5036_OUT21_CLR, 0x00}, + {LP5036_OUT22_CLR, 0x00}, + {LP5036_OUT23_CLR, 0x00}, + {LP5036_OUT24_CLR, 0x00}, + {LP5036_OUT25_CLR, 0x00}, + {LP5036_OUT26_CLR, 0x00}, + {LP5036_OUT27_CLR, 0x00}, + {LP5036_OUT28_CLR, 0x00}, + {LP5036_OUT29_CLR, 0x00}, + {LP5036_OUT30_CLR, 0x00}, + {LP5036_OUT31_CLR, 0x00}, + {LP5036_OUT32_CLR, 0x00}, + {LP5036_OUT33_CLR, 0x00}, + {LP5036_OUT34_CLR, 0x00}, + {LP5036_OUT35_CLR, 0x00}, + {LP5036_RESET, 0x00} +}; + +static const struct regmap_config lp5024_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = LP5024_RESET, + .reg_defaults = lp5024_reg_defs, + .num_reg_defaults = ARRAY_SIZE(lp5024_reg_defs), + .cache_type = REGCACHE_RBTREE, +}; + +static const struct regmap_config lp5036_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = LP5036_RESET, + .reg_defaults = lp5036_reg_defs, + .num_reg_defaults = ARRAY_SIZE(lp5036_reg_defs), + .cache_type = REGCACHE_RBTREE, +}; + +static struct lp50xx_led *rgbled_cdev_to_led(struct led_classdev_rgb *rgbled_cdev) +{ + return container_of(rgbled_cdev, struct lp50xx_led, rgb_cdev); +} + +static int lp50xx_set_color(struct led_classdev_rgb *rgbled_cdev) +{ + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + struct lp50xx_led *led = rgbled_cdev_to_led(rgbled_cdev); + struct lp50xx *priv = led->priv; + u8 red_reg, green_reg, blue_reg; + u8 led_offset; + int ret; + + if (led->ctrl_bank_enabled) { + red_reg = priv->bank_mix_reg; + green_reg = priv->bank_mix_reg + 1; + blue_reg = priv->bank_mix_reg + 2; + } else { + led_offset = (led->led_number * 3); + red_reg = priv->mix_out0_reg + led_offset; + green_reg = priv->mix_out0_reg + led_offset + 1; + blue_reg = priv->mix_out0_reg + led_offset + 2; + } + + ret = regmap_write(priv->regmap, red_reg, colors->red); + if (ret) { + dev_err(&priv->client->dev, "Cannot write LED value\n"); + goto out; + } + + ret = regmap_write(priv->regmap, green_reg, colors->green); + if (ret) { + dev_err(&priv->client->dev, "Cannot write LED value\n"); + goto out; + } + + ret = regmap_write(priv->regmap, blue_reg, colors->blue); + if (ret) + dev_err(&priv->client->dev, "Cannot write LED value\n"); + +out: + return ret; +} + +static int lp50xx_set_red(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + struct lp50xx_led *led = rgbled_cdev_to_led(rgbled_cdev); + struct lp50xx *priv = led->priv; + u8 led_offset; + u8 red_reg; + int ret; + + if (led->ctrl_bank_enabled) { + red_reg = priv->bank_mix_reg; + } else { + led_offset = (led->led_number * 3); + red_reg = priv->mix_out0_reg + led_offset; + } + + ret = regmap_write(priv->regmap, red_reg, brightness); + if (ret) + dev_err(&priv->client->dev, "Cannot write LED value\n"); + + return ret; +} + +static int lp50xx_set_green(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + struct lp50xx_led *led = rgbled_cdev_to_led(rgbled_cdev); + struct lp50xx *priv = led->priv; + u8 led_offset; + u8 green_reg; + int ret; + + if (led->ctrl_bank_enabled) { + green_reg = priv->bank_mix_reg + 1; + } else { + led_offset = (led->led_number * 3); + green_reg = priv->mix_out0_reg + led_offset + 1; + } + + ret = regmap_write(priv->regmap, green_reg, brightness); + if (ret) + dev_err(&priv->client->dev, "Cannot write LED value\n"); + + return ret; +} + +static int lp50xx_set_blue(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness brightness) +{ + struct lp50xx_led *led = rgbled_cdev_to_led(rgbled_cdev); + struct lp50xx *priv = led->priv; + u8 led_offset; + u8 blue_reg; + int ret; + + if (led->ctrl_bank_enabled) { + blue_reg = priv->bank_mix_reg + 2; + } else { + led_offset = (led->led_number * 3); + blue_reg = priv->mix_out0_reg + led_offset + 2; + } + + ret = regmap_write(priv->regmap, blue_reg, brightness); + if (ret) + dev_err(&priv->client->dev, "Cannot write LED value\n"); + + return ret; +} + +static int lp50xx_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brt_val) +{ + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + struct lp50xx_led *led = rgbled_cdev_to_led(rgbled_cdev); + int ret = 0; + u8 reg_val; + + mutex_lock(&led->priv->lock); + + if (led->ctrl_bank_enabled) + reg_val = led->priv->bank_brt_reg; + else + reg_val = led->priv->led_brightness0_reg + led->led_number; + + ret = regmap_write(led->priv->regmap, reg_val, brt_val); + + mutex_unlock(&led->priv->lock); + + return ret; +} + +static enum led_brightness lp50xx_brightness_get(struct led_classdev *led_cdev) +{ + struct led_classdev_rgb *rgbled_cdev = lcdev_to_rgbcdev(led_cdev); + struct lp50xx_led *led = rgbled_cdev_to_led(rgbled_cdev); + unsigned int brt_val = 0; + u8 reg_val; + int ret; + + mutex_lock(&led->priv->lock); + + if (led->ctrl_bank_enabled) + reg_val = led->priv->bank_brt_reg; + else + reg_val = led->priv->led_brightness0_reg + led->led_number; + + ret = regmap_read(led->priv->regmap, reg_val, &brt_val); + + mutex_unlock(&led->priv->lock); + + return brt_val; +} + +static void lp50xx_set_led_values(struct lp50xx *priv) +{ + if (priv->model_id == LP5018 || priv->model_id == LP5024) { + priv->led_brightness0_reg = LP5024_LED0_BRT; + priv->mix_out0_reg = LP5024_OUT0_CLR; + priv->bank_brt_reg = LP5024_BNK_BRT; + priv->bank_mix_reg = LP5024_BNKA_CLR; + priv->reset_reg = LP5024_RESET; + } else { + priv->led_brightness0_reg = LP5036_LED0_BRT; + priv->mix_out0_reg = LP5036_OUT0_CLR; + priv->bank_brt_reg = LP5036_BNK_BRT; + priv->bank_mix_reg = LP5036_BNKA_CLR; + priv->reset_reg = LP5036_RESET; + } +} + +static int lp50xx_set_banks(struct lp50xx *priv) +{ + struct lp50xx_led *led; + u8 led_ctrl_enable = 0; + u8 led1_ctrl_enable = 0; + u8 ctrl_ext = 0; + int i, j; + int ret; + + for (i = 0; i <= priv->num_of_leds; i++) { + led = &priv->leds[i]; + if (!led->ctrl_bank_enabled) + continue; + + for (j = 0; j <= priv->max_leds - 1; j++) { + if (led->led_strings[j] > (LP5024_MAX_LED_STRINGS - 1)) { + ctrl_ext = led->led_strings[j] - LP5024_MAX_LED_STRINGS; + led1_ctrl_enable |= (1 << ctrl_ext); + } else { + led_ctrl_enable |= (1 << led->led_strings[j]); + } + } + } + + ret = regmap_write(priv->regmap, LP50XX_LED_CFG0, led_ctrl_enable); + + if (led1_ctrl_enable) + ret = regmap_write(priv->regmap, LP5036_LED_CFG1, + led1_ctrl_enable); + + return ret; +} + +static int lp50xx_init(struct lp50xx *priv) +{ + int ret; + + lp50xx_set_led_values(priv); + + if (priv->enable_gpio) { + gpiod_direction_output(priv->enable_gpio, 1); + } else { + ret = regmap_write(priv->regmap, priv->reset_reg, + LP50XX_SW_RESET); + if (ret) { + dev_err(&priv->client->dev, + "Cannot reset the device\n"); + goto out; + } + } + + ret = lp50xx_set_banks(priv); + if (ret) { + dev_err(&priv->client->dev, "Cannot set the banks\n"); + goto out; + } + + ret = regmap_write(priv->regmap, LP50XX_DEV_CFG0, LP50XX_CHIP_EN); + if (ret) + dev_err(&priv->client->dev, "Cannot write ctrl enable\n"); + +out: + return ret; +} + +static struct led_rgb_ops lp50xx_rgb_ops = { + .set_color = lp50xx_set_color, + .set_red_brightness = lp50xx_set_red, + .set_green_brightness = lp50xx_set_green, + .set_blue_brightness = lp50xx_set_blue, +}; + +static int lp50xx_probe_dt(struct lp50xx *priv) +{ + struct fwnode_handle *child = NULL; + struct led_classdev *led_cdev; + struct lp50xx_led *led; + int control_bank_defined = 0; + const char *name; + int led_number; + size_t i = 0; + int ret; + + priv->enable_gpio = devm_gpiod_get_optional(&priv->client->dev, + "enable", GPIOD_OUT_LOW); + if (IS_ERR(priv->enable_gpio)) { + ret = PTR_ERR(priv->enable_gpio); + dev_err(&priv->client->dev, "Failed to get enable gpio: %d\n", + ret); + return ret; + } + + priv->regulator = devm_regulator_get(&priv->client->dev, "vled"); + if (IS_ERR(priv->regulator)) + priv->regulator = NULL; + + if (priv->model_id == LP5018) + priv->max_leds = LP5018_MAX_LED_STRINGS; + else if (priv->model_id == LP5024) + priv->max_leds = LP5024_MAX_LED_STRINGS; + else if (priv->model_id == LP5030) + priv->max_leds = LP5030_MAX_LED_STRINGS; + else + priv->max_leds = LP5036_MAX_LED_STRINGS; + + device_for_each_child_node(&priv->client->dev, child) { + led = &priv->leds[i]; + + if (fwnode_property_present(child, "ti,led-bank")) { + led->ctrl_bank_enabled = 1; + if (!control_bank_defined) + control_bank_defined = 1; + else { + dev_err(&priv->client->dev, + "ti,led-bank defined twice\n"); + fwnode_handle_put(child); + goto child_out; + } + } else { + led->ctrl_bank_enabled = 0; + } + + if (led->ctrl_bank_enabled) { + ret = fwnode_property_read_u32_array(child, + "ti,led-bank", + NULL, 0); + ret = fwnode_property_read_u32_array(child, + "ti,led-bank", + led->led_strings, + ret); + + led->led_number = led->led_strings[0]; + + } else { + ret = fwnode_property_read_u32(child, "ti,led-module", + &led_number); + + led->led_number = led_number; + } + if (ret) { + dev_err(&priv->client->dev, + "led sourcing property missing\n"); + fwnode_handle_put(child); + goto child_out; + } + + if (led_number > priv->max_leds) { + dev_err(&priv->client->dev, + "led-sources property is invalid\n"); + ret = -EINVAL; + fwnode_handle_put(child); + goto child_out; + } + + ret = fwnode_property_read_string(child, "label", &name); + if (ret) + snprintf(led->label, sizeof(led->label), + "%s::", priv->client->name); + else + snprintf(led->label, sizeof(led->label), + "%s:%s", priv->client->name, name); + + fwnode_property_read_string(child, "linux,default-trigger", + &led->led_dev.default_trigger); + + led->rgb_cdev.ops = &lp50xx_rgb_ops; + led->priv = priv; + + led_cdev = &led->rgb_cdev.led_cdev; + led_cdev->name = led->label; + led_cdev->brightness_set_blocking = lp50xx_brightness_set; + led_cdev->brightness_get = lp50xx_brightness_get; + + ret = led_classdev_rgb_register(&priv->client->dev, + &led->rgb_cdev); + if (ret) { + dev_err(&priv->client->dev, "led register err: %d\n", + ret); + fwnode_handle_put(child); + goto child_out; + } + i++; + } + priv->num_of_leds = i; + +child_out: + return ret; +} + +static int lp50xx_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct lp50xx *led; + int count; + int ret; + + count = device_get_child_node_count(&client->dev); + if (!count) { + dev_err(&client->dev, "LEDs are not defined in device tree!"); + return -ENODEV; + } + + led = devm_kzalloc(&client->dev, struct_size(led, leds, count), + GFP_KERNEL); + if (!led) + return -ENOMEM; + + mutex_init(&led->lock); + led->client = client; + led->dev = &client->dev; + led->model_id = id->driver_data; + i2c_set_clientdata(client, led); + + if (led->model_id == LP5018 || led->model_id == LP5024) + led->regmap = devm_regmap_init_i2c(client, + &lp5024_regmap_config); + else + led->regmap = devm_regmap_init_i2c(client, + &lp5036_regmap_config); + + if (IS_ERR(led->regmap)) { + ret = PTR_ERR(led->regmap); + dev_err(&client->dev, "Failed to allocate register map: %d\n", + ret); + return ret; + } + + ret = lp50xx_probe_dt(led); + if (ret) + return ret; + + ret = lp50xx_init(led); + if (ret) + return ret; + + return 0; +} + +static int lp50xx_remove(struct i2c_client *client) +{ + struct lp50xx *led = i2c_get_clientdata(client); + int ret; + + ret = regmap_update_bits(led->regmap, LP50XX_DEV_CFG0, + LP50XX_CHIP_EN, 0); + if (ret) { + dev_err(&led->client->dev, "Failed to disable regulator\n"); + return ret; + } + + if (led->enable_gpio) + gpiod_direction_output(led->enable_gpio, 0); + + if (led->regulator) { + ret = regulator_disable(led->regulator); + if (ret) + dev_err(&led->client->dev, + "Failed to disable regulator\n"); + } + + mutex_destroy(&led->lock); + + return 0; +} + +static const struct i2c_device_id lp50xx_id[] = { + { "lp5018", LP5018 }, + { "lp5024", LP5024 }, + { "lp5030", LP5030 }, + { "lp5036", LP5036 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, lp50xx_id); + +static const struct of_device_id of_lp50xx_leds_match[] = { + { .compatible = "ti,lp5018", }, + { .compatible = "ti,lp5024", }, + { .compatible = "ti,lp5030", }, + { .compatible = "ti,lp5036", }, + {}, +}; +MODULE_DEVICE_TABLE(of, of_lp50xx_leds_match); + +static struct i2c_driver lp50xx_driver = { + .driver = { + .name = "lp50xx", + .of_match_table = of_lp50xx_leds_match, + }, + .probe = lp50xx_probe, + .remove = lp50xx_remove, + .id_table = lp50xx_id, +}; +module_i2c_driver(lp50xx_driver); + +MODULE_DESCRIPTION("Texas Instruments LP5024 LED driver"); +MODULE_AUTHOR("Dan Murphy "); +MODULE_LICENSE("GPL v2"); From patchwork Mon Jan 21 21:56:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 156258 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6848734jaa; Mon, 21 Jan 2019 13:57:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN7HGWztzJOldrpNLC3hqbXaB8cRBCyAyg+FSb3WHjqd0CskFHT6uUlKUgY7KxkjR9lWSmHC X-Received: by 2002:a63:f444:: with SMTP id p4mr29385664pgk.124.1548107830972; Mon, 21 Jan 2019 13:57:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548107830; cv=none; d=google.com; s=arc-20160816; b=I2dsnfLlSJLUK6ztXlRSYDQAupdkXd6PLR75J0ZtUN8TkqZI1MMLadqR1RfGRKyWbj XGbf9KYxEf3A2vSofro737uCi1s+v/9R9eb86M2apAgNBU8i7JrgieMW7HLgazRMvwVm FxOfTG0TrLfPsA9P1eyvHnLqxxdYruaQuwm7iJ5iDYVGe/BxtyfJe3KSqHojdVmGpOKV PNF+jcvaeRAqunwZTTeMoh4JSpviGXxzF0RlOTmz1UYlNJplVK2qKzTAxWiGJTrOsH4u hkfc0pmKsvx2CXoxgdCP6ulIT2Tlv+0imoiLvrG6i4I2cj2cpGKHVRzbcqDw4gbXCUXr GEFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=57Dj8gV87Uw0bDKGkiBqskXLqAer7ww/13u0RdYkBzA=; b=UuMwhzv7gfj/FFVAooNsq+RWYmgzY1C3hGgt8fgfHdXgVWpcCaDRtVUSkgbyv3f0BU Jbd8xo4Uabw2DsnpYxa/s1m8iBiKpH1w9YZtIcEQnyttKaQLnQihfrD++1SsJ521mbrD ucUR3cIxpaOZqvwfEou7uVjeUqbl+PrkmQIRjHWMqjoqedYZIjyvD8NU9ou7+C83Q+Ec 8KKgc5mnVvtnySpPY9eftHRjdU7x2RFfOwVrFrAdfTU+ywRsXgszrHrpf5NTsLemuMwH Dj4tRY5QZXpHzzLYrpMsMwVMX/Fgwi/G9p9AdTAAFsE18k2Dyckbqtv4O6oRZ6j9Dt8h oJvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=EflN7UnC; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 9si14124932plc.40.2019.01.21.13.57.10; Mon, 21 Jan 2019 13:57:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-leds-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=EflN7UnC; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-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 S1725993AbfAUV5K (ORCPT + 1 other); Mon, 21 Jan 2019 16:57:10 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:33258 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727513AbfAUV5K (ORCPT ); Mon, 21 Jan 2019 16:57:10 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0LLv56e020291; Mon, 21 Jan 2019 15:57:05 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548107825; bh=57Dj8gV87Uw0bDKGkiBqskXLqAer7ww/13u0RdYkBzA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=EflN7UnC1mtKDBN4lFRL8Xl2xlGVSaQr9+uyxvl0iyetz/tEK3NCgjm6Iys8ys2IK OH/Q0xgfEPgeePKIaPwbLn/wBSSRBa38B7AW11M0L7xIgN/oAgVyLVNSAQg2f6hz+o StbUJPW0rsNiXwlTJqXY7VYTrKBxr2pb7HQoHSTc= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0LLv54p047465 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 21 Jan 2019 15:57:05 -0600 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Mon, 21 Jan 2019 15:57:05 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Mon, 21 Jan 2019 15:57:05 -0600 Received: from legion.dal.desgin.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0LLv5f0020877; Mon, 21 Jan 2019 15:57:05 -0600 Received: from localhost (a0272616local-lt.dhcp.ti.com [172.22.78.123]) by legion.dal.desgin.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id x0LLv4U20744; Mon, 21 Jan 2019 15:57:04 -0600 (CST) From: Dan Murphy To: CC: , , , Dan Murphy Subject: [RFC PATCH 6/6] leds: cpcap: Use the RGB framework for Droid4 Date: Mon, 21 Jan 2019 15:56:59 -0600 Message-ID: <20190121215659.31125-7-dmurphy@ti.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20190121215659.31125-1-dmurphy@ti.com> References: <20190121215659.31125-1-dmurphy@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Signed-off-by: Dan Murphy --- drivers/leds/leds-cpcap.c | 291 +++++++++++++++++++++++++++++++++-- drivers/mfd/motorola-cpcap.c | 8 +- 2 files changed, 288 insertions(+), 11 deletions(-) -- 2.20.1.98.gecbdaf0899 diff --git a/drivers/leds/leds-cpcap.c b/drivers/leds/leds-cpcap.c index f0f28c442807..4088a52de26b 100644 --- a/drivers/leds/leds-cpcap.c +++ b/drivers/leds/leds-cpcap.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -28,6 +29,10 @@ struct cpcap_led_info { u16 limit; u16 init_mask; u16 init_val; + u16 rgb_combo; + u16 red_reg; + u16 green_reg; + u16 blue_reg; }; static const struct cpcap_led_info cpcap_led_red = { @@ -48,6 +53,15 @@ static const struct cpcap_led_info cpcap_led_blue = { .limit = 31, }; +static const struct cpcap_led_info cpcap_led_rgb = { + .red_reg = CPCAP_REG_REDC, + .green_reg = CPCAP_REG_GREENC, + .blue_reg = CPCAP_REG_BLUEC, + .rgb_combo = 0x1, + .mask = 0x03FF, + .limit = 31, +}; + /* aux display light */ static const struct cpcap_led_info cpcap_led_adl = { .reg = CPCAP_REG_ADLC, @@ -68,6 +82,7 @@ static const struct cpcap_led_info cpcap_led_cp = { struct cpcap_led { struct led_classdev led; + struct led_classdev_rgb rgb_cdev; const struct cpcap_led_info *info; struct device *dev; struct regmap *regmap; @@ -116,6 +131,11 @@ static int cpcap_led_set(struct led_classdev *ledc, enum led_brightness value) mutex_lock(&led->update_lock); + if (led->info->rgb_combo) { + err = 0; + goto exit; + } + if (value > LED_OFF) { err = cpcap_led_set_power(led, true); if (err) @@ -154,10 +174,232 @@ static int cpcap_led_set(struct led_classdev *ledc, enum led_brightness value) return err; } +static struct cpcap_led *rgbled_cdev_to_led(struct led_classdev_rgb *rgbled_cdev) +{ + return container_of(rgbled_cdev, struct cpcap_led, rgb_cdev); +} + +static int cpcap_led_set_red(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness value) +{ + struct cpcap_led *led = rgbled_cdev_to_led(rgbled_cdev); + int brightness; + int err; + + mutex_lock(&led->update_lock); + + if (value > LED_OFF) { + err = cpcap_led_set_power(led, true); + if (err) + goto exit; + } + + if (value == LED_OFF) { + /* Avoid HW issue by turning off current before duty cycle */ + err = regmap_update_bits(led->regmap, + led->info->red_reg, led->info->mask, CPCAP_LED_NO_CURRENT); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + brightness = cpcap_led_val(value, LED_OFF); + } else { + brightness = cpcap_led_val(value, LED_ON); + } + + err = regmap_update_bits(led->regmap, led->info->red_reg, led->info->mask, + brightness); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + if (value == LED_OFF) + err = cpcap_led_set_power(led, false); + +exit: + mutex_unlock(&led->update_lock); + return err; +} + +static int cpcap_led_set_green(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness value) +{ + struct cpcap_led *led = rgbled_cdev_to_led(rgbled_cdev); + int brightness; + int err; + + mutex_lock(&led->update_lock); + + if (value > LED_OFF) { + err = cpcap_led_set_power(led, true); + if (err) + goto exit; + } + + if (value == LED_OFF) { + /* Avoid HW issue by turning off current before duty cycle */ + err = regmap_update_bits(led->regmap, + led->info->green_reg, led->info->mask, CPCAP_LED_NO_CURRENT); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + brightness = cpcap_led_val(value, LED_OFF); + } else { + brightness = cpcap_led_val(value, LED_ON); + } + + err = regmap_update_bits(led->regmap, led->info->green_reg, led->info->mask, + brightness); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + if (value == LED_OFF) + err = cpcap_led_set_power(led, false); +exit: + mutex_unlock(&led->update_lock); + return err; +} + +static int cpcap_led_set_blue(struct led_classdev_rgb *rgbled_cdev, + enum led_brightness value) +{ + struct cpcap_led *led = rgbled_cdev_to_led(rgbled_cdev); + int brightness; + int err; + + mutex_lock(&led->update_lock); + + if (value > LED_OFF) { + err = cpcap_led_set_power(led, true); + if (err) + goto exit; + } + + if (value == LED_OFF) { + /* Avoid HW issue by turning off current before duty cycle */ + err = regmap_update_bits(led->regmap, + led->info->blue_reg, led->info->mask, CPCAP_LED_NO_CURRENT); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + brightness = cpcap_led_val(value, LED_OFF); + } else { + brightness = cpcap_led_val(value, LED_ON); + } + + err = regmap_update_bits(led->regmap, led->info->blue_reg, led->info->mask, + brightness); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + if (value == LED_OFF) + err = cpcap_led_set_power(led, false); + +exit: + mutex_unlock(&led->update_lock); + return err; +} +static int cpcap_led_set_color(struct led_classdev_rgb *rgbled_cdev) +{ + struct led_rgb_colors *colors = &rgbled_cdev->rgb_colors; + struct cpcap_led *led = rgbled_cdev_to_led(rgbled_cdev); + int red_brightness, green_brightness, blue_brightness; + int err; + + mutex_lock(&led->update_lock); + + if (colors->red > LED_OFF || colors->green > LED_OFF || + colors->blue > LED_OFF) { + err = cpcap_led_set_power(led, true); + if (err) + goto exit; + } + + if (colors->red == LED_OFF && colors->green == LED_OFF && + colors->blue == LED_OFF) { + /* Avoid HW issue by turning off current before duty cycle */ + err = regmap_update_bits(led->regmap, + led->info->red_reg, led->info->mask, CPCAP_LED_NO_CURRENT); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + err = regmap_update_bits(led->regmap, + led->info->green_reg, led->info->mask, CPCAP_LED_NO_CURRENT); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + err = regmap_update_bits(led->regmap, + led->info->blue_reg, led->info->mask, CPCAP_LED_NO_CURRENT); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + red_brightness = cpcap_led_val(colors->red, LED_OFF); + green_brightness = cpcap_led_val(colors->green, LED_OFF); + blue_brightness = cpcap_led_val(colors->blue, LED_OFF); + } else { + red_brightness = cpcap_led_val(colors->red, LED_ON); + green_brightness = cpcap_led_val(colors->green, LED_ON); + blue_brightness = cpcap_led_val(colors->blue, LED_ON); + } + + err = regmap_update_bits(led->regmap, led->info->red_reg, led->info->mask, + red_brightness); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + err = regmap_update_bits(led->regmap, led->info->green_reg, led->info->mask, + green_brightness); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + err = regmap_update_bits(led->regmap, led->info->blue_reg, led->info->mask, + blue_brightness); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + goto exit; + } + + if (colors->red == LED_OFF && colors->green == LED_OFF && + colors->blue == LED_OFF) + err = cpcap_led_set_power(led, false); + +exit: + mutex_unlock(&led->update_lock); + return err; +} + +static struct led_rgb_ops cpcap_led_rgb_ops = { + .set_color = cpcap_led_set_color, + .set_red_brightness = cpcap_led_set_red, + .set_green_brightness = cpcap_led_set_green, + .set_blue_brightness = cpcap_led_set_blue, +}; + static const struct of_device_id cpcap_led_of_match[] = { { .compatible = "motorola,cpcap-led-red", .data = &cpcap_led_red }, { .compatible = "motorola,cpcap-led-green", .data = &cpcap_led_green }, { .compatible = "motorola,cpcap-led-blue", .data = &cpcap_led_blue }, + { .compatible = "motorola,cpcap-led-rgb", .data = &cpcap_led_rgb }, { .compatible = "motorola,cpcap-led-adl", .data = &cpcap_led_adl }, { .compatible = "motorola,cpcap-led-cp", .data = &cpcap_led_cp }, {}, @@ -167,6 +409,7 @@ MODULE_DEVICE_TABLE(of, cpcap_led_of_match); static int cpcap_led_probe(struct platform_device *pdev) { const struct of_device_id *match; + struct led_classdev *led_cdev; struct cpcap_led *led; int err; @@ -181,7 +424,7 @@ static int cpcap_led_probe(struct platform_device *pdev) led->info = match->data; led->dev = &pdev->dev; - if (led->info->reg == 0x0000) { + if (!led->info->rgb_combo && led->info->reg == 0x0000) { dev_err(led->dev, "Unsupported LED"); return -ENODEV; } @@ -204,19 +447,49 @@ static int cpcap_led_probe(struct platform_device *pdev) } if (led->info->init_mask) { - err = regmap_update_bits(led->regmap, led->info->reg, - led->info->init_mask, led->info->init_val); - if (err) { - dev_err(led->dev, "regmap failed: %d", err); - return err; + if (led->info->rgb_combo) { + err = regmap_update_bits(led->regmap, led->info->red_reg, + led->info->init_mask, led->info->init_val); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + return err; + } + err = regmap_update_bits(led->regmap, led->info->green_reg, + led->info->init_mask, led->info->init_val); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + return err; + } + err = regmap_update_bits(led->regmap, led->info->blue_reg, + led->info->init_mask, led->info->init_val); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + return err; + } + } else { + err = regmap_update_bits(led->regmap, led->info->reg, + led->info->init_mask, led->info->init_val); + if (err) { + dev_err(led->dev, "regmap failed: %d", err); + return err; + } } } mutex_init(&led->update_lock); - led->led.max_brightness = led->info->limit; - led->led.brightness_set_blocking = cpcap_led_set; - err = devm_led_classdev_register(&pdev->dev, &led->led); + if (!led->info->rgb_combo) { + led->led.max_brightness = led->info->limit; + led->led.brightness_set_blocking = cpcap_led_set; + err = devm_led_classdev_register(&pdev->dev, &led->led); + } else { + led->rgb_cdev.ops = &cpcap_led_rgb_ops; + led_cdev = &led->rgb_cdev.led_cdev; + led_cdev->name = led->led.name; + led_cdev->brightness_set_blocking = cpcap_led_set; + err = led_classdev_rgb_register(&pdev->dev, &led->rgb_cdev); + } + if (err) { dev_err(led->dev, "Couldn't register LED: %d", err); return err; diff --git a/drivers/mfd/motorola-cpcap.c b/drivers/mfd/motorola-cpcap.c index 20d9692640e1..beb7063559bb 100644 --- a/drivers/mfd/motorola-cpcap.c +++ b/drivers/mfd/motorola-cpcap.c @@ -253,11 +253,15 @@ static const struct mfd_cell cpcap_mfd_devices[] = { .of_compatible = "motorola,cpcap-led-blue", }, { .name = "cpcap-led", - .id = 3, + .id = 4, + .of_compatible = "motorola,cpcap-led-rgb", + }, { + .name = "cpcap-led", + .id = 5, .of_compatible = "motorola,cpcap-led-adl", }, { .name = "cpcap-led", - .id = 4, + .id = 6, .of_compatible = "motorola,cpcap-led-cp", }, { .name = "cpcap-codec",