From fb0ce79b97acf6ee68ec4a2a9e24d56080826766 Mon Sep 17 00:00:00 2001 From: Jacek Anaszewski Date: Sat, 19 Oct 2019 19:45:18 +0200 Subject: [PATCH] DT parser amendments --- drivers/leds/leds-lp55xx-common.c | 109 ++++++++++++++++-------------- include/linux/platform_data/leds-lp55xx.h | 1 + 2 files changed, 61 insertions(+), 49 deletions(-) diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 0764520bc4a8..0244ec9bad8d 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -590,82 +590,93 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs); -static int lp5xx_parse_common_child(struct device_node *np, - struct lp55xx_led_config *cfg, - int chan_num, bool is_multicolor, - int color_num) +static int lp55xx_parse_common_child(struct device_node *np, + struct lp55xx_led_config *cfg, + int led_number, int *chan_nr) { - u32 led_number; int ret; of_property_read_string(np, "chan-name", - &cfg[chan_num].name); + &cfg[led_number].name); of_property_read_u8(np, "led-cur", - &cfg[chan_num].led_current); + &cfg[led_number].led_current); of_property_read_u8(np, "max-cur", - &cfg[chan_num].max_current); + &cfg[led_number].max_current); - ret = of_property_read_u32(np, "reg", &led_number); + ret = of_property_read_u32(np, "reg", chan_nr); if (ret) return ret; - if (led_number < 0 || led_number > 6) + if (chan_nr < 0 || chan_nr > cfg->max_channel) return -EINVAL; - if (is_multicolor) - cfg[chan_num].color_components[color_num].output_num = - led_number; - else - cfg[chan_num].chan_nr = led_number; - return 0; } -static int lp5xx_parse_channel_child(struct device_node *np, - struct lp55xx_led_config *cfg, - int child_number) +static int lp55xx_parse_mutli_led_child(struct device_node *child, + struct lp55xx_led_config *cfg, + int child_number, int color_number) { - struct device_node *child; - int channel_color; - int num_colors = 0; - u32 color_id; - int ret; - - cfg[child_number].default_trigger = - of_get_property(np, "linux,default-trigger", NULL); + int chan_nr, color_id, ret; - ret = of_property_read_u32(np, "color", &channel_color); + ret = lp55xx_parse_common_child(child, cfg, child_number, &chan_nr); if (ret) - channel_color = ret; + return ret; + ret = of_property_read_u32(child, "color", &color_id); + if (ret) + return ret; - if (channel_color == LED_COLOR_ID_MULTI) { - for_each_child_of_node(np, child) { - ret = lp5xx_parse_common_child(child, cfg, - child_number, true, - num_colors); - if (ret) - return ret; + cfg[child_number].color_components[color_number].color_id = color_id; + cfg[child_number].color_components[color_number].output_num = chan_nr; + set_bit(color_id, &cfg[child_number].available_colors); - ret = of_property_read_u32(child, "color", &color_id); - if (ret) - return ret; + return 0; +} - cfg[child_number].color_components[num_colors].color_id = - color_id; - set_bit(color_id, &cfg[child_number].available_colors); - num_colors++; - } +static int lp55xx_parse_mutli_led(struct device_node *np, + struct lp55xx_led_config *cfg, + int child_number) +{ + struct device_node *child; + int num_colors = 0, ret; - cfg[child_number].num_colors = num_colors; - } else { - return lp5xx_parse_common_child(np, cfg, child_number, false, - num_colors); + for_each_child_of_node(np, child) { + ret = lp55xx_parse_mutli_led_child(child, cfg, child_number, + num_colors); + if (ret) + return ret; + num_colors++; } return 0; } +static int lp55xx_parse_logical_led(struct device_node *np, + struct lp55xx_led_config *cfg, + int child_number) +{ + int led_color, ret; + + cfg[child_number].default_trigger = + of_get_property(np, "linux,default-trigger", NULL); + + ret = of_property_read_u32(np, "color", &led_color); + + if (ret) { + int chan_nr; + ret = lp55xx_parse_common_child(np, cfg, child_number, + &chan_nr); + if (ret < 0) + return ret; + cfg[child_number].chan_nr = chan_nr; + } else if (led_color == LED_COLOR_ID_MULTI) { + return lp55xx_parse_mutli_led(np, cfg, child_number); + } + + return ret; +} + struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, struct device_node *np) { @@ -694,7 +705,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, pdata->num_channels = num_channels; for_each_child_of_node(np, child) { - ret = lp5xx_parse_channel_child(child, cfg, i); + ret = lp55xx_parse_logical_led(child, cfg, i); if (ret) return ERR_PTR(-EINVAL); i++; diff --git a/include/linux/platform_data/leds-lp55xx.h b/include/linux/platform_data/leds-lp55xx.h index ead9d145de0d..dca21b19a283 100644 --- a/include/linux/platform_data/leds-lp55xx.h +++ b/include/linux/platform_data/leds-lp55xx.h @@ -28,6 +28,7 @@ struct lp55xx_led_config { u8 led_current; /* mA x10, 0 if led is not connected */ u8 max_current; int num_colors; + unsigned int max_channel; unsigned long available_colors; struct led_mc_color_conversion color_components[LP55XX_MAX_GROUPED_CHAN]; }; -- 2.11.0