acpi-video-detect: Rewrite backlight interface selection logic
Currently we have 2 kernel commandline options + dmi-quirks in 3 places all interacting (in interesting ways) to select which which backlight interface to use. On the commandline we've acpi_backlight=[video|vendor] and video.use_native_backlight=[0|1]. DMI quirks we have in acpi/video-detect.c, acpi/video.c and drivers/platform/x86/*.c . This commit is the first step to cleaning this up, replacing the 2 cmdline options with just acpi_backlight=[video|vendor|native|none], and adds a new API to video_detect.c to reflect this. Follow up commits will also move other related code, like unregistering the acpi_video backlight interface if it was registered before other drivers which take priority over it are loaded, to video_detect.c where this logic really belongs. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
14ca7a47d0
commit
87521e16a7
2 changed files with 102 additions and 90 deletions
|
@ -1,4 +1,6 @@
|
||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2015 Red Hat Inc.
|
||||||
|
* Hans de Goede <hdegoede@redhat.com>
|
||||||
* Copyright (C) 2008 SuSE Linux Products GmbH
|
* Copyright (C) 2008 SuSE Linux Products GmbH
|
||||||
* Thomas Renninger <trenn@suse.de>
|
* Thomas Renninger <trenn@suse.de>
|
||||||
*
|
*
|
||||||
|
@ -9,44 +11,45 @@
|
||||||
* acpi_get_pci_dev() can be called to identify ACPI graphics
|
* acpi_get_pci_dev() can be called to identify ACPI graphics
|
||||||
* devices for which a real graphics card is plugged in
|
* devices for which a real graphics card is plugged in
|
||||||
*
|
*
|
||||||
* Now acpi_video_get_capabilities() can be called to check which
|
|
||||||
* capabilities the graphics cards plugged in support. The check for general
|
|
||||||
* video capabilities will be triggered by the first caller of
|
|
||||||
* acpi_video_get_capabilities(NULL); which will happen when the first
|
|
||||||
* backlight switching supporting driver calls:
|
|
||||||
* acpi_video_backlight_support();
|
|
||||||
*
|
|
||||||
* Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
|
* Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
|
||||||
* are available, video.ko should be used to handle the device.
|
* are available, video.ko should be used to handle the device.
|
||||||
*
|
*
|
||||||
* Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
|
* Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
|
||||||
* sony_acpi,... can take care about backlight brightness.
|
* sony_acpi,... can take care about backlight brightness.
|
||||||
*
|
*
|
||||||
* If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
|
* Backlight drivers can use acpi_video_get_backlight_type() to determine
|
||||||
* this file will not be compiled, acpi_video_get_capabilities() and
|
* which driver should handle the backlight.
|
||||||
* acpi_video_backlight_support() will always return 0 and vendor specific
|
|
||||||
* drivers always can handle backlight.
|
|
||||||
*
|
*
|
||||||
|
* If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
|
||||||
|
* this file will not be compiled and acpi_video_get_backlight_type() will
|
||||||
|
* always return acpi_backlight_vendor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/export.h>
|
#include <linux/export.h>
|
||||||
#include <linux/acpi.h>
|
#include <linux/acpi.h>
|
||||||
|
#include <linux/backlight.h>
|
||||||
#include <linux/dmi.h>
|
#include <linux/dmi.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/pci.h>
|
#include <linux/pci.h>
|
||||||
|
#include <linux/types.h>
|
||||||
|
#include <acpi/video.h>
|
||||||
|
|
||||||
ACPI_MODULE_NAME("video");
|
ACPI_MODULE_NAME("video");
|
||||||
#define _COMPONENT ACPI_VIDEO_COMPONENT
|
#define _COMPONENT ACPI_VIDEO_COMPONENT
|
||||||
|
|
||||||
static long acpi_video_support;
|
static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
|
||||||
static bool acpi_video_caps_checked;
|
static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
|
||||||
|
|
||||||
static void acpi_video_parse_cmdline(void)
|
static void acpi_video_parse_cmdline(void)
|
||||||
{
|
{
|
||||||
if (!strcmp("vendor", acpi_video_backlight_string))
|
if (!strcmp("vendor", acpi_video_backlight_string))
|
||||||
acpi_video_support |= ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR;
|
acpi_backlight_cmdline = acpi_backlight_vendor;
|
||||||
if (!strcmp("video", acpi_video_backlight_string))
|
if (!strcmp("video", acpi_video_backlight_string))
|
||||||
acpi_video_support |= ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO;
|
acpi_backlight_cmdline = acpi_backlight_video;
|
||||||
|
if (!strcmp("native", acpi_video_backlight_string))
|
||||||
|
acpi_backlight_cmdline = acpi_backlight_native;
|
||||||
|
if (!strcmp("none", acpi_video_backlight_string))
|
||||||
|
acpi_backlight_cmdline = acpi_backlight_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
static acpi_status
|
static acpi_status
|
||||||
|
@ -77,7 +80,7 @@ find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
|
||||||
* buggy */
|
* buggy */
|
||||||
static int video_detect_force_vendor(const struct dmi_system_id *d)
|
static int video_detect_force_vendor(const struct dmi_system_id *d)
|
||||||
{
|
{
|
||||||
acpi_video_support |= ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
|
acpi_backlight_dmi = acpi_backlight_vendor;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,99 +128,91 @@ static const struct dmi_system_id video_detect_dmi_table[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the video capabilities of a specific ACPI graphics device
|
* Determine which type of backlight interface to use on this system,
|
||||||
|
* First check cmdline, then dmi quirks, then do autodetect.
|
||||||
*
|
*
|
||||||
* if NULL is passed as argument all ACPI devices are enumerated and
|
* The autodetect order is:
|
||||||
* all graphics capabilities of physically present devices are
|
* 1) Is the acpi-video backlight interface supported ->
|
||||||
* summarized and returned. This is cached and done only once.
|
* no, use a vendor interface
|
||||||
|
* 2) Is this a win8 "ready" BIOS and do we have a native interface ->
|
||||||
|
* yes, use a native interface
|
||||||
|
* 3) Else use the acpi-video interface
|
||||||
|
*
|
||||||
|
* Arguably the native on win8 check should be done first, but that would
|
||||||
|
* be a behavior change, which may causes issues.
|
||||||
*/
|
*/
|
||||||
static long acpi_video_get_capabilities(acpi_handle graphics_handle)
|
enum acpi_backlight_type acpi_video_get_backlight_type(void)
|
||||||
{
|
{
|
||||||
long caps = 0;
|
static DEFINE_MUTEX(init_mutex);
|
||||||
struct acpi_device *tmp_dev;
|
static bool init_done;
|
||||||
acpi_status status;
|
static long video_caps;
|
||||||
|
|
||||||
if (acpi_video_caps_checked && graphics_handle == NULL)
|
/* Parse cmdline, dmi and acpi only once */
|
||||||
return acpi_video_support;
|
mutex_lock(&init_mutex);
|
||||||
|
if (!init_done) {
|
||||||
if (!graphics_handle) {
|
acpi_video_parse_cmdline();
|
||||||
/* Only do the global walk through all graphics devices once */
|
dmi_check_system(video_detect_dmi_table);
|
||||||
acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
|
acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
|
||||||
ACPI_UINT32_MAX, find_video, NULL,
|
ACPI_UINT32_MAX, find_video, NULL,
|
||||||
&caps, NULL);
|
&video_caps, NULL);
|
||||||
/* There might be boot param flags set already... */
|
init_done = true;
|
||||||
acpi_video_support |= caps;
|
}
|
||||||
acpi_video_caps_checked = 1;
|
mutex_unlock(&init_mutex);
|
||||||
/* Add blacklists here. Be careful to use the right *DMI* bits
|
|
||||||
* to still be able to override logic via boot params, e.g.:
|
|
||||||
*
|
|
||||||
* if (dmi_name_in_vendors("XY")) {
|
|
||||||
* acpi_video_support |=
|
|
||||||
* ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
|
|
||||||
*}
|
|
||||||
*/
|
|
||||||
|
|
||||||
dmi_check_system(video_detect_dmi_table);
|
if (acpi_backlight_cmdline != acpi_backlight_undef)
|
||||||
} else {
|
return acpi_backlight_cmdline;
|
||||||
status = acpi_bus_get_device(graphics_handle, &tmp_dev);
|
|
||||||
if (ACPI_FAILURE(status)) {
|
if (acpi_backlight_dmi != acpi_backlight_undef)
|
||||||
ACPI_EXCEPTION((AE_INFO, status, "Invalid device"));
|
return acpi_backlight_dmi;
|
||||||
return 0;
|
|
||||||
}
|
if (!(video_caps & ACPI_VIDEO_BACKLIGHT))
|
||||||
acpi_walk_namespace(ACPI_TYPE_DEVICE, graphics_handle,
|
return acpi_backlight_vendor;
|
||||||
ACPI_UINT32_MAX, find_video, NULL,
|
|
||||||
&caps, NULL);
|
if (acpi_osi_is_win8() && backlight_device_registered(BACKLIGHT_RAW))
|
||||||
}
|
return acpi_backlight_native;
|
||||||
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "We have 0x%lX video support %s %s\n",
|
|
||||||
graphics_handle ? caps : acpi_video_support,
|
return acpi_backlight_video;
|
||||||
graphics_handle ? "on device " : "in general",
|
|
||||||
graphics_handle ? acpi_device_bid(tmp_dev) : ""));
|
|
||||||
return caps;
|
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(acpi_video_get_backlight_type);
|
||||||
|
|
||||||
static void acpi_video_caps_check(void)
|
/*
|
||||||
{
|
* Set the preferred backlight interface type based on DMI info.
|
||||||
/*
|
* This function allows DMI blacklists to be implemented by external
|
||||||
* We must check whether the ACPI graphics device is physically plugged
|
|
||||||
* in. Therefore this must be called after binding PCI and ACPI devices
|
|
||||||
*/
|
|
||||||
if (!acpi_video_caps_checked) {
|
|
||||||
acpi_video_parse_cmdline();
|
|
||||||
acpi_video_get_capabilities(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Promote the vendor interface instead of the generic video module.
|
|
||||||
* This function allow DMI blacklists to be implemented by externals
|
|
||||||
* platform drivers instead of putting a big blacklist in video_detect.c
|
* platform drivers instead of putting a big blacklist in video_detect.c
|
||||||
|
*/
|
||||||
|
void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type)
|
||||||
|
{
|
||||||
|
acpi_backlight_dmi = type;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(acpi_video_set_dmi_backlight_type);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compatiblity function, this is going away as soon as all drivers are
|
||||||
|
* converted to acpi_video_set_dmi_backlight_type().
|
||||||
|
*
|
||||||
|
* Promote the vendor interface instead of the generic video module.
|
||||||
* After calling this function you will probably want to call
|
* After calling this function you will probably want to call
|
||||||
* acpi_video_unregister() to make sure the video module is not loaded
|
* acpi_video_unregister() to make sure the video module is not loaded
|
||||||
*/
|
*/
|
||||||
void acpi_video_dmi_promote_vendor(void)
|
void acpi_video_dmi_promote_vendor(void)
|
||||||
{
|
{
|
||||||
acpi_video_caps_check();
|
acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
|
||||||
acpi_video_support |= ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(acpi_video_dmi_promote_vendor);
|
EXPORT_SYMBOL(acpi_video_dmi_promote_vendor);
|
||||||
|
|
||||||
/* Returns true if video.ko can do backlight switching */
|
/*
|
||||||
|
* Compatiblity function, this is going away as soon as all drivers are
|
||||||
|
* converted to acpi_video_get_backlight_type().
|
||||||
|
*
|
||||||
|
* Returns true if video.ko can do backlight switching.
|
||||||
|
*/
|
||||||
int acpi_video_backlight_support(void)
|
int acpi_video_backlight_support(void)
|
||||||
{
|
{
|
||||||
acpi_video_caps_check();
|
/*
|
||||||
|
* This is done this way since vendor drivers call this to see
|
||||||
/* First check for boot param -> highest prio */
|
* if they should load, and we do not want them to load for both
|
||||||
if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR)
|
* the acpi_backlight_video and acpi_backlight_native cases.
|
||||||
return 0;
|
*/
|
||||||
else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO)
|
return acpi_video_get_backlight_type() != acpi_backlight_vendor;
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* Then check for DMI blacklist -> second highest prio */
|
|
||||||
if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VENDOR)
|
|
||||||
return 0;
|
|
||||||
else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VIDEO)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* Then go the default way */
|
|
||||||
return acpi_video_support & ACPI_VIDEO_BACKLIGHT;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(acpi_video_backlight_support);
|
EXPORT_SYMBOL(acpi_video_backlight_support);
|
||||||
|
|
|
@ -16,6 +16,14 @@ struct acpi_device;
|
||||||
#define ACPI_VIDEO_DISPLAY_LEGACY_PANEL 0x0110
|
#define ACPI_VIDEO_DISPLAY_LEGACY_PANEL 0x0110
|
||||||
#define ACPI_VIDEO_DISPLAY_LEGACY_TV 0x0200
|
#define ACPI_VIDEO_DISPLAY_LEGACY_TV 0x0200
|
||||||
|
|
||||||
|
enum acpi_backlight_type {
|
||||||
|
acpi_backlight_undef = -1,
|
||||||
|
acpi_backlight_none = 0,
|
||||||
|
acpi_backlight_video,
|
||||||
|
acpi_backlight_vendor,
|
||||||
|
acpi_backlight_native,
|
||||||
|
};
|
||||||
|
|
||||||
#if (defined CONFIG_ACPI_VIDEO || defined CONFIG_ACPI_VIDEO_MODULE)
|
#if (defined CONFIG_ACPI_VIDEO || defined CONFIG_ACPI_VIDEO_MODULE)
|
||||||
extern int acpi_video_register(void);
|
extern int acpi_video_register(void);
|
||||||
extern void acpi_video_unregister(void);
|
extern void acpi_video_unregister(void);
|
||||||
|
@ -23,6 +31,8 @@ extern void acpi_video_unregister_backlight(void);
|
||||||
extern int acpi_video_get_edid(struct acpi_device *device, int type,
|
extern int acpi_video_get_edid(struct acpi_device *device, int type,
|
||||||
int device_id, void **edid);
|
int device_id, void **edid);
|
||||||
extern bool acpi_video_verify_backlight_support(void);
|
extern bool acpi_video_verify_backlight_support(void);
|
||||||
|
extern enum acpi_backlight_type acpi_video_get_backlight_type(void);
|
||||||
|
extern void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type);
|
||||||
#else
|
#else
|
||||||
static inline int acpi_video_register(void) { return 0; }
|
static inline int acpi_video_register(void) { return 0; }
|
||||||
static inline void acpi_video_unregister(void) { return; }
|
static inline void acpi_video_unregister(void) { return; }
|
||||||
|
@ -33,6 +43,13 @@ static inline int acpi_video_get_edid(struct acpi_device *device, int type,
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
static inline bool acpi_video_verify_backlight_support(void) { return false; }
|
static inline bool acpi_video_verify_backlight_support(void) { return false; }
|
||||||
|
static inline enum acpi_backlight_type acpi_video_get_backlight_type(void)
|
||||||
|
{
|
||||||
|
return acpi_backlight_vendor;
|
||||||
|
}
|
||||||
|
static void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type)
|
||||||
|
{
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue