From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3BA2CCA482 for ; Tue, 12 Jul 2022 10:09:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbiGLKJb (ORCPT ); Tue, 12 Jul 2022 06:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232329AbiGLKJZ (ORCPT ); Tue, 12 Jul 2022 06:09:25 -0400 Received: from msg-4.mailo.com (ip-15.mailobj.net [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F24AAB7C1; Tue, 12 Jul 2022 03:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620538; bh=Dp2mRQO8dxIh3vCWhuPurEDJ8gsjkJ7IKTB/TsgnvYs=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=XtKDvcv+Gy6NF+/XudAD1oBjV3K4LHTzqyEq4qUrXw0I4xNsysPwsmRBh1wHlLxPR 5EJlOlMO82ciI6XLw60xf6nr5iw0wD0R1AG86w08CzNaukGkCzm7SUnNf1t8g6QokX gs+jl1s0HPBSJVW6UpclCGUfM2EGcwFeCFmemdwc= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:08:58 +0200 (CEST) X-EA-Auth: 2cXlOqzqFt+sZNALTKZX+0wDnBy9K3GwWSXD4u/Qmsxzh2ZIBBmKYxP1gw7N5fw4mFdiAc9U+fFlbIk5Bgd0SrTT74aw8RkU/RjO5kvFAZw= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com, Rob Herring Subject: [PATCH v5 01/12] dt-bindings: leds: Convert is31fl319x to dtschema Date: Tue, 12 Jul 2022 12:08:27 +0200 Message-Id: <20220712100841.1538395-2-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert leds-is31fl319x.txt to dtschema. Set license to the one recommended by DT project and set myself as maintainer. Reviewed-by: Rob Herring Signed-off-by: Vincent Knecht --- v3: - changed license back to (GPL-2.0-only OR BSD-2-Clause) and maintainer to myself, with Nikolaus agreement --- .../bindings/leds/issi,is31fl319x.yaml | 113 ++++++++++++++++++ .../bindings/leds/leds-is31fl319x.txt | 61 ---------- 2 files changed, 113 insertions(+), 61 deletions(-) create mode 100644 Documentation/devicetree/bindings/leds/issi,is31fl319x.= yaml delete mode 100644 Documentation/devicetree/bindings/leds/leds-is31fl319x.= txt diff --git a/Documentation/devicetree/bindings/leds/issi,is31fl319x.yaml b/= Documentation/devicetree/bindings/leds/issi,is31fl319x.yaml new file mode 100644 index 000000000000..0d684aeeb8cd --- /dev/null +++ b/Documentation/devicetree/bindings/leds/issi,is31fl319x.yaml @@ -0,0 +1,113 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/issi,is31fl319x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ISSI LED controllers bindings for IS31FL319{0,1,3,6,9} + +maintainers: + - Vincent Knecht + +description: | + The IS31FL319X are LED controllers with I2C interface. + Previously known as Si-En SN319{0,1,3,6,9}. + + For more product information please see the links below: + https://lumissil.com/assets/pdf/core/IS31FL3190_DS.pdf + https://lumissil.com/assets/pdf/core/IS31FL3191_DS.pdf + https://lumissil.com/assets/pdf/core/IS31FL3193_DS.pdf + https://lumissil.com/assets/pdf/core/IS31FL3196_DS.pdf + https://lumissil.com/assets/pdf/core/IS31FL3199_DS.pdf + +properties: + compatible: + enum: + - issi,is31fl3190 + - issi,is31fl3191 + - issi,is31fl3193 + - issi,is31fl3196 + - issi,is31fl3199 + - si-en,sn3199 + + reg: + maxItems: 1 + + shutdown-gpios: + maxItems: 1 + description: GPIO attached to the SDB pin. + + audio-gain-db: + $ref: /schemas/types.yaml#/definitions/uint32 + default: 0 + description: Audio gain selection for external analog modulation input. + enum: [0, 3, 6, 9, 12, 15, 18, 21] + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^led@[1-9]$": + type: object + $ref: common.yaml# + + properties: + reg: + description: Index of the LED. + minimum: 1 + maximum: 9 + + led-max-microamp: + default: 20000 + enum: [5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000] + description: + Note that a driver will take the lowest of all LED limits + since the chip has a single global setting. The lowest value + will be chosen due to the PWM specificity, where lower + brightness is achieved by reducing the duty-cycle of pulses + and not the current, which will always have its peak value + equal to led-max-microamp. + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + #include + + i2c0 { + #address-cells =3D <1>; + #size-cells =3D <0>; + + led-controller@65 { + compatible =3D "issi,is31fl3196"; + reg =3D <0x65>; + #address-cells =3D <1>; + #size-cells =3D <0>; + + shutdown-gpios =3D <&gpio0 11 GPIO_ACTIVE_HIGH>; + + led@1 { + reg =3D <1>; + label =3D "red:aux"; + led-max-microamp =3D <10000>; + }; + + led@5 { + reg =3D <5>; + label =3D "green:power"; + linux,default-trigger =3D "default-on"; + }; + }; + }; +... + diff --git a/Documentation/devicetree/bindings/leds/leds-is31fl319x.txt b/D= ocumentation/devicetree/bindings/leds/leds-is31fl319x.txt deleted file mode 100644 index 676d43ec8169..000000000000 --- a/Documentation/devicetree/bindings/leds/leds-is31fl319x.txt +++ /dev/null @@ -1,61 +0,0 @@ -LEDs connected to is31fl319x LED controller chip - -Required properties: -- compatible : Should be any of - "issi,is31fl3190" - "issi,is31fl3191" - "issi,is31fl3193" - "issi,is31fl3196" - "issi,is31fl3199" - "si-en,sn3199". -- #address-cells: Must be 1. -- #size-cells: Must be 0. -- reg: 0x64, 0x65, 0x66, or 0x67. - -Optional properties: -- audio-gain-db : audio gain selection for external analog modulation inpu= t. - Valid values: 0 - 21, step by 3 (rounded down) - Default: 0 -- shutdown-gpios : Specifier of the GPIO connected to SDB pin of the chip. - -Each led is represented as a sub-node of the issi,is31fl319x device. -There can be less leds subnodes than the chip can support but not more. - -Required led sub-node properties: -- reg : number of LED line - Valid values: 1 - number of leds supported by the chip variant. - -Optional led sub-node properties: -- label : see Documentation/devicetree/bindings/leds/common.txt. -- linux,default-trigger : - see Documentation/devicetree/bindings/leds/common.txt. -- led-max-microamp : (optional) - Valid values: 5000 - 40000, step by 5000 (rounded down) - Default: 20000 (20 mA) - Note: a driver will take the lowest of all led limits since the - chip has a single global setting. The lowest value will be chosen - due to the PWM specificity, where lower brightness is achieved - by reducing the dury-cycle of pulses and not the current, which - will always have its peak value equal to led-max-microamp. - -Examples: - -fancy_leds: leds@65 { - compatible =3D "issi,is31fl3196"; - #address-cells =3D <1>; - #size-cells =3D <0>; - reg =3D <0x65>; - shutdown-gpios =3D <&gpio0 11 GPIO_ACTIVE_HIGH>; - - red_aux: led@1 { - label =3D "red:aux"; - reg =3D <1>; - led-max-microamp =3D <10000>; - }; - - green_power: led@5 { - label =3D "green:power"; - reg =3D <5>; - linux,default-trigger =3D "default-on"; - }; -}; --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EF93CCA48A for ; Tue, 12 Jul 2022 10:09:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232859AbiGLKJ1 (ORCPT ); Tue, 12 Jul 2022 06:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232136AbiGLKJZ (ORCPT ); Tue, 12 Jul 2022 06:09:25 -0400 Received: from msg-4.mailo.com (ip-15.mailobj.net [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A657AB7CD; Tue, 12 Jul 2022 03:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620541; bh=Obre5IIa+wQZbNnEgE6NenQzK6E616sCX+q9jkhLXDk=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=dcia4nptDEadJ6VnE9bxiXu8IaBt9Sssxcw0jQ0r1NodilfmB/SvTMK58BCGgJDfY qOXZyRg9k3fW8nm38CzvGVDKafz/38/bS7i7n4Gz8nxgqNVyux9IOCJMG4ag4/kyNT mT2rcgTO7GW0jI1zZiT7+2hz6vub/8PkgXg1hqGI= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:01 +0200 (CEST) X-EA-Auth: W4/N4DzbLXrI9f1mQEmUFubnI1GrnUsm1t2VBR7btUs5J0A7MCDUxNVTZsfweTGHnqfFZvcLtbGaEr5PB9ZThZC3PHpWesKAtHducO/ayIw= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com, Rob Herring Subject: [PATCH v5 02/12] dt-bindings: leds: is31fl319x: Document variants specificities Date: Tue, 12 Jul 2022 12:08:28 +0200 Message-Id: <20220712100841.1538395-3-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add si-en compatibles for all chip variants and add conditionals depending on compatibles to document variants specs: - possible reg addresses - whether audio-gain-db is supported or not - maximum number of leds - led-max-microamp values Reviewed-by: Rob Herring Signed-off-by: Vincent Knecht --- .../bindings/leds/issi,is31fl319x.yaml | 84 ++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/leds/issi,is31fl319x.yaml b/= Documentation/devicetree/bindings/leds/issi,is31fl319x.yaml index 0d684aeeb8cd..940333f2d69c 100644 --- a/Documentation/devicetree/bindings/leds/issi,is31fl319x.yaml +++ b/Documentation/devicetree/bindings/leds/issi,is31fl319x.yaml @@ -28,6 +28,10 @@ properties: - issi,is31fl3193 - issi,is31fl3196 - issi,is31fl3199 + - si-en,sn3190 + - si-en,sn3191 + - si-en,sn3193 + - si-en,sn3196 - si-en,sn3199 =20 reg: @@ -61,8 +65,6 @@ patternProperties: maximum: 9 =20 led-max-microamp: - default: 20000 - enum: [5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000] description: Note that a driver will take the lowest of all LED limits since the chip has a single global setting. The lowest value @@ -71,6 +73,84 @@ patternProperties: and not the current, which will always have its peak value equal to led-max-microamp. =20 +allOf: + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3190 + - issi,is31fl3191 + - issi,is31fl3193 + - si-en,sn3190 + - si-en,sn3191 + - si-en,sn3193 + then: + properties: + reg: + enum: [0x68, 0x69, 0x6a, 0x6b] + + audio-gain-db: false + + patternProperties: + "^led@[1-9]$": + properties: + led-max-microamp: + default: 42000 + enum: [5000, 10000, 17500, 30000, 42000] + else: + properties: + reg: + enum: [0x64, 0x65, 0x66, 0x67] + + patternProperties: + "^led@[1-9]$": + properties: + led-max-microamp: + default: 20000 + enum: [5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000] + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3190 + - issi,is31fl3191 + - si-en,sn3190 + - si-en,sn3191 + then: + patternProperties: + "^led@[1-9]$": + properties: + reg: + maximum: 1 + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3193 + - si-en,sn3193 + then: + patternProperties: + "^led@[1-9]$": + properties: + reg: + maximum: 3 + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3196 + - si-en,sn3196 + then: + patternProperties: + "^led@[1-9]$": + properties: + reg: + maximum: 6 + required: - compatible - reg --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1081CCCA480 for ; Tue, 12 Jul 2022 10:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232865AbiGLKJa (ORCPT ); Tue, 12 Jul 2022 06:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbiGLKJZ (ORCPT ); Tue, 12 Jul 2022 06:09:25 -0400 Received: from msg-4.mailo.com (ip-15.mailobj.net [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A706AB7CF; Tue, 12 Jul 2022 03:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620544; bh=OnG6BofeKIcOc3qBoOMQcWAYSD8krtB0UZjVBxSp6Og=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=eQIKEU8Y2ssFLDbSj2PTojKLvrVGvVgtvAYgmiUbAGSs/pFicy/g2XBzyE9R0cg79 epSnalXGNM1FIenUKHf4C8Bu2HWs3RM64GgnG70t2l2Nap/4kzg1ADkbCsMwiJuU3o 7J9HZgI4tH+7u2HvchNpd6nbvLv9NAbNBzkjVO3c= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:04 +0200 (CEST) X-EA-Auth: HWMJJynSWi7IDzYSiMC0E/O+A/a4+aXlB4fTdTMNCxarogNwnAHdC29l9Gu8FCXVbfEOVyf/Y0jcJRF8p9nvlRk+KycnqTeHrF47MqrL3Fo= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com Subject: [PATCH v5 03/12] leds: is31fl319x: Add missing si-en compatibles Date: Tue, 12 Jul 2022 12:08:29 +0200 Message-Id: <20220712100841.1538395-4-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add si-en compatibles for all chip variants. Signed-off-by: Vincent Knecht --- drivers/leds/leds-is31fl319x.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 4161b9dd7e48..0db5d4988131 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -102,6 +102,10 @@ static const struct of_device_id of_is31fl319x_match[]= =3D { { .compatible =3D "issi,is31fl3193", .data =3D &is31fl3193_cdef, }, { .compatible =3D "issi,is31fl3196", .data =3D &is31fl3196_cdef, }, { .compatible =3D "issi,is31fl3199", .data =3D &is31fl3199_cdef, }, + { .compatible =3D "si-en,sn3190", .data =3D &is31fl3190_cdef, }, + { .compatible =3D "si-en,sn3191", .data =3D &is31fl3190_cdef, }, + { .compatible =3D "si-en,sn3193", .data =3D &is31fl3193_cdef, }, + { .compatible =3D "si-en,sn3196", .data =3D &is31fl3196_cdef, }, { .compatible =3D "si-en,sn3199", .data =3D &is31fl3199_cdef, }, { } }; @@ -432,6 +436,10 @@ static const struct i2c_device_id is31fl319x_id[] =3D { { "is31fl3193" }, { "is31fl3196" }, { "is31fl3199" }, + { "sn3190" }, + { "sn3191" }, + { "sn3193" }, + { "sn3196" }, { "sn3199" }, {}, }; --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1E08C43334 for ; Tue, 12 Jul 2022 10:09:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232890AbiGLKJh (ORCPT ); Tue, 12 Jul 2022 06:09:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232694AbiGLKJZ (ORCPT ); Tue, 12 Jul 2022 06:09:25 -0400 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88067AB7D1; Tue, 12 Jul 2022 03:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620547; bh=pLcUMgv/dXKmKRrmwVdSVuZEeAXknvxXhBkD5ccNHBs=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=GFFn/D4TiqL+O5FFJ3XIHtbXTh+53QAaxcudSXwt86z2olcdjh3r7lozRYry3/k1C 6Ft1+BEnYz36GybfRpqu7JzWVhSPATw9hAjfXepVPFKX43v5jcKjSp4Kxly9r4Pwze 4YSkNRqWegin2zwpAu5nEqqCYhRMSS5F4i1+9Chg= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:07 +0200 (CEST) X-EA-Auth: AcqZU9er+ewwynG6wKXuQMboLe9LMVJOiJZIkBWdadY88NWWwNPLSJSSN41PcQsbG/T0bKV+QRD7y4tqO5n8CX/Z0f85J252qso4l9qOEyk= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com Subject: [PATCH v5 04/12] leds: is31fl319x: Use non-wildcard names for vars, structs and defines Date: Tue, 12 Jul 2022 12:08:30 +0200 Message-Id: <20220712100841.1538395-5-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to add real support for is31fl3190, is31fl3191 and is31fl3193, rename variant-dependent elements to not use 319X where needed. 3190 suffix is used for is31fl3190, is31fl3191 and is31fl3193 circuits. 3196 suffix is used for is31fl3196 and is31fl3199. Those two groups have different register maps, current settings and even a different interpretation of the software shutdown bit: https://lumissil.com/assets/pdf/core/IS31FL3190_DS.pdf https://lumissil.com/assets/pdf/core/IS31FL3191_DS.pdf https://lumissil.com/assets/pdf/core/IS31FL3193_DS.pdf https://lumissil.com/assets/pdf/core/IS31FL3196_DS.pdf https://lumissil.com/assets/pdf/core/IS31FL3199_DS.pdf Rename variables, structures and defines in preparation of the splitting. No functional nor behaviour change. Signed-off-by: Vincent Knecht --- v4: - Reinstate u32 cast for IS31FL319X_AUDIO_GAIN_DB_MAX to silence a warning wrt. min() macro - Fix missing space before } in is31fl3196_reg_defaults v3: - rename IS31FL3196_BREATH_MASK to IS31FL3196_BREATH_MARK since it refers to "breathing mark" function, not to a bitmask - use GENMASK for IS31FL3196_CONFIG2_CS_MASK (Andy) - get rid of u32 castings in defines (Andy) - add _uA_ in IS31FL3196_CURRENT defines to denote the unit (Andy) - fix stuctures typo in commit message (Andy) --- drivers/leds/leds-is31fl319x.c | 142 ++++++++++++++++----------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 0db5d4988131..672b0e9e1d85 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -21,39 +21,39 @@ =20 /* register numbers */ #define IS31FL319X_SHUTDOWN 0x00 -#define IS31FL319X_CTRL1 0x01 -#define IS31FL319X_CTRL2 0x02 -#define IS31FL319X_CONFIG1 0x03 -#define IS31FL319X_CONFIG2 0x04 -#define IS31FL319X_RAMP_MODE 0x05 -#define IS31FL319X_BREATH_MASK 0x06 -#define IS31FL319X_PWM(channel) (0x07 + channel) -#define IS31FL319X_DATA_UPDATE 0x10 -#define IS31FL319X_T0(channel) (0x11 + channel) -#define IS31FL319X_T123_1 0x1a -#define IS31FL319X_T123_2 0x1b -#define IS31FL319X_T123_3 0x1c -#define IS31FL319X_T4(channel) (0x1d + channel) -#define IS31FL319X_TIME_UPDATE 0x26 -#define IS31FL319X_RESET 0xff - -#define IS31FL319X_REG_CNT (IS31FL319X_RESET + 1) +#define IS31FL3196_CTRL1 0x01 +#define IS31FL3196_CTRL2 0x02 +#define IS31FL3196_CONFIG1 0x03 +#define IS31FL3196_CONFIG2 0x04 +#define IS31FL3196_RAMP_MODE 0x05 +#define IS31FL3196_BREATH_MARK 0x06 +#define IS31FL3196_PWM(channel) (0x07 + channel) +#define IS31FL3196_DATA_UPDATE 0x10 +#define IS31FL3196_T0(channel) (0x11 + channel) +#define IS31FL3196_T123_1 0x1a +#define IS31FL3196_T123_2 0x1b +#define IS31FL3196_T123_3 0x1c +#define IS31FL3196_T4(channel) (0x1d + channel) +#define IS31FL3196_TIME_UPDATE 0x26 +#define IS31FL3196_RESET 0xff + +#define IS31FL3196_REG_CNT (IS31FL3196_RESET + 1) =20 #define IS31FL319X_MAX_LEDS 9 =20 /* CS (Current Setting) in CONFIG2 register */ -#define IS31FL319X_CONFIG2_CS_SHIFT 4 -#define IS31FL319X_CONFIG2_CS_MASK 0x7 -#define IS31FL319X_CONFIG2_CS_STEP_REF 12 +#define IS31FL3196_CONFIG2_CS_SHIFT 4 +#define IS31FL3196_CONFIG2_CS_MASK GENMASK(2, 0) +#define IS31FL3196_CONFIG2_CS_STEP_REF 12 =20 -#define IS31FL319X_CURRENT_MIN ((u32)5000) -#define IS31FL319X_CURRENT_MAX ((u32)40000) -#define IS31FL319X_CURRENT_STEP ((u32)5000) -#define IS31FL319X_CURRENT_DEFAULT ((u32)20000) +#define IS31FL3196_CURRENT_uA_MIN 5000 +#define IS31FL3196_CURRENT_uA_MAX 40000 +#define IS31FL3196_CURRENT_uA_STEP 5000 +#define IS31FL3196_CURRENT_uA_DEFAULT 20000 =20 /* Audio gain in CONFIG2 register */ -#define IS31FL319X_AUDIO_GAIN_DB_MAX ((u32)21) -#define IS31FL319X_AUDIO_GAIN_DB_STEP ((u32)3) +#define IS31FL3196_AUDIO_GAIN_DB_MAX ((u32)21) +#define IS31FL3196_AUDIO_GAIN_DB_STEP 3 =20 /* * regmap is used as a cache of chip's register space, @@ -111,7 +111,7 @@ static const struct of_device_id of_is31fl319x_match[] = =3D { }; MODULE_DEVICE_TABLE(of, of_is31fl319x_match); =20 -static int is31fl319x_brightness_set(struct led_classdev *cdev, +static int is31fl3196_brightness_set(struct led_classdev *cdev, enum led_brightness brightness) { struct is31fl319x_led *led =3D container_of(cdev, struct is31fl319x_led, @@ -127,7 +127,7 @@ static int is31fl319x_brightness_set(struct led_classde= v *cdev, mutex_lock(&is31->lock); =20 /* update PWM register */ - ret =3D regmap_write(is31->regmap, IS31FL319X_PWM(chan), brightness); + ret =3D regmap_write(is31->regmap, IS31FL3196_PWM(chan), brightness); if (ret < 0) goto out; =20 @@ -141,7 +141,7 @@ static int is31fl319x_brightness_set(struct led_classde= v *cdev, * the current setting, we read from the regmap cache */ =20 - ret =3D regmap_read(is31->regmap, IS31FL319X_PWM(i), &pwm_value); + ret =3D regmap_read(is31->regmap, IS31FL3196_PWM(i), &pwm_value); dev_dbg(&is31->client->dev, "%s read %d: ret=3D%d: %d\n", __func__, i, ret, pwm_value); on =3D ret >=3D 0 && pwm_value > LED_OFF; @@ -157,10 +157,10 @@ static int is31fl319x_brightness_set(struct led_class= dev *cdev, if (ctrl1 > 0 || ctrl2 > 0) { dev_dbg(&is31->client->dev, "power up %02x %02x\n", ctrl1, ctrl2); - regmap_write(is31->regmap, IS31FL319X_CTRL1, ctrl1); - regmap_write(is31->regmap, IS31FL319X_CTRL2, ctrl2); + regmap_write(is31->regmap, IS31FL3196_CTRL1, ctrl1); + regmap_write(is31->regmap, IS31FL3196_CTRL2, ctrl2); /* update PWMs */ - regmap_write(is31->regmap, IS31FL319X_DATA_UPDATE, 0x00); + regmap_write(is31->regmap, IS31FL3196_DATA_UPDATE, 0x00); /* enable chip from shut down */ ret =3D regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x01); } else { @@ -190,14 +190,14 @@ static int is31fl319x_parse_child_dt(const struct dev= ice *dev, if (ret < 0 && ret !=3D -EINVAL) /* is optional */ return ret; =20 - led->max_microamp =3D IS31FL319X_CURRENT_DEFAULT; + led->max_microamp =3D IS31FL3196_CURRENT_uA_DEFAULT; ret =3D of_property_read_u32(child, "led-max-microamp", &led->max_microamp); if (!ret) { - if (led->max_microamp < IS31FL319X_CURRENT_MIN) + if (led->max_microamp < IS31FL3196_CURRENT_uA_MIN) return -EINVAL; /* not supported */ led->max_microamp =3D min(led->max_microamp, - IS31FL319X_CURRENT_MAX); + IS31FL3196_CURRENT_uA_MAX); } =20 return 0; @@ -271,7 +271,7 @@ static int is31fl319x_parse_dt(struct device *dev, ret =3D of_property_read_u32(np, "audio-gain-db", &is31->audio_gain_db); if (!ret) is31->audio_gain_db =3D min(is31->audio_gain_db, - IS31FL319X_AUDIO_GAIN_DB_MAX); + IS31FL3196_AUDIO_GAIN_DB_MAX); =20 return 0; =20 @@ -285,55 +285,55 @@ static bool is31fl319x_readable_reg(struct device *de= v, unsigned int reg) return false; } =20 -static bool is31fl319x_volatile_reg(struct device *dev, unsigned int reg) +static bool is31fl3196_volatile_reg(struct device *dev, unsigned int reg) { /* volatile registers are not cached */ switch (reg) { - case IS31FL319X_DATA_UPDATE: - case IS31FL319X_TIME_UPDATE: - case IS31FL319X_RESET: + case IS31FL3196_DATA_UPDATE: + case IS31FL3196_TIME_UPDATE: + case IS31FL3196_RESET: return true; /* always write-through */ default: return false; } } =20 -static const struct reg_default is31fl319x_reg_defaults[] =3D { - { IS31FL319X_CONFIG1, 0x00}, - { IS31FL319X_CONFIG2, 0x00}, - { IS31FL319X_PWM(0), 0x00}, - { IS31FL319X_PWM(1), 0x00}, - { IS31FL319X_PWM(2), 0x00}, - { IS31FL319X_PWM(3), 0x00}, - { IS31FL319X_PWM(4), 0x00}, - { IS31FL319X_PWM(5), 0x00}, - { IS31FL319X_PWM(6), 0x00}, - { IS31FL319X_PWM(7), 0x00}, - { IS31FL319X_PWM(8), 0x00}, +static const struct reg_default is31fl3196_reg_defaults[] =3D { + { IS31FL3196_CONFIG1, 0x00 }, + { IS31FL3196_CONFIG2, 0x00 }, + { IS31FL3196_PWM(0), 0x00 }, + { IS31FL3196_PWM(1), 0x00 }, + { IS31FL3196_PWM(2), 0x00 }, + { IS31FL3196_PWM(3), 0x00 }, + { IS31FL3196_PWM(4), 0x00 }, + { IS31FL3196_PWM(5), 0x00 }, + { IS31FL3196_PWM(6), 0x00 }, + { IS31FL3196_PWM(7), 0x00 }, + { IS31FL3196_PWM(8), 0x00 }, }; =20 -static struct regmap_config regmap_config =3D { +static struct regmap_config is31fl3196_regmap_config =3D { .reg_bits =3D 8, .val_bits =3D 8, - .max_register =3D IS31FL319X_REG_CNT, + .max_register =3D IS31FL3196_REG_CNT, .cache_type =3D REGCACHE_FLAT, .readable_reg =3D is31fl319x_readable_reg, - .volatile_reg =3D is31fl319x_volatile_reg, - .reg_defaults =3D is31fl319x_reg_defaults, - .num_reg_defaults =3D ARRAY_SIZE(is31fl319x_reg_defaults), + .volatile_reg =3D is31fl3196_volatile_reg, + .reg_defaults =3D is31fl3196_reg_defaults, + .num_reg_defaults =3D ARRAY_SIZE(is31fl3196_reg_defaults), }; =20 -static inline int is31fl319x_microamp_to_cs(struct device *dev, u32 microa= mp) +static inline int is31fl3196_microamp_to_cs(struct device *dev, u32 microa= mp) { /* round down to nearest supported value (range check done by caller) */ - u32 step =3D microamp / IS31FL319X_CURRENT_STEP; + u32 step =3D microamp / IS31FL3196_CURRENT_uA_STEP; =20 - return ((IS31FL319X_CONFIG2_CS_STEP_REF - step) & - IS31FL319X_CONFIG2_CS_MASK) << - IS31FL319X_CONFIG2_CS_SHIFT; /* CS encoding */ + return ((IS31FL3196_CONFIG2_CS_STEP_REF - step) & + IS31FL3196_CONFIG2_CS_MASK) << + IS31FL3196_CONFIG2_CS_SHIFT; /* CS encoding */ } =20 -static inline int is31fl319x_db_to_gain(u32 dezibel) +static inline int is31fl3196_db_to_gain(u32 dezibel) { /* round down to nearest supported value (range check done by caller) */ - return dezibel / IS31FL319X_AUDIO_GAIN_DB_STEP; + return dezibel / IS31FL3196_AUDIO_GAIN_DB_STEP; } =20 static int is31fl319x_probe(struct i2c_client *client, @@ -343,7 +343,7 @@ static int is31fl319x_probe(struct i2c_client *client, struct device *dev =3D &client->dev; int err; int i =3D 0; - u32 aggregated_led_microamp =3D IS31FL319X_CURRENT_MAX; + u32 aggregated_led_microamp =3D IS31FL3196_CURRENT_uA_MAX; =20 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -EIO; @@ -365,7 +365,7 @@ static int is31fl319x_probe(struct i2c_client *client, } =20 is31->client =3D client; - is31->regmap =3D devm_regmap_init_i2c(client, ®map_config); + is31->regmap =3D devm_regmap_init_i2c(client, &is31fl3196_regmap_config); if (IS_ERR(is31->regmap)) { dev_err(&client->dev, "failed to allocate register map\n"); err =3D PTR_ERR(is31->regmap); @@ -375,7 +375,7 @@ static int is31fl319x_probe(struct i2c_client *client, i2c_set_clientdata(client, is31); =20 /* check for write-reply from chip (we can't read any registers) */ - err =3D regmap_write(is31->regmap, IS31FL319X_RESET, 0x00); + err =3D regmap_write(is31->regmap, IS31FL3196_RESET, 0x00); if (err < 0) { dev_err(&client->dev, "no response from chip write: err =3D %d\n", err); @@ -393,9 +393,9 @@ static int is31fl319x_probe(struct i2c_client *client, is31->leds[i].max_microamp < aggregated_led_microamp) aggregated_led_microamp =3D is31->leds[i].max_microamp; =20 - regmap_write(is31->regmap, IS31FL319X_CONFIG2, - is31fl319x_microamp_to_cs(dev, aggregated_led_microamp) | - is31fl319x_db_to_gain(is31->audio_gain_db)); + regmap_write(is31->regmap, IS31FL3196_CONFIG2, + is31fl3196_microamp_to_cs(dev, aggregated_led_microamp) | + is31fl3196_db_to_gain(is31->audio_gain_db)); =20 for (i =3D 0; i < is31->cdef->num_leds; i++) { struct is31fl319x_led *led =3D &is31->leds[i]; @@ -404,7 +404,7 @@ static int is31fl319x_probe(struct i2c_client *client, continue; =20 led->chip =3D is31; - led->cdev.brightness_set_blocking =3D is31fl319x_brightness_set; + led->cdev.brightness_set_blocking =3D is31fl3196_brightness_set; =20 err =3D devm_led_classdev_register(&client->dev, &led->cdev); if (err < 0) --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F565C43334 for ; Tue, 12 Jul 2022 10:10:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232926AbiGLKKC (ORCPT ); Tue, 12 Jul 2022 06:10:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbiGLKJj (ORCPT ); Tue, 12 Jul 2022 06:09:39 -0400 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E14EAB7ED; Tue, 12 Jul 2022 03:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620552; bh=LpEX2A+MFyDHACQMGbFUVipiSwhL1LxI/7Jun0xXolI=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=QzjSXjv3+Q+ek2D6orf5FRAsVMoZ3PIUDl9KwIO5Cyw2Sa5L6AYnPY40lmaT7jqP8 07oH6BxectVEuKubukgeJP5hRfajhI7ojnTi99tLGZy2OclVJcAYU15b84x2c40qx3 98kbtbf8Kk7uxnq9v3i4elWPXgOZj0+41pMDeiJA= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:11 +0200 (CEST) X-EA-Auth: tr20aj/MIGZFewFVGmKQVGZ70RRVk6KZ7S031m8PXIsL1l2KbQv5YFxl+Tt8+oci1dLVqph7wbUgMrASXMihI5t8b301WcquMTL4Zt5M7Uo= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com Subject: [PATCH v5 05/12] leds: is31fl319x: Move chipset-specific values in chipdef struct Date: Tue, 12 Jul 2022 12:08:31 +0200 Message-Id: <20220712100841.1538395-6-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Allow setting chips' specifics in chipdef struct by adding fields for: - the reset register address - a pointer to a regmap_config struct - a pointer to a brightness_set function - current default, min and max values - a boolean to distinguish 319{0,1,3} and 319{6,9} chips and use those fields in places where distinction has to be made. The fields for 319{0,1,3} still point to 319{6,9} values. No functional change. Signed-off-by: Vincent Knecht --- v4: - Fix non standard place for comments --- drivers/leds/leds-is31fl319x.c | 208 ++++++++++++++++++++------------- 1 file changed, 125 insertions(+), 83 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 672b0e9e1d85..fe0cb68b583b 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -78,38 +78,58 @@ struct is31fl319x_chip { =20 struct is31fl319x_chipdef { int num_leds; + u8 reset_reg; + const struct regmap_config *is31fl319x_regmap_config; + int (*brightness_set)(struct led_classdev *cdev, enum led_brightness brig= htness); + u32 current_default; + u32 current_min; + u32 current_max; + bool is_3196or3199; }; =20 -static const struct is31fl319x_chipdef is31fl3190_cdef =3D { - .num_leds =3D 1, -}; - -static const struct is31fl319x_chipdef is31fl3193_cdef =3D { - .num_leds =3D 3, -}; +static bool is31fl319x_readable_reg(struct device *dev, unsigned int reg) +{ + /* we have no readable registers */ + return false; +} =20 -static const struct is31fl319x_chipdef is31fl3196_cdef =3D { - .num_leds =3D 6, -}; +static bool is31fl3196_volatile_reg(struct device *dev, unsigned int reg) +{ + /* volatile registers are not cached */ + switch (reg) { + case IS31FL3196_DATA_UPDATE: + case IS31FL3196_TIME_UPDATE: + case IS31FL3196_RESET: + return true; /* always write-through */ + default: + return false; + } +} =20 -static const struct is31fl319x_chipdef is31fl3199_cdef =3D { - .num_leds =3D 9, +static const struct reg_default is31fl3196_reg_defaults[] =3D { + { IS31FL3196_CONFIG1, 0x00 }, + { IS31FL3196_CONFIG2, 0x00 }, + { IS31FL3196_PWM(0), 0x00 }, + { IS31FL3196_PWM(1), 0x00 }, + { IS31FL3196_PWM(2), 0x00 }, + { IS31FL3196_PWM(3), 0x00 }, + { IS31FL3196_PWM(4), 0x00 }, + { IS31FL3196_PWM(5), 0x00 }, + { IS31FL3196_PWM(6), 0x00 }, + { IS31FL3196_PWM(7), 0x00 }, + { IS31FL3196_PWM(8), 0x00 }, }; =20 -static const struct of_device_id of_is31fl319x_match[] =3D { - { .compatible =3D "issi,is31fl3190", .data =3D &is31fl3190_cdef, }, - { .compatible =3D "issi,is31fl3191", .data =3D &is31fl3190_cdef, }, - { .compatible =3D "issi,is31fl3193", .data =3D &is31fl3193_cdef, }, - { .compatible =3D "issi,is31fl3196", .data =3D &is31fl3196_cdef, }, - { .compatible =3D "issi,is31fl3199", .data =3D &is31fl3199_cdef, }, - { .compatible =3D "si-en,sn3190", .data =3D &is31fl3190_cdef, }, - { .compatible =3D "si-en,sn3191", .data =3D &is31fl3190_cdef, }, - { .compatible =3D "si-en,sn3193", .data =3D &is31fl3193_cdef, }, - { .compatible =3D "si-en,sn3196", .data =3D &is31fl3196_cdef, }, - { .compatible =3D "si-en,sn3199", .data =3D &is31fl3199_cdef, }, - { } +static struct regmap_config is31fl3196_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .max_register =3D IS31FL3196_REG_CNT, + .cache_type =3D REGCACHE_FLAT, + .readable_reg =3D is31fl319x_readable_reg, + .volatile_reg =3D is31fl3196_volatile_reg, + .reg_defaults =3D is31fl3196_reg_defaults, + .num_reg_defaults =3D ARRAY_SIZE(is31fl3196_reg_defaults), }; -MODULE_DEVICE_TABLE(of, of_is31fl319x_match); =20 static int is31fl3196_brightness_set(struct led_classdev *cdev, enum led_brightness brightness) @@ -175,9 +195,69 @@ static int is31fl3196_brightness_set(struct led_classd= ev *cdev, return ret; } =20 +static const struct is31fl319x_chipdef is31fl3190_cdef =3D { + .num_leds =3D 1, + .reset_reg =3D IS31FL3196_RESET, + .is31fl319x_regmap_config =3D &is31fl3196_regmap_config, + .brightness_set =3D is31fl3196_brightness_set, + .current_default =3D IS31FL3196_CURRENT_uA_DEFAULT, + .current_min =3D IS31FL3196_CURRENT_uA_MIN, + .current_max =3D IS31FL3196_CURRENT_uA_MAX, + .is_3196or3199 =3D true, +}; + +static const struct is31fl319x_chipdef is31fl3193_cdef =3D { + .num_leds =3D 3, + .reset_reg =3D IS31FL3196_RESET, + .is31fl319x_regmap_config =3D &is31fl3196_regmap_config, + .brightness_set =3D is31fl3196_brightness_set, + .current_default =3D IS31FL3196_CURRENT_uA_DEFAULT, + .current_min =3D IS31FL3196_CURRENT_uA_MIN, + .current_max =3D IS31FL3196_CURRENT_uA_MAX, + .is_3196or3199 =3D true, +}; + +static const struct is31fl319x_chipdef is31fl3196_cdef =3D { + .num_leds =3D 6, + .reset_reg =3D IS31FL3196_RESET, + .is31fl319x_regmap_config =3D &is31fl3196_regmap_config, + .brightness_set =3D is31fl3196_brightness_set, + .current_default =3D IS31FL3196_CURRENT_uA_DEFAULT, + .current_min =3D IS31FL3196_CURRENT_uA_MIN, + .current_max =3D IS31FL3196_CURRENT_uA_MAX, + .is_3196or3199 =3D true, +}; + +static const struct is31fl319x_chipdef is31fl3199_cdef =3D { + .num_leds =3D 9, + .reset_reg =3D IS31FL3196_RESET, + .is31fl319x_regmap_config =3D &is31fl3196_regmap_config, + .brightness_set =3D is31fl3196_brightness_set, + .current_default =3D IS31FL3196_CURRENT_uA_DEFAULT, + .current_min =3D IS31FL3196_CURRENT_uA_MIN, + .current_max =3D IS31FL3196_CURRENT_uA_MAX, + .is_3196or3199 =3D true, +}; + +static const struct of_device_id of_is31fl319x_match[] =3D { + { .compatible =3D "issi,is31fl3190", .data =3D &is31fl3190_cdef, }, + { .compatible =3D "issi,is31fl3191", .data =3D &is31fl3190_cdef, }, + { .compatible =3D "issi,is31fl3193", .data =3D &is31fl3193_cdef, }, + { .compatible =3D "issi,is31fl3196", .data =3D &is31fl3196_cdef, }, + { .compatible =3D "issi,is31fl3199", .data =3D &is31fl3199_cdef, }, + { .compatible =3D "si-en,sn3190", .data =3D &is31fl3190_cdef, }, + { .compatible =3D "si-en,sn3191", .data =3D &is31fl3190_cdef, }, + { .compatible =3D "si-en,sn3193", .data =3D &is31fl3193_cdef, }, + { .compatible =3D "si-en,sn3196", .data =3D &is31fl3196_cdef, }, + { .compatible =3D "si-en,sn3199", .data =3D &is31fl3199_cdef, }, + { } +}; +MODULE_DEVICE_TABLE(of, of_is31fl319x_match); + static int is31fl319x_parse_child_dt(const struct device *dev, const struct device_node *child, - struct is31fl319x_led *led) + struct is31fl319x_led *led, + struct is31fl319x_chip *is31) { struct led_classdev *cdev =3D &led->cdev; int ret; @@ -190,14 +270,14 @@ static int is31fl319x_parse_child_dt(const struct dev= ice *dev, if (ret < 0 && ret !=3D -EINVAL) /* is optional */ return ret; =20 - led->max_microamp =3D IS31FL3196_CURRENT_uA_DEFAULT; + led->max_microamp =3D is31->cdef->current_default; ret =3D of_property_read_u32(child, "led-max-microamp", &led->max_microamp); if (!ret) { - if (led->max_microamp < IS31FL3196_CURRENT_uA_MIN) + if (led->max_microamp < is31->cdef->current_min) return -EINVAL; /* not supported */ led->max_microamp =3D min(led->max_microamp, - IS31FL3196_CURRENT_uA_MAX); + is31->cdef->current_max); } =20 return 0; @@ -258,7 +338,7 @@ static int is31fl319x_parse_dt(struct device *dev, goto put_child_node; } =20 - ret =3D is31fl319x_parse_child_dt(dev, child, led); + ret =3D is31fl319x_parse_child_dt(dev, child, led, is31); if (ret) { dev_err(dev, "led %u DT parsing failed\n", reg); goto put_child_node; @@ -268,10 +348,12 @@ static int is31fl319x_parse_dt(struct device *dev, } =20 is31->audio_gain_db =3D 0; - ret =3D of_property_read_u32(np, "audio-gain-db", &is31->audio_gain_db); - if (!ret) - is31->audio_gain_db =3D min(is31->audio_gain_db, - IS31FL3196_AUDIO_GAIN_DB_MAX); + if (is31->cdef->is_3196or3199) { + ret =3D of_property_read_u32(np, "audio-gain-db", &is31->audio_gain_db); + if (!ret) + is31->audio_gain_db =3D min(is31->audio_gain_db, + IS31FL3196_AUDIO_GAIN_DB_MAX); + } =20 return 0; =20 @@ -280,48 +362,6 @@ static int is31fl319x_parse_dt(struct device *dev, return ret; } =20 -static bool is31fl319x_readable_reg(struct device *dev, unsigned int reg) -{ /* we have no readable registers */ - return false; -} - -static bool is31fl3196_volatile_reg(struct device *dev, unsigned int reg) -{ /* volatile registers are not cached */ - switch (reg) { - case IS31FL3196_DATA_UPDATE: - case IS31FL3196_TIME_UPDATE: - case IS31FL3196_RESET: - return true; /* always write-through */ - default: - return false; - } -} - -static const struct reg_default is31fl3196_reg_defaults[] =3D { - { IS31FL3196_CONFIG1, 0x00 }, - { IS31FL3196_CONFIG2, 0x00 }, - { IS31FL3196_PWM(0), 0x00 }, - { IS31FL3196_PWM(1), 0x00 }, - { IS31FL3196_PWM(2), 0x00 }, - { IS31FL3196_PWM(3), 0x00 }, - { IS31FL3196_PWM(4), 0x00 }, - { IS31FL3196_PWM(5), 0x00 }, - { IS31FL3196_PWM(6), 0x00 }, - { IS31FL3196_PWM(7), 0x00 }, - { IS31FL3196_PWM(8), 0x00 }, -}; - -static struct regmap_config is31fl3196_regmap_config =3D { - .reg_bits =3D 8, - .val_bits =3D 8, - .max_register =3D IS31FL3196_REG_CNT, - .cache_type =3D REGCACHE_FLAT, - .readable_reg =3D is31fl319x_readable_reg, - .volatile_reg =3D is31fl3196_volatile_reg, - .reg_defaults =3D is31fl3196_reg_defaults, - .num_reg_defaults =3D ARRAY_SIZE(is31fl3196_reg_defaults), -}; - static inline int is31fl3196_microamp_to_cs(struct device *dev, u32 microa= mp) { /* round down to nearest supported value (range check done by caller) */ u32 step =3D microamp / IS31FL3196_CURRENT_uA_STEP; @@ -343,7 +383,7 @@ static int is31fl319x_probe(struct i2c_client *client, struct device *dev =3D &client->dev; int err; int i =3D 0; - u32 aggregated_led_microamp =3D IS31FL3196_CURRENT_uA_MAX; + u32 aggregated_led_microamp; =20 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -EIO; @@ -365,7 +405,7 @@ static int is31fl319x_probe(struct i2c_client *client, } =20 is31->client =3D client; - is31->regmap =3D devm_regmap_init_i2c(client, &is31fl3196_regmap_config); + is31->regmap =3D devm_regmap_init_i2c(client, is31->cdef->is31fl319x_regm= ap_config); if (IS_ERR(is31->regmap)) { dev_err(&client->dev, "failed to allocate register map\n"); err =3D PTR_ERR(is31->regmap); @@ -375,7 +415,7 @@ static int is31fl319x_probe(struct i2c_client *client, i2c_set_clientdata(client, is31); =20 /* check for write-reply from chip (we can't read any registers) */ - err =3D regmap_write(is31->regmap, IS31FL3196_RESET, 0x00); + err =3D regmap_write(is31->regmap, is31->cdef->reset_reg, 0x00); if (err < 0) { dev_err(&client->dev, "no response from chip write: err =3D %d\n", err); @@ -388,14 +428,16 @@ static int is31fl319x_probe(struct i2c_client *client, * But the chip does not allow to limit individual LEDs. * So we take minimum from all subnodes for safety of hardware. */ + aggregated_led_microamp =3D is31->cdef->current_max; for (i =3D 0; i < is31->cdef->num_leds; i++) if (is31->leds[i].configured && is31->leds[i].max_microamp < aggregated_led_microamp) aggregated_led_microamp =3D is31->leds[i].max_microamp; =20 - regmap_write(is31->regmap, IS31FL3196_CONFIG2, - is31fl3196_microamp_to_cs(dev, aggregated_led_microamp) | - is31fl3196_db_to_gain(is31->audio_gain_db)); + if (is31->cdef->is_3196or3199) + regmap_write(is31->regmap, IS31FL3196_CONFIG2, + is31fl3196_microamp_to_cs(dev, aggregated_led_microamp) | + is31fl3196_db_to_gain(is31->audio_gain_db)); =20 for (i =3D 0; i < is31->cdef->num_leds; i++) { struct is31fl319x_led *led =3D &is31->leds[i]; @@ -404,7 +446,7 @@ static int is31fl319x_probe(struct i2c_client *client, continue; =20 led->chip =3D is31; - led->cdev.brightness_set_blocking =3D is31fl3196_brightness_set; + led->cdev.brightness_set_blocking =3D is31->cdef->brightness_set; =20 err =3D devm_led_classdev_register(&client->dev, &led->cdev); if (err < 0) --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FF55C43334 for ; Tue, 12 Jul 2022 10:10:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231820AbiGLKKQ (ORCPT ); Tue, 12 Jul 2022 06:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232908AbiGLKJj (ORCPT ); Tue, 12 Jul 2022 06:09:39 -0400 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CEAAB7F4; Tue, 12 Jul 2022 03:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620556; bh=bMVLpwURCtdlyJQbXLVquIPfxhhkdqs2u0k3NUi8+U8=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Type:Content-Transfer-Encoding; b=UNWcU0kGATPp65bVS1YXuSNWIpf2fuSGmNtFp+N/dxhbEWxiboZCcbyMVdm7/YLyJ nqzIZEge7GitHZU5nyukzmmFTeVChMsubmXeLAaLzbsB1qA4WUFstpjGBmLfu6k0m/ Okm/sQQW83yXRy3qiECpFsBe6R9/Fhb2ebSL1iGE= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:16 +0200 (CEST) X-EA-Auth: BFeD1CU2ySu5iUPhCd6/rNPySwQZq0NUQwp80ty+NRfqUe1Xf6OkZbJNq7XpfUGedf5GtN9DM/Jb7tQ4vvvwNgorElPXTyoc/X0JI7W8iXk= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com Subject: [PATCH v5 06/12] leds: is31fl319x: Add support for is31fl319{0,1,3} chips Date: Tue, 12 Jul 2022 12:08:32 +0200 Message-Id: <20220712100841.1538395-7-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Set specific chipset structs values for is31fl319{0,1,3} so that those chips can actually work. Datasheets: https://lumissil.com/assets/pdf/core/IS31FL3190_DS.pdf https://lumissil.com/assets/pdf/core/IS31FL3191_DS.pdf https://lumissil.com/assets/pdf/core/IS31FL3193_DS.pdf https://lumissil.com/assets/pdf/core/IS31FL3196_DS.pdf https://lumissil.com/assets/pdf/core/IS31FL3199_DS.pdf Signed-off-by: Vincent Knecht --- v4: - keep container_of() call on one line - remove dev_dbg() call after regmap_read() - change is31fl3190_microamp_to_cs() to return directly from the default case - fix non-standard place for comment - add missing space before } --- drivers/leds/leds-is31fl319x.c | 161 ++++++++++++++++++++++++++++++--- 1 file changed, 147 insertions(+), 14 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index fe0cb68b583b..2314922bc009 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -21,6 +21,31 @@ =20 /* register numbers */ #define IS31FL319X_SHUTDOWN 0x00 + +/* registers for 3190, 3191 and 3193 */ +#define IS31FL3190_BREATHING 0x01 +#define IS31FL3190_LEDMODE 0x02 +#define IS31FL3190_CURRENT 0x03 +#define IS31FL3190_PWM(channel) (0x04 + channel) +#define IS31FL3190_DATA_UPDATE 0x07 +#define IS31FL3190_T0(channel) (0x0a + channel) +#define IS31FL3190_T1T2(channel) (0x10 + channel) +#define IS31FL3190_T3T4(channel) (0x16 + channel) +#define IS31FL3190_TIME_UPDATE 0x1c +#define IS31FL3190_LEDCONTROL 0x1d +#define IS31FL3190_RESET 0x2f + +#define IS31FL3190_CURRENT_uA_MIN 5000 +#define IS31FL3190_CURRENT_uA_DEFAULT 42000 +#define IS31FL3190_CURRENT_uA_MAX 42000 +#define IS31FL3190_CURRENT_MASK GENMASK(4, 2) +#define IS31FL3190_CURRENT_5_mA 0x02 +#define IS31FL3190_CURRENT_10_mA 0x01 +#define IS31FL3190_CURRENT_17dot5_mA 0x04 +#define IS31FL3190_CURRENT_30_mA 0x03 +#define IS31FL3190_CURRENT_42_mA 0x00 + +/* registers for 3196 and 3199 */ #define IS31FL3196_CTRL1 0x01 #define IS31FL3196_CTRL2 0x02 #define IS31FL3196_CONFIG1 0x03 @@ -93,6 +118,38 @@ static bool is31fl319x_readable_reg(struct device *dev,= unsigned int reg) return false; } =20 +static bool is31fl3190_volatile_reg(struct device *dev, unsigned int reg) +{ + /* volatile registers are not cached */ + switch (reg) { + case IS31FL3190_DATA_UPDATE: + case IS31FL3190_TIME_UPDATE: + case IS31FL3190_RESET: + return true; /* always write-through */ + default: + return false; + } +} + +static const struct reg_default is31fl3190_reg_defaults[] =3D { + { IS31FL3190_LEDMODE, 0x00 }, + { IS31FL3190_CURRENT, 0x00 }, + { IS31FL3190_PWM(0), 0x00 }, + { IS31FL3190_PWM(1), 0x00 }, + { IS31FL3190_PWM(2), 0x00 }, +}; + +static struct regmap_config is31fl3190_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .max_register =3D IS31FL3190_RESET, + .cache_type =3D REGCACHE_FLAT, + .readable_reg =3D is31fl319x_readable_reg, + .volatile_reg =3D is31fl3190_volatile_reg, + .reg_defaults =3D is31fl3190_reg_defaults, + .num_reg_defaults =3D ARRAY_SIZE(is31fl3190_reg_defaults), +}; + static bool is31fl3196_volatile_reg(struct device *dev, unsigned int reg) { /* volatile registers are not cached */ @@ -131,6 +188,60 @@ static struct regmap_config is31fl3196_regmap_config = =3D { .num_reg_defaults =3D ARRAY_SIZE(is31fl3196_reg_defaults), }; =20 +static int is31fl3190_brightness_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + struct is31fl319x_led *led =3D container_of(cdev, struct is31fl319x_led, = cdev); + struct is31fl319x_chip *is31 =3D led->chip; + int chan =3D led - is31->leds; + int ret; + int i; + u8 ctrl =3D 0; + + dev_dbg(&is31->client->dev, "%s %d: %d\n", __func__, chan, brightness); + + mutex_lock(&is31->lock); + + /* update PWM register */ + ret =3D regmap_write(is31->regmap, IS31FL3190_PWM(chan), brightness); + if (ret < 0) + goto out; + + /* read current brightness of all PWM channels */ + for (i =3D 0; i < is31->cdef->num_leds; i++) { + unsigned int pwm_value; + bool on; + + /* + * since neither cdev nor the chip can provide + * the current setting, we read from the regmap cache + */ + + ret =3D regmap_read(is31->regmap, IS31FL3190_PWM(i), &pwm_value); + on =3D ret >=3D 0 && pwm_value > LED_OFF; + + ctrl |=3D on << i; + } + + if (ctrl > 0) { + dev_dbg(&is31->client->dev, "power up %02x\n", ctrl); + regmap_write(is31->regmap, IS31FL3190_LEDCONTROL, ctrl); + /* update PWMs */ + regmap_write(is31->regmap, IS31FL3190_DATA_UPDATE, 0x00); + /* enable chip from shut down and enable all channels */ + ret =3D regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x20); + } else { + dev_dbg(&is31->client->dev, "power down\n"); + /* shut down (no need to clear LEDCONTROL) */ + ret =3D regmap_write(is31->regmap, IS31FL319X_SHUTDOWN, 0x01); + } + +out: + mutex_unlock(&is31->lock); + + return ret; +} + static int is31fl3196_brightness_set(struct led_classdev *cdev, enum led_brightness brightness) { @@ -197,24 +308,24 @@ static int is31fl3196_brightness_set(struct led_class= dev *cdev, =20 static const struct is31fl319x_chipdef is31fl3190_cdef =3D { .num_leds =3D 1, - .reset_reg =3D IS31FL3196_RESET, - .is31fl319x_regmap_config =3D &is31fl3196_regmap_config, - .brightness_set =3D is31fl3196_brightness_set, - .current_default =3D IS31FL3196_CURRENT_uA_DEFAULT, - .current_min =3D IS31FL3196_CURRENT_uA_MIN, - .current_max =3D IS31FL3196_CURRENT_uA_MAX, - .is_3196or3199 =3D true, + .reset_reg =3D IS31FL3190_RESET, + .is31fl319x_regmap_config =3D &is31fl3190_regmap_config, + .brightness_set =3D is31fl3190_brightness_set, + .current_default =3D IS31FL3190_CURRENT_uA_DEFAULT, + .current_min =3D IS31FL3190_CURRENT_uA_MIN, + .current_max =3D IS31FL3190_CURRENT_uA_MAX, + .is_3196or3199 =3D false, }; =20 static const struct is31fl319x_chipdef is31fl3193_cdef =3D { .num_leds =3D 3, - .reset_reg =3D IS31FL3196_RESET, - .is31fl319x_regmap_config =3D &is31fl3196_regmap_config, - .brightness_set =3D is31fl3196_brightness_set, - .current_default =3D IS31FL3196_CURRENT_uA_DEFAULT, - .current_min =3D IS31FL3196_CURRENT_uA_MIN, - .current_max =3D IS31FL3196_CURRENT_uA_MAX, - .is_3196or3199 =3D true, + .reset_reg =3D IS31FL3190_RESET, + .is31fl319x_regmap_config =3D &is31fl3190_regmap_config, + .brightness_set =3D is31fl3190_brightness_set, + .current_default =3D IS31FL3190_CURRENT_uA_DEFAULT, + .current_min =3D IS31FL3190_CURRENT_uA_MIN, + .current_max =3D IS31FL3190_CURRENT_uA_MAX, + .is_3196or3199 =3D false, }; =20 static const struct is31fl319x_chipdef is31fl3196_cdef =3D { @@ -362,6 +473,25 @@ static int is31fl319x_parse_dt(struct device *dev, return ret; } =20 +static inline int is31fl3190_microamp_to_cs(struct device *dev, u32 microa= mp) +{ + switch (microamp) { + case 5000: + return IS31FL3190_CURRENT_5_mA; + case 10000: + return IS31FL3190_CURRENT_10_mA; + case 17500: + return IS31FL3190_CURRENT_17dot5_mA; + case 30000: + return IS31FL3190_CURRENT_30_mA; + case 42000: + return IS31FL3190_CURRENT_42_mA; + default: + dev_warn(dev, "Unsupported current value: %d, using 5000 =C2=B5A!\n", mi= croamp); + return IS31FL3190_CURRENT_5_mA; + } +} + static inline int is31fl3196_microamp_to_cs(struct device *dev, u32 microa= mp) { /* round down to nearest supported value (range check done by caller) */ u32 step =3D microamp / IS31FL3196_CURRENT_uA_STEP; @@ -438,6 +568,9 @@ static int is31fl319x_probe(struct i2c_client *client, regmap_write(is31->regmap, IS31FL3196_CONFIG2, is31fl3196_microamp_to_cs(dev, aggregated_led_microamp) | is31fl3196_db_to_gain(is31->audio_gain_db)); + else + regmap_update_bits(is31->regmap, IS31FL3190_CURRENT, IS31FL3190_CURRENT_= MASK, + is31fl3190_microamp_to_cs(dev, aggregated_led_microamp)); =20 for (i =3D 0; i < is31->cdef->num_leds; i++) { struct is31fl319x_led *led =3D &is31->leds[i]; --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B56BCCA487 for ; Tue, 12 Jul 2022 10:09:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232909AbiGLKJz (ORCPT ); Tue, 12 Jul 2022 06:09:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232902AbiGLKJh (ORCPT ); Tue, 12 Jul 2022 06:09:37 -0400 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89341AB7EA; Tue, 12 Jul 2022 03:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620559; bh=1+vh9VTFnt5gm/N3KxucKgiPLJLaNPtL9AV0RV0iAcY=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=hhoK3pYdSUmPw+GbRKoXc9keTXEbAkVpexzqwSamNZpyuCozMRtQ/eJWsi5YXodPZ zRsLSBx4H18274eQY97jroAmFXlCnHmrw/30oRKTFMg/hNuzPOP8GAxz45ynppLS2Y fS3Jxk7Qsjop++s1H8Nr7QTfDZRBG5sPjCyip9dg= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:19 +0200 (CEST) X-EA-Auth: kZ6iasHQB0VJ/1Bi2wwXhS4gOXMT0+LX3tVwz9tYS5kKj1n8j/m44XridU/C4osPWONqLV9SnIBFWPL+XVuRmiKp+yi9KGZl8T9TJi4qwb0= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com Subject: [PATCH v5 07/12] leds: is31fl319x: Cleanup formatting and dev_dbg calls Date: Tue, 12 Jul 2022 12:08:33 +0200 Message-Id: <20220712100841.1538395-8-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix remaining non-standard place for comments. Remove remaining dev_dbg after regmap_read in is31fl3196_brightness_set. Remove __func__ in dev_dbg calls, instead adding "channel" string to describe the first displayed value. Change remaining container_of() call to be on one line, as well as a few others. Signed-off-by: Vincent Knecht --- drivers/leds/leds-is31fl319x.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 2314922bc009..056cf3bcffdc 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -198,7 +198,7 @@ static int is31fl3190_brightness_set(struct led_classde= v *cdev, int i; u8 ctrl =3D 0; =20 - dev_dbg(&is31->client->dev, "%s %d: %d\n", __func__, chan, brightness); + dev_dbg(&is31->client->dev, "channel %d: %d\n", chan, brightness); =20 mutex_lock(&is31->lock); =20 @@ -245,15 +245,14 @@ static int is31fl3190_brightness_set(struct led_class= dev *cdev, static int is31fl3196_brightness_set(struct led_classdev *cdev, enum led_brightness brightness) { - struct is31fl319x_led *led =3D container_of(cdev, struct is31fl319x_led, - cdev); + struct is31fl319x_led *led =3D container_of(cdev, struct is31fl319x_led, = cdev); struct is31fl319x_chip *is31 =3D led->chip; int chan =3D led - is31->leds; int ret; int i; u8 ctrl1 =3D 0, ctrl2 =3D 0; =20 - dev_dbg(&is31->client->dev, "%s %d: %d\n", __func__, chan, brightness); + dev_dbg(&is31->client->dev, "channel %d: %d\n", chan, brightness); =20 mutex_lock(&is31->lock); =20 @@ -273,8 +272,6 @@ static int is31fl3196_brightness_set(struct led_classde= v *cdev, */ =20 ret =3D regmap_read(is31->regmap, IS31FL3196_PWM(i), &pwm_value); - dev_dbg(&is31->client->dev, "%s read %d: ret=3D%d: %d\n", - __func__, i, ret, pwm_value); on =3D ret >=3D 0 && pwm_value > LED_OFF; =20 if (i < 3) @@ -404,9 +401,7 @@ static int is31fl319x_parse_dt(struct device *dev, if (!np) return -ENODEV; =20 - is31->shutdown_gpio =3D devm_gpiod_get_optional(dev, - "shutdown", - GPIOD_OUT_HIGH); + is31->shutdown_gpio =3D devm_gpiod_get_optional(dev, "shutdown", GPIOD_OU= T_HIGH); if (IS_ERR(is31->shutdown_gpio)) { ret =3D PTR_ERR(is31->shutdown_gpio); dev_err(dev, "Failed to get shutdown gpio: %d\n", ret); @@ -493,7 +488,8 @@ static inline int is31fl3190_microamp_to_cs(struct devi= ce *dev, u32 microamp) } =20 static inline int is31fl3196_microamp_to_cs(struct device *dev, u32 microa= mp) -{ /* round down to nearest supported value (range check done by caller) */ +{ + /* round down to nearest supported value (range check done by caller) */ u32 step =3D microamp / IS31FL3196_CURRENT_uA_STEP; =20 return ((IS31FL3196_CONFIG2_CS_STEP_REF - step) & @@ -502,7 +498,8 @@ static inline int is31fl3196_microamp_to_cs(struct devi= ce *dev, u32 microamp) } =20 static inline int is31fl3196_db_to_gain(u32 dezibel) -{ /* round down to nearest supported value (range check done by caller) */ +{ + /* round down to nearest supported value (range check done by caller) */ return dezibel / IS31FL3196_AUDIO_GAIN_DB_STEP; } =20 @@ -547,8 +544,7 @@ static int is31fl319x_probe(struct i2c_client *client, /* check for write-reply from chip (we can't read any registers) */ err =3D regmap_write(is31->regmap, is31->cdef->reset_reg, 0x00); if (err < 0) { - dev_err(&client->dev, "no response from chip write: err =3D %d\n", - err); + dev_err(&client->dev, "no response from chip write: err =3D %d\n", err); err =3D -EIO; /* does not answer */ goto free_mutex; } --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76568C43334 for ; Tue, 12 Jul 2022 10:10:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbiGLKJ6 (ORCPT ); Tue, 12 Jul 2022 06:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232903AbiGLKJh (ORCPT ); Tue, 12 Jul 2022 06:09:37 -0400 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF817AB7F2; Tue, 12 Jul 2022 03:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620562; bh=kNonhr4zx1gBwqi84AZnY1idautIXixqqCWCbkJNdOk=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=J2UfVlH8qf5jH7X/4Cuv2P6RTHigpXwSxs/8pEYW0060HYypDnQ18vXvLK7sPfkLY YNZ3A8HVk9iqq338T1TXIeK5pfuU/t2Tl54kYTuvjrIiG0pvyIQSx+FlvKWLghCU2K hMi1d6k8mS1rXEgtUcrKYqIJOMpQ34zZTjcRIHHY= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:22 +0200 (CEST) X-EA-Auth: C/bbevPzM6cNNz9cI8u/tulE/4VTHyY+gw+geBuk0R9v3MT5OGG+ehG0CBjqUnaoqYdfQ1BaqEc6cF1QYinG7gzjJNe8wWmy6EyB4gGxghM= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com, Andy Shevchenko Subject: [PATCH v5 08/12] leds: is31fl319x: Make use of device properties Date: Tue, 12 Jul 2022 12:08:34 +0200 Message-Id: <20220712100841.1538395-9-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko Convert the module to be property provider agnostic and allow it to be used on non-OF platforms. Add mod_devicetable.h include. Signed-off-by: Andy Shevchenko Signed-off-by: Vincent Knecht --- drivers/leds/Kconfig | 2 +- drivers/leds/leds-is31fl319x.c | 44 ++++++++++++++++------------------ 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index a49979f41eee..9a896be26dc7 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -697,7 +697,7 @@ config LEDS_MENF21BMC =20 config LEDS_IS31FL319X tristate "LED Support for ISSI IS31FL319x I2C LED controller family" - depends on LEDS_CLASS && I2C && OF + depends on LEDS_CLASS && I2C select REGMAP_I2C help This option enables support for LEDs connected to ISSI IS31FL319x diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 056cf3bcffdc..b1a0ca340e24 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -11,9 +11,9 @@ #include #include #include +#include #include -#include -#include +#include #include #include #include @@ -362,25 +362,23 @@ static const struct of_device_id of_is31fl319x_match[= ] =3D { }; MODULE_DEVICE_TABLE(of, of_is31fl319x_match); =20 -static int is31fl319x_parse_child_dt(const struct device *dev, - const struct device_node *child, +static int is31fl319x_parse_child_fw(const struct device *dev, + const struct fwnode_handle *child, struct is31fl319x_led *led, struct is31fl319x_chip *is31) { struct led_classdev *cdev =3D &led->cdev; int ret; =20 - if (of_property_read_string(child, "label", &cdev->name)) - cdev->name =3D child->name; + if (fwnode_property_read_string(child, "label", &cdev->name)) + cdev->name =3D fwnode_get_name(child); =20 - ret =3D of_property_read_string(child, "linux,default-trigger", - &cdev->default_trigger); + ret =3D fwnode_property_read_string(child, "linux,default-trigger", &cdev= ->default_trigger); if (ret < 0 && ret !=3D -EINVAL) /* is optional */ return ret; =20 led->max_microamp =3D is31->cdef->current_default; - ret =3D of_property_read_u32(child, "led-max-microamp", - &led->max_microamp); + ret =3D fwnode_property_read_u32(child, "led-max-microamp", &led->max_mic= roamp); if (!ret) { if (led->max_microamp < is31->cdef->current_min) return -EINVAL; /* not supported */ @@ -391,16 +389,12 @@ static int is31fl319x_parse_child_dt(const struct dev= ice *dev, return 0; } =20 -static int is31fl319x_parse_dt(struct device *dev, - struct is31fl319x_chip *is31) +static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip = *is31) { - struct device_node *np =3D dev_of_node(dev), *child; + struct fwnode_handle *fwnode =3D dev_fwnode(dev), *child; int count; int ret; =20 - if (!np) - return -ENODEV; - is31->shutdown_gpio =3D devm_gpiod_get_optional(dev, "shutdown", GPIOD_OU= T_HIGH); if (IS_ERR(is31->shutdown_gpio)) { ret =3D PTR_ERR(is31->shutdown_gpio); @@ -410,7 +404,9 @@ static int is31fl319x_parse_dt(struct device *dev, =20 is31->cdef =3D device_get_match_data(dev); =20 - count =3D of_get_available_child_count(np); + count =3D 0; + fwnode_for_each_available_child_node(fwnode, child) + count++; =20 dev_dbg(dev, "probing with %d leds defined in DT\n", count); =20 @@ -420,11 +416,11 @@ static int is31fl319x_parse_dt(struct device *dev, return -ENODEV; } =20 - for_each_available_child_of_node(np, child) { + fwnode_for_each_available_child_node(fwnode, child) { struct is31fl319x_led *led; u32 reg; =20 - ret =3D of_property_read_u32(child, "reg", ®); + ret =3D fwnode_property_read_u32(child, "reg", ®); if (ret) { dev_err(dev, "Failed to read led 'reg' property\n"); goto put_child_node; @@ -444,7 +440,7 @@ static int is31fl319x_parse_dt(struct device *dev, goto put_child_node; } =20 - ret =3D is31fl319x_parse_child_dt(dev, child, led, is31); + ret =3D is31fl319x_parse_child_fw(dev, child, led, is31); if (ret) { dev_err(dev, "led %u DT parsing failed\n", reg); goto put_child_node; @@ -455,7 +451,7 @@ static int is31fl319x_parse_dt(struct device *dev, =20 is31->audio_gain_db =3D 0; if (is31->cdef->is_3196or3199) { - ret =3D of_property_read_u32(np, "audio-gain-db", &is31->audio_gain_db); + ret =3D fwnode_property_read_u32(fwnode, "audio-gain-db", &is31->audio_g= ain_db); if (!ret) is31->audio_gain_db =3D min(is31->audio_gain_db, IS31FL3196_AUDIO_GAIN_DB_MAX); @@ -464,7 +460,7 @@ static int is31fl319x_parse_dt(struct device *dev, return 0; =20 put_child_node: - of_node_put(child); + fwnode_handle_put(child); return ret; } =20 @@ -521,7 +517,7 @@ static int is31fl319x_probe(struct i2c_client *client, =20 mutex_init(&is31->lock); =20 - err =3D is31fl319x_parse_dt(&client->dev, is31); + err =3D is31fl319x_parse_fw(&client->dev, is31); if (err) goto free_mutex; =20 @@ -619,7 +615,7 @@ MODULE_DEVICE_TABLE(i2c, is31fl319x_id); static struct i2c_driver is31fl319x_driver =3D { .driver =3D { .name =3D "leds-is31fl319x", - .of_match_table =3D of_match_ptr(of_is31fl319x_match), + .of_match_table =3D of_is31fl319x_match, }, .probe =3D is31fl319x_probe, .remove =3D is31fl319x_remove, --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A54C9C43334 for ; Tue, 12 Jul 2022 10:10:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232313AbiGLKKG (ORCPT ); Tue, 12 Jul 2022 06:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232885AbiGLKJi (ORCPT ); Tue, 12 Jul 2022 06:09:38 -0400 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD989AB7EF; Tue, 12 Jul 2022 03:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620565; bh=ot1QY0W2gqQ8FHzqL+n9MiYv5sQHYxZYX0Y2iqO3/ds=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=M1WqVbKPG1BCZUunTQVsTCtvajxL+sB1QmEwh2OMpPja0TgmRs2H8xANY0sqVZ6Bk DaWQmZTrjd4J8QQIEkM4mQeS9/uAfh4RHThUD1+phSQDKkqJzBQwAMgTDoi3ghJCYa Sv0n+Zepadm2vD9PIOGJg0DKiEtLJzc9kS4KTuQg= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:25 +0200 (CEST) X-EA-Auth: aTk9wxyFnYR65KRpSAkuG5a0sOVuECX1n5dNry6wlRbP49nAbXGWd/ji9zl1Y6cPEqJ1KW199GphGo4s0Yq+g1gyeO5xXYWsiJqRLJg0oB4= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com, Andy Shevchenko Subject: [PATCH v5 09/12] leds: is31fl319x: Make use of dev_err_probe() Date: Tue, 12 Jul 2022 12:08:35 +0200 Message-Id: <20220712100841.1538395-10-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko Simplify the error handling in probe function by switching from dev_err() to dev_err_probe(). Signed-off-by: Andy Shevchenko Signed-off-by: Vincent Knecht --- drivers/leds/leds-is31fl319x.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index b1a0ca340e24..d9cf70505c43 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -396,11 +396,9 @@ static int is31fl319x_parse_fw(struct device *dev, str= uct is31fl319x_chip *is31) int ret; =20 is31->shutdown_gpio =3D devm_gpiod_get_optional(dev, "shutdown", GPIOD_OU= T_HIGH); - if (IS_ERR(is31->shutdown_gpio)) { - ret =3D PTR_ERR(is31->shutdown_gpio); - dev_err(dev, "Failed to get shutdown gpio: %d\n", ret); - return ret; - } + if (IS_ERR(is31->shutdown_gpio)) + return dev_err_probe(dev, PTR_ERR(is31->shutdown_gpio), + "Failed to get shutdown gpio\n"); =20 is31->cdef =3D device_get_match_data(dev); =20 @@ -410,11 +408,10 @@ static int is31fl319x_parse_fw(struct device *dev, st= ruct is31fl319x_chip *is31) =20 dev_dbg(dev, "probing with %d leds defined in DT\n", count); =20 - if (!count || count > is31->cdef->num_leds) { - dev_err(dev, "Number of leds defined must be between 1 and %u\n", - is31->cdef->num_leds); - return -ENODEV; - } + if (!count || count > is31->cdef->num_leds) + return dev_err_probe(dev, -ENODEV, + "Number of leds defined must be between 1 and %u\n", + is31->cdef->num_leds); =20 fwnode_for_each_available_child_node(fwnode, child) { struct is31fl319x_led *led; @@ -422,27 +419,25 @@ static int is31fl319x_parse_fw(struct device *dev, st= ruct is31fl319x_chip *is31) =20 ret =3D fwnode_property_read_u32(child, "reg", ®); if (ret) { - dev_err(dev, "Failed to read led 'reg' property\n"); + ret =3D dev_err_probe(dev, ret, "Failed to read led 'reg' property\n"); goto put_child_node; } =20 if (reg < 1 || reg > is31->cdef->num_leds) { - dev_err(dev, "invalid led reg %u\n", reg); - ret =3D -EINVAL; + ret =3D dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg); goto put_child_node; } =20 led =3D &is31->leds[reg - 1]; =20 if (led->configured) { - dev_err(dev, "led %u is already configured\n", reg); - ret =3D -EINVAL; + ret =3D dev_err_probe(dev, -EINVAL, "led %u is already configured\n", r= eg); goto put_child_node; } =20 ret =3D is31fl319x_parse_child_fw(dev, child, led, is31); if (ret) { - dev_err(dev, "led %u DT parsing failed\n", reg); + ret =3D dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg); goto put_child_node; } =20 @@ -530,8 +525,7 @@ static int is31fl319x_probe(struct i2c_client *client, is31->client =3D client; is31->regmap =3D devm_regmap_init_i2c(client, is31->cdef->is31fl319x_regm= ap_config); if (IS_ERR(is31->regmap)) { - dev_err(&client->dev, "failed to allocate register map\n"); - err =3D PTR_ERR(is31->regmap); + err =3D dev_err_probe(dev, PTR_ERR(is31->regmap), "failed to allocate re= gister map\n"); goto free_mutex; } =20 @@ -540,8 +534,7 @@ static int is31fl319x_probe(struct i2c_client *client, /* check for write-reply from chip (we can't read any registers) */ err =3D regmap_write(is31->regmap, is31->cdef->reset_reg, 0x00); if (err < 0) { - dev_err(&client->dev, "no response from chip write: err =3D %d\n", err); - err =3D -EIO; /* does not answer */ + err =3D dev_err_probe(dev, err, "no response from chip write\n"); goto free_mutex; } =20 --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C748C433EF for ; Tue, 12 Jul 2022 10:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232908AbiGLKKh (ORCPT ); Tue, 12 Jul 2022 06:10:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232934AbiGLKKE (ORCPT ); Tue, 12 Jul 2022 06:10:04 -0400 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 300CCACEC5; Tue, 12 Jul 2022 03:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620568; bh=QPaiosXXiLfprW1QKMGlsrlutLt4X1y8Mi0U75yNNnE=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=eMwOnH7sKrAPwzB3OUVeCEE64KV6GywamRnDop5h1Me44Zo4hdrphGyH0CCMZmpNq Rws5dxNSJ57ZA/dWF0VfEdMA8QYgDiYjK6brQyJyttBDRwmMZhcAqPwu1vSP77PPd+ QbttrTsMBDHutuUia0wVpcmUuSDVFqzNNkP9XOIE= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:28 +0200 (CEST) X-EA-Auth: MQRRJPI1nAyjNRO1tYIhT+FBIakUUHQ7XpPZ+79dlMpyxjhL+K00u1Q0MeZqunGVhsrHPXIE6X3AgUYZRbjNvY4Kj8sGkJgwJzDtb4twffE= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com, Andy Shevchenko Subject: [PATCH v5 10/12] leds: is31fl319x: Fix devm vs. non-devm ordering Date: Tue, 12 Jul 2022 12:08:36 +0200 Message-Id: <20220712100841.1538395-11-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko When non-devm resources are allocated they mustn't be followed by devm allocations, otherwise it will break the tear down ordering and might lead to crashes or other bugs during ->remove() stage. Fix this by wrapping mutex_destroy() call with devm_add_action_or_reset(). Signed-off-by: Andy Shevchenko Signed-off-by: Vincent Knecht --- drivers/leds/leds-is31fl319x.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index d9cf70505c43..233ed67830a3 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -511,10 +511,13 @@ static int is31fl319x_probe(struct i2c_client *client, return -ENOMEM; =20 mutex_init(&is31->lock); + err =3D devm_add_action(dev, (void (*)(void *))mutex_destroy, &is31->lock= ); + if (err) + return err; =20 err =3D is31fl319x_parse_fw(&client->dev, is31); if (err) - goto free_mutex; + return err; =20 if (is31->shutdown_gpio) { gpiod_direction_output(is31->shutdown_gpio, 0); @@ -524,19 +527,15 @@ static int is31fl319x_probe(struct i2c_client *client, =20 is31->client =3D client; is31->regmap =3D devm_regmap_init_i2c(client, is31->cdef->is31fl319x_regm= ap_config); - if (IS_ERR(is31->regmap)) { - err =3D dev_err_probe(dev, PTR_ERR(is31->regmap), "failed to allocate re= gister map\n"); - goto free_mutex; - } + if (IS_ERR(is31->regmap)) + return dev_err_probe(dev, PTR_ERR(is31->regmap), "failed to allocate reg= ister map\n"); =20 i2c_set_clientdata(client, is31); =20 /* check for write-reply from chip (we can't read any registers) */ err =3D regmap_write(is31->regmap, is31->cdef->reset_reg, 0x00); - if (err < 0) { - err =3D dev_err_probe(dev, err, "no response from chip write\n"); - goto free_mutex; - } + if (err < 0) + return dev_err_probe(dev, err, "no response from chip write\n"); =20 /* * Kernel conventions require per-LED led-max-microamp property. @@ -568,22 +567,10 @@ static int is31fl319x_probe(struct i2c_client *client, =20 err =3D devm_led_classdev_register(&client->dev, &led->cdev); if (err < 0) - goto free_mutex; + return err; } =20 return 0; - -free_mutex: - mutex_destroy(&is31->lock); - return err; -} - -static int is31fl319x_remove(struct i2c_client *client) -{ - struct is31fl319x_chip *is31 =3D i2c_get_clientdata(client); - - mutex_destroy(&is31->lock); - return 0; } =20 /* @@ -611,7 +598,6 @@ static struct i2c_driver is31fl319x_driver =3D { .of_match_table =3D of_is31fl319x_match, }, .probe =3D is31fl319x_probe, - .remove =3D is31fl319x_remove, .id_table =3D is31fl319x_id, }; =20 --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F926CCA483 for ; Tue, 12 Jul 2022 10:10:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232936AbiGLKKe (ORCPT ); Tue, 12 Jul 2022 06:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230316AbiGLKJ5 (ORCPT ); Tue, 12 Jul 2022 06:09:57 -0400 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8689BAC07D; Tue, 12 Jul 2022 03:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620571; bh=DPGdqSGhmEWAw3do58iJLw426/BrSVvrm6dZCPnb6sg=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=BIab1jSnrcfjyXtaTMcv7H4c7NE2AllXhnRsNsf1gOGJv/aFzXPAcxwGaJGfeyKTn 6Z2VU9VVNaUOegGkPy1cJBkSxGXe4MXXKWrQLuIaEl4cDoMU+YO0bH7VyQ7W2QIHU9 jYCngFyhKbVQyEGK/2p0TMgwRdDhSiPbpmtPfejQ= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:31 +0200 (CEST) X-EA-Auth: fIrO8Uw6UjpI8UagY7F1eZ1Uw0kxVaPs37zeJksxAxhmSq+YBb/2S1e6o2g3EKOv74B247gUIO06e/piUEPUmhAwo9gB2YmeaWYA0PpaIX0= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com, Andy Shevchenko Subject: [PATCH v5 11/12] leds: is31fl319x: use simple i2c probe function Date: Tue, 12 Jul 2022 12:08:37 +0200 Message-Id: <20220712100841.1538395-12-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko The i2c probe functions here don't use the id information provided in their second argument, so the single-parameter i2c probe function ("probe_new") can be used instead. Signed-off-by: Andy Shevchenko Signed-off-by: Vincent Knecht --- drivers/leds/leds-is31fl319x.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 233ed67830a3..52b59b62f437 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -494,8 +494,7 @@ static inline int is31fl3196_db_to_gain(u32 dezibel) return dezibel / IS31FL3196_AUDIO_GAIN_DB_STEP; } =20 -static int is31fl319x_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int is31fl319x_probe(struct i2c_client *client) { struct is31fl319x_chip *is31; struct device *dev =3D &client->dev; @@ -597,7 +596,7 @@ static struct i2c_driver is31fl319x_driver =3D { .name =3D "leds-is31fl319x", .of_match_table =3D of_is31fl319x_match, }, - .probe =3D is31fl319x_probe, + .probe_new =3D is31fl319x_probe, .id_table =3D is31fl319x_id, }; =20 --=20 2.35.3 From nobody Sat Apr 18 17:26:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A518C43334 for ; Tue, 12 Jul 2022 10:10:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233000AbiGLKKp (ORCPT ); Tue, 12 Jul 2022 06:10:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232941AbiGLKKK (ORCPT ); Tue, 12 Jul 2022 06:10:10 -0400 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7E44ACECB; Tue, 12 Jul 2022 03:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1657620574; bh=RqYJd9WMWhQUUPRvy802P6+p3an2H7CBe1ZE7v+RG6w=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=El4ILC98AkU+I3Dq50xTlRQoOKxrSKTUcRVgbyv0OtHFG6I2NdOA4ZrUttZwuKfGw y6+AGHIt7sOVj4C433VdY7k/rVou4+pZ4DW55PPsD1+Ma52+s5q3dIi9DIsCDx8Hwc GVtB+uNMqnVvh+HyrydWTqQ6+pSIz9GFGCcrsdMU= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via [213.182.55.207] Tue, 12 Jul 2022 12:09:34 +0200 (CEST) X-EA-Auth: 1ZnJIAviytXjtFSUkRB449lCznmGB4XeZrGQZaNC9QK2ENtalrcSZv0MzIjhZzjrYoD5RKUJOwcskrzMzHvOgZS6RhqV+cds6nFq4/RRlwg= From: Vincent Knecht To: Pavel Machek , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, hns@goldelico.com, Andy Shevchenko Subject: [PATCH v5 12/12] leds: is31fl319x: sort header inclusion alphabetically Date: Tue, 12 Jul 2022 12:08:38 +0200 Message-Id: <20220712100841.1538395-13-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220712100841.1538395-1-vincent.knecht@mailoo.org> References: <20220712100841.1538395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko Sort header inclusion alphabetically. Signed-off-by: Andy Shevchenko Signed-off-by: Vincent Knecht --- drivers/leds/leds-is31fl319x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c index 52b59b62f437..f2d05ae91753 100644 --- a/drivers/leds/leds-is31fl319x.c +++ b/drivers/leds/leds-is31fl319x.c @@ -8,7 +8,9 @@ * effect LEDs. */ =20 +#include #include +#include #include #include #include @@ -16,8 +18,6 @@ #include #include #include -#include -#include =20 /* register numbers */ #define IS31FL319X_SHUTDOWN 0x00 --=20 2.35.3