public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Frank <mail@dmitryfrank.com>
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>
Cc: Dmitry Frank <mail@dmitryfrank.com>,
	Zhang Rui <rui.zhang@intel.com>, Len Brown <lenb@kernel.org>,
	Felipe Contreras <felipe.contreras@gmail.com>,
	linux-acpi@vger.kernel.org
Subject: [PATCH v2 3/3] ACPI: video: add comments about subtle cases
Date: Wed, 19 Apr 2017 12:48:09 +0300	[thread overview]
Message-ID: <20170419094809.12895-4-mail@dmitryfrank.com> (raw)
In-Reply-To: <20170419094809.12895-1-mail@dmitryfrank.com>

The comment for acpi_video_bqc_quirk is by Felipe Contreras, taken from
the git history.

Signed-off-by: Dmitry Frank <mail@dmitryfrank.com>
---
 drivers/acpi/acpi_video.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index cfd3bed57bed..7fd16efa84c8 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -148,7 +148,15 @@ struct acpi_video_device_attrib {
 				   the VGA device. */
 	u32 pipe_id:3;		/* For VGA multiple-head devices. */
 	u32 reserved:10;	/* Must be 0 */
-	u32 device_id_scheme:1;	/* Device ID Scheme */
+
+	/*
+	 * The device ID might not actually follow the scheme described by this
+	 * struct acpi_video_device_attrib. If it does, then this bit
+	 * device_id_scheme is set; otherwise, other fields should be ignored.
+	 *
+	 * (but also see the global flag force_device_id_scheme)
+	 */
+	u32 device_id_scheme:1;
 };
 
 struct acpi_video_enumerated_device {
@@ -732,7 +740,33 @@ static int acpi_video_bqc_quirk(struct acpi_video_device *device,
 
 	/*
 	 * Some systems always report current brightness level as maximum
-	 * through _BQC, we need to test another value for them.
+	 * through _BQC, we need to test another value for them. However,
+	 * there is a subtlety:
+	 *
+	 * If the _BCL package ordering is descending, the first level
+	 * (br->levels[2]) is likely to be 0, and if the number of levels
+	 * matches the number of steps, we might confuse a returned level to
+	 * mean the index.
+	 *
+	 * For example:
+	 *
+	 *     current_level = max_level = 100
+	 *     test_level = 0
+	 *     returned level = 100
+	 *
+	 * In this case 100 means the level, not the index, and _BCM failed.
+	 * Still, if the _BCL package ordering is descending, the index of
+	 * level 0 is also 100, so we assume _BQC is indexed, when it's not.
+	 *
+	 * This causes all _BQC calls to return bogus values causing weird
+	 * behavior from the user's perspective.  For example:
+	 *
+	 * xbacklight -set 10; xbacklight -set 20;
+	 *
+	 * would flash to 90% and then slowly down to the desired level (20).
+	 *
+	 * The solution is simple; test anything other than the first level
+	 * (e.g. 1).
 	 */
 	test_level = current_level == max_level
 		? br->levels[ACPI_VIDEO_FIRST_LEVEL + 1]
@@ -793,6 +827,11 @@ int acpi_video_get_levels(struct acpi_device *device,
 		goto out;
 	}
 
+	/*
+	 * Note that we have to reserve 2 extra items (ACPI_VIDEO_FIRST_LEVEL),
+	 * in order to account for buggy BIOS which don't export the first two
+	 * special levels (see below)
+	 */
 	br->levels = kmalloc((obj->package.count + ACPI_VIDEO_FIRST_LEVEL) *
 	                     sizeof(*br->levels), GFP_KERNEL);
 	if (!br->levels) {
-- 
2.11.0


  parent reply	other threads:[~2017-04-19  9:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-18 12:35 [PATCH] acpi: video: get rid of magic numbers and use enum instead Dmitry Frank
2017-04-19  0:42 ` Rafael J. Wysocki
2017-04-19  9:58   ` Dmitry Frank
2017-04-19 10:12   ` Dmitry Frank
2017-04-19  9:48 ` [PATCH v2 0/3] ACPI: video: get rid of magic numbers, do other refactoring Dmitry Frank
2017-04-19  9:48   ` [PATCH v2 1/3] ACPI: video: get rid of magic numbers and use enum instead Dmitry Frank
2017-04-19  9:48   ` [PATCH v2 2/3] ACPI: video: rename the global flag device_id_scheme Dmitry Frank
2017-04-19 10:23     ` Rafael J. Wysocki
2017-04-19 10:40       ` Dmitry Frank
2017-04-19  9:48   ` Dmitry Frank [this message]
2017-04-19 10:36 ` [PATCH v3 0/2] ACPI: video: get rid of magic numbers, do other refactoring Dmitry Frank
2017-04-19 10:36   ` [PATCH v3 1/2] ACPI: video: get rid of magic numbers and use enum instead Dmitry Frank
2017-04-19 19:36     ` Rafael J. Wysocki
2017-04-19 19:44       ` Dmitry Frank
2017-04-19 20:15         ` Rafael J. Wysocki
2017-04-20 10:40           ` Rafael J. Wysocki
2017-04-20 10:46             ` Dmitry Frank
2017-04-19 10:36   ` [PATCH v3 2/2] ACPI: video: add comments about subtle cases Dmitry Frank

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170419094809.12895-4-mail@dmitryfrank.com \
    --to=mail@dmitryfrank.com \
    --cc=felipe.contreras@gmail.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox