From patchwork Tue Nov 5 16:10:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vicentiu Galanopulo X-Patchwork-Id: 841939 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F3E215DBB3 for ; Tue, 5 Nov 2024 16:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823054; cv=none; b=u0QcdwSAlbBfBYQ1vPaecPbw2GQW2TDkb9TmO6eXRmqPGE9i9J4/BnvZjIKbLrwWJ+B1FwISUMUZrSDfnMhSuiDKla09As0Fyr7LPoSTLEvbOc7+bRpCCZRzq1QXqagYYC7TBuN2mXGKLHOGNEQQhNG0c7ayIf6kfU+76YMMIOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823054; c=relaxed/simple; bh=GOR+kBMKKKTUIGtKRM9XCI7YPrZNWfva3GQbxSEtoSM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Z25HAmRjvkUFS4sxJU5rL4fT6mqVdzTrH5R70mYbs2ngir+lFRFFwdxhizlim1Q+uFSFOaShfsKNpe5B/nxNfqGKnhxuB0VOiM/wmjjRvXycywA39oQRTBSJahWxFFRrc3WzMMFR3sXoKr3sJ8XD/B4wkYyUggGxWGGKwxvFmUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=remote-tech.co.uk; spf=pass smtp.mailfrom=remote-tech.co.uk; dkim=pass (2048-bit key) header.d=remote-tech-co-uk.20230601.gappssmtp.com header.i=@remote-tech-co-uk.20230601.gappssmtp.com header.b=A28ZCbSU; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=remote-tech.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=remote-tech.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=remote-tech-co-uk.20230601.gappssmtp.com header.i=@remote-tech-co-uk.20230601.gappssmtp.com header.b="A28ZCbSU" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a9eb3794a04so142203866b.3 for ; Tue, 05 Nov 2024 08:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=remote-tech-co-uk.20230601.gappssmtp.com; s=20230601; t=1730823050; x=1731427850; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=I8iWPAz9+BWvksPjr7PaPX4v4WYSbjtCmVf883G/l4A=; b=A28ZCbSUe1sy7nr+smYopJ15aGJDyBhkG0ZSSY/Uhrw7QSx2w3rPwewWEXN3xKx8Oy 88ICBj4vP2tP8ZHoj29LPsCL+AS2Oao0K08YCvwuUuymC/4F4NKPkuZx0p2egP0mADgn UPAjYBbmJUqrLG3YwSChwu7k0bRXofnEaaoacFRi1N7X8Gd/tWzpx8sM9Xhu7RPHzFsn eviUj7y93Vv4MOx0RwJeDXV1wdbYYt0pcltIuxSxg86PYMcQlymGBGSnekJ1RZJZVBq5 AI9iJFqVOVfLIZnEwkVA6BmR19z42XFP2oP4kiWd8AhcHfZftDmkVMdsz12Wyz8ILyua QA8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730823050; x=1731427850; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I8iWPAz9+BWvksPjr7PaPX4v4WYSbjtCmVf883G/l4A=; b=rcfpB0+5ZsCg1IZOuLt70+++koECcOi1ZdKRtgxJVM7CKz/oqtKUNIjrjGuzDk3QlJ o198TYNzdheidue7axvw4pzzR+h8k4XXKAKBb2Pfm7ndTkywgc477O+wqfQDAyBX0hvm FcB7NlR/48OjtJ0opZoiaib/z8ngkQO30ti13Af+rJ/KoxYPL57Xm+R+hcDHgBk4EJd9 IwBTndaxcBHlSfev1fcXl4iWkQNB8iMeKv6QXTMYONkWadY0OMQZf/MySm8vSEdKydNe efeMmXQcDXec8NEJeDgvIx1ToDnx5Gz6DOUIu/wa1Hgg74lrq12bI76QzloO4jsRePxt 0uHw== X-Forwarded-Encrypted: i=1; AJvYcCXJe5eQCZI2MyacJnJJkl5bQffQ8Q48NFBJj71lxRX9wKyLFJwV8GsCY5rRE+8v3pC1HrG0KGsUAu4l@vger.kernel.org X-Gm-Message-State: AOJu0Yyc5kdtnZ7EUr5VAg0n4QA3h0cW2xO3aJyDlUpxyUHr5T1lJwAO TqNsgwcMg1vT7giB8k2HLNlx4pI27gjsnuT7vX+HotVX3YJRlPo3yz23dgpE161tISTFXwdCcLb hb6GB25jwaGdVRU4STB3WCezE1WgyPPqyWb2MrPP1eAdoF2lrO5H142BWSNNbDS5vY6jBqCSqeM QJ6WKNeUJPQ7x5l0WFkpkPJnnR X-Google-Smtp-Source: AGHT+IGkmJfi7dRHZtTpmNCLlbGTZDSTQBEvMTQNo52T6AzDkPM1XFezL57iku5tpryplHLQ/GERnQ== X-Received: by 2002:a17:907:948a:b0:a9a:238a:381d with SMTP id a640c23a62f3a-a9e3a6ca29cmr2346666466b.52.1730823049770; Tue, 05 Nov 2024 08:10:49 -0800 (PST) Received: from localhost.localdomain ([178.27.36.125]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9eb17f7928sm151184666b.138.2024.11.05.08.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 08:10:49 -0800 (PST) From: Vicentiu Galanopulo To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Vicentiu Galanopulo , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 1/3] [PATCH v3] Documentation:leds: Add leds-st1202.rst Date: Tue, 5 Nov 2024 16:10:36 +0000 Message-Id: <20241105161041.4813-1-vicentiu.galanopulo@remote-tech.co.uk> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add usage for sysfs hw_pattern entry for leds-st1202 Signed-off-by: Vicentiu Galanopulo --- - Changes in v3: Add leds-st1202 to index.rst - Changes in v2: Implement review comments --- Documentation/leds/index.rst | 1 + Documentation/leds/leds-st1202.rst | 36 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Documentation/leds/leds-st1202.rst diff --git a/Documentation/leds/index.rst b/Documentation/leds/index.rst index 3ade16c18328..0ab0a2128a11 100644 --- a/Documentation/leds/index.rst +++ b/Documentation/leds/index.rst @@ -28,4 +28,5 @@ LEDs leds-mlxcpld leds-mt6370-rgb leds-sc27xx + leds-st1202.rst leds-qcom-lpg diff --git a/Documentation/leds/leds-st1202.rst b/Documentation/leds/leds-st1202.rst new file mode 100644 index 000000000000..e647966e496c --- /dev/null +++ b/Documentation/leds/leds-st1202.rst @@ -0,0 +1,36 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============================================ +Kernel driver for STMicroelectronics LED1202 +============================================ + +/sys/class/leds//hw_pattern +-------------------------------- + +Specify a hardware pattern for the ST1202 LED. The LED +controller implements 12 low-side current generators +with independent dimming control. Internal volatile memory +allows the user to store up to 8 different patterns. +Each pattern is a particular output configuration in terms +of PWM duty-cycle and duration (ms). + +To be compatible with the hardware pattern +format, maximum 8 tuples of brightness (PWM) and duration must +be written to hw_pattern. + +- Min pattern duration: 22 ms +- Max pattern duration: 5660 ms + +The format of the hardware pattern values should be: +"brightness duration brightness duration ..." + +/sys/class/leds//repeat +---------------------------- + +Specify a pattern repeat number, which is common for all channels. +Default is 1; negative numbers and 0 are invalid. + +This file will always return the originally written repeat number. + +When the 255 value is written to it, all patterns will repeat +indefinitely. From patchwork Tue Nov 5 16:10:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vicentiu Galanopulo X-Patchwork-Id: 840950 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E88617A5A4 for ; Tue, 5 Nov 2024 16:10:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823059; cv=none; b=IKCOwdDBe/znqTpf6BrdasSzS3RUKu0SiaLnKbQi5qsHmql/Pj9G4yprcdn8A5pCftnRotruVwJwWMwxuCj+lt5h5jenkxmNDT42Rm+Qu3LuVW801NB7NvJE222VUklJE0wM0U3kSTI2o9fubqjr4YMjCTswp8A138SrjHRCd3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823059; c=relaxed/simple; bh=w+XHq9w7Bz9O2dHFT5zj8vUvIOCoNUqwqvDDMjf/3u0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jufaFj6xPez/Mp8dX/DX1R3fWzVDQj6K+MTpoJ3M4rbN5aLTneG3shiOy3iDh80t0o+3hpMkmjYHPUZJYy/x0InHX/0RA2bW4qsxPzzc0KffrQqA1ThbZwfhaI/BNIoJhig7aQm9i/6DS6TF517fA1JRdzbJb/tiSjk0lL6wXoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=remote-tech.co.uk; spf=pass smtp.mailfrom=remote-tech.co.uk; dkim=pass (2048-bit key) header.d=remote-tech-co-uk.20230601.gappssmtp.com header.i=@remote-tech-co-uk.20230601.gappssmtp.com header.b=kd7Eg5rb; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=remote-tech.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=remote-tech.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=remote-tech-co-uk.20230601.gappssmtp.com header.i=@remote-tech-co-uk.20230601.gappssmtp.com header.b="kd7Eg5rb" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2fb4af0b6beso86923271fa.3 for ; Tue, 05 Nov 2024 08:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=remote-tech-co-uk.20230601.gappssmtp.com; s=20230601; t=1730823056; x=1731427856; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zHi7Lp38jT8FmPt7TMK4PF42l87ejDv0GI3ZM6aDB/0=; b=kd7Eg5rbYM++BwMbFzFGP0IwFmtKZt82trmlT+ZwCjUSrSPMPG0JgpJ/tTDE8/bq7K 0V/BE7G8riRYFKe6ePN9oEskDp/hT1jOinXuSPVPxZ871D8CQDlet53uNiHukt3PFoY3 XmkcgqO9hfqtu3sn/PflqytBd3yHk85UrchONzy7E+NxBSB4U9RkJZgq6O/PCm3kaahb Q9YQhg2u8CSF28xFSObEe32WsxbpqDDcIAdMJiBsKdo/qCOGgImiMS9oJ6WsuUg+DBOF pM3fKfdPa1QYRh82ZAQz+3kdJeT/1kugUsFBDMrs/2Utk4B68piGQSy5njllGbkjqmV7 +M8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730823056; x=1731427856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zHi7Lp38jT8FmPt7TMK4PF42l87ejDv0GI3ZM6aDB/0=; b=uV57Gor3GMENF5YNgikUJ2JDKovpabclext9D0SrDgOo0lvh5PAqBEB/XwLb4yhSw9 A+f4rKDRFxTiit2f6ubndwetIuR23kjQV0oLm6l5IpA0pms9XyjVHatd1ifSgHt/CBUL c0+IXPyB6qnxSAqkdVOjo1BwwbByqgmsiOKWSzXIi/NYNwaEx/6PBjO/ySRl9PhsWVLN WMZEYfneU1bdJ+M4qPEGRtdtFq6OW1wGvt4ye5RJZ7BOclPYcrQJogA6qgdue2jnKJ1c R84eIUt7ti94BfOCOO7og31FqN9WN0QF43m1d8joqvfgVkVUaOs9ABQ1sS16lmHol9cK K8yQ== X-Forwarded-Encrypted: i=1; AJvYcCUw0t5gPIfe6cqsPaV6sTNQI4bWgi07paKhfUkPf4FSE6RZtp7aE4KWJzaJhjbj4gZGD6urrguhdzDa@vger.kernel.org X-Gm-Message-State: AOJu0YylNlS8K3Q3oP5mpVp+V12JlUD45WUnJA4gEJy6vMoysLUfvDW1 87vmsES7bktyoY9oInTcoKRectz+mqoy0h7b/qh6qMbUgkucfO+w9/pOH//9ojFa9i00Wic3cdc vlJSGoXffTz1l/AupkwU7UPWh1R5rhMmfaCkQrY/prFev0EV0Qq+QtJGtq13GxThAt+k45zZt2k sdIF4EGenG+nHnNzjzRFGUuuTm X-Google-Smtp-Source: AGHT+IHDuD8+xEUGCr7lKtRUPyXfy9Q6dyYFtIlDZz++QeysYZt0+vINN/SdZ6xr3U9/UqhQeiHppg== X-Received: by 2002:a05:651c:b2b:b0:2fb:3960:9667 with SMTP id 38308e7fff4ca-2fedb7a2aa3mr109659971fa.14.1730823054168; Tue, 05 Nov 2024 08:10:54 -0800 (PST) Received: from localhost.localdomain ([178.27.36.125]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9eb17f7928sm151184666b.138.2024.11.05.08.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 08:10:53 -0800 (PST) From: Vicentiu Galanopulo To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Vicentiu Galanopulo , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 2/3] [PATCH v4] dt-bindings: leds: Add LED1202 LED Controller Date: Tue, 5 Nov 2024 16:10:37 +0000 Message-Id: <20241105161041.4813-2-vicentiu.galanopulo@remote-tech.co.uk> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241105161041.4813-1-vicentiu.galanopulo@remote-tech.co.uk> References: <20241105161041.4813-1-vicentiu.galanopulo@remote-tech.co.uk> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The LED1202 is a 12-channel low quiescent current LED driver with: * Supply range from 2.6 V to 5 V * 20 mA current capability per channel * 1.8 V compatible I2C control interface * 8-bit analog dimming individual control * 12-bit local PWM resolution * 8 programmable patterns If the led node is present in the controller then the channel is set to active. v1: https://lore.kernel.org/lkml/ZnCnnQfwuRueCIQ0@admins-Air/T/ v2: https://lore.kernel.org/all/ZniNdGgKyUMV-hjq@admins-Air/T/ v3: https://lore.kernel.org/all/ZniNdGgKyUMV-hjq@admins-Air/T/ Signed-off-by: Vicentiu Galanopulo --- Changes in v4: - remove label property, use devm_led_classdev_register_ext instead - use as base patch the v3 Changes in v3: - remove active property Changes in v2: - renamed label to remove color from it - add color property for each node - add function and function-enumerator property for each node --- .../devicetree/bindings/leds/st,led1202.yaml | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/st,led1202.yaml diff --git a/Documentation/devicetree/bindings/leds/st,led1202.yaml b/Documentation/devicetree/bindings/leds/st,led1202.yaml new file mode 100644 index 000000000000..7e49e6464d41 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/st,led1202.yaml @@ -0,0 +1,132 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/st,led1202.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ST LED1202 LED controllers + +maintainers: + - Vicentiu Galanopulo + +description: | + The LED1202 is a 12-channel low quiescent current LED controller + programmable via I2C; The output current can be adjusted separately + for each channel by 8-bit analog and 12-bit digital dimming control. + Datasheet available at + https://www.st.com/en/power-management/led1202.html + +properties: + compatible: + const: st,led1202 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^led@[0-9a-f]$": + type: object + $ref: common.yaml# + unevaluatedProperties: false + + properties: + reg: + minimum: 0 + maximum: 11 + + required: + - reg + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + led-controller@58 { + compatible = "st,led1202"; + reg = <0x58>; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0x0>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <1>; + }; + + led@1 { + reg = <0x1>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <2>; + }; + + led@2 { + reg = <0x2>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <3>; + }; + + led@3 { + reg = <0x3>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <4>; + }; + + led@4 { + reg = <0x4>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <5>; + }; + + led@5 { + reg = <0x5>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <6>; + }; + + led@6 { + reg = <0x6>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <7>; + }; + + led@7 { + reg = <0x7>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <8>; + }; + + led@8 { + reg = <0x8>; + function = LED_FUNCTION_STATUS; + color = ; + function-enumerator = <9>; + }; + }; + }; +... From patchwork Tue Nov 5 16:10:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vicentiu Galanopulo X-Patchwork-Id: 841938 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B4E517BB1C for ; Tue, 5 Nov 2024 16:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823062; cv=none; b=UX6/uurXssnj6EQm2JfMmBJv0a9e9/zvp0jAAavfWuT9OwC8A2H2GgQW9n6Ce6tnnzFF3JSVohAVqYQTfYVZF4pNLVhVg9dJJO3X33qeT3pE37Fn9sW4r0krrf8R+LC/XgKivFL2rM2mOhFHSpOvNWdvmkvHXB7PhmXIRIMgKpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823062; c=relaxed/simple; bh=jRwCYD6I+LXxliE9QSqQPxv9oQSaV1QcYWFcWedy+OM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Na+ttY7wEgkdQeXyVOu++Q+JK5xsfuML2sro7bB4NwBAJwSxVwbQjV4gFHz22KpPa9vejCKh4PfiOh3Dwu1wVK9n5NOakcSZ0PlPzsDSZLRrtoUiZ66pdybaA6fpaCRNR4+ngTGzVbEowUu4fEKsWwFlbHO27swSWpzIV5eM1po= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=remote-tech.co.uk; spf=pass smtp.mailfrom=remote-tech.co.uk; dkim=pass (2048-bit key) header.d=remote-tech-co-uk.20230601.gappssmtp.com header.i=@remote-tech-co-uk.20230601.gappssmtp.com header.b=QoJyOyV/; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=remote-tech.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=remote-tech.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=remote-tech-co-uk.20230601.gappssmtp.com header.i=@remote-tech-co-uk.20230601.gappssmtp.com header.b="QoJyOyV/" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-53b13ea6b78so8914708e87.2 for ; Tue, 05 Nov 2024 08:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=remote-tech-co-uk.20230601.gappssmtp.com; s=20230601; t=1730823058; x=1731427858; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=FyQWsFLgu84Zg0FlOAGhapW+7L9D+QhFgFMNEc4Pqjo=; b=QoJyOyV/+nGTlM3WymsrAHQsxFXawzUGhPnq7YIakJbWEAI+6Znotionl+h0qS4Gl1 EgjoK99x7QTxhr07yPowO9jHajhc+XFmwHj9oy3u1ofquDiFDB3wz9ONt6+RyUJqJItI K9SQBoBEcy7MDlmcvg73l8SGo90+1ubcONom21/joLLhkOzfHIzrVoZ1pu6R03YGm2pb Cc67AUe2WbIe6NQjZ+RL5hQ3PS5OgQuJVU+T3erHLuGSRUITw/jZHyPe3WWQMzcBpYyd sNO+nw3vi+XW49YhcXCDiWIph5/cP3smVmCGTrm2lMIBE+Fs8d4hi251B+MRjATH74hT JqAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730823058; x=1731427858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FyQWsFLgu84Zg0FlOAGhapW+7L9D+QhFgFMNEc4Pqjo=; b=gUhWXKuwcL3KtUZq8dcRfruXEmehLvTFGW6XQ9QPpMIVodoTgqDkbD3zcK7g01SPg/ VFMRN++uqRcVKpM0cG0BOQ71DFTS0vxI/L3j81dXoZnUvmwCyz2yf3R5MN54kNNpqjYj t//gyixbvdH16ZY5XiYwN3Bg5PVhwYB6v3UT7h/TG/I4XkLjFH5je2qDk4qvq0GKeJ98 1rRE720hkhTGmPNzYcx+W4Zas4rO88qCrXbAmdhnKypIQAEjz2Q51uVDk3jUFUli7+XZ nHokYlM3XsBlGWz739Bzdrh27oCXbnt9WarLRf/vu+iIi4aL3XlSX2+OlL/6xeUPRs02 ikSA== X-Forwarded-Encrypted: i=1; AJvYcCWBGrksKxPT5x9rNNEzdvDyM4Wi++jcojFPi2aIkY4mKg17848zqEwuQY2m7+WblxzzcjAbXNt2oXGZ@vger.kernel.org X-Gm-Message-State: AOJu0Yyut+jpUeNUEwxMjwDch8/hcvvHRAuUFLmcIT/doz6/tDHJUrRJ an4CHQNOQ5RwJL2eOIMCulHeXpescG+C4cPCLiFwLLZjEaOT9KigS+kYaQ0Yw3U+DqHTSeZA2c6 EJ7GRr/a0qL/CkgZmFDsAw9hx3gsQ0zt2q+9zLnN2eXG+6JwScrk7EZg2buW66mFoi6xJGTbIzs eE4N4mGCnEoebf/tXdBehkT37q X-Google-Smtp-Source: AGHT+IHIPQavs95fNZitaFE7SYxytahMk1/sPBtPMi0AhLBEXru7S168Re2c40Wn6uNCPfezDF53JA== X-Received: by 2002:a05:6512:acf:b0:533:483f:9562 with SMTP id 2adb3069b0e04-53d65e0b459mr12671803e87.42.1730823057946; Tue, 05 Nov 2024 08:10:57 -0800 (PST) Received: from localhost.localdomain ([178.27.36.125]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9eb17f7928sm151184666b.138.2024.11.05.08.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 08:10:57 -0800 (PST) From: Vicentiu Galanopulo To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Vicentiu Galanopulo , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 3/3] [PATCH v5] leds: Add LED1202 I2C driver Date: Tue, 5 Nov 2024 16:10:38 +0000 Message-Id: <20241105161041.4813-3-vicentiu.galanopulo@remote-tech.co.uk> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241105161041.4813-1-vicentiu.galanopulo@remote-tech.co.uk> References: <20241105161041.4813-1-vicentiu.galanopulo@remote-tech.co.uk> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The output current can be adjusted separately for each channel by 8-bit analog (current sink input) and 12-bit digital (PWM) dimming control. The LED1202 implements 12 low-side current generators with independent dimming control. Internal volatile memory allows the user to store up to 8 different patterns, each pattern is a particular output configuration in terms of PWM duty-cycle (on 4096 steps). Analog dimming (on 256 steps) is per channel but common to all patterns. Each device tree LED node will have a corresponding entry in /sys/class/leds with the label name. The brightness property corresponds to the per channel analog dimming, while the patterns[1-8] to the PWM dimming control. Signed-off-by: Vicentiu Galanopulo --- Changes in v5: - remove unused macros - switch to using devm_led_classdev_register_ext (struct st1202_led update) - add prescalar_to_milliseconds (convert [22..5660]ms to [0..255] reg value) - remove register range check in dt_init (range protected by yaml) - address all review comments in v4 Changes in v4: - Remove attributes/extended attributes implementation - Use /sys/class/leds//hw_pattern (Pavel suggestion) - Implement review findings of Christophe JAILLET Changes in v3: - Rename all ll1202 to st1202, including driver file name - Convert all magic numbers to defines - Refactor the show/store callbacks as per Lee's and Thomas's review - Remove ll1202_get_channel and use dev_ext_attributes instead - Log all error values for all the functions - Use sysfs_emit for show callbacks Changes in v2: - Fix build error for device_attribute modes --- drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/leds-st1202.c | 510 +++++++++++++++++++++++++++++++++++++ 3 files changed, 522 insertions(+) create mode 100644 drivers/leds/leds-st1202.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index b784bb74a837..c4fdacc00066 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -931,6 +931,17 @@ config LEDS_LM36274 Say Y to enable the LM36274 LED driver for TI LMU devices. This supports the LED device LM36274. +config LEDS_ST1202 + tristate "LED Support for STMicroelectronics LED1202 I2C chips" + depends on LEDS_CLASS + depends on I2C + depends on OF + select LEDS_TRIGGERS + help + Say Y to enable support for LEDs connected to LED1202 + LED driver chips accessed via the I2C bus. + Supported devices include LED1202. + config LEDS_TPS6105X tristate "LED support for TI TPS6105X" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 18afbb5a23ee..e8b39ef760cc 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -81,6 +81,7 @@ obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_PWM) += leds-pwm.o obj-$(CONFIG_LEDS_REGULATOR) += leds-regulator.o obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o +obj-$(CONFIG_LEDS_ST1202) += leds-st1202.o obj-$(CONFIG_LEDS_SUN50I_A100) += leds-sun50i-a100.o obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o diff --git a/drivers/leds/leds-st1202.c b/drivers/leds/leds-st1202.c new file mode 100644 index 000000000000..565c8fbfe515 --- /dev/null +++ b/drivers/leds/leds-st1202.c @@ -0,0 +1,510 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * LED driver for STMicroelectronics LED1202 chip + * + * Copyright (C) 2024 Remote-Tech Ltd. UK + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ST1202_CHAN_DISABLE_ALL 0x00 +#define ST1202_CHAN_ENABLE_HIGH 0x03 +#define ST1202_CHAN_ENABLE_LOW 0x02 +#define ST1202_CONFIG_REG 0x04 +/* PATS: Pattern sequence feature enable */ +#define ST1202_CONFIG_REG_PATS BIT(7) +/* PATSR: Pattern sequence runs (self-clear when sequence is finished) */ +#define ST1202_CONFIG_REG_PATSR BIT(6) +#define ST1202_CONFIG_REG_SHFT BIT(3) +#define ST1202_DEV_ENABLE 0x01 +#define ST1202_DEV_ENABLE_ON BIT(0) +#define ST1202_DEV_ENABLE_RESET BIT(7) +#define ST1202_DEVICE_ID 0x00 +#define ST1202_ILED_REG0 0x09 +#define ST1202_MAX_LEDS 12 +#define ST1202_MAX_PATTERNS 8 +#define ST1202_MILLIS_PATTERN_DUR_MAX 5660 +#define ST1202_MILLIS_PATTERN_DUR_MIN 22 +#define ST1202_PATTERN_DUR 0x16 +#define ST1202_PATTERN_PWM 0x1E +#define ST1202_PATTERN_REP 0x15 + +struct st1202_led { + struct fwnode_handle *fwnode; + struct led_classdev led_cdev; + struct st1202_chip *chip; + bool is_active; + int led_num; +}; + +struct st1202_chip { + struct i2c_client *client; + struct mutex lock; + struct st1202_led leds[ST1202_MAX_LEDS]; +}; + +static struct st1202_led *cdev_to_st1202_led(struct led_classdev *cdev) +{ + return container_of(cdev, struct st1202_led, led_cdev); +} + +static int st1202_read_reg(struct st1202_chip *chip, int reg, uint8_t *val) +{ + int ret; + + ret = i2c_smbus_read_byte_data(chip->client, reg); + if (ret < 0) + return ret; + + *val = (uint8_t)ret; + return 0; +} + +static int st1202_write_reg(struct st1202_chip *chip, int reg, uint8_t val) +{ + return i2c_smbus_write_byte_data(chip->client, reg, val); +} + +static uint8_t st1202_prescalar_to_miliseconds(unsigned int value) +{ + return value/ST1202_MILLIS_PATTERN_DUR_MIN - 1; +} + +static int st1202_pwm_pattern_write(struct st1202_chip *chip, int led_num, + int pattern, unsigned int value) +{ + u8 value_l, value_h; + int ret; + + value_l = (u8)value; + value_h = (u8)(value >> 8); + + /* + * Datasheet: Register address low = 1Eh + 2*(xh) + 18h*(yh), + * where x is the channel number (led number) in hexadecimal (x = 00h .. 0Bh) + * and y is the pattern number in hexadecimal (y = 00h .. 07h) + */ + ret = st1202_write_reg(chip, (ST1202_PATTERN_PWM + (led_num * 2) + 0x18 * pattern), + value_l); + if (ret != 0) { + dev_err(&chip->client->dev, "Failed writing value %d to register [0x%x], error: %d\n", + value_l, ST1202_PATTERN_PWM + (led_num * 2) + 0x18 * pattern, ret); + return ret; + } + + /* + * Datasheet: Register address high = 1Eh + 01h + 2(xh) +18h*(yh), + * where x is the channel number in hexadecimal (x = 00h .. 0Bh) + * and y is the pattern number in hexadecimal (y = 00h .. 07h) + */ + ret = st1202_write_reg(chip, (ST1202_PATTERN_PWM + 0x1 + (led_num * 2) + 0x18 * pattern), + value_h); + if (ret != 0) { + dev_err(&chip->client->dev, "Failed writing value %d to register [0x%x], error: %d\n", + value_h, ST1202_PATTERN_PWM + 0x1 + (led_num * 2) + 0x18 * pattern, ret); + return ret; + } + + return 0; +} + +static int st1202_duration_pattern_write(struct st1202_chip *chip, int pattern, + unsigned int value) +{ + int ret; + + ret = st1202_write_reg(chip, (ST1202_PATTERN_DUR + pattern), + st1202_prescalar_to_miliseconds(value)); + if (ret != 0) { + dev_err(&chip->client->dev, "Writing to register [0x%x] failed, value %u\n", + ST1202_PATTERN_DUR + pattern, value); + return ret; + } + + return 0; +} + +static void st1202_brightness_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct st1202_led *led; + struct st1202_chip *chip; + int ret; + + led = cdev_to_st1202_led(led_cdev); + chip = led->chip; + + mutex_lock(&chip->lock); + + ret = st1202_write_reg(chip, ST1202_ILED_REG0 + led->led_num, value); + if (ret != 0) + dev_err(&chip->client->dev, "Reading register [0x%x] failed, error: %d\n", + ST1202_ILED_REG0 + led->led_num, ret); + + mutex_unlock(&chip->lock); +} + +static enum led_brightness st1202_brightness_get(struct led_classdev *led_cdev) +{ + struct st1202_led *led; + struct st1202_chip *chip; + u8 value; + int ret; + + led = cdev_to_st1202_led(led_cdev); + chip = led->chip; + + mutex_lock(&chip->lock); + + ret = st1202_read_reg(chip, ST1202_ILED_REG0 + led->led_num, + &value); + if (ret != 0) + dev_err(&chip->client->dev, "Reading register [0x%x] failed, error: %d\n", + ST1202_ILED_REG0 + led->led_num, ret); + + mutex_unlock(&chip->lock); + + return value; +} + +static int st1202_channel_set(struct st1202_chip *chip, int led_num, bool active) +{ + u8 chan_low, chan_high; + int ret; + + mutex_lock(&chip->lock); + + if (led_num <= 7) { + ret = st1202_read_reg(chip, ST1202_CHAN_ENABLE_LOW, &chan_low); + if (ret < 0) { + dev_err(&chip->client->dev, "Failed reading register [0x%x], error: %d\n", + ST1202_CHAN_ENABLE_LOW, ret); + goto exit; + } + + chan_low = active ? chan_low | BIT(led_num) : chan_low & ~BIT(led_num); + + ret = st1202_write_reg(chip, ST1202_CHAN_ENABLE_LOW, chan_low); + if (ret < 0) { + dev_err(&chip->client->dev, "Failed writing to register [0x%x], error: %d\n", + ST1202_CHAN_ENABLE_LOW, ret); + goto exit; + } + } else { + ret = st1202_read_reg(chip, ST1202_CHAN_ENABLE_HIGH, &chan_high); + if (ret < 0) { + dev_err(&chip->client->dev, "Failed reading register [0x%x], error: %d\n", + ST1202_CHAN_ENABLE_HIGH, ret); + goto exit; + } + + chan_high = active ? chan_high | (BIT(led_num) >> 8) : + chan_high & ~(BIT(led_num) >> 8); + + ret = st1202_write_reg(chip, ST1202_CHAN_ENABLE_HIGH, chan_high); + if (ret < 0) + dev_err(&chip->client->dev, "Failed writing to register [0x%x], error: %d\n", + ST1202_CHAN_ENABLE_HIGH, ret); + } + +exit: + mutex_unlock(&chip->lock); + return ret; +} + +static int st1202_led_set(struct led_classdev *ldev, enum led_brightness value) +{ + struct st1202_led *led; + struct st1202_chip *chip; + int ret; + + led = cdev_to_st1202_led(ldev); + chip = led->chip; + + ret = st1202_channel_set(chip, led->led_num, value == LED_OFF ? false : true); + + return ret; +} + +static int st1202_led_pattern_clear(struct led_classdev *ldev) +{ + struct st1202_led *led; + struct st1202_chip *chip; + int ret; + + led = cdev_to_st1202_led(ldev); + chip = led->chip; + + mutex_lock(&chip->lock); + + for (int patt = 0; patt < ST1202_MAX_PATTERNS; patt++) { + ret = st1202_pwm_pattern_write(chip, led->led_num, patt, LED_OFF); + if (ret != 0) + goto exit; + + ret = st1202_duration_pattern_write(chip, patt, ST1202_MILLIS_PATTERN_DUR_MIN); + if (ret != 0) + goto exit; + } + +exit: + mutex_unlock(&chip->lock); + + return ret; +} + +static int st1202_led_pattern_set(struct led_classdev *ldev, + struct led_pattern *pattern, + u32 len, int repeat) +{ + struct st1202_led *led; + struct st1202_chip *chip; + int ret; + + led = cdev_to_st1202_led(ldev); + chip = led->chip; + + if (len > ST1202_MAX_PATTERNS) + return -EINVAL; + + mutex_lock(&chip->lock); + + for (int patt = 0; patt < len; patt++) { + if (pattern[patt].delta_t < ST1202_MILLIS_PATTERN_DUR_MIN || + pattern[patt].delta_t > ST1202_MILLIS_PATTERN_DUR_MAX) { + ret = -EINVAL; + goto exit; + } + + ret = st1202_pwm_pattern_write(chip, led->led_num, patt, pattern[patt].brightness); + if (ret != 0) + goto exit; + + ret = st1202_duration_pattern_write(chip, patt, pattern[patt].delta_t); + if (ret != 0) + goto exit; + } + + ret = st1202_write_reg(chip, ST1202_PATTERN_REP, repeat); + if (ret != 0) { + dev_err(&chip->client->dev, "Writing register [0x%x] failed, error: %d\n", + ST1202_PATTERN_REP, ret); + goto exit; + } + + ret = st1202_write_reg(chip, ST1202_CONFIG_REG, + (ST1202_CONFIG_REG_PATSR | ST1202_CONFIG_REG_PATS | + ST1202_CONFIG_REG_SHFT)); + if (ret != 0) { + dev_err(&chip->client->dev, "Failed writing value %ld to register [0x%x], error: %d\n", + (ST1202_CONFIG_REG_PATSR | ST1202_CONFIG_REG_PATS | ST1202_CONFIG_REG_SHFT), + ST1202_CONFIG_REG, ret); + goto exit; + } + +exit: + mutex_unlock(&chip->lock); + + return ret; +} + +static int st1202_dt_init(struct st1202_chip *chip) +{ + struct device *dev = &chip->client->dev; + struct st1202_led *led; + int err, reg; + + for_each_available_child_of_node_scoped(dev_of_node(dev), child) { + struct led_init_data init_data = {}; + + err = of_property_read_u32(child, "reg", ®); + if (err) { + of_node_put(child); + return dev_err_probe(dev, err, "Invalid register, error: %d\n", err); + } + + led = &chip->leds[reg]; + led->is_active = true; + led->fwnode = of_fwnode_handle(child); + + led->led_cdev.max_brightness = U8_MAX; + led->led_cdev.brightness_set_blocking = st1202_led_set; + led->led_cdev.pattern_set = st1202_led_pattern_set; + led->led_cdev.pattern_clear = st1202_led_pattern_clear; + led->led_cdev.default_trigger = "pattern"; + + init_data.fwnode = led->fwnode; + init_data.devicename = "st1202"; + init_data.default_label = ":"; + err = devm_led_classdev_register_ext(dev, + &led->led_cdev, &init_data); + if (err < 0) { + dev_err_probe(dev, err, "Failed to register LED class dev, + error: %d\n", err); + return err; + } + led->led_cdev.brightness_set = st1202_brightness_set; + led->led_cdev.brightness_get = st1202_brightness_get; + } + + return 0; +} + +static int st1202_setup(struct st1202_chip *chip) +{ + int ret; + + mutex_lock(&chip->lock); + /* + * Once the supply voltage is applied, the LED1202 executes some internal checks, + * afterwords it stops the oscillator and puts the internal LDO in quiescent mode. + * To start the device, EN bit must be set inside the “Device Enable” register at + * address 01h. As soon as EN is set, the LED1202 loads the adjustment parameters + * from the internal non-volatile memory and performs an auto-calibration procedure + * in order to increase the output current precision. + * Such initialization lasts about 6.5 ms. + */ + + /* Reset the chip during setup */ + ret = st1202_write_reg(chip, ST1202_DEV_ENABLE, ST1202_DEV_ENABLE_RESET); + if (ret < 0) { + dev_err_probe(&chip->client->dev, -EIO, + "Failed to write to register [0x%x], error: %d\n", + ST1202_DEV_ENABLE, ret); + goto exit; + } + + /* Enable phase-shift delay feature */ + ret = st1202_write_reg(chip, ST1202_CONFIG_REG, ST1202_CONFIG_REG_SHFT); + if (ret < 0) { + dev_err_probe(&chip->client->dev, -EIO, + "Failed to write to register [0x%x], error: %d\n", + ST1202_CONFIG_REG, ret); + goto exit; + } + + /* Enable the device */ + ret = st1202_write_reg(chip, ST1202_DEV_ENABLE, ST1202_DEV_ENABLE_ON); + if (ret < 0) { + dev_err_probe(&chip->client->dev, -EIO, + "Failed to write to register [0x%x], error: %d\n", + ST1202_DEV_ENABLE, ret); + goto exit; + } + + /* Duration of initialization */ + usleep_range(6500, 10000); + + /* Deactivate all LEDS (channels) and activate only the ones found in Device Tree */ + ret = st1202_write_reg(chip, ST1202_CHAN_ENABLE_LOW, ST1202_CHAN_DISABLE_ALL); + if (ret < 0) { + dev_err_probe(&chip->client->dev, -EIO, + "Failed writing to register [0x%x], error: %d\n", + ST1202_CHAN_ENABLE_LOW, ret); + goto exit; + } + + ret = st1202_write_reg(chip, ST1202_CHAN_ENABLE_HIGH, ST1202_CHAN_DISABLE_ALL); + if (ret < 0) { + dev_err_probe(&chip->client->dev, -EIO, + "Failed writing to register [0x%x], error: %d\n", + ST1202_CHAN_ENABLE_HIGH, ret); + goto exit; + } + + ret = st1202_write_reg(chip, ST1202_CONFIG_REG, + ST1202_CONFIG_REG_PATS | ST1202_CONFIG_REG_PATSR); + if (ret < 0) { + dev_err_probe(&chip->client->dev, -EIO, + "Failed writing to register [0x%lx], error: %d\n", + ST1202_CONFIG_REG_PATS | ST1202_CONFIG_REG_PATSR, ret); + goto exit; + } + +exit: + mutex_unlock(&chip->lock); + return ret; +} + +static int st1202_probe(struct i2c_client *client) +{ + struct st1202_chip *chip; + struct st1202_led *led; + int ret; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + return dev_err_probe(&client->dev, -EIO, "SMBUS Byte Data not Supported\n"); + + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + i2c_set_clientdata(client, chip); + + devm_mutex_init(&client->dev, &chip->lock); + chip->client = client; + + ret = st1202_dt_init(chip); + if (ret < 0) + return ret; + + ret = st1202_setup(chip); + if (ret < 0) + return ret; + + for (int i = 0; i < ST1202_MAX_LEDS; i++) { + led = &chip->leds[i]; + led->chip = chip; + led->led_num = i; + + if (led->is_active) { + ret = st1202_channel_set(led->chip, led->led_num, true); + if (ret < 0) { + return dev_err_probe(&client->dev, -EIO, + "Failed to activate LED channel, error: %d\n", ret); + } + + ret = st1202_led_pattern_clear(&led->led_cdev); + if (ret < 0) { + return dev_err_probe(&client->dev, -EIO, + "Failed to clear LED pattern, error: %d\n", ret); + } + } + } + + return 0; +} + +static const struct i2c_device_id st1202_id[] = { + { "st1202-i2c" }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(i2c, st1202_id); + +static const struct of_device_id st1202_dt_ids[] = { + { .compatible = "st,led1202", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, st1202_dt_ids); + +static struct i2c_driver st1202_driver = { + .driver = { + .name = "leds-st1202", + .of_match_table = of_match_ptr(st1202_dt_ids), + }, + .probe = st1202_probe, + .id_table = st1202_id, +}; +module_i2c_driver(st1202_driver); + +MODULE_AUTHOR("Remote Tech LTD"); +MODULE_DESCRIPTION("STMicroelectronics LED1202 : 12-channel constant current LED driver"); +MODULE_LICENSE("GPL");