Re: [PATCH v2 2/2] leds: leds-pca995x: Add support for NXP PCA9956B

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 !




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux