Skip to content

Commit 3dbc80a

Browse files
committed
ACPI: video: Make backlight class device registration a separate step (v2)
On x86/ACPI boards the acpi_video driver will usually initialize before the kms driver (except i915). This causes /sys/class/backlight/acpi_video0 to show up and then the kms driver registers its own native backlight device after which the drivers/acpi/video_detect.c code unregisters the acpi_video0 device (when acpi_video_get_backlight_type()==native). This means that userspace briefly sees 2 devices and the disappearing of acpi_video0 after a brief time confuses the systemd backlight level save/restore code, see e.g.: https://bbs.archlinux.org/viewtopic.php?id=269920 To fix this make backlight class device registration a separate step done by a new acpi_video_register_backlight() function. The intend is for this to be called by the drm/kms driver *after* it is done setting up its own native backlight device. So that acpi_video_get_backlight_type() knows if a native backlight will be available or not at acpi_video backlight registration time, avoiding the add + remove dance. Note the new acpi_video_register_backlight() function is also called from a delayed work to ensure that the acpi_video backlight devices does get registered if necessary even if there is no drm/kms driver or when it is disabled. Changes in v2: - Make register_backlight_delay a module parameter, mainly so that it can be disabled by Nvidia binary driver users Acked-by: Rafael J. Wysocki <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent 038a819 commit 3dbc80a

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

drivers/acpi/acpi_video.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ module_param(device_id_scheme, bool, 0444);
7373
static int only_lcd = -1;
7474
module_param(only_lcd, int, 0444);
7575

76+
/*
77+
* Display probing is known to take up to 5 seconds, so delay the fallback
78+
* backlight registration by 5 seconds + 3 seconds for some extra margin.
79+
*/
80+
static int register_backlight_delay = 8;
81+
module_param(register_backlight_delay, int, 0444);
82+
MODULE_PARM_DESC(register_backlight_delay,
83+
"Delay in seconds before doing fallback (non GPU driver triggered) "
84+
"backlight registration, set to 0 to disable.");
85+
7686
static bool may_report_brightness_keys;
7787
static int register_count;
7888
static DEFINE_MUTEX(register_count_mutex);
@@ -81,6 +91,9 @@ static LIST_HEAD(video_bus_head);
8191
static int acpi_video_bus_add(struct acpi_device *device);
8292
static int acpi_video_bus_remove(struct acpi_device *device);
8393
static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
94+
static void acpi_video_bus_register_backlight_work(struct work_struct *ignored);
95+
static DECLARE_DELAYED_WORK(video_bus_register_backlight_work,
96+
acpi_video_bus_register_backlight_work);
8497
void acpi_video_detect_exit(void);
8598

8699
/*
@@ -1859,8 +1872,6 @@ static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
18591872
if (video->backlight_registered)
18601873
return 0;
18611874

1862-
acpi_video_run_bcl_for_osi(video);
1863-
18641875
if (acpi_video_get_backlight_type() != acpi_backlight_video)
18651876
return 0;
18661877

@@ -2086,7 +2097,11 @@ static int acpi_video_bus_add(struct acpi_device *device)
20862097
list_add_tail(&video->entry, &video_bus_head);
20872098
mutex_unlock(&video_list_lock);
20882099

2089-
acpi_video_bus_register_backlight(video);
2100+
/*
2101+
* The userspace visible backlight_device gets registered separately
2102+
* from acpi_video_register_backlight().
2103+
*/
2104+
acpi_video_run_bcl_for_osi(video);
20902105
acpi_video_bus_add_notify_handler(video);
20912106

20922107
return 0;
@@ -2125,6 +2140,11 @@ static int acpi_video_bus_remove(struct acpi_device *device)
21252140
return 0;
21262141
}
21272142

2143+
static void acpi_video_bus_register_backlight_work(struct work_struct *ignored)
2144+
{
2145+
acpi_video_register_backlight();
2146+
}
2147+
21282148
static int __init is_i740(struct pci_dev *dev)
21292149
{
21302150
if (dev->device == 0x00D1)
@@ -2235,6 +2255,18 @@ int acpi_video_register(void)
22352255
*/
22362256
register_count = 1;
22372257

2258+
/*
2259+
* acpi_video_bus_add() skips registering the userspace visible
2260+
* backlight_device. The intend is for this to be registered by the
2261+
* drm/kms driver calling acpi_video_register_backlight() *after* it is
2262+
* done setting up its own native backlight device. The delayed work
2263+
* ensures that acpi_video_register_backlight() always gets called
2264+
* eventually, in case there is no drm/kms driver or it is disabled.
2265+
*/
2266+
if (register_backlight_delay)
2267+
schedule_delayed_work(&video_bus_register_backlight_work,
2268+
register_backlight_delay * HZ);
2269+
22382270
leave:
22392271
mutex_unlock(&register_count_mutex);
22402272
return ret;
@@ -2245,6 +2277,7 @@ void acpi_video_unregister(void)
22452277
{
22462278
mutex_lock(&register_count_mutex);
22472279
if (register_count) {
2280+
cancel_delayed_work_sync(&video_bus_register_backlight_work);
22482281
acpi_bus_unregister_driver(&acpi_video_bus);
22492282
register_count = 0;
22502283
may_report_brightness_keys = false;
@@ -2253,6 +2286,17 @@ void acpi_video_unregister(void)
22532286
}
22542287
EXPORT_SYMBOL(acpi_video_unregister);
22552288

2289+
void acpi_video_register_backlight(void)
2290+
{
2291+
struct acpi_video_bus *video;
2292+
2293+
mutex_lock(&video_list_lock);
2294+
list_for_each_entry(video, &video_bus_head, entry)
2295+
acpi_video_bus_register_backlight(video);
2296+
mutex_unlock(&video_list_lock);
2297+
}
2298+
EXPORT_SYMBOL(acpi_video_register_backlight);
2299+
22562300
void acpi_video_unregister_backlight(void)
22572301
{
22582302
struct acpi_video_bus *video;

include/acpi/video.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum acpi_backlight_type {
5353
#if IS_ENABLED(CONFIG_ACPI_VIDEO)
5454
extern int acpi_video_register(void);
5555
extern void acpi_video_unregister(void);
56+
extern void acpi_video_register_backlight(void);
5657
extern int acpi_video_get_edid(struct acpi_device *device, int type,
5758
int device_id, void **edid);
5859
extern enum acpi_backlight_type acpi_video_get_backlight_type(void);
@@ -69,6 +70,7 @@ extern int acpi_video_get_levels(struct acpi_device *device,
6970
#else
7071
static inline int acpi_video_register(void) { return -ENODEV; }
7172
static inline void acpi_video_unregister(void) { return; }
73+
static inline void acpi_video_register_backlight(void) { return; }
7274
static inline int acpi_video_get_edid(struct acpi_device *device, int type,
7375
int device_id, void **edid)
7476
{

0 commit comments

Comments
 (0)