mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Gregory CLEMENT <gregory.clement@free-electrons.com>
To: barebox <barebox@lists.infradead.org>
Subject: [RFC/PATCH 1/2] backlight: Add backlight framework to support backlight driver
Date: Thu, 06 Oct 2011 10:05:12 +0200	[thread overview]
Message-ID: <4E8D6138.3090702@free-electrons.com> (raw)

Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
---
 drivers/video/Kconfig               |    3 +-
 drivers/video/Makefile              |    2 +
 drivers/video/backlight/Kconfig     |    8 +++
 drivers/video/backlight/Makefile    |    1 +
 drivers/video/backlight/backlight.c |   85 +++++++++++++++++++++++++++++++++++
 include/backlight.h                 |   21 +++++++++
 6 files changed, 119 insertions(+), 1 deletions(-)
 create mode 100644 drivers/video/backlight/Kconfig
 create mode 100644 drivers/video/backlight/Makefile
 create mode 100644 drivers/video/backlight/backlight.c
 create mode 100644 include/backlight.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 28bcfed..e3e6894 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -39,5 +39,6 @@ config DRIVER_VIDEO_S3C_VERBOSE
 	bool "S3C244x verbose framebuffer info"
 
 endif
-
+source "drivers/video/backlight/Kconfig"
 endif
+
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 66b08d8..a619b09 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -4,3 +4,5 @@ obj-$(CONFIG_DRIVER_VIDEO_STM) += stm.o
 obj-$(CONFIG_DRIVER_VIDEO_IMX) += imx.o
 obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
 obj-$(CONFIG_DRIVER_VIDEO_S3C) += s3c.o
+
+obj-$(CONFIG_BACKLIGHT) += backlight/
\ No newline at end of file
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
new file mode 100644
index 0000000..b593a82
--- /dev/null
+++ b/drivers/video/backlight/Kconfig
@@ -0,0 +1,8 @@
+#
+# Backlight configuration
+#
+
+menuconfig BACKLIGHT
+	bool "Backlight support"
+	help
+	  Add support for backlight
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
new file mode 100644
index 0000000..3c63230
--- /dev/null
+++ b/drivers/video/backlight/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_BACKLIGHT) += backlight.o
\ No newline at end of file
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
new file mode 100644
index 0000000..d4161e9
--- /dev/null
+++ b/drivers/video/backlight/backlight.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2011 Gregory Clement, Free Electrons
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ *
+ */
+#include <common.h>
+#include <backlight.h>
+#include <errno.h>
+#include <init.h>
+
+static int backlight_set_brightness(struct device_d *dev,
+				    struct param_d *param, const char *val)
+{
+	struct backlight_dev *backlight;
+	int percent = 0;
+	unsigned char new[4];
+
+	backlight = (struct backlight_dev *)dev->priv;
+
+	if (!val)
+		return dev_param_set_generic(dev, param, NULL);
+
+	percent = simple_strtoul(val, NULL, 0);
+
+	if (backlight->set_brightness) {
+		percent = backlight->set_brightness(backlight, percent);
+		snprintf(new, 4, "%.3d", percent);
+		dev_param_set_generic(dev, param, new);
+	} else {
+		dev_err(dev, "unsupported function\n");
+	}
+
+	return 0;
+}
+
+int register_backlight(struct backlight_dev *backlight)
+{
+	int id = get_free_deviceid("backlight");
+	struct device_d *dev;
+
+	dev = &backlight->dev;
+
+	dev->priv = backlight;
+	dev->id = id;
+
+	sprintf(dev->name, "backlight");
+
+	register_device(&backlight->dev);
+	dev_add_param(dev, "brightness", backlight_set_brightness, NULL, 0);
+	dev_set_param(dev, "brightness", "0");
+	return 0;
+}
+EXPORT_SYMBOL(register_backlight);
+
+static int backlight_probe(struct device_d *hw_dev)
+{
+	return 0;
+}
+
+static struct driver_d backlight_driver = {
+	.name = "backlight",
+	.probe = backlight_probe,
+};
+
+static int backlight_init_driver(void)
+{
+	register_driver(&backlight_driver);
+	return 0;
+}
+
+device_initcall(backlight_init_driver);
diff --git a/include/backlight.h b/include/backlight.h
new file mode 100644
index 0000000..7785c63
--- /dev/null
+++ b/include/backlight.h
@@ -0,0 +1,21 @@
+/*
+ * backlight.h - definitions for the barebox backlight framework
+ *
+ * Copyright (C) 2011 Gregory Clement, Free Electrons
+ *
+ * This file is released under the GPLv2 or later
+ *
+ */
+
+#ifndef BACKLIGHT_H
+#define BACKLIGHT_H
+
+struct backlight_dev {
+	struct device_d dev;
+	void *priv;
+	int (*set_brightness) (struct backlight_dev *backlight, int percent);
+};
+
+int register_backlight(struct backlight_dev *backlight);
+
+#endif /* BACKLIGHT_H */
-- 
1.7.4.1




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

                 reply	other threads:[~2011-10-06  8:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4E8D6138.3090702@free-electrons.com \
    --to=gregory.clement@free-electrons.com \
    --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