Skip to content

Commit

Permalink
ACPI: video: Simplify __acpi_video_get_backlight_type()
Browse files Browse the repository at this point in the history
[ Upstream commit a5df425 ]

Simplify __acpi_video_get_backlight_type() removing a nested if which
makes the flow harder to follow.

This also results in having only 1 exit point with
return acpi_backlight_native instead of 2.

Note this drops the (video_caps & ACPI_VIDEO_BACKLIGHT) check from
the if (acpi_osi_is_win8() && native_available) return native path.
Windows 8's hardware certification requirements include that there must
be ACPI video bus backlight control, so the ACPI_VIDEO_BACKLIGHT check
is redundant.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
jwrdegoede authored and gregkh committed Jan 7, 2023
1 parent 33c25c3 commit 923c192
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions drivers/acpi/video_detect.c
Expand Up @@ -734,6 +734,16 @@ static bool google_cros_ec_present(void)
return acpi_dev_found("GOOG0004") || acpi_dev_found("GOOG000C");
}

/*
* Windows 8 and newer no longer use the ACPI video interface, so it often
* does not work. So on win8+ systems prefer native brightness control.
* Chromebooks should always prefer native backlight control.
*/
static bool prefer_native_over_acpi_video(void)
{
return acpi_osi_is_win8() || google_cros_ec_present();
}

/*
* Determine which type of backlight interface to use on this system,
* First check cmdline, then dmi quirks, then do autodetect.
Expand Down Expand Up @@ -779,26 +789,14 @@ static enum acpi_backlight_type __acpi_video_get_backlight_type(bool native)
if (apple_gmux_backlight_present())
return acpi_backlight_apple_gmux;

/* Chromebooks should always prefer native backlight control. */
if (google_cros_ec_present() && native_available)
return acpi_backlight_native;
/* Use ACPI video if available, except when native should be preferred. */
if ((video_caps & ACPI_VIDEO_BACKLIGHT) &&
!(native_available && prefer_native_over_acpi_video()))
return acpi_backlight_video;

/* On systems with ACPI video use either native or ACPI video. */
if (video_caps & ACPI_VIDEO_BACKLIGHT) {
/*
* Windows 8 and newer no longer use the ACPI video interface,
* so it often does not work. If the ACPI tables are written
* for win8 and native brightness ctl is available, use that.
*
* The native check deliberately is inside the if acpi-video
* block on older devices without acpi-video support native
* is usually not the best choice.
*/
if (acpi_osi_is_win8() && native_available)
return acpi_backlight_native;
else
return acpi_backlight_video;
}
/* Use native if available */
if (native_available && prefer_native_over_acpi_video())
return acpi_backlight_native;

/* No ACPI video (old hw), use vendor specific fw methods. */
return acpi_backlight_vendor;
Expand Down

0 comments on commit 923c192

Please sign in to comment.