From patchwork Thu Apr 9 06:24:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 17339 X-Patchwork-Delegate: rui.zhang@intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n396Nu8B003438 for ; Thu, 9 Apr 2009 06:24:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755174AbZDIGYS (ORCPT ); Thu, 9 Apr 2009 02:24:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755885AbZDIGYS (ORCPT ); Thu, 9 Apr 2009 02:24:18 -0400 Received: from mga03.intel.com ([143.182.124.21]:58067 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755174AbZDIGYR (ORCPT ); Thu, 9 Apr 2009 02:24:17 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 08 Apr 2009 23:24:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.40,159,1239001200"; d="scan'208";a="129586160" Received: from rzhang-dt.sh.intel.com (HELO [10.239.36.94]) ([10.239.36.94]) by azsmga001.ch.intel.com with ESMTP; 08 Apr 2009 23:24:15 -0700 Subject: [PATCH] ACPI video: handle indexed _BQC correctly From: Zhang Rui To: Len Brown Cc: linux-acpi , Thomas Renninger , Matthew Garrett , "Zhang, Rui" Date: Thu, 09 Apr 2009 14:24:35 +0800 Message-Id: <1239258275.7661.193.camel@rzhang-dt> Mime-Version: 1.0 X-Mailer: Evolution 2.22.1 (2.22.1-2.fc9) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In the current code, for a box with an indexed _BQC method, we 1. get the current brightness level by evaluating _BQC 2. set the value gotten in step 1 to _BCM 3. get the current brightness level again 4. set the _BQC_use_index flag if the results gotten in step 1 and in step 3 don't equal. But this logic doesn't work actually, because the _BQC_use_index is not set when acpi_video_device_lcd_set_level is invoked. This results in a failure in step 2. http://bugzilla.kernel.org/show_bug.cgi?id=12249#c83 Now, we set the _BQC_use_index flag after invoking _BQC for the first time. And reevaluate the _BQC to get the correct brightness level. Signed-off-by: Zhang Rui --- drivers/acpi/video.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-2.6/drivers/acpi/video.c =================================================================== --- linux-2.6.orig/drivers/acpi/video.c +++ linux-2.6/drivers/acpi/video.c @@ -805,12 +805,19 @@ acpi_video_init_brightness(struct acpi_v br->flags._BCM_use_index = br->flags._BCL_use_index; /* _BQC uses INDEX while _BCL uses VALUE in some laptops */ - br->curr = max_level; + br->curr = level_old = max_level; + + if (!device->cap._BQC) + goto set_level; + result = acpi_video_device_lcd_get_level_current(device, &level_old); if (result) goto out_free_levels; - result = acpi_video_device_lcd_set_level(device, br->curr); + /* + * Set the level to maximum and check if _BQC uses indexed value + */ + result = acpi_video_device_lcd_set_level(device, max_level); if (result) goto out_free_levels; @@ -818,25 +825,19 @@ acpi_video_init_brightness(struct acpi_v if (result) goto out_free_levels; - if ((level != level_old) && !br->flags._BCM_use_index) { - /* Note: - * This piece of code does not work correctly if the current - * brightness levels is 0. - * But I guess boxes that boot with such a dark screen are rare - * and no more code is needed to cover this specifial case. - */ - - if (level_ac_battery != 2) { - /* - * For now, we don't support the _BCL like this: - * 16, 15, 0, 1, 2, 3, ..., 14, 15, 16 - * because we may mess up the index returned by _BQC. - * Plus: we have not got a box like this. - */ - ACPI_ERROR((AE_INFO, "_BCL not supported\n")); - } - br->flags._BQC_use_index = 1; - } + br->flags._BQC_use_index = (level == max_level ? 0 : 1); + + if (!br->flags._BQC_use_index) + goto set_level; + + if (br->flags._BCL_reversed) + level_old = (br->count - 1) - level_old; + level_old = br->levels[level_old]; + +set_level: + result = acpi_video_device_lcd_set_level(device, level_old); + if (result) + goto out_free_levels; ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count - 2));