asus-wmi: add support for ROG XFlow tablet mode
Luke D. Jones
maintainerv3 cover asus-wmi: add support for ROG XFlow tablet mode
This patch series refactors a part of the tablet/lid-flip code to use an enum to set the different behaviours, and adds support for the ASUS ROG XFlow (X13) 2-in-1 laptop.
Changelog:
- V3:
+ Use dev_err() in place of pr_err() in asus_wmi_input_init()
+ Adjust declaration of variables vs instantiation to match expected pattern
- V2:
+ Refactor the base handling paths of tablet modes to use enum
+ Add support for ROG XFlow using the refactored code
This obsoletes a previous patch I submitted:
- https://lkml.org/lkml/2022/8/3/94
Luke D. Jones (2):
asus-wmi: Adjust tablet/lidflip handling to use enum
asus-wmi: Add support for ROG X13 tablet mode
drivers/platform/x86/asus-nb-wmi.c | 28 ++++-- drivers/platform/x86/asus-wmi.c | 104 ++++++++++++++++----- drivers/platform/x86/asus-wmi.h | 10 +- include/linux/platform_data/x86/asus-wmi.h | 1 + 4 files changed, 112 insertions(+), 31 deletions(-)
Signature · 1 line
2.37.1
Luke D. Jones
maintainerPATCH v3 1/2 asus-wmi: Adjust tablet/lidflip handling to use enum
Due to multiple types of tablet/lidflip, the existing code for handling these events is refactored to use an enum for each type.
--- drivers/platform/x86/asus-nb-wmi.c | 13 +++--- drivers/platform/x86/asus-wmi.c | 67 ++++++++++++++++++++---------- drivers/platform/x86/asus-wmi.h | 9 +++- 3 files changed, 58 insertions(+), 31 deletions(-)
drivers/platform/x86/asus-nb-wmi.c +5 -8
@@ -115,12 +115,12 @@ static struct quirk_entry quirk_asus_forceals = { };static struct quirk_entry quirk_asus_use_kbd_dock_devid = { - .use_kbd_dock_devid = true, + .tablet_switch_mode = asus_wmi_kbd_dock_devid, };static struct quirk_entry quirk_asus_use_lid_flip_devid = { .wmi_backlight_set_devstate = true, - .use_lid_flip_devid = true, + .tablet_switch_mode = asus_wmi_lid_flip_devid, };static int dmi_matched (const struct dmi_system_id *dmi)
@@ -492,16 +492,13 @@ static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver)switch (tablet_mode_sw) {case 0 : - quirks->use_kbd_dock_devid = false; - quirks->use_lid_flip_devid = false; + quirks->tablet_switch_mode = asus_wmi_no_tablet_switch;break ;case 1 : - quirks->use_kbd_dock_devid = true; - quirks->use_lid_flip_devid = false; + quirks->tablet_switch_mode = asus_wmi_kbd_dock_devid;break ;case 2 : - quirks->use_kbd_dock_devid = false; - quirks->use_lid_flip_devid = true; + quirks->tablet_switch_mode = asus_wmi_lid_flip_devid;break ; }
drivers/platform/x86/asus-wmi.c +46 -21
133 lines not on this page · raw message
drivers/platform/x86/asus-wmi.h +7 -2
@@ -25,6 +25,12 @@ struct module;struct key_entry ;struct asus_wmi ; +enum asus_wmi_tablet_switch_mode { + asus_wmi_no_tablet_switch, + asus_wmi_kbd_dock_devid, + asus_wmi_lid_flip_devid, +}; +struct quirk_entry {bool hotplug_wireless;bool scalar_panel_brightness;
@@ -33,8 +39,7 @@ struct quirk_entry {bool wmi_backlight_native;bool wmi_backlight_set_devstate;bool wmi_force_als_set; -bool use_kbd_dock_devid; -bool use_lid_flip_devid; +enum asus_wmi_tablet_switch_mode tablet_switch_mode;int wapf;/* * For machines with AMD graphic chips, it will send out WMI event
Signature · 1 line
2.37.1
Re: [PATCH v3 1/2] asus-wmi: Adjust tablet/lidflip handling to use enum
Quoted 3 lines · Luke D. Jones
Due to multiple types of tablet/lidflip, the existing code for handling these events is refactored to use an enum for each type.
...
drivers/platform/x86/asus-wmi.c static bool asus_wmi_dev_is_present(struct asus_wmi *asus, u32 dev_id) · line 514
Quoted 7 lines
static int
asus_wmi_input_init(struct asus_wmi *asus){drivers/platform/x86/asus-wmi.c +3
-0+struct device *dev;int err, result; + dev = &asus->platform_device->dev; +
While the discussed pattern of splitting assignments is a good practice, for some cases we don't do it when we rely on the guarantee by the callers that some of the stuff won't be problematic. Here the device is part of the platform device and can't be NULL, there is no point to split definition and assignment (and you may find plenty examples in the kernel), so
struct device *dev = &asus->platform_device->dev;
is better to have as it's guaranteed not to be NULL and since that we don't check it in the code anyway.
...
drivers/platform/x86/asus-wmi.c static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus) · line 3422
Quoted 3 lines
input_report_switch(asus->inputdev, SW_TABLET_MODE,drivers/platform/x86/asus-wmi.c +1
-1- !result); + !result);
Irrelevant change.
...
It also seems you switched to dev_err() here for the pr_err() that aren't related to the change, either split that to a separate patch, or don't do it right now. I.o.w. use dev_err() only in the lines your change touches, otherwise it's irrelevant.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Luke D. Jones
maintainerPATCH v3 2/2 asus-wmi: Add support for ROG X13 tablet mode
In reply to Luke D. JonesAdd quirk for ASUS ROG X13 Flow 2-in-1 to enable tablet mode with lid flip (all screen rotations).
--- drivers/platform/x86/asus-nb-wmi.c | 15 +++++++++ drivers/platform/x86/asus-wmi.c | 37 ++++++++++++++++++++++ drivers/platform/x86/asus-wmi.h | 1 + include/linux/platform_data/x86/asus-wmi.h | 1 + 4 files changed, 54 insertions(+)
drivers/platform/x86/asus-nb-wmi.c +15 -0
@@ -123,6 +123,11 @@ static struct quirk_entry quirk_asus_use_lid_flip_devid = { .tablet_switch_mode = asus_wmi_lid_flip_devid, }; +static struct quirk_entry quirk_asus_tablet_mode = { + .wmi_backlight_set_devstate = true, + .tablet_switch_mode = asus_wmi_lid_flip_rog_devid, +}; +static int dmi_matched (const struct dmi_system_id *dmi) {pr_info ("Identified laptop model '%s'\n" , dmi->ident);
@@ -471,6 +476,15 @@ static const struct dmi_system_id asus_quirks[] = { }, .driver_data = &quirk_asus_use_lid_flip_devid, }, + { + .callback = dmi_matched, + .ident = "ASUS ROG FLOW X13", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_PRODUCT_NAME, "GV301Q"), + }, + .driver_data = &quirk_asus_tablet_mode, + }, {}, };
@@ -575,6 +589,7 @@ static const struct key_entry asus_nb_wmi_keymap[] = { { KE_KEY, 0xC5, { KEY_KBDILLUMDOWN } }, { KE_IGNORE, 0xC6, }, /* Ambient Light Sensor notification */ { KE_KEY, 0xFA, { KEY_PROG2 } }, /* Lid flip action */ + { KE_KEY, 0xBD, { KEY_PROG2 } }, /* Lid flip action on ROG xflow laptops */ { KE_END, 0}, };
drivers/platform/x86/asus-wmi.c +37 -0
@@ -69,6 +69,7 @@ module_param(fnlock_default, bool, 0444);#define NOTIFY_KBD_FBM 0x99#define NOTIFY_KBD_TTP 0xae#define NOTIFY_LID_FLIP 0xfa +#define NOTIFY_LID_FLIP_ROG 0xbd#define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0)
@@ -551,6 +552,19 @@ static int asus_wmi_input_init(struct asus_wmi *asus)dev_err (dev,"Error checking for lid-flip: %d\n" , result); }break ; +case asus_wmi_lid_flip_rog_devid: + result =asus_wmi_get_devstate_simple (asus,ASUS_WMI_DEVID_LID_FLIP_ROG ); +if (result <0 ) + asus->driver->quirks->tablet_switch_mode = asus_wmi_no_tablet_switch; +if (result >=0 ) { +input_set_capability (asus->inputdev,EV_SW ,SW_TABLET_MODE ); +input_report_switch (asus->inputdev,SW_TABLET_MODE , result); + }else if (result == -ENODEV ) { +dev_err (dev,"This device has lid-flip-rog quirk but got ENODEV checking it. This is a bug." ); + }else { +dev_err (dev,"Error checking for lid-flip: %d\n" , result); + } +break ; } err =input_register_device (asus->inputdev);
@@ -585,6 +599,17 @@ static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus) } } +static void lid_flip_rog_tablet_mode_get_state (struct asus_wmi *asus) +{ +int result; + + result =asus_wmi_get_devstate_simple (asus,ASUS_WMI_DEVID_LID_FLIP_ROG ); +if (result >=0 ) { +input_report_switch (asus->inputdev,SW_TABLET_MODE , result); +input_sync (asus->inputdev); + } +} +/* dGPU ********************************************************************/ static int dgpu_disable_check_present (struct asus_wmi *asus) {
@@ -3431,6 +3456,12 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)return ; }break ; +case asus_wmi_lid_flip_rog_devid: +if (code ==NOTIFY_LID_FLIP_ROG ) { +lid_flip_rog_tablet_mode_get_state (asus); +return ; + } +break ; }if (asus->fan_boost_mode_available && code ==NOTIFY_KBD_FBM ) {
@@ -4105,6 +4136,9 @@ static int asus_hotk_resume(struct device *device)case asus_wmi_lid_flip_devid:lid_flip_tablet_mode_get_state (asus);break ; +case asus_wmi_lid_flip_rog_devid: +lid_flip_rog_tablet_mode_get_state (asus); +break ; }return 0 ;
@@ -4153,6 +4187,9 @@ static int asus_hotk_restore(struct device *device)case asus_wmi_lid_flip_devid:lid_flip_tablet_mode_get_state (asus);break ; +case asus_wmi_lid_flip_rog_devid: +lid_flip_rog_tablet_mode_get_state (asus); +break ; }return 0 ;
drivers/platform/x86/asus-wmi.h +1 -0
@@ -29,6 +29,7 @@ enum asus_wmi_tablet_switch_mode { asus_wmi_no_tablet_switch, asus_wmi_kbd_dock_devid, asus_wmi_lid_flip_devid, + asus_wmi_lid_flip_rog_devid, }; struct quirk_entry {
include/linux/platform_data/x86/asus-wmi.h +1 -0
@@ -64,6 +64,7 @@#define ASUS_WMI_DEVID_PANEL_OD 0x00050019#define ASUS_WMI_DEVID_CAMERA 0x00060013#define ASUS_WMI_DEVID_LID_FLIP 0x00060062 +#define ASUS_WMI_DEVID_LID_FLIP_ROG 0x00060077/* Storage */ #define ASUS_WMI_DEVID_CARDREADER 0x00080013
Signature · 1 line
2.37.1
Re: [PATCH v3 2/2] asus-wmi: Add support for ROG X13 tablet mode
Quoted 3 lines · Luke D. Jones
Add quirk for ASUS ROG X13 Flow 2-in-1 to enable tablet mode with lid flip (all screen rotations).
...
Quoted 3 lines
{ KE_IGNORE, 0xC6, }, /* Ambient Light Sensor notification */ { KE_KEY, 0xFA, { KEY_PROG2 } }, /* Lid flip action */+ {
KE_KEY,0xBD, {KEY_PROG2} }, /* Lid flip action on ROG xflow laptops */
Shouldn't you keep it sorted by value?
...
Quoted 4 lines
#define
NOTIFY_KBD_FBM0x99
#defineNOTIFY_KBD_TTP0xae
#defineNOTIFY_LID_FLIP0xfa
+#defineNOTIFY_LID_FLIP_ROG0xbd
Ditto.
...
drivers/platform/x86/asus-wmi.c static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus) · line 607
Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6
-0+static void lid_flip_rog_tablet_mode_get_state (struct asus_wmi *asus) +{ +int result; + + result =asus_wmi_get_devstate_simple (asus,ASUS_WMI_DEVID_LID_FLIP_ROG ); +if (result >=0 ) {
You missed the second part of my comment. Please, read carefully _all_ reviewer's comments.
drivers/platform/x86/asus-wmi.c static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus) · line 611
Quoted 4 lines
drivers/platform/x86/asus-wmi.c +4
-0+input_report_switch (asus->inputdev,SW_TABLET_MODE , result); +input_sync (asus->inputdev); + } +}
...
Overall, it's getting better!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/2] asus-wmi: Add support for ROG X13 tablet mode
Hi,
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Luke D. Jones
Add quirk for ASUS ROG X13 Flow 2-in-1 to enable tablet mode with lid flip (all screen rotations).
Quoted 7 lines
...
Quoted 3 lines
{ KE_IGNORE, 0xC6, }, /* Ambient Light Sensor notification */ { KE_KEY, 0xFA, { KEY_PROG2 } }, /* Lid flip action */+ {
KE_KEY,0xBD, {KEY_PROG2} }, /* Lid flip action on ROG xflow laptops */Shouldn't you keep it sorted by value?
Actually as I mentioned in my review of v1, we don't want this addition at all, see:
https://lore.kernel.org/platform-driver-x86/[email protected]/
Regards,
Hans
Quoted 31 lines
...
Quoted 4 lines
#define
NOTIFY_KBD_FBM0x99
#defineNOTIFY_KBD_TTP0xae
#defineNOTIFY_LID_FLIP0xfa
+#defineNOTIFY_LID_FLIP_ROG0xbdDitto.
...
drivers/platform/x86/asus-wmi.c static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus) · line 607
Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6
-0+static void lid_flip_rog_tablet_mode_get_state (struct asus_wmi *asus) +{ +int result; + + result =asus_wmi_get_devstate_simple (asus,ASUS_WMI_DEVID_LID_FLIP_ROG ); +if (result >=0 ) {You missed the second part of my comment. Please, read carefully _all_ reviewer's comments.
drivers/platform/x86/asus-wmi.c static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus) · line 611
Quoted 4 lines
drivers/platform/x86/asus-wmi.c +4
-0+input_report_switch (asus->inputdev,SW_TABLET_MODE , result); +input_sync (asus->inputdev); + } +}...
Overall, it's getting better!
Luke Jones
maintainerRe: [PATCH v3 2/2] asus-wmi: Add support for ROG X13 tablet mode
Hello,
Quoted 18 lines · Hans de Goede
Hi,
Quoted 15 lines · Andy Shevchenko
Quoted 3 lines · Luke D. Jones
Add quirk for ASUS ROG X13 Flow 2-in-1 to enable tablet mode with lid flip (all screen rotations).
...
Quoted 6 lines
{ KE_IGNORE, 0xC6, }, /* Ambient Light Sensor notification */ { KE_KEY, 0xFA, { KEY_PROG2 } }, /* Lid flipaction */
+ {KE_KEY,0xBD, {KEY_PROG2} }, /* Lid flip action on ROG
xflow laptops */
Quoted 7 lines
Quoted 1 line
Shouldn't you keep it sorted by value?
Actually as I mentioned in my review of v1, we don't want this addition at all, see:
https://lore.kernel.org/platform-driver-x86/[email protected]/
My apologies, I will fix this.
Quoted 41 lines
Regards,
Hans
Quoted 35 lines
...
Quoted 4 lines
#define
NOTIFY_KBD_FBM0x99
#defineNOTIFY_KBD_TTP0xae
#defineNOTIFY_LID_FLIP0xfa
+#defineNOTIFY_LID_FLIP_ROG0xbdDitto.
...
Quoted 8 lines
+static void lid_flip_rog_tablet_mode_get_state(struct
asus_wmi
*asus)
+{
+ int result;
+
+ result = asus_wmi_get_devstate_simple(asus,ASUS_WMI_DEVID_LID_FLIP_ROG);
+ if (result >= 0) {You missed the second part of my comment. Please, read carefully
_all_
reviewer's comments.Quoted 5 lines
+ input_report_switch(asus->inputdev,
SW_TABLET_MODE, result);
+input_sync(asus->inputdev);
+ }
+}...
Overall, it's getting better!