From patchwork Tue Oct 8 20:47:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 175572 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6207096ill; Tue, 8 Oct 2019 13:49:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqz39hnuXrQu8kUn68SiGHolZFTFPXVR2fpY8a0Owtx389jHSz1ZpW+YAjt8LE2Tf/Qe21W6 X-Received: by 2002:aa7:d313:: with SMTP id p19mr35416914edq.197.1570567754169; Tue, 08 Oct 2019 13:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570567754; cv=none; d=google.com; s=arc-20160816; b=BCYaOW4fxIaDeI+yQVAuYdwE9mQAF9a9J+YpfQ894/2ckeQR3g2tS/a9ljrXQDv6So ven42b0qVluZT1H5MG8hiD4oIr3M3iyxFcrQ08AqepbIDhJfcWqiIDE+3ojCWnrzfmmH Jn5XDg7IeDzgBH2WcOdrRZybXSjKMsTcwCzK3WiSuyhq02tLBZKim5hBl3jl9MmtGm5o UAJeq5V2a2zCCzaG3W4yIJ3Rb4p0t828Wb6r6dLY8gN4hSH/a2JnAAA2SiKnyjXKSv1r yxBAZ4vZPX7biCIlslwZGmMG52aP9h49IpykwesilXGMd+TX31cxScfe6FJJjgnsoPJR IG1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U/CdL3ky1UgHUUHC2UlJw+Bp+HRLVkYO6pdXvDYGyfg=; b=GiwZKdDJKny1EI2RQrNskfEkIR1y2AsRPfZb3L3e9YjfXrdQn1qWtAKIdzAUwzU3VA wbVcxFNZ/tGOLnSncrXkbdFUOwu0WEoKZxrSXdNW8dqhqKojIsD5Tjr/ncqBSSDyr5R6 S0vDhaRSTV4ipasocZlesphVAMJyR+rIT9p+DoB6lDduROZQzLaNBSnMvGyhX28YPtwS 0Z8/JN3FNnApQxk3AKQjtQrb2OT8KcQ7KvGcujXE2rkqDwtRt1dYUSeBfDC04FTY8qSU NpkFM6EqJiAVKXojgLYBBj3JSn14yQBt7BDB709bKtLQBhj/T7J4cG28eNXVT8cgGQaD /Mvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=YiRkzoaN; 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 p1si98921eda.406.2019.10.08.13.49.14; Tue, 08 Oct 2019 13:49:14 -0700 (PDT) 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=YiRkzoaN; 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 S1731038AbfJHUtN (ORCPT + 1 other); Tue, 8 Oct 2019 16:49:13 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:43362 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730873AbfJHUsY (ORCPT ); Tue, 8 Oct 2019 16:48:24 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x98KmJLD092455; Tue, 8 Oct 2019 15:48:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570567699; bh=U/CdL3ky1UgHUUHC2UlJw+Bp+HRLVkYO6pdXvDYGyfg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=YiRkzoaNhMOK8w4ftTS/+h9j/q5yNpDnDt2+h8huFK2tR/BspQ21vaWoD8IMjtWLs +uWZu4xfb9BwsldpXlumHg5nArih7w2bjkVJeHcn2WX1EXQE1V8oKN1z6MCkfr4uIq IGC3XCx7rDTBGkh6Beyyt1p26NkjB4ZEOmcFBulk= 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 x98KmJe8042335 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 8 Oct 2019 15:48:19 -0500 Received: from DFLE106.ent.ti.com (10.64.6.27) 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.1713.5; Tue, 8 Oct 2019 15:48:16 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 8 Oct 2019 15:48:18 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id x98KmI5w022723; Tue, 8 Oct 2019 15:48:18 -0500 From: Dan Murphy To: , CC: , , Dan Murphy Subject: [PATCH v11 01/16] dt: bindings: Add multicolor class dt bindings documention Date: Tue, 8 Oct 2019 15:47:45 -0500 Message-ID: <20191008204800.19870-2-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20191008204800.19870-1-dmurphy@ti.com> References: <20191008204800.19870-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 Add DT bindings for the LEDs multicolor class framework. Signed-off-by: Dan Murphy --- .../bindings/leds/leds-class-multicolor.txt | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-class-multicolor.txt -- 2.22.0.214.g8dca754b1e diff --git a/Documentation/devicetree/bindings/leds/leds-class-multicolor.txt b/Documentation/devicetree/bindings/leds/leds-class-multicolor.txt new file mode 100644 index 000000000000..8619c9bf1811 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-class-multicolor.txt @@ -0,0 +1,98 @@ +* Multicolor LED properties + +Bindings for multi color LEDs show how to describe current outputs of +either integrated multi-color LED elements (like RGB, RGBW, RGBWA-UV +etc.) or standalone LEDs, to achieve logically grouped multi-color LED +modules. This is achieved by adding multi-led nodes layer to the +monochrome LED bindings. + +The nodes and properties defined in this document are unique to the multicolor +LED class. Common LED nodes and properties are inherited from the common.txt +within this documentation directory. + +Required LED Child properties: + - color : For multicolor LED support this property should be defined as + LED_COLOR_ID_MULTI and further definition can be found in + include/linux/leds/common.h. + +led-controller@30 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "ti,lp5024"; + reg = <0x29>; + + multi-led@1 { + #address-cells = <1>; + #size-cells = <0>; + reg = <1>; + color = ; + function = LED_FUNCTION_STATUS; + + + led@3 { + reg = <3>; + color = ; + }; + + led@4 { + reg = <4>; + color = ; + }; + + led@5 { + reg = <5>; + color = ; + }; + }; + + multi-led@2 { + #address-cells = <1>; + #size-cells = <0>; + color = ; + function = LED_FUNCTION_ACTIVITY; + reg = <2>; + ti,led-bank = <2 3 5>; + + led@6 { + reg = <0x6>; + color = ; + led-sources = <6 9 15>; + }; + + led@7 { + reg = <0x7>; + color = ; + led-sources = <7 10 16>; + }; + + led@8 { + reg = <0x8>; + color = ; + led-sources = <8 11 17>; + }; + }; + + multi-led@4 { + #address-cells = <1>; + #size-cells = <0>; + reg = <4>; + color = ; + function = LED_FUNCTION_ACTIVITY; + + led@12 { + reg = <12>; + color = ; + }; + + led@13 { + reg = <13>; + color = ; + }; + + led@14 { + reg = <14>; + color = ; + }; + }; + +}; From patchwork Tue Oct 8 20:47:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 175568 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6206828ill; Tue, 8 Oct 2019 13:48:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5PrXLAe7pcArvaOIR6lirEBb2WDQSbS13q0KM09Z2247yVziOfzRJEYanHfhiulpvTnk4 X-Received: by 2002:a17:906:7499:: with SMTP id e25mr22608505ejl.326.1570567737206; Tue, 08 Oct 2019 13:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570567737; cv=none; d=google.com; s=arc-20160816; b=s/1Bn6kVJ0fPz8ATXr5rqJVrgWDIQFeCGztLtHlUvA+/ntoyLIWXQb/hlAgyVEJc0A xufOEM0czbGcxbPViMs7sepLntxhjGF9sFMWtVaiM/KxpktP3JahWV2YiUn0TnSdqwGI BfOBYDe0f8kk7fjn1G0dbNly90xiNbDLXxB7Xsl5YDxx5HZGOBn7cPODOo1aKPvEHH1v +P3kiW1pWlwEGtdYI4QOd9tKr794zUU2qUk3iKtyxHZHZehe5PWyHrvbFw0+QvRdGxF0 9fRxFx9nsSGPwr/OrJKFNwrbL3XljmpMSkdT0HsQVa6cRrjmIl1lnh0LpHoAkw3m3Scy syuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nH6UYP7j8bNzmqqvg0LobJDQZsNiF2jLEoJu23iXftw=; b=fxzhSYgwYu4Jp/8kOIR9BO1FB3xO04EJa1i/hGlLpjzdLr+FI9MlVINPQ1Cf5ENEkR /SL3VC+pajAcwXk5a8LNcaq+fkGvivKrir4Tr3QAq6Fb/i4QOp82F40HgYWwePMF+3I0 ROV3f8Zvlt8WFpBMfSZAgYzLPXES20oD4GR4m6IioKy2SoO0c2p6r36Y1uNrY/0YrVbS oMsHEjz/Gjz/UviQMMjAS4pnNDF4/OlDBgG2GcP/3IZJXRwyLA3CQfd1vIiq94eFWZBK tbT975xq26X8KiCLpQf6MccyBQUG1AliYSlivsN0mOkhwAfUzFdlJC9gFqJkwgqoBx7y /Z0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=YN9ILxQO; 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 u8si115726edq.84.2019.10.08.13.48.56; Tue, 08 Oct 2019 13:48:57 -0700 (PDT) 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=YN9ILxQO; 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 S1731175AbfJHUs4 (ORCPT + 1 other); Tue, 8 Oct 2019 16:48:56 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:43366 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730987AbfJHUsY (ORCPT ); Tue, 8 Oct 2019 16:48:24 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x98KmKKm092468; Tue, 8 Oct 2019 15:48:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570567700; bh=nH6UYP7j8bNzmqqvg0LobJDQZsNiF2jLEoJu23iXftw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=YN9ILxQOyw7bFzQvrZYbBYIcAsAdTW8HA1t4PPgOsyRaEy7nxzSapSaldnVATxmeR tyfOcy3gVqfTUMpg4YdxOQz/dz4A16I38D7Ev0kBzq/VDAFfFNPFHC6scuyYeDQqVj KQHB6nw5ziSyCo8ONFCJXBhi8Ic9gHgFb2/7TQag= 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 x98KmKQo042344 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 8 Oct 2019 15:48:20 -0500 Received: from DLEE107.ent.ti.com (157.170.170.37) 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.1713.5; Tue, 8 Oct 2019 15:48:17 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 8 Oct 2019 15:48:19 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x98KmJWI095727; Tue, 8 Oct 2019 15:48:19 -0500 From: Dan Murphy To: , CC: , , Dan Murphy Subject: [PATCH v11 04/16] leds: multicolor: Introduce a multicolor class definition Date: Tue, 8 Oct 2019 15:47:48 -0500 Message-ID: <20191008204800.19870-5-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20191008204800.19870-1-dmurphy@ti.com> References: <20191008204800.19870-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 multicolor class that groups colored LEDs within a LED node. The multi color class groups monochrome LEDs and allows controlling two aspects of the final combined color: hue and lightness. The former is controlled via _intensity files and the latter is controlled via brightness file. Signed-off-by: Dan Murphy --- .../ABI/testing/sysfs-class-led-multicolor | 35 +++ Documentation/leds/index.rst | 1 + Documentation/leds/leds-class-multicolor.rst | 96 +++++++ drivers/leds/Kconfig | 10 + drivers/leds/Makefile | 1 + drivers/leds/led-class-multicolor.c | 271 ++++++++++++++++++ include/linux/led-class-multicolor.h | 143 +++++++++ 7 files changed, 557 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-led-multicolor create mode 100644 Documentation/leds/leds-class-multicolor.rst create mode 100644 drivers/leds/led-class-multicolor.c create mode 100644 include/linux/led-class-multicolor.h -- 2.22.0.214.g8dca754b1e diff --git a/Documentation/ABI/testing/sysfs-class-led-multicolor b/Documentation/ABI/testing/sysfs-class-led-multicolor new file mode 100644 index 000000000000..65cb43de26e6 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-led-multicolor @@ -0,0 +1,35 @@ +What: /sys/class/leds//brightness +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy +Description: read/write + Writing to this file will update all LEDs within the group to a + calculated percentage of what each color LED intensity is set + to. The percentage is calculated via the equation below: + + led_brightness = brightness * _intensity/_max_intensity + + For additional details please refer to + Documentation/leds/leds-class-multicolor.rst. + + The value of the color is from 0 to + /sys/class/leds//max_brightness. + +What: /sys/class/leds//colors/_intensity +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy +Description: read/write + The _intensity file is created based on the color + defined by the registrar of the class. + There is one file per color presented. + + The value of the color is from 0 to + /sys/class/leds//colors/_max_intensity. + +What: /sys/class/leds//colors/_max_intensity +Date: Sept 2019 +KernelVersion: 5.5 +Contact: Dan Murphy +Description: read only + Maximum intensity level for the LED color. diff --git a/Documentation/leds/index.rst b/Documentation/leds/index.rst index 060f4e485897..bc70c6aa7138 100644 --- a/Documentation/leds/index.rst +++ b/Documentation/leds/index.rst @@ -9,6 +9,7 @@ LEDs leds-class leds-class-flash + leds-class-multicolor ledtrig-oneshot ledtrig-transient ledtrig-usbport diff --git a/Documentation/leds/leds-class-multicolor.rst b/Documentation/leds/leds-class-multicolor.rst new file mode 100644 index 000000000000..7a695a29377e --- /dev/null +++ b/Documentation/leds/leds-class-multicolor.rst @@ -0,0 +1,96 @@ +==================================== +Multi Color LED handling under Linux +==================================== + +Description +=========== +The multi color class groups monochrome LEDs and allows controlling two +aspects of the final combined color: hue and lightness. The former is +controlled via _intensity files and the latter is controlled +via brightness file. + +For more details on hue and lightness notions please refer to +https://en.wikipedia.org/wiki/CIECAM02. + +Note that intensity files only cache the written value and the actual +change of hardware state occurs upon writing brightness file. This +allows for changing many factors of the perceived color in a virtually +unnoticeable way for the human observer. + +Multicolor Class Control +======================== +The multicolor class presents the LED groups under a directory called "colors". +This directory is a child under the LED parent node created by the led_class +framework. The led_class framework is documented in led-class.rst within this +documentation directory. + +Each colored LED will have two files created under the colors directory +_intensity and _max_intensity. These files will contain +one of LED_COLOR_ID_* definitions from the header +include/dt-bindings/leds/common.h. + +Directory Layout Example +======================== +root:/sys/class/leds/rgb:grouped_leds# ls -lR colors/ +-rw-r--r-- 1 root root 4096 Jul 7 03:10 blue_intensity +-r--r--r-- 1 root root 4096 Jul 7 03:10 blue_max_intensity +-rw-r--r-- 1 root root 4096 Jul 7 03:10 green_intensity +-r--r--r-- 1 root root 4096 Jul 7 03:10 green_max_intensity +-rw-r--r-- 1 root root 4096 Jul 7 03:10 red_intensity +-r--r--r-- 1 root root 4096 Jul 7 03:10 red_max_intensity + +Multicolor Class Brightness Control +=================================== +The multiclor class framework will calculate each monochrome LEDs intensity. + +The brightness level for each LED is calculated based on the color LED +intensity setting divided by the color LED max intensity setting multiplied by +the requested brightness. + +led_brightness = brightness * _intensity/_max_intensity + +Example: +Three LEDs are present in the group as defined in "Directory Layout Example" +within this document. + +A user first writes the color LED brightness file with the brightness level that +is necessary to achieve a blueish violet output from the RGB LED group. + +echo 138 > /sys/class/leds/rgb:grouped_leds/red_intensity +echo 43 > /sys/class/leds/rgb:grouped_leds/green_intensity +echo 226 > /sys/class/leds/rgb:grouped_leds/blue_intensity + +red - + intensity = 138 + max_intensity = 255 +green - + intensity = 43 + max_intensity = 255 +blue - + intensity = 226 + max_intensity = 255 + +The user can control the brightness of that RGB group by writing the parent +'brightness' control. Assuming a parent max_brightness of 255 the user may want +to dim the LED color group to half. The user would write a value of 128 to the +parent brightness file then the values written to each LED will be adjusted +base on this value + +cat /sys/class/leds/rgb:grouped_leds/max_brightness +255 +echo 128 > /sys/class/leds/rgb:grouped_leds/brightness + +adjusted_red_value = 128 * 138/255 = 69 +adjusted_green_value = 128 * 43/255 = 21 +adjusted_blue_value = 128 * 226/255 = 113 + +Reading the parent brightness file will return the current brightness value of +the color LED group. + +cat /sys/class/leds/rgb:grouped_leds/max_brightness +255 + +echo 128 > /sys/class/leds/rgb:grouped_leds/brightness + +cat /sys/class/leds/rgb:grouped_leds/brightness +128 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 4b68520ac251..a1ede89afc9e 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -30,6 +30,16 @@ config LEDS_CLASS_FLASH for the flash related features of a LED device. It can be built as a module. +config LEDS_CLASS_MULTI_COLOR + tristate "LED Mulit Color LED Class Support" + depends on LEDS_CLASS + help + This option enables the multicolor LED sysfs class in /sys/class/leds. + It wraps LED class and adds multicolor LED specific sysfs attributes + and kernel internal API to it. You'll need this to provide support + for multicolor LEDs that are grouped together. This class is not + intended for single color LEDs. 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 2da39e896ce8..841038cfe35b 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_MULTI_COLOR) += led-class-multicolor.o obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o # LED Platform Drivers diff --git a/drivers/leds/led-class-multicolor.c b/drivers/leds/led-class-multicolor.c new file mode 100644 index 000000000000..89f4bc9e057c --- /dev/null +++ b/drivers/leds/led-class-multicolor.c @@ -0,0 +1,271 @@ +// SPDX-License-Identifier: GPL-2.0 +// LED Multi Color class interface +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + +#include +#include +#include +#include +#include +#include + +#include "leds.h" + +#define INTENSITY_NAME "_intensity" +#define MAX_INTENSITY_NAME "_max_intensity" + +int led_mc_calc_brightness(struct led_classdev_mc *mcled_cdev, + enum led_brightness brightness, + struct led_mc_color_conversion color_component[]) +{ + struct led_mc_color_entry *priv; + int i = 0; + + list_for_each_entry(priv, &mcled_cdev->color_list, list) { + color_component[i].color_id = priv->led_color_id; + color_component[i].brightness = brightness * + priv->intensity / priv->max_intensity; + i++; + } + + return 0; +} +EXPORT_SYMBOL_GPL(led_mc_calc_brightness); + +static ssize_t intensity_store(struct device *dev, + struct device_attribute *intensity_attr, + const char *buf, size_t size) +{ + struct led_mc_color_entry *priv = container_of(intensity_attr, + struct led_mc_color_entry, + intensity_attr); + struct led_classdev *led_cdev = priv->mcled_cdev->led_cdev; + unsigned long value; + ssize_t ret; + + mutex_lock(&led_cdev->led_access); + + ret = kstrtoul(buf, 10, &value); + if (ret) + goto unlock; + + if (value > priv->max_intensity) { + ret = -EINVAL; + goto unlock; + } + + priv->intensity = value; + ret = size; + +unlock: + mutex_unlock(&led_cdev->led_access); + return ret; +} + +static ssize_t intensity_show(struct device *dev, + struct device_attribute *intensity_attr, + char *buf) +{ + struct led_mc_color_entry *priv = container_of(intensity_attr, + struct led_mc_color_entry, + intensity_attr); + + return sprintf(buf, "%d\n", priv->intensity); +} + +static ssize_t max_intensity_show(struct device *dev, + struct device_attribute *max_intensity_attr, + char *buf) +{ + struct led_mc_color_entry *priv = container_of(max_intensity_attr, + struct led_mc_color_entry, + max_intensity_attr); + + return sprintf(buf, "%d\n", priv->max_intensity); +} + +static struct attribute *led_color_attrs[] = { + NULL, +}; + +static struct attribute_group led_color_group = { + .name = "colors", + .attrs = led_color_attrs, +}; + +static int led_multicolor_init_color(struct led_classdev_mc *mcled_cdev, + int color_id) +{ + struct led_classdev *led_cdev = mcled_cdev->led_cdev; + struct led_mc_color_entry *mc_priv; + char *intensity_file_name; + char *max_intensity_file_name; + size_t len; + int ret; + + mc_priv = devm_kzalloc(led_cdev->dev, sizeof(*mc_priv), GFP_KERNEL); + if (!mc_priv) + return -ENOMEM; + + mc_priv->led_color_id = color_id; + mc_priv->mcled_cdev = mcled_cdev; + + sysfs_attr_init(&mc_priv->intensity_attr.attr); + len = strlen(led_colors[color_id]) + strlen(INTENSITY_NAME) + 1; + intensity_file_name = kzalloc(len, GFP_KERNEL); + if (!intensity_file_name) + return -ENOMEM; + + snprintf(intensity_file_name, len, "%s%s", + led_colors[color_id], INTENSITY_NAME); + mc_priv->intensity_attr.attr.name = intensity_file_name; + mc_priv->intensity_attr.attr.mode = 0644; + mc_priv->intensity_attr.store = intensity_store; + mc_priv->intensity_attr.show = intensity_show; + ret = sysfs_add_file_to_group(&led_cdev->dev->kobj, + &mc_priv->intensity_attr.attr, + led_color_group.name); + if (ret) + goto intensity_err_out; + + sysfs_attr_init(&mc_priv->max_intensity_attr.attr); + len = strlen(led_colors[color_id]) + strlen(MAX_INTENSITY_NAME) + 1; + max_intensity_file_name = kzalloc(len, GFP_KERNEL); + if (!max_intensity_file_name) { + ret = -ENOMEM; + goto intensity_err_out; + } + + snprintf(max_intensity_file_name, len, "%s%s", + led_colors[color_id], MAX_INTENSITY_NAME); + mc_priv->max_intensity_attr.attr.name = max_intensity_file_name; + mc_priv->max_intensity_attr.attr.mode = 0444; + mc_priv->max_intensity_attr.show = max_intensity_show; + ret = sysfs_add_file_to_group(&led_cdev->dev->kobj, + &mc_priv->max_intensity_attr.attr, + led_color_group.name); + if (ret) + goto max_intensity_err_out; + + mc_priv->max_intensity = LED_FULL; + list_add_tail(&mc_priv->list, &mcled_cdev->color_list); + +max_intensity_err_out: + kfree(max_intensity_file_name); +intensity_err_out: + kfree(intensity_file_name); + return ret; +} + +static int led_multicolor_init_color_dir(struct led_classdev_mc *mcled_cdev) +{ + struct led_classdev *led_cdev = mcled_cdev->led_cdev; + int ret; + int i; + + ret = sysfs_create_group(&led_cdev->dev->kobj, &led_color_group); + if (ret) + return ret; + + for (i = 0; i < LED_COLOR_ID_MAX; i++) { + if (test_bit(i, &mcled_cdev->available_colors)) { + ret = led_multicolor_init_color(mcled_cdev, i); + if (ret) + break; + + } + } + + return ret; +} + +int led_classdev_multicolor_register_ext(struct device *parent, + struct led_classdev_mc *mcled_cdev, + struct led_init_data *init_data) +{ + struct led_classdev *led_cdev; + int ret; + + if (!mcled_cdev) + return -EINVAL; + + led_cdev = mcled_cdev->led_cdev; + INIT_LIST_HEAD(&mcled_cdev->color_list); + + /* Register led class device */ + ret = led_classdev_register_ext(parent, led_cdev, init_data); + if (ret) + return ret; + + return led_multicolor_init_color_dir(mcled_cdev); +} +EXPORT_SYMBOL_GPL(led_classdev_multicolor_register_ext); + +void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) +{ + struct led_mc_color_entry *priv, *next; + + if (!mcled_cdev) + return; + + list_for_each_entry_safe(priv, next, &mcled_cdev->color_list, list) + list_del(&priv->list); + + sysfs_remove_group(&mcled_cdev->led_cdev->dev->kobj, &led_color_group); + led_classdev_unregister(mcled_cdev->led_cdev); +} +EXPORT_SYMBOL_GPL(led_classdev_multicolor_unregister); + +static void devm_led_classdev_multicolor_release(struct device *dev, void *res) +{ + led_classdev_multicolor_unregister(*(struct led_classdev_mc **)res); +} + +int devm_led_classdev_multicolor_register_ext(struct device *parent, + struct led_classdev_mc *mcled_cdev, + struct led_init_data *init_data) +{ + struct led_classdev_mc **dr; + int ret; + + dr = devres_alloc(devm_led_classdev_multicolor_release, + sizeof(*dr), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + ret = led_classdev_multicolor_register(parent, mcled_cdev); + if (ret) { + devres_free(dr); + return ret; + } + + *dr = mcled_cdev; + devres_add(parent, dr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_led_classdev_multicolor_register_ext); + +static int devm_led_classdev_multicolor_match(struct device *dev, + void *res, void *data) +{ + struct led_classdev_mc **p = res; + + if (WARN_ON(!p || !*p)) + return 0; + + return *p == data; +} + +void devm_led_classdev_multicolor_unregister(struct device *dev, + struct led_classdev_mc *mcled_cdev) +{ + WARN_ON(devres_release(dev, + devm_led_classdev_multicolor_release, + devm_led_classdev_multicolor_match, mcled_cdev)); +} +EXPORT_SYMBOL_GPL(devm_led_classdev_multicolor_unregister); + +MODULE_AUTHOR("Dan Murphy "); +MODULE_DESCRIPTION("Multi Color LED class interface"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/led-class-multicolor.h b/include/linux/led-class-multicolor.h new file mode 100644 index 000000000000..5d0cdca32223 --- /dev/null +++ b/include/linux/led-class-multicolor.h @@ -0,0 +1,143 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* LED Multicolor class interface + * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ + */ + +#ifndef __LINUX_MULTICOLOR_LEDS_H_INCLUDED +#define __LINUX_MULTICOLOR_LEDS_H_INCLUDED + +#include +#include + +struct led_classdev_mc; + +struct led_mc_color_conversion { + int color_id; + int brightness; + int output_num; +}; + +struct led_mc_color_entry { + struct led_classdev_mc *mcled_cdev; + + struct device_attribute max_intensity_attr; + struct device_attribute intensity_attr; + + enum led_brightness max_intensity; + enum led_brightness intensity; + + struct list_head list; + + int led_color_id; +}; + +struct led_classdev_mc { + /* led class device */ + struct led_classdev *led_cdev; + struct list_head color_list; + + unsigned long available_colors; + int num_leds; +}; +#ifdef CONFIG_LEDS_CLASS_MULTI_COLOR +static inline struct led_classdev_mc *lcdev_to_mccdev( + struct led_classdev *lcdev) +{ + return container_of(lcdev, struct led_classdev_mc, led_cdev); +} + +/** + * led_classdev_multicolor_register_ext - register a new object of led_classdev + * class with support for multicolor LEDs + * @parent: the multicolor LED to register + * @mcled_cdev: the led_classdev_mc structure for this device + * @init_data: the LED class Multi color device initialization data + * + * Returns: 0 on success or negative error value on failure + */ +int led_classdev_multicolor_register_ext(struct device *parent, + struct led_classdev_mc *mcled_cdev, + struct led_init_data *init_data); + +static inline int led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); +} + +/** + * led_classdev_multicolor_unregister - unregisters an object of led_classdev + * class with support for multicolor LEDs + * @mcled_cdev: the multicolor LED to unregister + * + * Unregister a previously registered via led_classdev_multicolor_register + * object + */ +void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev); + +/* Calculate brightness for the monochrome LED cluster */ +int led_mc_calc_brightness(struct led_classdev_mc *mcled_cdev, + enum led_brightness brightness, + struct led_mc_color_conversion color_component[]); + +int devm_led_classdev_multicolor_register_ext(struct device *parent, + struct led_classdev_mc *mcled_cdev, + struct led_init_data *init_data); + +static inline int devm_led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev, + NULL); +} + +void devm_led_classdev_multicolor_unregister(struct device *parent, + struct led_classdev_mc *mcled_cdev); +#else + +static inline struct led_classdev_mc *lcdev_to_mccdev( + struct led_classdev *lcdev) +{ + return NULL; +} + +static inline int led_classdev_multicolor_register_ext(struct device *parent, + struct led_classdev_mc *mcled_cdev, + struct led_init_data *init_data) +{ + return -EINVAL; +} + +static inline int led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return -EINVAL; +} + +static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {} + +static inline int led_mc_calc_brightness(struct led_classdev_mc *mcled_cdev, + enum led_brightness brightness, + struct led_mc_color_conversion color_component[]) +{ + return -EINVAL; +} + +static inline int devm_led_classdev_multicolor_register_ext(struct device *parent, + struct led_classdev_mc *mcled_cdev, + struct led_init_data *init_data) +{ + return -EINVAL; +} + +static inline int devm_led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return -EINVAL; +} + +static inline void devm_led_classdev_multicolor_unregister(struct device *parent, + struct led_classdev_mc *mcled_cdev) {} + +#endif /* CONFIG_LEDS_CLASS_MULTI_COLOR */ +#endif /* __LINUX_MULTICOLOR_LEDS_H_INCLUDED */ From patchwork Tue Oct 8 20:47: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: 175559 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6206409ill; Tue, 8 Oct 2019 13:48:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyO7Uky9WighqyfUIcR/x4lC7JVsKmP+Uu9HwcgBdqYP08ZpmfVMk53lQWmAKkGWPv2Dn2i X-Received: by 2002:a17:906:1152:: with SMTP id i18mr30886888eja.113.1570567711234; Tue, 08 Oct 2019 13:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570567711; cv=none; d=google.com; s=arc-20160816; b=P6S2USkkXqM7LoRycjpFOzL4VwNVBdM9LyQ9f2brESwh8lzSgS7h7CxoJcEx80kE7Q uYvjjLqn3XZ6vtQb2FhdzPagplxEtfCG2zUcgQa44sEhvKcK1K7iRuZbg8kVA26mt5t2 KnlDK0RTFlFwLnaNe+aJD1RE13vwqfH+8MrAN9hCmDSC3eS6i8tgp8KkBLjMCpLHNmQl /tSWO+6BBwcbByA2pJHYwI+lQSayRtlfjoDVdr9QQaV2JdA0UMMbmYG5dr0GRIDGVlmh ZXQeG7Iy6OusbuDPI+xiuGr2rhqVigBj4xtl8iiSe6Tlv8RrAN1AWoRhNJkB4l4cS7Fw bavA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+q0t9yIqoXldgQgmx1v5usIYhNbt//7Lyrd4aFmtnyk=; b=HrLVNp5NrV00tNKCYAWmtcCsUsH/u09wgUE6XX+axLI/Rqn2B6TbYZcFjOPyzPdAOu FP8tU/0MAN/zELDNN02oZPWqmuDYhSAjK99zFfJP/XcIHlwqcBuZc/gxIeccGDRW7s7k 5doZ6K7NI5Sg65MxtdJv2xZ7t98JnFTRj2iX7w6LNgcUfzZ0iYd84kAkFHrEKkZQ6kyg aPT6xPzgNAdiovcKl+e/sGkVw7LEGEN6CbL+FQtrmRf/bFDdDyuFD86nv+/8jwA8kCEz K7t2xHfPfocreZEIRjyqsYcTQmMC9/XeFQv4RSRoU6/8+MurWqRNqJ/Ns8zfYEj//e3J z7TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=XGGpgL9T; 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 s27si115462edm.226.2019.10.08.13.48.30; Tue, 08 Oct 2019 13:48:31 -0700 (PDT) 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=XGGpgL9T; 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 S1731173AbfJHUs1 (ORCPT + 1 other); Tue, 8 Oct 2019 16:48:27 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:45054 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731138AbfJHUs0 (ORCPT ); Tue, 8 Oct 2019 16:48:26 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x98KmMlS092704; Tue, 8 Oct 2019 15:48:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570567702; bh=+q0t9yIqoXldgQgmx1v5usIYhNbt//7Lyrd4aFmtnyk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XGGpgL9TveEx/HptuRJL25GumD1iO7r17Sl9RuefuszO4XuGJJDuU7DZ3Kbfar5ra rRBhf4sPzwhRbLYk58p5ZvC2aeUIyUSowZfwkB+N+vd0QsaTYm04OGmQnW1zL0TcKa rDEj+b+E6Z9e5yA1IUjkqyg8PWZTbif2KbWCJDB0= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x98KmM5S042370 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 8 Oct 2019 15:48:22 -0500 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 8 Oct 2019 15:48:18 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 8 Oct 2019 15:48:21 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x98KmLCc095754; Tue, 8 Oct 2019 15:48:21 -0500 From: Dan Murphy To: , CC: , , Dan Murphy Subject: [PATCH v11 12/16] leds: lp55xx: Add multicolor framework support to lp55xx Date: Tue, 8 Oct 2019 15:47:56 -0500 Message-ID: <20191008204800.19870-13-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20191008204800.19870-1-dmurphy@ti.com> References: <20191008204800.19870-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 Add multicolor framework support for the lp55xx family. Signed-off-by: Dan Murphy --- drivers/leds/Kconfig | 1 + drivers/leds/leds-lp55xx-common.c | 176 +++++++++++++++++++--- drivers/leds/leds-lp55xx-common.h | 11 ++ include/linux/platform_data/leds-lp55xx.h | 5 + 4 files changed, 169 insertions(+), 24 deletions(-) -- 2.22.0.214.g8dca754b1e diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index fb614a6b9afa..5706bf8d8bd1 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -377,6 +377,7 @@ config LEDS_LP50XX 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 + depends on OF select FW_LOADER select FW_LOADER_USER_HELPER help diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 44ced02b49f9..85629f836082 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -131,14 +131,54 @@ static struct attribute *lp55xx_led_attrs[] = { }; ATTRIBUTE_GROUPS(lp55xx_led); +static int lp55xx_map_channel(struct lp55xx_led *led, int color_id, + enum led_brightness brightness) +{ + int i; + + for (i = 0; i < led->mc_cdev.num_leds; i++) { + if (led->color_component[i].color_id == color_id) { + led->color_component[i].brightness = brightness; + return 0; + } + } + + return -EINVAL; +} + static int lp55xx_set_brightness(struct led_classdev *cdev, enum led_brightness brightness) { + struct led_mc_color_conversion color_component[LP55XX_MAX_GROUPED_CHAN]; struct lp55xx_led *led = cdev_to_lp55xx_led(cdev); struct lp55xx_device_config *cfg = led->chip->cfg; + int ret; + int i; - led->brightness = (u8)brightness; - return cfg->brightness_fn(led); + if (led->mc_cdev.num_leds > 1) { + if (!cfg->color_intensity_fn) + return -EINVAL; + + led_mc_calc_brightness(&led->mc_cdev, brightness, + color_component); + + for (i = 0; i < led->mc_cdev.num_leds; i++) { + ret = lp55xx_map_channel(led, + color_component[i].color_id, + color_component[i].brightness); + if (ret) + return ret; + } + + ret = cfg->color_intensity_fn(led); + if (ret) + return ret; + } else { + led->brightness = (u8)brightness; + ret = cfg->brightness_fn(led); + } + + return ret; } static int lp55xx_init_led(struct lp55xx_led *led, @@ -147,9 +187,9 @@ static int lp55xx_init_led(struct lp55xx_led *led, struct lp55xx_platform_data *pdata = chip->pdata; struct lp55xx_device_config *cfg = chip->cfg; struct device *dev = &chip->cl->dev; + int max_channel = cfg->max_channel; char name[32]; int ret; - int max_channel = cfg->max_channel; if (chan >= max_channel) { dev_err(dev, "invalid channel: %d / %d\n", chan, max_channel); @@ -159,10 +199,34 @@ static int lp55xx_init_led(struct lp55xx_led *led, if (pdata->led_config[chan].led_current == 0) return 0; + if (pdata->led_config[chan].name) { + led->cdev.name = pdata->led_config[chan].name; + } else { + snprintf(name, sizeof(name), "%s:channel%d", + pdata->label ? : chip->cl->name, chan); + led->cdev.name = name; + } + + if (pdata->led_config[chan].num_colors > 1) { + led->mc_cdev.led_cdev = &led->cdev; + led->cdev.brightness_set_blocking = lp55xx_set_brightness; + led->cdev.groups = lp55xx_led_groups; + led->mc_cdev.num_leds = pdata->led_config[chan].num_colors; + led->mc_cdev.available_colors = + pdata->led_config[chan].available_colors; + memcpy(led->color_component, + pdata->led_config[chan].color_component, + sizeof(led->color_component)); + } else { + + led->cdev.default_trigger = + pdata->led_config[chan].default_trigger; + led->cdev.brightness_set_blocking = lp55xx_set_brightness; + } led->cdev.groups = lp55xx_led_groups; + led->led_current = pdata->led_config[chan].led_current; led->max_current = pdata->led_config[chan].max_current; led->chan_nr = pdata->led_config[chan].chan_nr; - led->cdev.default_trigger = pdata->led_config[chan].default_trigger; if (led->chan_nr >= max_channel) { dev_err(dev, "Use channel numbers between 0 and %d\n", @@ -170,18 +234,11 @@ static int lp55xx_init_led(struct lp55xx_led *led, return -EINVAL; } - led->cdev.brightness_set_blocking = lp55xx_set_brightness; - led->cdev.groups = lp55xx_led_groups; - - if (pdata->led_config[chan].name) { - led->cdev.name = pdata->led_config[chan].name; - } else { - snprintf(name, sizeof(name), "%s:channel%d", - pdata->label ? : chip->cl->name, chan); - led->cdev.name = name; - } + if (pdata->led_config[chan].num_colors > 1) + ret = led_classdev_multicolor_register(dev, &led->mc_cdev); + else + ret = led_classdev_register(dev, &led->cdev); - ret = led_classdev_register(dev, &led->cdev); if (ret) { dev_err(dev, "led register err: %d\n", ret); return ret; @@ -466,7 +523,6 @@ int lp55xx_register_leds(struct lp55xx_led *led, struct lp55xx_chip *chip) dev_err(&chip->cl->dev, "empty brightness configuration\n"); return -EINVAL; } - for (i = 0; i < num_channels; i++) { /* do not initialize channels that are not connected */ @@ -538,6 +594,82 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs); +static int lp5xx_parse_common_child(struct device_node *np, + struct lp55xx_led_config *cfg, + int chan_num, bool is_multicolor, + int color_num) +{ + u32 led_number; + int ret; + + of_property_read_string(np, "chan-name", + &cfg[chan_num].name); + of_property_read_u8(np, "led-cur", + &cfg[chan_num].led_current); + of_property_read_u8(np, "max-cur", + &cfg[chan_num].max_current); + + ret = of_property_read_u32(np, "reg", &led_number); + if (ret) + return ret; + + if (led_number < 0 || led_number > 6) + return -EINVAL; + + if (is_multicolor) + cfg[chan_num].color_component[color_num].output_num = + led_number; + else + cfg[chan_num].chan_nr = led_number; + + return 0; +} + +static int lp5xx_parse_channel_child(struct device_node *np, + struct lp55xx_led_config *cfg, + int child_number) +{ + struct device_node *child; + int channel_color; + int num_colors = 0; + u32 color_id; + int ret; + + cfg[child_number].default_trigger = + of_get_property(np, "linux,default-trigger", NULL); + + ret = of_property_read_u32(np, "color", &channel_color); + if (ret) + channel_color = ret; + + + if (channel_color == LED_COLOR_ID_MULTI) { + for_each_child_of_node(np, child) { + ret = lp5xx_parse_common_child(child, cfg, + child_number, true, + num_colors); + if (ret) + return ret; + + ret = of_property_read_u32(child, "color", &color_id); + if (ret) + return ret; + + cfg[child_number].color_component[num_colors].color_id = + color_id; + set_bit(color_id, &cfg[child_number].available_colors); + num_colors++; + } + + cfg[child_number].num_colors = num_colors; + } else { + return lp5xx_parse_common_child(np, cfg, child_number, false, + num_colors); + } + + return 0; +} + struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, struct device_node *np) { @@ -546,6 +678,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, struct lp55xx_led_config *cfg; int num_channels; int i = 0; + int ret; pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) @@ -565,14 +698,9 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, pdata->num_channels = num_channels; for_each_child_of_node(np, child) { - cfg[i].chan_nr = i; - - of_property_read_string(child, "chan-name", &cfg[i].name); - of_property_read_u8(child, "led-cur", &cfg[i].led_current); - of_property_read_u8(child, "max-cur", &cfg[i].max_current); - cfg[i].default_trigger = - of_get_property(child, "linux,default-trigger", NULL); - + ret = lp5xx_parse_channel_child(child, cfg, i); + if (ret) + return ERR_PTR(-EINVAL); i++; } diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index 783ed5103ce5..55d420f704d1 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -12,6 +12,10 @@ #ifndef _LEDS_LP55XX_COMMON_H #define _LEDS_LP55XX_COMMON_H +#include + +#define LP55XX_MAX_GROUPED_CHAN 4 + enum lp55xx_engine_index { LP55XX_ENGINE_INVALID, LP55XX_ENGINE_1, @@ -109,6 +113,9 @@ struct lp55xx_device_config { /* access brightness register */ int (*brightness_fn)(struct lp55xx_led *led); + /* access specific brightness register */ + int (*color_intensity_fn)(struct lp55xx_led *led); + /* current setting function */ void (*set_led_current) (struct lp55xx_led *led, u8 led_current); @@ -159,6 +166,8 @@ struct lp55xx_chip { * struct lp55xx_led * @chan_nr : Channel number * @cdev : LED class device + * @mc_cdev : Multi color class device + * @color_component : Multi color LED map information * @led_current : Current setting at each led channel * @max_current : Maximun current at each led channel * @brightness : Brightness value @@ -167,6 +176,8 @@ struct lp55xx_chip { struct lp55xx_led { int chan_nr; struct led_classdev cdev; + struct led_classdev_mc mc_cdev; + struct led_mc_color_conversion color_component[LP55XX_MAX_GROUPED_CHAN]; u8 led_current; u8 max_current; u8 brightness; diff --git a/include/linux/platform_data/leds-lp55xx.h b/include/linux/platform_data/leds-lp55xx.h index 96a787100fda..1e7a25ed9a87 100644 --- a/include/linux/platform_data/leds-lp55xx.h +++ b/include/linux/platform_data/leds-lp55xx.h @@ -12,6 +12,8 @@ #ifndef _LEDS_LP55XX_H #define _LEDS_LP55XX_H +#include + /* Clock configuration */ #define LP55XX_CLOCK_AUTO 0 #define LP55XX_CLOCK_INT 1 @@ -23,6 +25,9 @@ struct lp55xx_led_config { u8 chan_nr; u8 led_current; /* mA x10, 0 if led is not connected */ u8 max_current; + int num_colors; + unsigned long available_colors; + struct led_mc_color_conversion color_component[LED_COLOR_ID_MAX]; }; struct lp55xx_predef_pattern { From patchwork Tue Oct 8 20:47: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: 175570 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6206913ill; Tue, 8 Oct 2019 13:49:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfVijeoK3Fef91OeafmGUOi90n1Nuh9TePEC8qsASB+ySR5/dixyeStiy+zFuRKtg/Em2y X-Received: by 2002:a05:6402:150a:: with SMTP id f10mr35037031edw.110.1570567743797; Tue, 08 Oct 2019 13:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570567743; cv=none; d=google.com; s=arc-20160816; b=umuEcdkAeFSi7gC4Ma/BPI7l9Aq8IWWDkVmm73PPJX8BBgkZDDaHZkpeAxkV2frhad ihamiGDLx24ZeZVenCLBPMoWgkrzAi5RHgRQNGa3UosKawHl32OwOca8BrWpn0V+xC+M 07eoRdtePUsTf/ufwSq3IpgSx0YQ9A3DnirphEjit4niTWl4qxYb1oyvRoAOrn08mXzk PINJrZ+E9BkfB8atafgQ8uFf91YaZmdJy7HPNFGg1C72Fux0KS7pmdPQuJSyXMZjV+Ys nr2S3R+CAtkpLdiqnRHBPwTgIN6E9fz1zZx0q14729if/SCF4BDE8nSiqLIIH7UcsVAI AOaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t6ZN8MsoaN09y80TS8iaHGApS9NVGVswvlApmF+sfMA=; b=nshZRsz8x0X2smaqWDBudFrIzMNagLNQnvR8ZQTWuh3rU6Jvisu5GvJlE/+heQyof4 Jt+ohrWufuCXxz6K/Ei35wAL1rq01yV0vfft4+ksydtGugK6Cw+mszlApV4M9IpJqUqG XLM9lB98DtWidrlkuTiNB7rd4AQfAnkwUX2dvja6ofi3MYT/1eTVYW7BqUmc9T5bD9EN Ga//rIXlLWnpRBCL0t83RyC97QTqJdUjepGzCOF/00ygyjwApIOExuI1zlIZHGVe2QV/ 3Gvgnn10Cs3wwMus1TDMqndZoSeX91TX4FolifYAxHWL/LyhioQVtsEsynLttOEanNiO zOdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="LT/nDEAR"; 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 u8si115726edq.84.2019.10.08.13.49.03; Tue, 08 Oct 2019 13:49:03 -0700 (PDT) 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="LT/nDEAR"; 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 S1731216AbfJHUtC (ORCPT + 1 other); Tue, 8 Oct 2019 16:49:02 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:43378 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731122AbfJHUsY (ORCPT ); Tue, 8 Oct 2019 16:48:24 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x98KmMx3092492; Tue, 8 Oct 2019 15:48:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570567702; bh=t6ZN8MsoaN09y80TS8iaHGApS9NVGVswvlApmF+sfMA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=LT/nDEARqicZ77dsH+MQKji9VW+iKHwrXlQKKww9AVG4lMcDqWjf/wBJEhgYRhRfG A/S8P7vLAZaE48wGe9l55v6299N0ZcYVGwvsMQnxneHoutiN9EljwEZXzdtSopf0Lu e1e/i3NvWGD9/SInAnqkcnoC8jQNZn1icC0H0p0s= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id x98KmM43110747; Tue, 8 Oct 2019 15:48:22 -0500 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 8 Oct 2019 15:48:19 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 8 Oct 2019 15:48:21 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x98KmLgX066693; Tue, 8 Oct 2019 15:48:21 -0500 From: Dan Murphy To: , CC: , , Dan Murphy Subject: [PATCH v11 13/16] leds: lp5523: Update the lp5523 code to add intensity function Date: Tue, 8 Oct 2019 15:47:57 -0500 Message-ID: <20191008204800.19870-14-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20191008204800.19870-1-dmurphy@ti.com> References: <20191008204800.19870-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 Add the intensity function call back to support the multicolor framework. This function allows setting a specific brightness on a specific channel. Signed-off-by: Dan Murphy --- drivers/leds/leds-lp5523.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) -- 2.22.0.214.g8dca754b1e diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index d0b931a136b9..5d6002e4d657 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -791,6 +791,25 @@ static ssize_t store_master_fader_leds(struct device *dev, return ret; } +static int lp5523_led_intensity(struct lp55xx_led *led) +{ + struct lp55xx_chip *chip = led->chip; + int ret; + int i; + + mutex_lock(&chip->lock); + for (i = 0; i < led->mc_cdev.num_leds; i++) { + ret = lp55xx_write(chip, + LP5523_REG_LED_PWM_BASE + + led->color_component[i].output_num, + led->color_component[i].brightness); + if (ret) + break; + } + mutex_unlock(&chip->lock); + return ret; +} + static int lp5523_led_brightness(struct lp55xx_led *led) { struct lp55xx_chip *chip = led->chip; @@ -857,6 +876,7 @@ static struct lp55xx_device_config lp5523_cfg = { .max_channel = LP5523_MAX_LEDS, .post_init_device = lp5523_post_init_device, .brightness_fn = lp5523_led_brightness, + .color_intensity_fn = lp5523_led_intensity, .set_led_current = lp5523_set_led_current, .firmware_cb = lp5523_firmware_loaded, .run_engine = lp5523_run_engine, From patchwork Tue Oct 8 20:47: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: 175567 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6206821ill; Tue, 8 Oct 2019 13:48:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXClQw+VxfNMtNuScP9Q6YFOBrxcxAWRWGN3tPfVbXOA32Il9xS6YfEnS9MmDUmBEPPNK+ X-Received: by 2002:a50:baab:: with SMTP id x40mr36034703ede.60.1570567736730; Tue, 08 Oct 2019 13:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570567736; cv=none; d=google.com; s=arc-20160816; b=hFuozCQVd198dlqJxM9+2J07UljkeXBkWdb2jg1kTfQVL6P1Uz/SB73eBVfMGqns75 3E08mhxyrfpUds1kDocVwK2rmkfoZgwJ7Q5IDwVQfDx0RllBYxzcxaZSKKQrLkyVJeLK yXEhWQx3zFCsYHyiE1VL2UYF8DGXglUfjUlZYuisQhihIQHEZK0bPzPQWblcj7uxESYl exiE434SqM2N27NAKBf7dNO+gq0/TS07GgKPuKoaHeg4+FZ63vbSfJ2rsaEgFDi8VsI4 Ym43TnRf+lzSHMkvVNDdRywvy7HnVm/aARj8eb8HO40+vxaWMc0Qp+clAteIGndmOHLn FzNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DWlAPkPyGPLMlgt95vLmSAWY5AQ+1wT9MtJDSpag9us=; b=FPczPJirgqg6QfEa56wmuNAqAbxCQdvio6JP3c/Zj5sBpWR8i6nJfMpGdcV2SPx5+5 LUBtwcLOCY8w/NWRXQoGUDmAdXqHVsWZr5MucdJqVlCXD+KSLFPxV9osNmG+UPOpxwYx JD3NidcSEEVzeaygO7JKmCB6p6TlxCsxy0FQtTP6dib8OH4+ElKpmSYIz777NDC747zi utN7VN88u5BB3fgGTtBAl5Lm5NiMvVQDqpcWLiuqU3E24exVhicAseaDaq8sf9h2lvU0 rKA4+vtU6BlZ5mA8+ex5we491RO034jS0gXrvN4FwJmlYOQxIYrgHW8E26lp/NaFnYnV aTFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=LYGHrPTn; 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 u8si115726edq.84.2019.10.08.13.48.56; Tue, 08 Oct 2019 13:48:56 -0700 (PDT) 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=LYGHrPTn; 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 S1731051AbfJHUsz (ORCPT + 1 other); Tue, 8 Oct 2019 16:48:55 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:45800 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731127AbfJHUsY (ORCPT ); Tue, 8 Oct 2019 16:48:24 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x98KmMlk097369; Tue, 8 Oct 2019 15:48:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570567702; bh=DWlAPkPyGPLMlgt95vLmSAWY5AQ+1wT9MtJDSpag9us=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=LYGHrPTnNtKtCzDRJsLgICNdgnZSZ9b3wbgwf4ovaCzoKPWOfo8bj1lVo0LmeGJrY mD7tQENm72502kHdhA2hUfm+8UX1uhx0QeycmSAgom+KqTwwpkSfMOwCjRjOCFr645 YFVu9KB65NL4mUijJsGkLvNS+4Ib9yGhv73go6qk= 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 x98KmM2T042373 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 8 Oct 2019 15:48:22 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) 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.1713.5; Tue, 8 Oct 2019 15:48:19 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 8 Oct 2019 15:48:22 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id x98KmLSN073126; Tue, 8 Oct 2019 15:48:21 -0500 From: Dan Murphy To: , CC: , , Dan Murphy Subject: [PATCH v11 14/16] leds: lp5521: Add multicolor framework intensity support Date: Tue, 8 Oct 2019 15:47:58 -0500 Message-ID: <20191008204800.19870-15-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20191008204800.19870-1-dmurphy@ti.com> References: <20191008204800.19870-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 Add the intensity function call back to support the multicolor framework. This function allows setting a specific brightness on a specific channel. Signed-off-by: Dan Murphy --- drivers/leds/leds-lp5521.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) -- 2.22.0.214.g8dca754b1e diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 6f0272249dc8..05731f405c9a 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -349,6 +349,25 @@ static int lp5521_run_selftest(struct lp55xx_chip *chip, char *buf) return 0; } +static int lp5521_led_intensity(struct lp55xx_led *led) +{ + struct lp55xx_chip *chip = led->chip; + int ret; + int i; + + mutex_lock(&chip->lock); + for (i = 0; i < led->mc_cdev.num_leds; i++) { + ret = lp55xx_write(chip, + LP5521_REG_LED_PWM_BASE + + led->color_component[i].output_num, + led->color_component[i].brightness); + if (ret) + break; + } + mutex_unlock(&chip->lock); + return ret; +} + static int lp5521_led_brightness(struct lp55xx_led *led) { struct lp55xx_chip *chip = led->chip; @@ -490,6 +509,7 @@ static struct lp55xx_device_config lp5521_cfg = { .max_channel = LP5521_MAX_LEDS, .post_init_device = lp5521_post_init_device, .brightness_fn = lp5521_led_brightness, + .color_intensity_fn = lp5521_led_intensity, .set_led_current = lp5521_set_led_current, .firmware_cb = lp5521_firmware_loaded, .run_engine = lp5521_run_engine, From patchwork Tue Oct 8 20:47: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: 175560 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6206420ill; Tue, 8 Oct 2019 13:48:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxf2yYtkg9G63EtF3WAOSEvESqfzijmQtBqJ2dYKWE9x9nGu+2O0MLkeNxeUJNQRM8C9/m4 X-Received: by 2002:a50:fa98:: with SMTP id w24mr36277701edr.47.1570567711547; Tue, 08 Oct 2019 13:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570567711; cv=none; d=google.com; s=arc-20160816; b=ZsaNg3uMACCRINN+DdIEWPOg5ktdcFA/EYCHkTt8bzEDFS6rTH7XY1PjNJ/BhvbuYi KXq0tPbqwcuLe+16II0Wh6m5e82J3O3/X5cdhqAu+vb6FXNyKPnDMm+yx0qJaEChB1lT p84hqD0kjBP3XkO/bajoNCgvBbN4BdXBE2DiW7P3F+6g9AKsWPyRaisHkY05QlRPPXPx Lz2+k+9NxabQcnxKlWHay0W+efnQl4e/tk0E3r4/hCSqIL8LpxzltVCwL9i5xzgAAmaB b4yc2PIAKjHM3OJH/YQTvzUwiu3wmrIJHnkLVFuH8D66l9pTFCO4ydJnNr7u8FaQwQ3P ESzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z4PZA7STOJQqwmrnX0Trv7XrUhkqugQl6U0wq3z09nk=; b=JmfXwYHRkoEI37nx/s9E6RTK3IZvmF8j+/DgKuhLm2S8ctRcL3TMWAtfFbMs0C4/DE i7zoUcXTxlWvMxeuKZlCgmWTI24wLiLKdhhyuyHpBUQYbOiLU44ApEgpmwU0bcL+WbbY C3DCcp1VQMCA9piNMHkXG5hcmWm2CBf5XtKkkvHTQdKnRqLVyxPryx5I5ruLGJBInrgm SrutOqGbR2k/9oA/mCMbSGjD28nrRNBAZe/atC5uYFObw4SDb2aMYTYpa3H9kaM9nfUV geQl7smtIAf8UqDVjIuD3Syh8TeKUX1vpy6X2rmzocwtl1oR8RATvtRUaha0CzgG3oPZ 41HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=pbPK9HYV; 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 s27si115462edm.226.2019.10.08.13.48.31; Tue, 08 Oct 2019 13:48:31 -0700 (PDT) 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=pbPK9HYV; 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 S1731175AbfJHUs1 (ORCPT + 1 other); Tue, 8 Oct 2019 16:48:27 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:45052 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731135AbfJHUs0 (ORCPT ); Tue, 8 Oct 2019 16:48:26 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x98KmMuw092708; Tue, 8 Oct 2019 15:48:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570567702; bh=Z4PZA7STOJQqwmrnX0Trv7XrUhkqugQl6U0wq3z09nk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=pbPK9HYVhsRW+ivkPANEXcP99CLpykzuerIIoS4FJ7p2yi3fO7a4NcV9B6NWSyhdP kenZXCPnl1GyrNLKmuQ5RQXniZLpMep7vf3AK/DclEtamSoI+8mt60XdMe54ehZJnm rCFFxS0jw8aBQ600xmT8xrCarp5mzI8u6YpmYiYs= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x98KmM1O062222 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 8 Oct 2019 15:48:22 -0500 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 8 Oct 2019 15:48:19 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 8 Oct 2019 15:48:22 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x98KmMqq095766; Tue, 8 Oct 2019 15:48:22 -0500 From: Dan Murphy To: , CC: , , Dan Murphy Subject: [PATCH v11 15/16] leds: lp55xx: Fix checkpatch file permissions issues Date: Tue, 8 Oct 2019 15:47:59 -0500 Message-ID: <20191008204800.19870-16-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20191008204800.19870-1-dmurphy@ti.com> References: <20191008204800.19870-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 Fix the checkpatch warnings for the use of the file permission macros. In converting the file permissions to the DEVICE_ATTR_XX macros the call back function names needed to be updated within the code. This means that the lp55xx_ needed to be dropped in the name to keep in harmony with the ABI documentation. Signed-off-by: Dan Murphy --- drivers/leds/leds-lp55xx-common.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) -- 2.22.0.214.g8dca754b1e diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 85629f836082..fc5224108c64 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -78,7 +78,7 @@ static int lp55xx_post_init_device(struct lp55xx_chip *chip) return cfg->post_init_device(chip); } -static ssize_t lp55xx_show_current(struct device *dev, +static ssize_t led_current_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -87,7 +87,7 @@ static ssize_t lp55xx_show_current(struct device *dev, return scnprintf(buf, PAGE_SIZE, "%d\n", led->led_current); } -static ssize_t lp55xx_store_current(struct device *dev, +static ssize_t led_current_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -111,7 +111,7 @@ static ssize_t lp55xx_store_current(struct device *dev, return len; } -static ssize_t lp55xx_show_max_current(struct device *dev, +static ssize_t max_current_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -120,9 +120,8 @@ static ssize_t lp55xx_show_max_current(struct device *dev, return scnprintf(buf, PAGE_SIZE, "%d\n", led->max_current); } -static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, lp55xx_show_current, - lp55xx_store_current); -static DEVICE_ATTR(max_current, S_IRUGO , lp55xx_show_max_current, NULL); +static DEVICE_ATTR_RW(led_current); +static DEVICE_ATTR_RO(max_current); static struct attribute *lp55xx_led_attrs[] = { &dev_attr_led_current.attr, @@ -282,7 +281,7 @@ static int lp55xx_request_firmware(struct lp55xx_chip *chip) GFP_KERNEL, chip, lp55xx_firmware_loaded); } -static ssize_t lp55xx_show_engine_select(struct device *dev, +static ssize_t select_engine_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -292,7 +291,7 @@ static ssize_t lp55xx_show_engine_select(struct device *dev, return sprintf(buf, "%d\n", chip->engine_idx); } -static ssize_t lp55xx_store_engine_select(struct device *dev, +static ssize_t select_engine_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -334,7 +333,7 @@ static inline void lp55xx_run_engine(struct lp55xx_chip *chip, bool start) chip->cfg->run_engine(chip, start); } -static ssize_t lp55xx_store_engine_run(struct device *dev, +static ssize_t run_engine_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -359,9 +358,8 @@ static ssize_t lp55xx_store_engine_run(struct device *dev, return len; } -static DEVICE_ATTR(select_engine, S_IRUGO | S_IWUSR, - lp55xx_show_engine_select, lp55xx_store_engine_select); -static DEVICE_ATTR(run_engine, S_IWUSR, NULL, lp55xx_store_engine_run); +static DEVICE_ATTR_RW(select_engine); +static DEVICE_ATTR_WO(run_engine); static struct attribute *lp55xx_engine_attributes[] = { &dev_attr_select_engine.attr, From patchwork Tue Oct 8 20:48:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Murphy X-Patchwork-Id: 175565 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6206718ill; Tue, 8 Oct 2019 13:48:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpfWg2WW4r/2LiRHC/27z9zP0lRZbK0RbKp2NYxuWCz8pRfGrkoJGtjjAowBaO0xb6eNNZ X-Received: by 2002:a50:eac4:: with SMTP id u4mr36273230edp.36.1570567729498; Tue, 08 Oct 2019 13:48:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570567729; cv=none; d=google.com; s=arc-20160816; b=OuRModY05SmfwqR/9K8fFXs1TEi6o1n7YNEUQe0Hwz91T2RKLDCoVS+HgvIaI8nAbL M/vx+F2FzEzjaqoOwgqpI6IoueYOi+TcmRQZZ4UIs1jV/6go9Q5Xgr5oMmu0fvbzPhnm KaOXgaYTweke/xBzeJDAFv43+ZSP4p5Lj/lS1gZXUotas6VwgPS+6mXyy5GSE/2ej3Wq WqgEfKrSgFQPQZg7/fuvd0n3a5uOnvvIvv7rU8vNF/plShooN7ElaqBwasLMquJ0IuO+ RhhjBaFZGNg6jrcAsgDHOHTBF4R/CeZTxvtbh7IEa/VRNYzVVi2/Xxu0ctUy0t+n/Af1 Wv+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nbVVUZ3Qhf2Oih+Vzfzrpge7klNd8/7wkUn5sxV3aTo=; b=PFF82+aDhBQUCR++nsEtvGBrL1kwhXX5jS4Sw0lkidVz525gPmdQX4hYwldy4e4HQ8 2NGVtqZXcWdlxrW09ASqPluGLvvrhbQwPwer9cCqUz9gTMHxo4sRI68NL6r8K4gwIb6h gHbV8cRfhDGKshM9b1qNPw6fiXRckbjkT7ZxEDMoBd37gl+BWFopln92ZeHOTdvET5Cn 3ydwnc7tNq4P0WHXMuelDF0Xs+pM8zXAhT19dY+z7fejXeFlhG6p6adcBZhLC68qwq5R lw4e5szIXtj3+CAYOo12yLe43GMxDsJVZY6A7x6yu6bNUnjUe7tidGhAm/030zRRNx6l EEnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=OmHvTmqp; 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 l22si105336edq.174.2019.10.08.13.48.49; Tue, 08 Oct 2019 13:48:49 -0700 (PDT) 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=OmHvTmqp; 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 S1731261AbfJHUst (ORCPT + 1 other); Tue, 8 Oct 2019 16:48:49 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:43492 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731134AbfJHUsZ (ORCPT ); Tue, 8 Oct 2019 16:48:25 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x98KmMpG114907; Tue, 8 Oct 2019 15:48:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570567702; bh=nbVVUZ3Qhf2Oih+Vzfzrpge7klNd8/7wkUn5sxV3aTo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=OmHvTmqpYXk3YehzINLxlEUsn8Y8eJXtOKxzN8ef+hzdC2q+OWNj4EL25/9h8LkH5 F159exaMX4q3nMIFTFvAA6+CDV5k1G5RwZYSKeOYrm+V2R3OLWrUX6UE5ekzV6Ypad yalNbSB+ghNpLKE7A7icLFl6twNL5iJFqcL9u6Bc= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x98KmMih027727 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 8 Oct 2019 15:48:22 -0500 Received: from DFLE107.ent.ti.com (10.64.6.28) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 8 Oct 2019 15:48:22 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 8 Oct 2019 15:48:19 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x98KmMXt066700; Tue, 8 Oct 2019 15:48:22 -0500 From: Dan Murphy To: , CC: , , Dan Murphy Subject: [PATCH v11 16/16] leds: lp5523: Fix checkpatch issues in the code Date: Tue, 8 Oct 2019 15:48:00 -0500 Message-ID: <20191008204800.19870-17-dmurphy@ti.com> X-Mailer: git-send-email 2.22.0.214.g8dca754b1e In-Reply-To: <20191008204800.19870-1-dmurphy@ti.com> References: <20191008204800.19870-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 Fix checkpatch errors and warnings for the LP5523.c device driver. Signed-off-by: Dan Murphy --- drivers/leds/leds-lp5523.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) -- 2.22.0.214.g8dca754b1e diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 5d6002e4d657..3c7c2e68e137 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -23,13 +23,13 @@ #define LP5523_PROGRAM_LENGTH 32 /* bytes */ /* Memory is used like this: - 0x00 engine 1 program - 0x10 engine 2 program - 0x20 engine 3 program - 0x30 engine 1 muxing info - 0x40 engine 2 muxing info - 0x50 engine 3 muxing info -*/ + * 0x00 engine 1 program + * 0x10 engine 2 program + * 0x20 engine 3 program + * 0x30 engine 1 muxing info + * 0x40 engine 2 muxing info + * 0x50 engine 3 muxing info + */ #define LP5523_MAX_LEDS 9 /* Registers */ @@ -326,7 +326,7 @@ static int lp5523_update_program_memory(struct lp55xx_chip *chip, const u8 *data, size_t size) { u8 pattern[LP5523_PROGRAM_LENGTH] = {0}; - unsigned cmd; + unsigned int cmd; char c[3]; int nrchars; int ret; @@ -468,6 +468,7 @@ static int lp5523_mux_parse(const char *buf, u16 *mux, size_t len) static void lp5523_mux_to_array(u16 led_mux, char *array) { int i, pos = 0; + for (i = 0; i < LP5523_MAX_LEDS; i++) pos += sprintf(array + pos, "%x", LED_ACTIVE(led_mux, i)); @@ -506,7 +507,7 @@ static int lp5523_load_mux(struct lp55xx_chip *chip, u16 mux, int nr) if (ret) return ret; - ret = lp55xx_write(chip, LP5523_REG_PROG_MEM , (u8)(mux >> 8)); + ret = lp55xx_write(chip, LP5523_REG_PROG_MEM, (u8)(mux >> 8)); if (ret) return ret;