mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/6] video: Add backlight support
Date: Fri, 12 Jun 2015 11:53:37 +0200	[thread overview]
Message-ID: <1434102821-10555-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1434102821-10555-1-git-send-email-s.hauer@pengutronix.de>

This adds a small backlight layer. It provides a backlight device
on which the brightness parameter can be used to adjust the brightness.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/video/Kconfig     |  4 +++
 drivers/video/Makefile    |  1 +
 drivers/video/backlight.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++
 include/video/backlight.h | 20 +++++++++++
 4 files changed, 115 insertions(+)
 create mode 100644 drivers/video/backlight.c
 create mode 100644 include/video/backlight.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index f096a54..e108d8a 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -93,4 +93,8 @@ config DRIVER_VIDEO_EDID
 	  This enabled support for reading and parsing EDID data from an attached
 	  monitor.
 
+config DRIVER_VIDEO_BACKLIGHT
+	bool "Add backlight support"
+	help
+	  Enable this for backlight support.
 endif
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index ae9f6e5..0655b0f 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -1,6 +1,7 @@
 obj-$(CONFIG_VIDEO) += fb.o
 obj-$(CONFIG_DRIVER_VIDEO_EDID) += edid.o
 obj-$(CONFIG_OFDEVICE) += of_display_timing.o
+obj-$(CONFIG_DRIVER_VIDEO_BACKLIGHT) += backlight.o
 
 obj-$(CONFIG_DRIVER_VIDEO_ATMEL) += atmel_lcdfb.o atmel_lcdfb_core.o
 obj-$(CONFIG_DRIVER_VIDEO_ATMEL_HLCD) += atmel_hlcdfb.o atmel_lcdfb_core.o
diff --git a/drivers/video/backlight.c b/drivers/video/backlight.c
new file mode 100644
index 0000000..ddde6f8
--- /dev/null
+++ b/drivers/video/backlight.c
@@ -0,0 +1,90 @@
+#include <common.h>
+#include <driver.h>
+#include <linux/list.h>
+#include <video/backlight.h>
+
+static LIST_HEAD(backlights);
+
+int backlight_set_brightness(struct backlight_device *bl, int brightness)
+{
+	int ret, step, i, num_steps;
+
+	if (brightness > bl->brightness_max)
+		brightness = bl->brightness_max;
+
+	if (brightness == bl->brightness_cur)
+		return 0;
+
+	if (brightness > bl->brightness_cur)
+		step = 1;
+	else
+		step = -1;
+
+	i = bl->brightness_cur;
+
+	num_steps = abs(brightness - bl->brightness_cur);
+
+	while (1) {
+		i += step;
+
+		ret = bl->brightness_set(bl, i);
+		if (ret)
+			return ret;
+
+		if (i == brightness)
+			break;
+
+		udelay(100000 / num_steps);
+	}
+
+
+	bl->brightness_cur = bl->brightness = brightness;
+
+	return ret;
+}
+
+int backlight_set_brightness_default(struct backlight_device *bl)
+{
+	int ret;
+
+	ret = backlight_set_brightness(bl, bl->brightness_default);
+
+	return ret;
+}
+
+static int backlight_brightness_set(struct param_d *p, void *priv)
+{
+	struct backlight_device *bl = priv;
+
+	return backlight_set_brightness(bl, bl->brightness);
+}
+
+int backlight_register(struct backlight_device *bl)
+{
+	int ret;
+
+	sprintf(bl->dev.name, "backlight");
+	bl->dev.id = DEVICE_ID_DYNAMIC;
+
+	ret = register_device(&bl->dev);
+	if (ret)
+		return ret;
+
+	dev_add_param_int(&bl->dev, "brightness", backlight_brightness_set,
+			NULL, &bl->brightness, "%d", bl);
+
+	list_add_tail(&bl->list, &backlights);
+
+	return ret;
+}
+
+struct backlight_device *of_backlight_find(struct device_node *node)
+{
+	struct backlight_device *bl;
+
+	list_for_each_entry(bl, &backlights, list)
+		if (bl->node == node)
+			return bl;
+
+	return NULL;
+}
diff --git a/include/video/backlight.h b/include/video/backlight.h
new file mode 100644
index 0000000..56e0341
--- /dev/null
+++ b/include/video/backlight.h
@@ -0,0 +1,20 @@
+#ifndef __VIDEO_BACKLIGHT_H
+#define __VIDEO_BACKLIGHT_H
+
+struct backlight_device {
+	int brightness;
+	int brightness_cur;
+	int brightness_max;
+	int brightness_default;
+	int (*brightness_set)(struct backlight_device *, int brightness);
+	struct list_head list;
+	struct device_d dev;
+	struct device_node *node;
+};
+
+int backlight_set_brightness(struct backlight_device *, int brightness);
+int backlight_set_brightness_default(struct backlight_device *);
+int backlight_register(struct backlight_device *);
+struct backlight_device *of_backlight_find(struct device_node *node);
+
+#endif /* __VIDEO_BACKLIGHT_H */
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2015-06-12  9:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12  9:53 [PATCH 1/6] video: stmfb: Add device tree support Sascha Hauer
2015-06-12  9:53 ` Sascha Hauer [this message]
2015-06-12  9:53 ` [PATCH 3/6] video: Add PWM backlight support Sascha Hauer
2015-06-12  9:58   ` Marc Kleine-Budde
2015-06-12  9:53 ` [PATCH 4/6] ARM: i.MX28: Add PWM clk support Sascha Hauer
2015-06-12  9:53 ` [PATCH 5/6] PWM: Allow multiple PWMs per device node Sascha Hauer
2015-06-12  9:53 ` [PATCH 6/6] PWM: Add MXS PWM support Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434102821-10555-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox