[PATCH v6 3/8] Loongson: YeeLoong: add backlight driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Wu Zhangjin <wuzhangjin@xxxxxxxxx>

This patch adds YeeLoong Backlight Driver, which provides standard
interface for user-space applications to control the brightness of the
backlight.

Signed-off-by: Wu Zhangjin <wuzhangjin@xxxxxxxxx>
---
 .../loongson/lemote-2f/yeeloong_laptop/Kconfig     |    9 ++-
 .../loongson/lemote-2f/yeeloong_laptop/Makefile    |    2 +
 .../lemote-2f/yeeloong_laptop/ec_kb3310b.h         |    1 +
 .../lemote-2f/yeeloong_laptop/yl_backlight.c       |   93 ++++++++++++++++++++
 4 files changed, 104 insertions(+), 1 deletions(-)
 create mode 100644 arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c

diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
index d6df9b7..02d36d8 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Kconfig
@@ -10,6 +10,13 @@ menuconfig LEMOTE_YEELOONG2F
 
 if LEMOTE_YEELOONG2F
 
-
+config YEELOONG_BACKLIGHT
+	tristate "Backlight Driver"
+	select BACKLIGHT_CLASS_DEVICE
+	default y
+	help
+	  This option adds YeeLoong Backlight Driver, which provides standard
+	  interface for user-space applications to control the brightness of
+	  the backlight.
 
 endif
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
index 90c4ce5..6c3d3dc 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/Makefile
@@ -1,3 +1,5 @@
 # YeeLoong Specific
 
 obj-y += ec_kb3310b.o
+
+obj-$(CONFIG_YEELOONG_BACKLIGHT) += yl_backlight.o
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
index 762d888..0e3b5ad 100644
--- a/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/ec_kb3310b.h
@@ -23,6 +23,7 @@ typedef int (*sci_handler) (int status);
 extern sci_handler yeeloong_report_lid_status;
 
 #define SCI_IRQ_NUM 0x0A
+#define MAX_BRIGHTNESS 8
 
 /*
  * The following registers are determined by the EC index configuration.
diff --git a/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c
new file mode 100644
index 0000000..481d2ca
--- /dev/null
+++ b/arch/mips/loongson/lemote-2f/yeeloong_laptop/yl_backlight.c
@@ -0,0 +1,93 @@
+/*
+ * YeeLoong Backlight Driver
+ *
+ *  Copyright (C) 2009 Lemote Inc.
+ *  Author: Wu Zhangjin <wuzj@xxxxxxxxxx>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+#include <linux/backlight.h>
+#include <linux/err.h>
+#include <linux/fb.h>
+
+#include <asm/bootinfo.h>
+
+#include "ec_kb3310b.h"
+
+MODULE_AUTHOR("Wu Zhangjin <wuzj@xxxxxxxxxx>");
+MODULE_DESCRIPTION("YeeLoong laptop backlight driver");
+MODULE_LICENSE("GPL");
+
+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 */
+	current_level = ec_read(REG_DISPLAY_BRIGHTNESS);
+	if ((old_level == current_level) && (old_level != level))
+		ec_write(REG_DISPLAY_BRIGHTNESS, level);
+	old_level = level;
+
+	return 0;
+}
+
+static int yeeloong_get_brightness(struct backlight_device *bd)
+{
+	return (int)ec_read(REG_DISPLAY_BRIGHTNESS);
+}
+
+static struct backlight_ops backlight_ops = {
+	.get_brightness = yeeloong_get_brightness,
+	.update_status = yeeloong_set_brightness,
+};
+
+static struct backlight_device *yeeloong_backlight_dev;
+
+static int __init yeeloong_backlight_init(void)
+{
+	int ret;
+
+	if (mips_machtype != MACH_LEMOTE_YL2F89) {
+		pr_err("This Driver is only for YeeLoong laptop\n");
+		return -EFAULT;
+	}
+
+	yeeloong_backlight_dev = backlight_device_register("backlight0", NULL,
+			NULL, &backlight_ops);
+
+	if (IS_ERR(yeeloong_backlight_dev)) {
+		ret = PTR_ERR(yeeloong_backlight_dev);
+		yeeloong_backlight_dev = NULL;
+		return ret;
+	}
+
+	yeeloong_backlight_dev->props.max_brightness = MAX_BRIGHTNESS;
+	yeeloong_backlight_dev->props.brightness =
+		yeeloong_get_brightness(yeeloong_backlight_dev);
+	backlight_update_status(yeeloong_backlight_dev);
+
+	return 0;
+}
+
+static void __exit yeeloong_backlight_exit(void)
+{
+	if (yeeloong_backlight_dev) {
+		backlight_device_unregister(yeeloong_backlight_dev);
+		yeeloong_backlight_dev = NULL;
+	}
+}
+
+module_init(yeeloong_backlight_init);
+module_exit(yeeloong_backlight_exit);
-- 
1.6.2.1



[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux