From 90b066b15eda028ed44299f01236f8576dd8551d Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 22 Dec 2015 19:09:48 +0100 Subject: ACPI / video: Add a acpi_video_handles_brightness_key_presses() helper Several drivers want to know if the acpi-video is generating key-presses for brightness change hotkeys to avoid sending double key-events to userspace for these. Currently these driver use this construct for this: if (acpi_video_get_backlight_type() == acpi_backlight_vendor) report_brightness_key_event(); This indirect way of detecting if acpi-video is active does not make the code easier to understand, and in some cases it is wrong because just because the preferred type != vendor does not mean that acpi-video is actually listening for brightness events, e.g. there may be no acpi-video bus on the system at all. This commit adds a acpi_video_handles_brightness_key_presses() helper function, making the code needing this functionality both easier to read and more correct. Signed-off-by: Hans de Goede Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpi_video.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'drivers') diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index 3405f7a41e25..2a649f3edefb 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -2072,6 +2072,18 @@ void acpi_video_unregister_backlight(void) mutex_unlock(®ister_count_mutex); } +bool acpi_video_handles_brightness_key_presses(void) +{ + bool have_video_busses; + + mutex_lock(&video_list_lock); + have_video_busses = !list_empty(&video_bus_head); + mutex_unlock(&video_list_lock); + + return have_video_busses; +} +EXPORT_SYMBOL(acpi_video_handles_brightness_key_presses); + /* * This is kind of nasty. Hardware using Intel chipsets may require * the video opregion code to be run first in order to initialise -- cgit v1.2.3-59-g8ed1b From 61679c725553ccffd8b281955186410550bd1eaf Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 22 Dec 2015 19:09:49 +0100 Subject: dell-wmi: Use acpi_video_handles_brightness_key_presses() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the new acpi_video_handles_brightness_key_presses function to check if we should report brightness key-presses. This makes the code both easier to read and makes it properly report key-presses when acpi-video is not reporting them for reasons other then the backlight type being vendor. Signed-off-by: Hans de Goede Acked-by: Pali Rohár Signed-off-by: Rafael J. Wysocki --- drivers/platform/x86/dell-wmi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c index f2d77fe696ac..cb8a9c2a3a1f 100644 --- a/drivers/platform/x86/dell-wmi.c +++ b/drivers/platform/x86/dell-wmi.c @@ -43,8 +43,6 @@ MODULE_LICENSE("GPL"); #define DELL_EVENT_GUID "9DBB5994-A997-11DA-B012-B622A1EF5492" -static int acpi_video; - MODULE_ALIAS("wmi:"DELL_EVENT_GUID); /* @@ -159,7 +157,8 @@ static void dell_wmi_process_key(int reported_key) /* Don't report brightness notifications that will also come via ACPI */ if ((key->keycode == KEY_BRIGHTNESSUP || - key->keycode == KEY_BRIGHTNESSDOWN) && acpi_video) + key->keycode == KEY_BRIGHTNESSDOWN) && + acpi_video_handles_brightness_key_presses()) return; sparse_keymap_report_entry(dell_wmi_input_dev, key, 1, true); @@ -398,7 +397,6 @@ static int __init dell_wmi_init(void) } dmi_walk(find_hk_type, NULL); - acpi_video = acpi_video_get_backlight_type() != acpi_backlight_vendor; err = dell_wmi_input_setup(); if (err) -- cgit v1.2.3-59-g8ed1b From 7714687a2b2d4afcfac8c3bcc99ace16efa98882 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 22 Dec 2015 19:09:50 +0100 Subject: thinkpad_acpi: Use acpi_video_handles_brightness_key_presses() Use the new acpi_video_handles_brightness_key_presses function to check if we should report brightness key-presses. This makes the code both easier to read and makes it properly report key-presses when acpi-video is not reporting them for reasons other then the backlight type being vendor. Signed-off-by: Hans de Goede Acked-by: Henrique de Moraes Holschuh Signed-off-by: Rafael J. Wysocki --- drivers/platform/x86/thinkpad_acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 0bed4733c4f0..f453d5dc085e 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -3488,7 +3488,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) /* Do not issue duplicate brightness change events to * userspace. tpacpi_detect_brightness_capabilities() must have * been called before this point */ - if (acpi_video_get_backlight_type() != acpi_backlight_vendor) { + if (acpi_video_handles_brightness_key_presses()) { pr_info("This ThinkPad has standard ACPI backlight " "brightness control, supported by the ACPI " "video driver\n"); -- cgit v1.2.3-59-g8ed1b From 05bc59a079eaa6c38b049473fe62fab84d934802 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 22 Dec 2015 19:09:51 +0100 Subject: ACPI / video: Add a module option to disable the reporting of keypresses Add a module option to disable the reporting of keypresses, in some buggy firmware implementatinon, the reported events are wrong. E.g. they lag reality by one event in the case triggering the writing of this patch. In this case it is better to not forward these wrong events to userspace (esp.) when there is another source of the same events which is not buggy. Note this is only intended to work around implementations which send events which are plain wrong. In some cases we get double events, e.g. from both acpi-video and the atkbd driver, in this case acpi-video is considered the canonical source, and the events from the other source should be filtered (using e.g. /lib/udev/hwdb.d/60-keyboard.hwdb). Signed-off-by: Hans de Goede Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpi_video.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index 2a649f3edefb..2971154fdd62 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -77,6 +77,13 @@ module_param(allow_duplicates, bool, 0644); static int disable_backlight_sysfs_if = -1; module_param(disable_backlight_sysfs_if, int, 0444); +#define REPORT_OUTPUT_KEY_EVENTS 0x01 +#define REPORT_BRIGHTNESS_KEY_EVENTS 0x02 +static int report_key_events = -1; +module_param(report_key_events, int, 0644); +MODULE_PARM_DESC(report_key_events, + "0: none, 1: output changes, 2: brightness changes, 3: all"); + static bool device_id_scheme = false; module_param(device_id_scheme, bool, 0444); @@ -1480,7 +1487,7 @@ static void acpi_video_bus_notify(struct acpi_device *device, u32 event) /* Something vetoed the keypress. */ keycode = 0; - if (keycode) { + if (keycode && (report_key_events & REPORT_OUTPUT_KEY_EVENTS)) { input_report_key(input, keycode, 1); input_sync(input); input_report_key(input, keycode, 0); @@ -1544,7 +1551,7 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) acpi_notifier_call_chain(device, event, 0); - if (keycode) { + if (keycode && (report_key_events & REPORT_BRIGHTNESS_KEY_EVENTS)) { input_report_key(input, keycode, 1); input_sync(input); input_report_key(input, keycode, 0); @@ -2080,7 +2087,8 @@ bool acpi_video_handles_brightness_key_presses(void) have_video_busses = !list_empty(&video_bus_head); mutex_unlock(&video_list_lock); - return have_video_busses; + return have_video_busses && + (report_key_events & REPORT_BRIGHTNESS_KEY_EVENTS); } EXPORT_SYMBOL(acpi_video_handles_brightness_key_presses); -- cgit v1.2.3-59-g8ed1b From 4b4b3b20e8e645be103cf737827372f86479867a Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 22 Dec 2015 19:09:52 +0100 Subject: ACPI / video: Add quirks for the Dell Vostro V131 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Dell Vostro V131 has an especially broken acpi-video implementation. The backlight control bits work, but when the brightness is changed via the acpi-video interface the backlight flickers annoyingly before settling at the new brightness, switching to using the native interface fixes the flickering so add a quirk for this (the vendor interface has the same problem). Brightness keypresses reported through the acpi-video-bus are also broken, they get reported one event delayed, so if you press the brightness-up hotkey on the keyboard nothing happens, then if you press brightness-down, the previous brightness-up event gets reported. Since the keypresses are also reported via wmi (if active) and via atkbd (when wmi is not active) add a quirk to simply filter out the delayed (broken) events. Reported-and-tested-by: Michał Kępień Signed-off-by: Hans de Goede Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpi_video.c | 25 +++++++++++++++++++++++++ drivers/acpi/video_detect.c | 8 ++++++++ 2 files changed, 33 insertions(+) (limited to 'drivers') diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index 2971154fdd62..80b13d498091 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -419,6 +419,13 @@ static int video_enable_only_lcd(const struct dmi_system_id *d) return 0; } +static int video_set_report_key_events(const struct dmi_system_id *id) +{ + if (report_key_events == -1) + report_key_events = (uintptr_t)id->driver_data; + return 0; +} + static struct dmi_system_id video_dmi_table[] = { /* * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121 @@ -507,6 +514,24 @@ static struct dmi_system_id video_dmi_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Mobile M9410"), }, }, + /* + * Some machines report wrong key events on the acpi-bus, suppress + * key event reporting on these. Note this is only intended to work + * around events which are plain wrong. In some cases we get double + * events, in this case acpi-video is considered the canonical source + * and the events from the other source should be filtered. E.g. + * by calling acpi_video_handles_brightness_key_presses() from the + * vendor acpi/wmi driver or by using /lib/udev/hwdb.d/60-keyboard.hwdb + */ + { + .callback = video_set_report_key_events, + .driver_data = (void *)((uintptr_t)REPORT_OUTPUT_KEY_EVENTS), + .ident = "Dell Vostro V131", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), + }, + }, {} }; diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c index daaf1c4e1e0f..8fe2682380e9 100644 --- a/drivers/acpi/video_detect.c +++ b/drivers/acpi/video_detect.c @@ -279,6 +279,14 @@ static const struct dmi_system_id video_detect_dmi_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"), }, }, + { + .callback = video_detect_force_native, + .ident = "Dell Vostro V131", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), + }, + }, { }, }; -- cgit v1.2.3-59-g8ed1b From 49eb5208220a9eef7529decbdefd95e4b94a928b Mon Sep 17 00:00:00 2001 From: Aaron Lu Date: Wed, 30 Dec 2015 13:11:24 +0800 Subject: ACPI / video: Add a quirk to force acpi-video backlight on SAMSUNG 530U4E/540U4E The native interface on SAMSUNG 530U4E/540U4E doesn't work even though the firmware claims Win8 compatible while the acpi_video interface works, add a quirk for this. Link: https://bugzilla.kernel.org/show_bug.cgi?id=108971 Reported-and-tested-by: adam bk Signed-off-by: Aaron Lu Signed-off-by: Rafael J. Wysocki --- drivers/acpi/video_detect.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers') diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c index 8fe2682380e9..90e2d54be526 100644 --- a/drivers/acpi/video_detect.c +++ b/drivers/acpi/video_detect.c @@ -250,6 +250,15 @@ static const struct dmi_system_id video_detect_dmi_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"), }, }, + { + /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */ + .callback = video_detect_force_video, + .ident = "SAMSUNG 530U4E/540U4E", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"), + }, + }, /* Non win8 machines which need native backlight nevertheless */ { -- cgit v1.2.3-59-g8ed1b From aecbd9b1bff6afbe349921b406b99d285b412820 Mon Sep 17 00:00:00 2001 From: Adrien Schildknecht Date: Mon, 4 Jan 2016 23:22:28 +0100 Subject: ACPI / video: driver must be registered before checking for keypresses acpi_video_handles_brightness_key_presses() may use an uninitialized mutex. The error has been reported by lockdep: DEBUG_LOCKS_WARN_ON(l->magic != l). The function assumes that the video driver has been registered before being called. As explained in the comment of acpi_video_init(), the registration of the video class may be defered and thus may not take place in the init function of the module. Use completion mechanisms to make sure that acpi_video_handles_brightness_key_presses() wait for the completion of acpi_video_register() before using the mutex. Also get rid of register_count since task completion can replace it. Signed-off-by: Adrien Schildknecht Reviewed-by: Hans de Goede Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpi_video.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'drivers') diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c index 80b13d498091..06a006ff89b0 100644 --- a/drivers/acpi/acpi_video.c +++ b/drivers/acpi/acpi_video.c @@ -90,8 +90,8 @@ module_param(device_id_scheme, bool, 0444); static bool only_lcd = false; module_param(only_lcd, bool, 0444); -static int register_count; -static DEFINE_MUTEX(register_count_mutex); +static DECLARE_COMPLETION(register_done); +static DEFINE_MUTEX(register_done_mutex); static struct mutex video_list_lock; static struct list_head video_bus_head; static int acpi_video_bus_add(struct acpi_device *device); @@ -2049,8 +2049,8 @@ int acpi_video_register(void) { int ret = 0; - mutex_lock(®ister_count_mutex); - if (register_count) { + mutex_lock(®ister_done_mutex); + if (completion_done(®ister_done)) { /* * if the function of acpi_video_register is already called, * don't register the acpi_vide_bus again and return no error. @@ -2071,22 +2071,22 @@ int acpi_video_register(void) * When the acpi_video_bus is loaded successfully, increase * the counter reference. */ - register_count = 1; + complete(®ister_done); leave: - mutex_unlock(®ister_count_mutex); + mutex_unlock(®ister_done_mutex); return ret; } EXPORT_SYMBOL(acpi_video_register); void acpi_video_unregister(void) { - mutex_lock(®ister_count_mutex); - if (register_count) { + mutex_lock(®ister_done_mutex); + if (completion_done(®ister_done)) { acpi_bus_unregister_driver(&acpi_video_bus); - register_count = 0; + reinit_completion(®ister_done); } - mutex_unlock(®ister_count_mutex); + mutex_unlock(®ister_done_mutex); } EXPORT_SYMBOL(acpi_video_unregister); @@ -2094,20 +2094,21 @@ void acpi_video_unregister_backlight(void) { struct acpi_video_bus *video; - mutex_lock(®ister_count_mutex); - if (register_count) { + mutex_lock(®ister_done_mutex); + if (completion_done(®ister_done)) { mutex_lock(&video_list_lock); list_for_each_entry(video, &video_bus_head, entry) acpi_video_bus_unregister_backlight(video); mutex_unlock(&video_list_lock); } - mutex_unlock(®ister_count_mutex); + mutex_unlock(®ister_done_mutex); } bool acpi_video_handles_brightness_key_presses(void) { bool have_video_busses; + wait_for_completion(®ister_done); mutex_lock(&video_list_lock); have_video_busses = !list_empty(&video_bus_head); mutex_unlock(&video_list_lock); -- cgit v1.2.3-59-g8ed1b