From patchwork Fri Dec 2 20:29:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 128965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 3948C1007D4 for ; Sat, 3 Dec 2011 07:29:54 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1RWZjp-0004HE-Pq; Fri, 02 Dec 2011 20:29:41 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1RWZjn-0004H0-5M for kernel-team@lists.ubuntu.com; Fri, 02 Dec 2011 20:29:39 +0000 Received: from 64-126-113-183.dyn.everestkc.net ([64.126.113.183] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1RWZjm-0002So-Ok for kernel-team@lists.ubuntu.com; Fri, 02 Dec 2011 20:29:39 +0000 From: Seth Forshee To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/1][Oneiric SRU] Platform: Brightness quirk for samsung laptop driver Date: Fri, 2 Dec 2011 14:29:28 -0600 Message-Id: <1322857768-6470-2-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1322857768-6470-1-git-send-email-seth.forshee@canonical.com> References: <1322857768-6470-1-git-send-email-seth.forshee@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com From: Jason Stubbs On some Samsung laptops the brightness regulation works slightly different. All SABI commands except for set_brightness work as expected. The behaviour of set_brightness is as follows: - Setting a new brightness will only step one level toward the new brightness level. For example, setting a level of 5 when the current level is 2 will result in a brightness level of 3. - A spurious KEY_BRIGHTNESS_UP or KEY_BRIGHTNESS_DOWN event is also generated along with the change in brightness. - Neither of the above two issues occur when changing from/to brightness level 0. This patch adds detection and a non-intrusive workaround for the above issues. Signed-off-by: Jason Stubbs Tested-by: David Herrmann Signed-off-by: Greg Kroah-Hartman Signed-off-by: Matthew Garrett (cherry picked from commit ac080523141d5bfa5f60ef2436480f645f915e9c) BugLink: http://bugs.launchpad.net/bugs/897378 Signed-off-by: Seth Forshee --- drivers/platform/x86/samsung-laptop.c | 43 +++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) diff --git a/drivers/platform/x86/samsung-laptop.c b/drivers/platform/x86/samsung-laptop.c index ec85987..c32dc39 100644 --- a/drivers/platform/x86/samsung-laptop.c +++ b/drivers/platform/x86/samsung-laptop.c @@ -226,6 +226,7 @@ static struct backlight_device *backlight_device; static struct mutex sabi_mutex; static struct platform_device *sdev; static struct rfkill *rfk; +static bool has_stepping_quirk; static int force; module_param(force, bool, 0); @@ -382,6 +383,17 @@ static void set_brightness(u8 user_brightness) { u8 user_level = user_brightness + sabi_config->min_brightness; + if (has_stepping_quirk && user_level != 0) { + /* + * short circuit if the specified level is what's already set + * to prevent the screen from flickering needlessly + */ + if (user_brightness == read_brightness()) + return; + + sabi_set_command(sabi_config->commands.set_brightness, 0); + } + sabi_set_command(sabi_config->commands.set_brightness, user_level); } @@ -390,6 +402,34 @@ static int get_brightness(struct backlight_device *bd) return (int)read_brightness(); } +static void check_for_stepping_quirk(void) +{ + u8 initial_level = read_brightness(); + u8 check_level; + + /* + * Some laptops exhibit the strange behaviour of stepping toward + * (rather than setting) the brightness except when changing to/from + * brightness level 0. This behaviour is checked for here and worked + * around in set_brightness. + */ + + if (initial_level <= 2) + check_level = initial_level + 2; + else + check_level = initial_level - 2; + + has_stepping_quirk = false; + set_brightness(check_level); + + if (read_brightness() != check_level) { + has_stepping_quirk = true; + pr_info("enabled workaround for brightness stepping quirk\n"); + } + + set_brightness(initial_level); +} + static int update_status(struct backlight_device *bd) { set_brightness(bd->props.brightness); @@ -813,6 +853,9 @@ static int __init samsung_init(void) } } + /* Check for stepping quirk */ + check_for_stepping_quirk(); + /* knock up a platform device to hang stuff off of */ sdev = platform_device_register_simple("samsung", -1, NULL, 0); if (IS_ERR(sdev))