linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: pieterjanca@gmail.com, Pavel Machek <pavel@ucw.cz>,
	Lee Jones <lee@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Isai Gaspar <isaiezequiel.gaspar@nxp.com>
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] leds: leds-pca995x: Add support for NXP PCA9956B
Date: Thu, 11 Jul 2024 03:29:28 +0200	[thread overview]
Message-ID: <fe6d1df7-eefc-4e4e-9f3c-989f982b0daa@denx.de> (raw)
In-Reply-To: <20240710-pca995x-v2-2-8fafb6e4b7d5@gmail.com>

On 7/10/24 4:32 PM, Pieterjan Camerlynck via B4 Relay wrote:

[...]

> @@ -52,9 +68,9 @@ struct pca995x_led {
>   };
>   
>   struct pca995x_chip {
> +	const struct pca995x_chipdef *chipdef;
>   	struct regmap *regmap;
> -	struct pca995x_led leds[PCA995X_MAX_OUTPUTS];
> -	int btype;
> +	struct pca995x_led leds[];

Please increase PCA995X_MAX_OUTPUTS to 24 and avoid this variable length 
array at the end.

>   };
>   
>   static int pca995x_brightness_set(struct led_classdev *led_cdev,
> @@ -62,10 +78,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;

Parenthesis around (chipdef->pwm_base) not needed.

>   	ledout_addr = PCA995X_LEDOUT0 + (led->led_no / PCA995X_OUTPUTS_PER_REG);
>   	shift = PCA995X_LDRX_BITS * (led->led_no % PCA995X_OUTPUTS_PER_REG);
>   
> @@ -101,24 +118,24 @@ static const struct regmap_config pca995x_regmap = {
>   
>   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 reg, ret;
>   
> -	btype = (unsigned long)device_get_match_data(&client->dev);
> +	chipdef = device_get_match_data(&client->dev);
>   
>   	np = dev_fwnode(dev);
>   	if (!np)
>   		return -ENODEV;
>   
> -	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
> +	chip = devm_kzalloc(dev, struct_size(chip, leds, chipdef->num_leds), GFP_KERNEL);

This won't be needed once you fix up PCA995X_MAX_OUTPUTS above.

>   	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);

It is starting to look pretty good, thanks !

      reply	other threads:[~2024-07-11  1:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-10 14:32 [PATCH v2 0/2] leds: leds-pca995x: Add support for NXP PCA9956B Pieterjan Camerlynck via B4 Relay
2024-07-10 14:32 ` [PATCH v2 1/2] dt-bindings: leds: pca995x: Add new nxp,pca9956b compatible Pieterjan Camerlynck via B4 Relay
2024-07-10 14:32 ` [PATCH v2 2/2] leds: leds-pca995x: Add support for NXP PCA9956B Pieterjan Camerlynck via B4 Relay
2024-07-11  1:29   ` Marek Vasut [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fe6d1df7-eefc-4e4e-9f3c-989f982b0daa@denx.de \
    --to=marex@denx.de \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=isaiezequiel.gaspar@nxp.com \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=pieterjanca@gmail.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).