Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenpad Plus Backlight Control #6

Closed
Qonfused opened this issue Aug 18, 2022 · 5 comments · Fixed by #19 or #32
Closed

Screenpad Plus Backlight Control #6

Qonfused opened this issue Aug 18, 2022 · 5 comments · Fixed by #19 or #32
Labels
status:done All issue tasks are completed. type:feature New feature request

Comments

@Qonfused
Copy link
Owner

Qonfused commented Aug 18, 2022

Backlight is set by ACPI calls exposed through a WMI driver. For reference, there is a linux module that probes ACPI for methods controlling backlight of the screenpad. Below details basic methods for the display's backlight control implemented similarly to keyboard backlight control in AsusSMC:

asus-wmi.h#L50-L74
50    | struct asus_wmi_driver {
51    | 	int			brightness;
52    | 	int			panel_power;
53    | 	int			wlan_ctrl_by_user;
54    | 
55    | 	const char		*name;
56    | 	struct module		*owner;
57    | 
58    | 	const char		*event_guid;
59    | 
60    | 	const struct key_entry	*keymap;
61    | 	const char		*input_name;
62    | 	const char		*input_phys;
63    | 	struct quirk_entry	*quirks;
64    | 	/* Returns new code, value, and autorelease values in arguments.
65    | 	 * Return ASUS_WMI_KEY_IGNORE in code if event should be ignored. */
66    | 	void (*key_filter) (struct asus_wmi_driver *driver, int *code,
67    | 			    unsigned int *value, bool *autorelease);
68    | 
69    | 	int (*probe) (struct platform_device *device);
70    | 	void (*detect_quirks) (struct asus_wmi_driver *driver);
71    | 
72    | 	struct platform_driver	platform_driver;
73    | 	struct platform_device *platform_device;
74    | };
asus-wmi.c#L819-L831
819   |	if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_SCREENPAD)
820   |		&& !screenpad_led_read(asus, &led_val)) {
821   |		asus->screenpad_led_wk = led_val;
822   |		INIT_WORK(&asus->screenpad_led_work, screenpad_led_update);
823   |
824   |		asus->screenpad_led.name = "asus::screenpad";
825   |		asus->screenpad_led.brightness_set = screenpad_led_set;
826   |		asus->screenpad_led.brightness_get = screenpad_led_get;
827   |		asus->screenpad_led.max_brightness = 0xff;
828   |
829   |		rv = led_classdev_register(&asus->platform_device->dev,
830   |					   &asus->screenpad_led);
831   |	}

If it can't be controlled in the same submenu as the primary display, then mapping Screenpad backlight brightness in a control center slider like keyboard brightness may be a good alternative UX implementation:

image

@Qonfused Qonfused added the type:feature New feature request label Aug 18, 2022
@Qonfused Qonfused changed the title Screenpad Plus Backlight Control FN Keys and Screenpad Plus Backlight Control Nov 27, 2022
@Qonfused
Copy link
Owner Author

For reference, @shiecldk has a breakdown of EC events for the UX582 in hieplpvip/AsusSMC#102 (comment).

It's worth mentioning that SSDT-ASUSFN.aml in the original repo only has control logic for the primary display's backlight, and SSDT-AsusSMC.aml has logic for the ambient light sensor and keyboard backlight.

@Qonfused
Copy link
Owner Author

Qonfused commented Dec 5, 2022

Continuing on the screenpad plus backlight discussion in #4 (comment)

In another thread, I also found mention of a WMNB method that controls backlight (refers to \_SB.ATKD.WMNB, which seems to be what wern-apfel was mentioning?): s-light/ASUS-ZenBook-Pro-Duo-UX581GV#1 (comment)

* Control backlight: `echo '\_SB.ATKD.WMNB 0x0 0x53564544 b32000500xx000000' | sudo tee /proc/acpi/call` (xx is a hex value from `00` to `FF`).

* Disable backlight: `echo '\_SB.ATKD.WMNB 0x0 0x53564544 b3100050000000000' | sudo tee /proc/acpi/call`

^^^ They're using the acpi_call linux kernel module to call this method, though assumedly an SSDT could also call the same method with these values to change backlight (and in your case disable backlight).

