Skip to content

Commit 2b8db57

Browse files
geo-starklag-linaro
authored andcommitted
leds: aw200xx: Calculate dts property display_rows in the driver
Get rid of device tree property "awinic,display-rows". The property value actually means number of current switches and depends on how LEDs are connected to the device. It should be calculated manually by max used LED number. In the same way it is computed automatically now. Max used LED is taken from LED definition subnodes. Signed-off-by: George Stark <gnstark@salutedevices.com> Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20231125200519.1750-5-ddrokosov@salutedevices.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 20dbf6d commit 2b8db57

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

drivers/leds/leds-aw200xx.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -379,25 +379,42 @@ static void aw200xx_disable(const struct aw200xx *const chip)
379379
return gpiod_set_value_cansleep(chip->hwen, 0);
380380
}
381381

382+
static int aw200xx_probe_get_display_rows(struct device *dev,
383+
struct aw200xx *chip)
384+
{
385+
struct fwnode_handle *child;
386+
u32 max_source = 0;
387+
388+
device_for_each_child_node(dev, child) {
389+
u32 source;
390+
int ret;
391+
392+
ret = fwnode_property_read_u32(child, "reg", &source);
393+
if (ret || source >= chip->cdef->channels)
394+
continue;
395+
396+
max_source = max(max_source, source);
397+
}
398+
399+
if (max_source == 0)
400+
return -EINVAL;
401+
402+
chip->display_rows = max_source / chip->cdef->display_size_columns + 1;
403+
404+
return 0;
405+
}
406+
382407
static int aw200xx_probe_fw(struct device *dev, struct aw200xx *chip)
383408
{
384409
struct fwnode_handle *child;
385410
u32 current_min, current_max, min_uA;
386411
int ret;
387412
int i;
388413

389-
ret = device_property_read_u32(dev, "awinic,display-rows",
390-
&chip->display_rows);
414+
ret = aw200xx_probe_get_display_rows(dev, chip);
391415
if (ret)
392416
return dev_err_probe(dev, ret,
393-
"Failed to read 'display-rows' property\n");
394-
395-
if (!chip->display_rows ||
396-
chip->display_rows > chip->cdef->display_size_rows_max) {
397-
return dev_err_probe(dev, -EINVAL,
398-
"Invalid leds display size %u\n",
399-
chip->display_rows);
400-
}
417+
"No valid led definitions found\n");
401418

402419
current_max = aw200xx_imax_from_global(chip, AW200XX_IMAX_MAX_uA);
403420
current_min = aw200xx_imax_from_global(chip, AW200XX_IMAX_MIN_uA);

0 commit comments

Comments
 (0)