From patchwork Thu Mar 12 08:57:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 11296 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 n2C8u29D007246 for ; Thu, 12 Mar 2009 08:56:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754013AbZCLI4L (ORCPT ); Thu, 12 Mar 2009 04:56:11 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750852AbZCLI4K (ORCPT ); Thu, 12 Mar 2009 04:56:10 -0400 Received: from mga11.intel.com ([192.55.52.93]:22690 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754013AbZCLI4H (ORCPT ); Thu, 12 Mar 2009 04:56:07 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 12 Mar 2009 01:53:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.38,349,1233561600"; d="scan'208";a="438298569" Received: from rzhang-dt.sh.intel.com (HELO [10.239.36.58]) ([10.239.36.58]) by fmsmga002.fm.intel.com with ESMTP; 12 Mar 2009 01:51:41 -0700 Subject: [RESEND PATCH 3/7] ACPI video: support _BCL packages that don't export brightness levels when machine is on AC/Battery From: Zhang Rui To: Len Brown Cc: linux-acpi , Matthew Garrett , Thomas Renninger , "Zhang, Rui" Date: Thu, 12 Mar 2009 16:57:03 +0800 Message-Id: <1236848223.2807.72.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 Many buggy BIOSes don't export the brightness levels when machine is on AC/Battery in the _BCL method. Reformat the _BCL package for these laptops: now the elements in device->brightness->levels[] are like: levels[0]: brightness level when on AC power. levels[1]: brightness level when on Battery power. levels[2]: supported brightness level 1. levels[3]: supported brightness level 2. ... levels[n]: supported brightness level n-1. levels[n + 1]: supported brightness level n. So if there are n supported brightness levels on this laptop, we will have n+2 entries in device->brightnes->levels[]. level[0] and level[1] are invalid on the laptops that don't export the brightness levels on AC/Battery. Fortunately, we never use these two values at all, even for the valid ones. Signed-off-by: Zhang Rui Acked-by: Matthew Garrett Acked-by: Thomas Renninger --- drivers/acpi/video.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 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 @@ -168,10 +168,15 @@ struct acpi_video_device_cap { u8 _DSS:1; /*Device state set */ }; +struct acpi_video_brightness_flags { + u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */ +}; + struct acpi_video_device_brightness { int curr; int count; int *levels; + struct acpi_video_brightness_flags flags; }; struct acpi_video_device { @@ -682,7 +687,7 @@ static int acpi_video_init_brightness(struct acpi_video_device *device) { union acpi_object *obj = NULL; - int i, max_level = 0, count = 0; + int i, max_level = 0, count = 0, level_ac_battery = 0; union acpi_object *o; struct acpi_video_device_brightness *br = NULL; @@ -701,7 +706,7 @@ acpi_video_init_brightness(struct acpi_v goto out; } - br->levels = kmalloc(obj->package.count * sizeof *(br->levels), + br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels), GFP_KERNEL); if (!br->levels) goto out_free; @@ -719,16 +724,34 @@ acpi_video_init_brightness(struct acpi_v count++; } - /* don't sort the first two brightness levels */ + /* + * some buggy BIOS don't export the levels + * when machine is on AC/Battery in _BCL package. + * In this case, the first two elements in _BCL packages + * are also supported brightness levels that OS should take care of. + */ + for (i = 2; i < count; i++) + if (br->levels[i] == br->levels[0] || + br->levels[i] == br->levels[1]) + level_ac_battery++; + + if (level_ac_battery < 2) { + level_ac_battery = 2 - level_ac_battery; + br->flags._BCL_no_ac_battery_levels = 1; + for (i = (count - 1 + level_ac_battery); i >= 2; i--) + br->levels[i] = br->levels[i - level_ac_battery]; + count += level_ac_battery; + } else if (level_ac_battery > 2) + ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n")); + + /* sort all the supported brightness levels */ sort(&br->levels[2], count - 2, sizeof(br->levels[2]), acpi_video_cmp_level, NULL); - if (count < 2) - goto out_free_levels; - br->count = count; device->brightness = br; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count)); + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "found %d brightness levels\n", count - 2)); kfree(obj); return max_level;