Below is the WMNB method that executes the above ACPI calls
// \_SB.ATKD.WMNB
54953 | Method (WMNB, 3, Serialized)
54954 | {
54955 |     CreateDWordField (Arg2, Zero, IIA0)
54956 |     CreateDWordField (Arg2, 0x04, IIA1)
54957 |     Local0 = (Arg1 & 0xFFFFFFFF)
...
55362 |     If ((Local0 == 0x53564544))
55363 |     {
...
55524 |         Name (TMBF, Buffer (0x02)
55525 |         {
55526 |             0x00, 0x00
55527 |         })
55528 |         If ((IIA0 == 0x00050031))
55529 |         {
55530 |             TMBF [Zero] = Zero
55531 |             Local0 = ^^PCI0.LPCB.EC0.REBC (0x12, 0x02)
55532 |             Local1 = DerefOf (Local0 [Zero])
55533 |             If ((IIA1 == One))
55534 |             {
55535 |                 Local1 &= 0xFD
55536 |             }
55537 |             Else
55538 |             {
55539 |                 Local1 |= 0x02
55540 |             }
55541 |         
55542 |             TMBF [One] = Local1
55543 |             Return (^^PCI0.LPCB.EC0.WEBC (0x13, 0x02, TMBF))
55544 |             Return (Zero)
55545 |         }
55546 |         
55547 |         If ((IIA0 == 0x00050032))
55548 |         {
55549 |             TMBF [One] = IIA1 /* \_SB_.ATKD.WMNB.IIA1 */
55550 |             TMBF [Zero] = One
55551 |             Return (^^PCI0.LPCB.EC0.WEBC (0x13, 0x02, TMBF))
55552 |             Return (Zero)
55553 |         }
55554 |         
55555 |         If ((IIA0 == 0x00050035))
55556 |         {
55557 |             TMBF [Zero] = Zero
55558 |             Local0 = ^^PCI0.LPCB.EC0.REBC (0x12, 0x02)
55559 |             Local1 = DerefOf (Local0 [Zero])
55560 |             If ((IIA1 == Zero))
55561 |             {
55562 |                 Local1 &= 0xF7
55563 |             }
55564 |             ElseIf ((IIA1 == One))
55565 |             {
55566 |                 Local1 |= 0x08
55567 |             }
55568 |         
55569 |             TMBF [One] = Local1
55570 |             Return (^^PCI0.LPCB.EC0.WEBC (0x13, 0x02, TMBF))
55571 |             Return (Zero)
55572 |         }

I have an example SSDT for disabling the screenpad plus display connector that writes to the EC's memory instead (based on @wern-apfel's SSDT-UX481FA.aml):

DISABLE-SCREENPAD.dsl
Disable the Screenpad Plus display connector

Rather than reading or writing to the embedded controller's memory directly (REBC/WEBC), the WMNB method (which handles all asus wmi functions) should be called instead:

External (\_SB.ATKD.WMNB, MethodObj)
// Sets the screenpad plus backlight intensity,
// where 'xx' is a hex value between 00 and FF.
\_SB.ATKD.WMNB(0x0, 0x53564544, /*b32000500xx000000*/)
// Disables screenpad plus until next backlight change.
\_SB.ATKD.WMNB(0x0, 0x53564544, /*b3100050000000000*/)

Some behavior can be ported to AsusSMC from the asus-wmi-screenpad repo.

@Qonfused Qonfused changed the title FN Keys and Screenpad Plus Backlight Control Screenpad Plus Backlight Control Dec 14, 2022
@Qonfused Qonfused linked a pull request Jan 3, 2023 that will close this issue
28 tasks
@Qonfused Qonfused added the status:in-progress Implementation is in progress. label Jan 5, 2023
@Qonfused Qonfused added project:UX481 For variants UX481FA (14", 2019) and UX481FL (14", 2019) project:UX581 For variants UX581GV (15.6", 2019) and UX581LV (15.6", 2020) project:UX582 For variant UX582LV (15.6", 2021) labels Jan 12, 2023
@Qonfused Qonfused pinned this issue Jan 12, 2023
@Qonfused Qonfused added status:done All issue tasks are completed. and removed project:UX481 For variants UX481FA (14", 2019) and UX481FL (14", 2019) project:UX581 For variants UX581GV (15.6", 2019) and UX581LV (15.6", 2020) project:UX582 For variant UX582LV (15.6", 2021) status:in-progress Implementation is in progress. labels Jan 12, 2023
@Qonfused Qonfused unpinned this issue Jan 22, 2023
@Qonfused Qonfused added status:in-progress Implementation is in progress. and removed status:done All issue tasks are completed. labels Jan 23, 2023
@Qonfused
Copy link
Owner Author

Added refactor in 9de3d05.

@Qonfused Qonfused added status:done All issue tasks are completed. and removed status:in-progress Implementation is in progress. labels Jan 23, 2023
@Qonfused Qonfused linked a pull request Jan 23, 2023 that will close this issue
@shiecldk
Copy link
Contributor

Do you solve this with SSDT-SPLC.aml?

@Qonfused
Copy link
Owner Author

Qonfused commented Jan 25, 2023

Yes. Its been fully implemented since the above PR, though an idea for #21 is to use an additional fake PNLF device to store and buffer backlight data to manipulate WMI methods. It should work more natively with those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:done All issue tasks are completed. type:feature New feature request
Projects
Status: Done
2 participants