From patchwork Fri Jan 9 09:26:06 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 1465 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 n099NxNQ003124 for ; Fri, 9 Jan 2009 01:24:05 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752462AbZAIJ1r (ORCPT ); Fri, 9 Jan 2009 04:27:47 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752596AbZAIJ1q (ORCPT ); Fri, 9 Jan 2009 04:27:46 -0500 Received: from vms173001pub.verizon.net ([206.46.173.1]:40893 "EHLO vms173001pub.verizon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752424AbZAIJ1o (ORCPT ); Fri, 9 Jan 2009 04:27:44 -0500 Received: from localhost.localdomain ([96.237.168.40]) by vms173001.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0KD700L3O6A6LJF7@vms173001.mailsrvcs.net> for linux-acpi@vger.kernel.org; Fri, 09 Jan 2009 03:27:43 -0600 (CST) Received: from localhost.localdomain (d975xbx2 [127.0.0.1]) by localhost.localdomain (8.14.2/8.14.2) with ESMTP id n099Rgoj011815; Fri, 09 Jan 2009 04:27:42 -0500 Received: (from lenb@localhost) by localhost.localdomain (8.14.2/8.14.2/Submit) id n099Rgiv011814; Fri, 09 Jan 2009 04:27:42 -0500 Date: Fri, 09 Jan 2009 04:26:06 -0500 From: Len Brown Subject: [PATCH 04/94] ACPI: video: Fix reversed brightness behavior on ThinkPad SL series In-reply-to: <1231493256-11678-1-git-send-email-lenb@kernel.org> In-reply-to: To: linux-acpi@vger.kernel.org Cc: Zhang Rui , Len Brown Message-id: <935e5f290ec1eb0f1c15004421f5fd3154380fd5.1231492607.git.len.brown@intel.com> Organization: Intel Open Source Technology Center X-Mailer: git-send-email 1.6.1.76.gc123b References: <1231493256-11678-1-git-send-email-lenb@kernel.org> References: Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Zhang Rui Section B.6.2 of ACPI 3.0b specification that defines _BCL method doesn't require the brightness levels returned to be sorted. At least ThinkPad SL300 (and probably all IdeaPads) returns the array reversed (i.e. bightest levels have lowest indexes), which causes the brightness management behave in completely reversed manner on these machines (brightness increases when the laptop is idle, while the display dims when used). Sorting the array by brightness level values after reading the list fixes the issue. http://bugzilla.kernel.org/show_bug.cgi?id=12037 Signed-off-by: Zhang Rui Tested-by: Lubomir Rintel Signed-off-by: Len Brown --- drivers/acpi/video.c | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index baa4419..38bf8b4 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -626,6 +627,16 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) } /* + * Simple comparison function used to sort backlight levels. + */ + +static int +acpi_video_cmp_level(const void *a, const void *b) +{ + return *(int *)a - *(int *)b; +} + +/* * Arg: * device : video output device (LCD, CRT, ..) * @@ -676,6 +687,10 @@ acpi_video_init_brightness(struct acpi_video_device *device) count++; } + /* don't sort the first two brightness levels */ + sort(&br->levels[2], count - 2, sizeof(br->levels[2]), + acpi_video_cmp_level, NULL); + if (count < 2) goto out_free_levels;