From 12ec7e56ce95d7b6fd4cd74e634c1181e2b424e1 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 19 Oct 2020 13:08:08 +0200 Subject: Documentation: leds: remove invalidated information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The contents of the Future Development section of leds-class Documentation was invalidated when support for LED-private triggers was merged. Remove this section. Signed-off-by: Marek Behún Fixes: 93690cdf3060 ("leds: trigger: add support for LED-private device...") Signed-off-by: Pavel Machek --- Documentation/leds/leds-class.rst | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst index a0708d3f3d0b..cd155ead8703 100644 --- a/Documentation/leds/leds-class.rst +++ b/Documentation/leds/leds-class.rst @@ -177,13 +177,3 @@ The LED Trigger core cannot be a module as the simple trigger functions would cause nightmare dependency issues. I see this as a minor issue compared to the benefits the simple trigger functionality brings. The rest of the LED subsystem can be modular. - - -Future Development -================== - -At the moment, a trigger can't be created specifically for a single LED. -There are a number of cases where a trigger might only be mappable to a -particular LED (ACPI?). The addition of triggers provided by the LED driver -should cover this option and be possible to add without breaking the -current interface. -- cgit v1.2.3 From 311066aa9ebcd6f1789c829da5039ca02f2dfe46 Mon Sep 17 00:00:00 2001 From: Yu Kuai Date: Thu, 29 Oct 2020 17:23:05 +0800 Subject: leds: netxbig: add missing put_device() call in netxbig_leds_get_of_pdata() if of_find_device_by_node() succeed, netxbig_leds_get_of_pdata() doesn't have a corresponding put_device(). Thus add jump target to fix the exception handling for this function implementation. Fixes: 2976b1798909 ("leds: netxbig: add device tree binding") Signed-off-by: Yu Kuai Signed-off-by: Pavel Machek --- drivers/leds/leds-netxbig.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c index e6fd47365b58..68fbf0b66fad 100644 --- a/drivers/leds/leds-netxbig.c +++ b/drivers/leds/leds-netxbig.c @@ -448,31 +448,39 @@ static int netxbig_leds_get_of_pdata(struct device *dev, gpio_ext = devm_kzalloc(dev, sizeof(*gpio_ext), GFP_KERNEL); if (!gpio_ext) { of_node_put(gpio_ext_np); - return -ENOMEM; + ret = -ENOMEM; + goto put_device; } ret = netxbig_gpio_ext_get(dev, gpio_ext_dev, gpio_ext); of_node_put(gpio_ext_np); if (ret) - return ret; + goto put_device; pdata->gpio_ext = gpio_ext; /* Timers (optional) */ ret = of_property_count_u32_elems(np, "timers"); if (ret > 0) { - if (ret % 3) - return -EINVAL; + if (ret % 3) { + ret = -EINVAL; + goto put_device; + } + num_timers = ret / 3; timers = devm_kcalloc(dev, num_timers, sizeof(*timers), GFP_KERNEL); - if (!timers) - return -ENOMEM; + if (!timers) { + ret = -ENOMEM; + goto put_device; + } for (i = 0; i < num_timers; i++) { u32 tmp; of_property_read_u32_index(np, "timers", 3 * i, &timers[i].mode); - if (timers[i].mode >= NETXBIG_LED_MODE_NUM) - return -EINVAL; + if (timers[i].mode >= NETXBIG_LED_MODE_NUM) { + ret = -EINVAL; + goto put_device; + } of_property_read_u32_index(np, "timers", 3 * i + 1, &tmp); timers[i].delay_on = tmp; @@ -488,12 +496,15 @@ static int netxbig_leds_get_of_pdata(struct device *dev, num_leds = of_get_available_child_count(np); if (!num_leds) { dev_err(dev, "No LED subnodes found in DT\n"); - return -ENODEV; + ret = -ENODEV; + goto put_device; } leds = devm_kcalloc(dev, num_leds, sizeof(*leds), GFP_KERNEL); - if (!leds) - return -ENOMEM; + if (!leds) { + ret = -ENOMEM; + goto put_device; + } led = leds; for_each_available_child_of_node(np, child) { @@ -574,6 +585,8 @@ static int netxbig_leds_get_of_pdata(struct device *dev, err_node_put: of_node_put(child); +put_device: + put_device(gpio_ext_dev); return ret; } -- cgit v1.2.3 From 6d8d014c7dcf85a79da71ef586d06d03d2cae558 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Tue, 22 Sep 2020 23:05:15 +0200 Subject: leds: lp50xx: Fix an error handling path in 'lp50xx_probe_dt()' In case of memory allocation failure, we must release some resources as done in all other error handling paths of the function. 'goto child_out' instead of a direct return so that 'fwnode_handle_put()' is called when we break out of a 'device_for_each_child_node' loop. Fixes: 242b81170fb8 ("leds: lp50xx: Add the LP50XX family of the RGB LED driver") Signed-off-by: Christophe JAILLET Acked-by: Dan Murphy Signed-off-by: Pavel Machek --- drivers/leds/leds-lp50xx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c index 5fb4f24aeb2e..f13117eed976 100644 --- a/drivers/leds/leds-lp50xx.c +++ b/drivers/leds/leds-lp50xx.c @@ -487,8 +487,10 @@ static int lp50xx_probe_dt(struct lp50xx *priv) */ mc_led_info = devm_kcalloc(priv->dev, LP50XX_LEDS_PER_MODULE, sizeof(*mc_led_info), GFP_KERNEL); - if (!mc_led_info) - return -ENOMEM; + if (!mc_led_info) { + ret = -ENOMEM; + goto child_out; + } fwnode_for_each_child_node(child, led_node) { ret = fwnode_property_read_u32(led_node, "color", -- cgit v1.2.3 From 0fe5ac3d9667176e236d536ff9c1ec30eb2e6080 Mon Sep 17 00:00:00 2001 From: Alexander Dahl Date: Mon, 5 Oct 2020 22:34:41 +0200 Subject: dt-bindings: leds: Convert pwm to yaml The example was adapted in the following ways: - make use of the now supported 'function' and 'color' properties - remove pwm nodes, those are documented elsewhere - align node names to new dt schema rules and dt recommendations License was not explicitly set before. The license set now is recommended by DT project. Suggested-by: Jacek Anaszewski Signed-off-by: Alexander Dahl Reviewed-by: Krzysztof Kozlowski Reviewed-by: Rob Herring Cc: Peter Ujfalusi [For the license change only:] Acked-by: Russell King Signed-off-by: Pavel Machek --- .../devicetree/bindings/leds/leds-pwm.txt | 50 ---------------- .../devicetree/bindings/leds/leds-pwm.yaml | 70 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 50 deletions(-) delete mode 100644 Documentation/devicetree/bindings/leds/leds-pwm.txt create mode 100644 Documentation/devicetree/bindings/leds/leds-pwm.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-pwm.txt b/Documentation/devicetree/bindings/leds/leds-pwm.txt deleted file mode 100644 index 6c6583c35f2f..000000000000 --- a/Documentation/devicetree/bindings/leds/leds-pwm.txt +++ /dev/null @@ -1,50 +0,0 @@ -LED connected to PWM - -Required properties: -- compatible : should be "pwm-leds". - -Each LED is represented as a sub-node of the pwm-leds device. Each -node's name represents the name of the corresponding LED. - -LED sub-node properties: -- pwms : PWM property to point to the PWM device (phandle)/port (id) and to - specify the period time to be used: <&phandle id period_ns>; -- pwm-names : (optional) Name to be used by the PWM subsystem for the PWM device - For the pwms and pwm-names property please refer to: - Documentation/devicetree/bindings/pwm/pwm.txt -- max-brightness : Maximum brightness possible for the LED -- active-low : (optional) For PWMs where the LED is wired to supply - rather than ground. -- label : (optional) - see Documentation/devicetree/bindings/leds/common.txt -- linux,default-trigger : (optional) - see Documentation/devicetree/bindings/leds/common.txt - -Example: - -twl_pwm: pwm { - /* provides two PWMs (id 0, 1 for PWM1 and PWM2) */ - compatible = "ti,twl6030-pwm"; - #pwm-cells = <2>; -}; - -twl_pwmled: pwmled { - /* provides one PWM (id 0 for Charing indicator LED) */ - compatible = "ti,twl6030-pwmled"; - #pwm-cells = <2>; -}; - -pwmleds { - compatible = "pwm-leds"; - kpad { - label = "omap4::keypad"; - pwms = <&twl_pwm 0 7812500>; - max-brightness = <127>; - }; - - charging { - label = "omap4:green:chrg"; - pwms = <&twl_pwmled 0 7812500>; - max-brightness = <255>; - }; -}; diff --git a/Documentation/devicetree/bindings/leds/leds-pwm.yaml b/Documentation/devicetree/bindings/leds/leds-pwm.yaml new file mode 100644 index 000000000000..fe4d5fd25913 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-pwm.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-pwm.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LEDs connected to PWM + +maintainers: + - Pavel Machek + +description: + Each LED is represented as a sub-node of the pwm-leds device. Each + node's name represents the name of the corresponding LED. + +properties: + compatible: + const: pwm-leds + +patternProperties: + "^led(-[0-9a-f]+)?$": + type: object + + $ref: common.yaml# + + properties: + pwms: + maxItems: 1 + + pwm-names: true + + max-brightness: + description: + Maximum brightness possible for the LED + $ref: /schemas/types.yaml#/definitions/uint32 + + active-low: + description: + For PWMs where the LED is wired to supply rather than ground. + type: boolean + + required: + - pwms + - max-brightness + +additionalProperties: false + +examples: + - | + + #include + + led-controller { + compatible = "pwm-leds"; + + led-1 { + label = "omap4::keypad"; + pwms = <&twl_pwm 0 7812500>; + max-brightness = <127>; + }; + + led-2 { + color = ; + function = LED_FUNCTION_CHARGING; + pwms = <&twl_pwmled 0 7812500>; + max-brightness = <255>; + }; + }; + +... -- cgit v1.2.3 From 493d2e432f38cd366ab78dcec53781a0fddc2822 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Fri, 30 Oct 2020 03:39:02 +0100 Subject: leds: turris-omnia: use constants instead of macros for color command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use integer constants directly when building I2C messages for LED color change command, instead of macros. The command is simple enough to understand what is going on even without these names. Signed-off-by: Marek Behún Signed-off-by: Pavel Machek --- drivers/leds/leds-turris-omnia.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 8c5bdc3847ee..80b2d94844f2 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -27,14 +27,6 @@ #define CMD_LED_SET_BRIGHTNESS 7 #define CMD_LED_GET_BRIGHTNESS 8 -#define OMNIA_CMD 0 - -#define OMNIA_CMD_LED_COLOR_LED 1 -#define OMNIA_CMD_LED_COLOR_R 2 -#define OMNIA_CMD_LED_COLOR_G 3 -#define OMNIA_CMD_LED_COLOR_B 4 -#define OMNIA_CMD_LED_COLOR_LEN 5 - struct omnia_led { struct led_classdev_mc mc_cdev; struct mc_subled subled_info[OMNIA_LED_NUM_CHANNELS]; @@ -55,21 +47,21 @@ static int omnia_led_brightness_set_blocking(struct led_classdev *cdev, struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev); struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); struct omnia_led *led = to_omnia_led(mc_cdev); - u8 buf[OMNIA_CMD_LED_COLOR_LEN], state; + u8 buf[5], state; int ret; mutex_lock(&leds->lock); led_mc_calc_color_components(&led->mc_cdev, brightness); - buf[OMNIA_CMD] = CMD_LED_COLOR; - buf[OMNIA_CMD_LED_COLOR_LED] = led->reg; - buf[OMNIA_CMD_LED_COLOR_R] = mc_cdev->subled_info[0].brightness; - buf[OMNIA_CMD_LED_COLOR_G] = mc_cdev->subled_info[1].brightness; - buf[OMNIA_CMD_LED_COLOR_B] = mc_cdev->subled_info[2].brightness; + buf[0] = CMD_LED_COLOR; + buf[1] = led->reg; + buf[2] = mc_cdev->subled_info[0].brightness; + buf[3] = mc_cdev->subled_info[1].brightness; + buf[4] = mc_cdev->subled_info[2].brightness; state = CMD_LED_STATE_LED(led->reg); - if (buf[OMNIA_CMD_LED_COLOR_R] || buf[OMNIA_CMD_LED_COLOR_G] || buf[OMNIA_CMD_LED_COLOR_B]) + if (buf[2] || buf[3] || buf[4]) state |= CMD_LED_STATE_ON; ret = i2c_smbus_write_byte_data(leds->client, CMD_LED_STATE, state); @@ -250,18 +242,18 @@ static int omnia_leds_probe(struct i2c_client *client, static int omnia_leds_remove(struct i2c_client *client) { - u8 buf[OMNIA_CMD_LED_COLOR_LEN]; + u8 buf[5]; /* put all LEDs into default (HW triggered) mode */ i2c_smbus_write_byte_data(client, CMD_LED_MODE, CMD_LED_MODE_LED(OMNIA_BOARD_LEDS)); /* set all LEDs color to [255, 255, 255] */ - buf[OMNIA_CMD] = CMD_LED_COLOR; - buf[OMNIA_CMD_LED_COLOR_LED] = OMNIA_BOARD_LEDS; - buf[OMNIA_CMD_LED_COLOR_R] = 255; - buf[OMNIA_CMD_LED_COLOR_G] = 255; - buf[OMNIA_CMD_LED_COLOR_B] = 255; + buf[0] = CMD_LED_COLOR; + buf[1] = OMNIA_BOARD_LEDS; + buf[2] = 255; + buf[3] = 255; + buf[4] = 255; i2c_master_send(client, buf, 5); -- cgit v1.2.3 From 5d47ce1d814e9136b24341fc5dedcd058caef312 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Fri, 30 Oct 2020 03:39:03 +0100 Subject: leds: turris-omnia: wrap to 80 columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Although checkpatch changed the max-line-length default to 100 columns, we still prefer 80 columns somewhere. Signed-off-by: Marek Behún Signed-off-by: Pavel Machek --- drivers/leds/leds-turris-omnia.c | 43 ++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 80b2d94844f2..096ed7b81957 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -12,20 +12,20 @@ #include #include "leds.h" -#define OMNIA_BOARD_LEDS 12 -#define OMNIA_LED_NUM_CHANNELS 3 +#define OMNIA_BOARD_LEDS 12 +#define OMNIA_LED_NUM_CHANNELS 3 -#define CMD_LED_MODE 3 -#define CMD_LED_MODE_LED(l) ((l) & 0x0f) -#define CMD_LED_MODE_USER 0x10 +#define CMD_LED_MODE 3 +#define CMD_LED_MODE_LED(l) ((l) & 0x0f) +#define CMD_LED_MODE_USER 0x10 -#define CMD_LED_STATE 4 -#define CMD_LED_STATE_LED(l) ((l) & 0x0f) -#define CMD_LED_STATE_ON 0x10 +#define CMD_LED_STATE 4 +#define CMD_LED_STATE_LED(l) ((l) & 0x0f) +#define CMD_LED_STATE_ON 0x10 -#define CMD_LED_COLOR 5 -#define CMD_LED_SET_BRIGHTNESS 7 -#define CMD_LED_GET_BRIGHTNESS 8 +#define CMD_LED_COLOR 5 +#define CMD_LED_SET_BRIGHTNESS 7 +#define CMD_LED_GET_BRIGHTNESS 8 struct omnia_led { struct led_classdev_mc mc_cdev; @@ -33,7 +33,7 @@ struct omnia_led { int reg; }; -#define to_omnia_led(l) container_of(l, struct omnia_led, mc_cdev) +#define to_omnia_led(l) container_of(l, struct omnia_led, mc_cdev) struct omnia_leds { struct i2c_client *client; @@ -118,18 +118,21 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, CMD_LED_MODE_LED(led->reg) | CMD_LED_MODE_USER); if (ret < 0) { - dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np, ret); + dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np, + ret); return ret; } /* disable the LED */ - ret = i2c_smbus_write_byte_data(client, CMD_LED_STATE, CMD_LED_STATE_LED(led->reg)); + ret = i2c_smbus_write_byte_data(client, CMD_LED_STATE, + CMD_LED_STATE_LED(led->reg)); if (ret < 0) { dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret); return ret; } - ret = devm_led_classdev_multicolor_register_ext(dev, &led->mc_cdev, &init_data); + ret = devm_led_classdev_multicolor_register_ext(dev, &led->mc_cdev, + &init_data); if (ret < 0) { dev_err(dev, "Cannot register LED %pOF: %i\n", np, ret); return ret; @@ -149,7 +152,8 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, * file lives in the device directory of the LED controller, not an individual * LED, so it should not confuse users. */ -static ssize_t brightness_show(struct device *dev, struct device_attribute *a, char *buf) +static ssize_t brightness_show(struct device *dev, struct device_attribute *a, + char *buf) { struct i2c_client *client = to_i2c_client(dev); struct omnia_leds *leds = i2c_get_clientdata(client); @@ -165,8 +169,8 @@ static ssize_t brightness_show(struct device *dev, struct device_attribute *a, c return sprintf(buf, "%d\n", ret); } -static ssize_t brightness_store(struct device *dev, struct device_attribute *a, const char *buf, - size_t count) +static ssize_t brightness_store(struct device *dev, struct device_attribute *a, + const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev); struct omnia_leds *leds = i2c_get_clientdata(client); @@ -180,7 +184,8 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a, return -EINVAL; mutex_lock(&leds->lock); - ret = i2c_smbus_write_byte_data(client, CMD_LED_SET_BRIGHTNESS, (u8) brightness); + ret = i2c_smbus_write_byte_data(client, CMD_LED_SET_BRIGHTNESS, + (u8)brightness); mutex_unlock(&leds->lock); if (ret < 0) -- cgit v1.2.3 From fca050bb3c81dc7e6df9b1d02f3007cbec0dd898 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Fri, 30 Oct 2020 03:39:04 +0100 Subject: leds: turris-omnia: fix checkpatch warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use kstrtoul instead of sscanf to satisfy checkpatch. Signed-off-by: Marek Behún Signed-off-by: Pavel Machek --- drivers/leds/leds-turris-omnia.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index 096ed7b81957..c0b4e1e0e945 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -174,10 +174,10 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a, { struct i2c_client *client = to_i2c_client(dev); struct omnia_leds *leds = i2c_get_clientdata(client); - unsigned int brightness; + unsigned long brightness; int ret; - if (sscanf(buf, "%u", &brightness) != 1) + if (kstrtoul(buf, 10, &brightness)) return -EINVAL; if (brightness > 100) -- cgit v1.2.3 From 98650b0874171cc443251f7b369d3b1544db9d4e Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Fri, 30 Oct 2020 03:39:06 +0100 Subject: leds: turris-omnia: check for LED_COLOR_ID_RGB instead LED_COLOR_ID_MULTI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LED core does not allow LED_COLOR_ID_MULTI for now and instead for RGB LEDs prefers LED_COLOR_ID_RGB. Signed-off-by: Marek Behún Fixes: 77dce3a22e89 ("leds: disallow /sys/class/leds/*:multi:* for now") Signed-off-by: Pavel Machek --- drivers/leds/leds-turris-omnia.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-turris-omnia.c b/drivers/leds/leds-turris-omnia.c index c0b4e1e0e945..7b2f4d0ae3fe 100644 --- a/drivers/leds/leds-turris-omnia.c +++ b/drivers/leds/leds-turris-omnia.c @@ -90,9 +90,9 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, } ret = of_property_read_u32(np, "color", &color); - if (ret || color != LED_COLOR_ID_MULTI) { + if (ret || color != LED_COLOR_ID_RGB) { dev_warn(dev, - "Node %pOF: must contain 'color' property with value LED_COLOR_ID_MULTI\n", + "Node %pOF: must contain 'color' property with value LED_COLOR_ID_RGB\n", np); return 0; } -- cgit v1.2.3