From: Wu Zhangjin <wuzhangjin@gmail.com>
To: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org, Wu Zhangjin <wuzhangjin@gmail.com>,
Zhou Yajin <yajinzhou@vm-kernel.org>
Subject: [PATCH 3/9] Loongson: YeeLoong: add backlight driver
Date: Sun, 23 May 2010 21:57:58 +0800 [thread overview]
Message-ID: <48db65e2f21d523cd515bad7d24c69d45c1221f9.1274622624.git.wuzhangjin@gmail.com> (raw)
In-Reply-To: <cover.1274622624.git.wuzhangjin@gmail.com>
In-Reply-To: <cover.1274622624.git.wuzhangjin@gmail.com>
This patch adds YeeLoong Backlight Driver, it provides standard
interface(/sys/class/backlight/) for user-space applications(e.g.
kpowersave, gnome-power-manager) to control the brightness of the
backlight.
Signed-off-by: Zhou Yajin <yajinzhou@vm-kernel.org>
Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
drivers/platform/mips/Kconfig | 1 +
drivers/platform/mips/yeeloong_laptop.c | 83 +++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/drivers/platform/mips/Kconfig b/drivers/platform/mips/Kconfig
index 5ac5215..c1ba03d 100644
--- a/drivers/platform/mips/Kconfig
+++ b/drivers/platform/mips/Kconfig
@@ -17,6 +17,7 @@ if MIPS_PLATFORM_DEVICES
config LEMOTE_YEELOONG2F
tristate "Lemote YeeLoong Laptop"
depends on LEMOTE_MACH2F
+ select BACKLIGHT_CLASS_DEVICE
help
YeeLoong netbook is a mini laptop made by Lemote, which is basically
compatible to FuLoong2F mini PC, but it has an extra Embedded
diff --git a/drivers/platform/mips/yeeloong_laptop.c b/drivers/platform/mips/yeeloong_laptop.c
index 09f606c..0ec8c03 100644
--- a/drivers/platform/mips/yeeloong_laptop.c
+++ b/drivers/platform/mips/yeeloong_laptop.c
@@ -10,6 +10,81 @@
#include <linux/err.h>
#include <linux/platform_device.h>
+#include <linux/backlight.h> /* for backlight subdriver */
+#include <linux/fb.h>
+
+#include <ec_kb3310b.h>
+
+/* backlight subdriver */
+#define MAX_BRIGHTNESS 8
+
+static int yeeloong_set_brightness(struct backlight_device *bd)
+{
+ unsigned int level, current_level;
+ static unsigned int old_level;
+
+ level = (bd->props.fb_blank == FB_BLANK_UNBLANK &&
+ bd->props.power == FB_BLANK_UNBLANK) ?
+ bd->props.brightness : 0;
+
+ if (level > MAX_BRIGHTNESS)
+ level = MAX_BRIGHTNESS;
+ else if (level < 0)
+ level = 0;
+
+ /* Avoid to modify the brightness when EC is tuning it */
+ if (old_level != level) {
+ current_level = ec_read(REG_DISPLAY_BRIGHTNESS);
+ if (old_level == current_level)
+ ec_write(REG_DISPLAY_BRIGHTNESS, level);
+ old_level = level;
+ }
+
+ return 0;
+}
+
+static int yeeloong_get_brightness(struct backlight_device *bd)
+{
+ return ec_read(REG_DISPLAY_BRIGHTNESS);
+}
+
+static const struct backlight_ops backlight_ops = {
+ .get_brightness = yeeloong_get_brightness,
+ .update_status = yeeloong_set_brightness,
+};
+
+static struct backlight_device *yeeloong_backlight_dev;
+
+static int yeeloong_backlight_init(void)
+{
+ int ret;
+ struct backlight_properties props;
+
+ memset(&props, 0, sizeof(struct backlight_properties));
+ props.max_brightness = MAX_BRIGHTNESS;
+ yeeloong_backlight_dev = backlight_device_register("backlight0", NULL,
+ NULL, &backlight_ops, &props);
+
+ if (IS_ERR(yeeloong_backlight_dev)) {
+ ret = PTR_ERR(yeeloong_backlight_dev);
+ yeeloong_backlight_dev = NULL;
+ return ret;
+ }
+
+ yeeloong_backlight_dev->props.brightness =
+ yeeloong_get_brightness(yeeloong_backlight_dev);
+ backlight_update_status(yeeloong_backlight_dev);
+
+ return 0;
+}
+
+static void yeeloong_backlight_exit(void)
+{
+ if (yeeloong_backlight_dev) {
+ backlight_device_unregister(yeeloong_backlight_dev);
+ yeeloong_backlight_dev = NULL;
+ }
+}
static struct platform_device_id platform_device_ids[] = {
{
@@ -41,11 +116,19 @@ static int __init yeeloong_init(void)
return ret;
}
+ ret = yeeloong_backlight_init();
+ if (ret) {
+ pr_err("Fail to register yeeloong backlight driver.\n");
+ yeeloong_backlight_exit();
+ return ret;
+ }
+
return 0;
}
static void __exit yeeloong_exit(void)
{
+ yeeloong_backlight_exit();
platform_driver_unregister(&platform_driver);
pr_info("Unload YeeLoong Platform Specific Driver.\n");
--
1.7.0.4
next prev parent reply other threads:[~2010-05-23 13:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-23 13:57 [PATCH v12 0/9] Loongson: YeeLoong: add platform specific driver Wu Zhangjin
2010-05-23 13:57 ` [PATCH 1/9] MIPS: add subdirectory for platform extension drivers Wu Zhangjin
2010-05-23 13:57 ` Wu Zhangjin [this message]
2010-05-23 13:57 ` [PATCH 4/9] Loongson: YeeLoong: add hardware monitoring driver Wu Zhangjin
2010-05-23 13:58 ` [PATCH 5/9] Loongson: YeeLoong: add video output driver Wu Zhangjin
2010-05-23 13:58 ` [PATCH 6/9] Loongson: YeeLoong: add suspend support Wu Zhangjin
2010-05-23 13:58 ` [PATCH 7/9] Loongson: YeeLoong: add input/hotkey driver Wu Zhangjin
2010-05-23 13:58 ` [PATCH 8/9] Loongson: YeeLoong: add power_supply based battery driver Wu Zhangjin
2010-05-23 13:58 ` [PATCH 9/9] Loongson: YeeLoong: Co-operate with the revisions of EC Wu Zhangjin
2010-05-23 13:59 ` [PATCH 2/9] Loongson: YeeLoong: add platform driver Wu Zhangjin
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=48db65e2f21d523cd515bad7d24c69d45c1221f9.1274622624.git.wuzhangjin@gmail.com \
--to=wuzhangjin@gmail.com \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
--cc=yajinzhou@vm-kernel.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;
as well as URLs for NNTP newsgroup(s).