All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Added possibility to use pwm_bl.c with percentage instead of levels
@ 2014-06-27  5:32 Johannes Pointner
  2014-06-27  6:12 ` Thierry Reding
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Pointner @ 2014-06-27  5:32 UTC (permalink / raw)
  To: Thierry Reding; +Cc: linux-pwm

[-- Attachment #1: Type: text/plain, Size: 4713 bytes --]

Hello,

I'm new working on the linux device drivers, so if I made something wrong
please point me into the right direction.

I'd like to use the pwm_bl driver for a sitara based terminal and for this
I would need the possibility to set the backlight within a percentage
range. The following patch should add this possibility to the pwm_bl
driver. The idea is to keep backward compatibility by moving the required
option brightness levels to optional. Therefore if there is no node with
brightness levels the percentage levels are used.

Signed-off-by: Johannes Pointner <johannes.pointner@gmail.com>
---
 .../bindings/video/backlight/
pwm-backlight.txt     | 11 +++---
 drivers/video/backlight/pwm_bl.c                   | 46
++++++++++++----------
 2 files changed, 31 insertions(+), 26 deletions(-)

diff --git
a/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
b/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
index 764db86..ea09669 100644
--- a/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
+++ b/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
@@ -3,16 +3,17 @@ pwm-backlight bindings
 Required properties:
   - compatible: "pwm-backlight"
   - pwms: OF device-tree PWM specification (see PWM binding[0])
+  - default-brightness-level: the default brightness level (in case of
defined levels:
+      index into the array defined by the "brightness-levels" property
otherwise the
+      percentage)
+  - power-supply: regulator for supply voltage
+
+Optional properties:
   - brightness-levels: Array of distinct brightness levels. Typically these
       are in the range from 0 to 255, but any range starting at 0 will do.
       The actual brightness level (PWM duty cycle) will be interpolated
       from these values. 0 means a 0% duty cycle (darkest/off), while the
       last value in the array represents a 100% duty cycle (brightest).
-  - default-brightness-level: the default brightness level (index into the
-      array defined by the "brightness-levels" property)
-  - power-supply: regulator for supply voltage
-
-Optional properties:
   - pwm-names: a list of names for the PWM devices specified in the
                "pwms" property (see PWM binding[0])
   - enable-gpios: contains a single GPIO specifier for the GPIO which
enables
diff --git a/drivers/video/backlight/pwm_bl.c
b/drivers/video/backlight/pwm_bl.c
index 38ca88b..f9f1f43 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -24,6 +24,8 @@
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>

+#define MAX_PERCENT_BRIGHTNESS        100    /* max brightness if no
levels are used */
+
 struct pwm_bl_data {
     struct pwm_device    *pwm;
     struct device        *dev;
@@ -151,33 +153,35 @@ static int pwm_backlight_parse_dt(struct device *dev,

     /* determine the number of brightness levels */
     prop = of_find_property(node, "brightness-levels", &length);
-    if (!prop)
-        return -EINVAL;
+    if (prop) {
+        data->max_brightness = length / sizeof(u32);

-    data->max_brightness = length / sizeof(u32);
+        /* read brightness levels from DT property */
+        if (data->max_brightness > 0) {
+            size_t size = sizeof(*data->levels) * data->max_brightness;

-    /* read brightness levels from DT property */
-    if (data->max_brightness > 0) {
-        size_t size = sizeof(*data->levels) * data->max_brightness;
+            data->levels = devm_kzalloc(dev, size, GFP_KERNEL);
+            if (!data->levels)
+                return -ENOMEM;

-        data->levels = devm_kzalloc(dev, size, GFP_KERNEL);
-        if (!data->levels)
-            return -ENOMEM;
+            ret = of_property_read_u32_array(node, "brightness-levels",
+                            data->levels,
+                            data->max_brightness);
+            if (ret < 0)
+                return ret;

-        ret = of_property_read_u32_array(node, "brightness-levels",
-                         data->levels,
-                         data->max_brightness);
-        if (ret < 0)
-            return ret;
+            data->max_brightness--;
+        }
+    } else {
+        data->max_brightness = MAX_PERCENT_BRIGHTNESS;
+    }

-        ret = of_property_read_u32(node, "default-brightness-level",
-                       &value);
-        if (ret < 0)
-            return ret;
+    ret = of_property_read_u32(node, "default-brightness-level",
+                          &value);
+    if (ret < 0)
+        return ret;

-        data->dft_brightness = value;
-        data->max_brightness--;
-    }
+    data->dft_brightness = value;

     return 0;
 }

-- 
2.0.0

[-- Attachment #2: Type: text/html, Size: 6167 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-27  8:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-27  5:32 [PATCH] Added possibility to use pwm_bl.c with percentage instead of levels Johannes Pointner
2014-06-27  6:12 ` Thierry Reding
2014-06-27  6:58   ` Johannes Pointner
2014-06-27  7:09     ` Thierry Reding
2014-06-27  8:17       ` Johannes Pointner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.