From patchwork Thu Jul 11 12:49:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieterjan Camerlynck via B4 Relay X-Patchwork-Id: 812169 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A4971E892; Thu, 11 Jul 2024 12:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720702204; cv=none; b=KQLwqCYt6Sk+Ym7QYaWnpQW/Fb6yOsY9bbfiXB5rnhPXmU5OVhfV6SlZWaqnrSjCJclsz2SSqJrlme7lA6CPtuLypc3W9/Z0R0sgUvMYFTVV9qDpd1lRlkBcHwWAgBesW+A9jHZqITo8fI1byf3gEkN+GsvXCj/fEd+eDqV3zIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720702204; c=relaxed/simple; bh=2S6wiPTFHPJdM/v1Q7GToqIDc7o81c9D6s45n8dLLl4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o4P4pglwdJUhXTP5CZLUh2GSwVWsIAomMtY1plHdQ/Zv+swqfcI2n1TjHlUGxLKNHF5Qn6/3rDHL9TmAM9jFn7dndhjtoouRuTPqGF9ykOHNnvnuKsJvu946jjBKhC1sNTdqxwnbcYSdy7I/QKjXPpXZ+CTyDSIPdNPc/uxiT9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TUdj8Ohg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TUdj8Ohg" Received: by smtp.kernel.org (Postfix) with ESMTPS id 30FC6C4AF07; Thu, 11 Jul 2024 12:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720702204; bh=2S6wiPTFHPJdM/v1Q7GToqIDc7o81c9D6s45n8dLLl4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=TUdj8OhgVu+xwIpAi7gXmZ41mLjGy1wZLsMej0ZwAy17IcxJuhVWdTVroyu7CKbQC p1++B9q3bo1m9QSVbY8nQacwKsW/moWO8E8V7PapRfOIbHtjGxPyszDdhq+sL9xYfA QD5n655OqkULy4GAKjhCqgjZSW0Bhj1aRVdbAdOepxJXpIcYX3C7xKr7rYmuDSPn01 FEGOzdmYrJb8bRvBP5ITVKz5+440iFlpEZiLuAvZgzTdRoXzrkI41Ex64HMQPrMBYj 4R3XFpj4ILptfmry0rnPlruoVCOdNbLjSOhI09hyeuv3dT+K8MQHB+94VA84JNq2NY C02kAZoaZgp3A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E096C3DA41; Thu, 11 Jul 2024 12:50:04 +0000 (UTC) From: Pieterjan Camerlynck via B4 Relay Date: Thu, 11 Jul 2024 14:49:50 +0200 Subject: [PATCH v4 1/2] dt-bindings: leds: pca995x: Add new nxp,pca9956b compatible Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-pca995x-v4-1-702a67148065@gmail.com> References: <20240711-pca995x-v4-0-702a67148065@gmail.com> In-Reply-To: <20240711-pca995x-v4-0-702a67148065@gmail.com> To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Isai Gaspar , Marek Vasut Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieterjan Camerlynck , Conor Dooley X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720702203; l=1529; i=pieterjanca@gmail.com; s=20240709; h=from:subject:message-id; bh=6vO+6FBkF83NNJD/iYLLMy7G/J0jk6c6K0j7e/z+Ghg=; b=GUnNEmh0FyyZTNKqn3AY72mRzXaK+C2ZMPDAmBBY9oTGMGqhB5/3KklfWAdJNfdBDCybuSLes nA67CZL0PQGDEa98kY/OyFf/3Oklmd3f6Q64PrSOTmcFnrG1ULFQyQ6 X-Developer-Key: i=pieterjanca@gmail.com; a=ed25519; pk=gSAHfvqQjVhNa1MhUClqbt7d3S+fviKz6FdQVaWFRyM= X-Endpoint-Received: by B4 Relay for pieterjanca@gmail.com/20240709 with auth_id=182 X-Original-From: Pieterjan Camerlynck Reply-To: pieterjanca@gmail.com From: Pieterjan Camerlynck Add nxp,pca9956b compatible, which has 24 instead of 16 outputs. Adjust the documentation for the difference. Reviewed-by: Marek Vasut Acked-by: Conor Dooley Signed-off-by: Pieterjan Camerlynck --- Documentation/devicetree/bindings/leds/nxp,pca995x.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/leds/nxp,pca995x.yaml b/Documentation/devicetree/bindings/leds/nxp,pca995x.yaml index 654915c1f687..ab8c90cbadb5 100644 --- a/Documentation/devicetree/bindings/leds/nxp,pca995x.yaml +++ b/Documentation/devicetree/bindings/leds/nxp,pca995x.yaml @@ -11,19 +11,21 @@ maintainers: - Marek Vasut description: - The NXP PCA9952/PCA9955B are programmable LED controllers connected via I2C - that can drive 16 separate lines. Each of them can be individually switched + The NXP PCA995x family are programmable LED controllers connected via I2C + that can drive separate lines. Each of them can be individually switched on and off, and brightness can be controlled via individual PWM. Datasheets are available at https://www.nxp.com/docs/en/data-sheet/PCA9952_PCA9955.pdf https://www.nxp.com/docs/en/data-sheet/PCA9955B.pdf + https://www.nxp.com/docs/en/data-sheet/PCA9956B.pdf properties: compatible: enum: - nxp,pca9952 - nxp,pca9955b + - nxp,pca9956b reg: maxItems: 1 From patchwork Thu Jul 11 12:49:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieterjan Camerlynck via B4 Relay X-Patchwork-Id: 812168 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB52315DBD8; Thu, 11 Jul 2024 12:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720702204; cv=none; b=D36+87KYQGA5oOHx861yQnsz22SrejUDFN77VyIJqll+pzBZmTinT4rp1WylF2SfSjPa0yrlgqaiKTE36t4ZPUZ7xk5emlc8NQw6388nv5l9dRgPdSd8DGTEgOJZZsM/UoE9O/yFWjCPYCdE+kRaFHk6zPso+gYw/hs/tUAD9vY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720702204; c=relaxed/simple; bh=LChaZQrDDIvn0psEh8DZJO9LEOgGVb1xHMb/crsN88M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EuiCQNxF9ge+4cOGg7LkGv6mfFOewUZi+eR4AcxoZwZ1Yc0yRnymWViZrieBy39MPHNY8voZFFSfDoXvhuAP+v52K+mkAZIax+zOHJz4gWutPEfRCJoooLX0CDV3FULpClP04RLc1EVac6vOvJnw0yj93EZ+GaQTButRHhfuRPw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bZ3toTfq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bZ3toTfq" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3E2B4C4AF0A; Thu, 11 Jul 2024 12:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720702204; bh=LChaZQrDDIvn0psEh8DZJO9LEOgGVb1xHMb/crsN88M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bZ3toTfq37IOsGeGswVa2TiiC3WZnEZPBakMzYZBaSP+dHzanLvdSYBDihohKZ+/G NPzrFkun/bDfo/sTxarufr4Mu8jDj1MhzJImWOHjAIaIb0E9FnWOZJJxcTAWDUxrKk EInjlRq3rSGQmEMH5nFBEivvyq0qIr7pu3vBi5zqQsGo6EYEBBdc3Vu2qwjDI6QYp1 8v5B3dfxSatal9gl/YZQm6Fcb+LtBUjFhrhoYx9OIzJ/ImPQgrJjN3eJ8Lq09Iwtxk ZaDEMarBQ0HQw7sKN7NWiWXdaDPDSFJnijZI9USbWKviaXcEOGpk5JcFq09b/x/EYX 0+D88HXVUSKkg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B48BC3DA4D; Thu, 11 Jul 2024 12:50:04 +0000 (UTC) From: Pieterjan Camerlynck via B4 Relay Date: Thu, 11 Jul 2024 14:49:51 +0200 Subject: [PATCH v4 2/2] leds: leds-pca995x: Add support for NXP PCA9956B Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-pca995x-v4-2-702a67148065@gmail.com> References: <20240711-pca995x-v4-0-702a67148065@gmail.com> In-Reply-To: <20240711-pca995x-v4-0-702a67148065@gmail.com> To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Isai Gaspar , Marek Vasut Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieterjan Camerlynck X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720702203; l=4852; i=pieterjanca@gmail.com; s=20240709; h=from:subject:message-id; bh=T4iJuBVE1eU6/XQMFNfp3e4U02iQNfiueccUGicFjdY=; b=dM5AR45rO16uxS9wb8YOLntCo6aQIxBImqozba3Dg5YYianG3AQ1qdQexYHr4ixwL5o9kv4HK ZJ9CqNClfIdAtpZsdPIMFR7Tj0yPx2FJkWxBWfdzJlyvyp92JhA2JlN X-Developer-Key: i=pieterjanca@gmail.com; a=ed25519; pk=gSAHfvqQjVhNa1MhUClqbt7d3S+fviKz6FdQVaWFRyM= X-Endpoint-Received: by B4 Relay for pieterjanca@gmail.com/20240709 with auth_id=182 X-Original-From: Pieterjan Camerlynck Reply-To: pieterjanca@gmail.com From: Pieterjan Camerlynck Add support for PCA9956B chip, which belongs to the same family. This chip features 24 instead of 16 outputs, so add a chipdef struct to deal with the different register layouts. Reviewed-by: Marek Vasut Signed-off-by: Pieterjan Camerlynck --- drivers/leds/leds-pca995x.c | 59 ++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/drivers/leds/leds-pca995x.c b/drivers/leds/leds-pca995x.c index 78215dff1499..686b77772cce 100644 --- a/drivers/leds/leds-pca995x.c +++ b/drivers/leds/leds-pca995x.c @@ -19,10 +19,6 @@ #define PCA995X_MODE1 0x00 #define PCA995X_MODE2 0x01 #define PCA995X_LEDOUT0 0x02 -#define PCA9955B_PWM0 0x08 -#define PCA9952_PWM0 0x0A -#define PCA9952_IREFALL 0x43 -#define PCA9955B_IREFALL 0x45 /* Auto-increment disabled. Normal mode */ #define PCA995X_MODE1_CFG 0x00 @@ -34,17 +30,38 @@ #define PCA995X_LDRX_MASK 0x3 #define PCA995X_LDRX_BITS 2 -#define PCA995X_MAX_OUTPUTS 16 +#define PCA995X_MAX_OUTPUTS 24 #define PCA995X_OUTPUTS_PER_REG 4 #define PCA995X_IREFALL_FULL_CFG 0xFF #define PCA995X_IREFALL_HALF_CFG (PCA995X_IREFALL_FULL_CFG / 2) -#define PCA995X_TYPE_NON_B 0 -#define PCA995X_TYPE_B 1 - #define ldev_to_led(c) container_of(c, struct pca995x_led, ldev) +struct pca995x_chipdef { + unsigned int num_leds; + u8 pwm_base; + u8 irefall; +}; + +static const struct pca995x_chipdef pca9952_chipdef = { + .num_leds = 16, + .pwm_base = 0x0a, + .irefall = 0x43, +}; + +static const struct pca995x_chipdef pca9955b_chipdef = { + .num_leds = 16, + .pwm_base = 0x08, + .irefall = 0x45, +}; + +static const struct pca995x_chipdef pca9956b_chipdef = { + .num_leds = 24, + .pwm_base = 0x0a, + .irefall = 0x40, +}; + struct pca995x_led { unsigned int led_no; struct led_classdev ldev; @@ -54,7 +71,7 @@ struct pca995x_led { struct pca995x_chip { struct regmap *regmap; struct pca995x_led leds[PCA995X_MAX_OUTPUTS]; - int btype; + const struct pca995x_chipdef *chipdef; }; static int pca995x_brightness_set(struct led_classdev *led_cdev, @@ -62,10 +79,11 @@ static int pca995x_brightness_set(struct led_classdev *led_cdev, { struct pca995x_led *led = ldev_to_led(led_cdev); struct pca995x_chip *chip = led->chip; + const struct pca995x_chipdef *chipdef = chip->chipdef; u8 ledout_addr, pwmout_addr; int shift, ret; - pwmout_addr = (chip->btype ? PCA9955B_PWM0 : PCA9952_PWM0) + led->led_no; + pwmout_addr = chipdef->pwm_base + led->led_no; ledout_addr = PCA995X_LEDOUT0 + (led->led_no / PCA995X_OUTPUTS_PER_REG); shift = PCA995X_LDRX_BITS * (led->led_no % PCA995X_OUTPUTS_PER_REG); @@ -104,11 +122,12 @@ static int pca995x_probe(struct i2c_client *client) struct fwnode_handle *led_fwnodes[PCA995X_MAX_OUTPUTS] = { 0 }; struct fwnode_handle *np, *child; struct device *dev = &client->dev; + const struct pca995x_chipdef *chipdef; struct pca995x_chip *chip; struct pca995x_led *led; - int i, btype, reg, ret; + int i, reg, ret; - btype = (unsigned long)device_get_match_data(&client->dev); + chipdef = device_get_match_data(&client->dev); np = dev_fwnode(dev); if (!np) @@ -118,7 +137,7 @@ static int pca995x_probe(struct i2c_client *client) if (!chip) return -ENOMEM; - chip->btype = btype; + chip->chipdef = chipdef; chip->regmap = devm_regmap_init_i2c(client, &pca995x_regmap); if (IS_ERR(chip->regmap)) return PTR_ERR(chip->regmap); @@ -170,21 +189,21 @@ static int pca995x_probe(struct i2c_client *client) return ret; /* IREF Output current value for all LEDn outputs */ - return regmap_write(chip->regmap, - btype ? PCA9955B_IREFALL : PCA9952_IREFALL, - PCA995X_IREFALL_HALF_CFG); + return regmap_write(chip->regmap, chipdef->irefall, PCA995X_IREFALL_HALF_CFG); } static const struct i2c_device_id pca995x_id[] = { - { "pca9952", .driver_data = (kernel_ulong_t)PCA995X_TYPE_NON_B }, - { "pca9955b", .driver_data = (kernel_ulong_t)PCA995X_TYPE_B }, + { "pca9952", .driver_data = (kernel_ulong_t)&pca9952_chipdef }, + { "pca9955b", .driver_data = (kernel_ulong_t)&pca9955b_chipdef }, + { "pca9956b", .driver_data = (kernel_ulong_t)&pca9956b_chipdef }, {} }; MODULE_DEVICE_TABLE(i2c, pca995x_id); static const struct of_device_id pca995x_of_match[] = { - { .compatible = "nxp,pca9952", .data = (void *)PCA995X_TYPE_NON_B }, - { .compatible = "nxp,pca9955b", .data = (void *)PCA995X_TYPE_B }, + { .compatible = "nxp,pca9952", .data = &pca9952_chipdef }, + { .compatible = "nxp,pca9955b", . data = &pca9955b_chipdef }, + { .compatible = "nxp,pca9956b", .data = &pca9956b_chipdef }, {}, }; MODULE_DEVICE_TABLE(of, pca995x_of_match);