Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755539AbZLHOQp (ORCPT ); Tue, 8 Dec 2009 09:16:45 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755501AbZLHOQg (ORCPT ); Tue, 8 Dec 2009 09:16:36 -0500 Received: from mail-px0-f194.google.com ([209.85.216.194]:42223 "EHLO mail-px0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755233AbZLHOQ2 (ORCPT ); Tue, 8 Dec 2009 09:16:28 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=BNa0/DUA5lb+R6GsEzei8XMaeyJ/GWVZrnVTjYmvINghsUlxQzl4tHSiaAzELCcZfL 2/GvotVN1Zd5KiCN/99/Uh4dB+iuZJxIxr0Y1eeWhTQh9v8WY+ubV8wuozNRX79nn+yj ObP0XjrmxyZRP4/j/Bx5vo7TbyO4oEf0UMoHI= From: Wu Zhangjin To: Ralf Baechle Cc: akpm@linux-foundation.org, Wu Zhangjin , linux-mips@linux-mips.org, linux-kernel@vger.kernel.org, Dmitry Torokhov , "Rafael J . Wysocki" , zhangfx@lemote.com, linux-laptop@vger.kernel.org, Stephen Rothwell , Pavel Machek Subject: [PATCH v9 3/8] Loongson: YeeLoong: add backlight driver Date: Tue, 8 Dec 2009 22:15:51 +0800 Message-Id: <4d821efaecc3dee0b9124119507a694e81572437.1260281599.git.wuzhangjin@gmail.com> X-Mailer: git-send-email 1.6.2.1 In-Reply-To: <7676d8397e593dbec0d40e24429b7ccbcecfa588.1260281599.git.wuzhangjin@gmail.com> References: <39d232e3f8359e9c11bad7536f0162444401ec94.1260281599.git.wuzhangjin@gmail.com> <7676d8397e593dbec0d40e24429b7ccbcecfa588.1260281599.git.wuzhangjin@gmail.com> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3848 Lines: 137 From: Wu Zhangjin 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: Wu Zhangjin --- drivers/platform/mips/Kconfig | 1 + drivers/platform/mips/yeeloong_laptop.c | 81 +++++++++++++++++++++++++++++++ 2 files changed, 82 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 85fc7ed..be674c5 100644 --- a/drivers/platform/mips/yeeloong_laptop.c +++ b/drivers/platform/mips/yeeloong_laptop.c @@ -11,6 +11,79 @@ #include #include +#include /* for backlight subdriver */ +#include + +#include + +/* 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 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; + + 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 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[] = { { @@ -42,11 +115,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.6.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/