asus_wmi: Support of ASUS TUF laptops on Ryzen CPUs
v2 cover asus_wmi: Support of ASUS TUF laptops on Ryzen CPUs
Hi,
this patch series adds support of ASUS TUF laptops on Ryzen CPUs to existing asus_wmi platform driver and also fixes minor bug.
v2: fixed indentation.
Leonid Maksymchuk (3):
asus_wmi: Fix return value of fan_boost_mode_store
asus_wmi: Add support for fan boost mode on FX505DY/FX705DY
asus_wmi: Set default fan boost mode to normal
drivers/platform/x86/asus-wmi.c | 57 ++++++++++++++++++++++-------- include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 43 insertions(+), 15 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/3 platform/x86: asus_wmi: Fix return value of fan_boost_mode_store
Function fan_boost_mode_store should return number of bytes written but instead it returns return value of kstrtou8 which is 0 if conversion is succefull. This leads to infinite loop after any write to it's SysFS entry.
--- drivers/platform/x86/asus-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +1 -1
@@ -1718,7 +1718,7 @@ static ssize_t fan_boost_mode_store(struct device *dev, asus->fan_boost_mode = new_mode;fan_boost_mode_write (asus); -return result; +return count; }// Fan boost mode: 0 - normal, 1 - overboost, 2 - silent
Signature · 1 line
1.8.3.1
PATCH v2 2/3 platform/x86: asus_wmi: Support fan boost mode on FX505DY/FX705DY
In reply to Leonid MaksymchukOn ASUS FX505DY/FX705DY laptops fan boost mode is same as in other TUF laptop models but have different ACPI device ID and different key code.
--- drivers/platform/x86/asus-wmi.c | 42 ++++++++++++++++++++---------- include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 29 insertions(+), 14 deletions(-)
drivers/platform/x86/asus-wmi.c +28 -14
@@ -61,6 +61,7 @@#define NOTIFY_KBD_BRTDWN 0xc5#define NOTIFY_KBD_BRTTOGGLE 0xc7#define NOTIFY_KBD_FBM 0x99 +#define NOTIFY_KBD_FBM_2 0xae#define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0)
@@ -194,7 +195,7 @@ struct asus_wmi {int fan_pwm_mode;int agfn_pwm; -bool fan_boost_mode_available; +int fan_boost_mode_available;u8 fan_boost_mode_mask;u8 fan_boost_mode;
@@ -1616,24 +1617,33 @@ static int fan_boost_mode_check_present(struct asus_wmi *asus)u32 result;int err; - asus->fan_boost_mode_available = false; + asus->fan_boost_mode_available =0 ; err =asus_wmi_get_devstate (asus,ASUS_WMI_DEVID_FAN_BOOST_MODE , &result); -if (err) { -if (err == -ENODEV ) -return 0 ; -else -return err; + +if (err ==0 && + (result &ASUS_WMI_DSTS_PRESENCE_BIT ) && + (result &ASUS_FAN_BOOST_MODES_MASK )) { + asus->fan_boost_mode_available =1 ; + asus->fan_boost_mode_mask = result &ASUS_FAN_BOOST_MODES_MASK ; +return 0 ; } -if ((result &ASUS_WMI_DSTS_PRESENCE_BIT ) && + err =asus_wmi_get_devstate (asus,ASUS_WMI_DEVID_FAN_BOOST_MODE_2 , + &result); + +if (err ==0 && + (result &ASUS_WMI_DSTS_PRESENCE_BIT ) && (result &ASUS_FAN_BOOST_MODES_MASK )) { - asus->fan_boost_mode_available = true; + asus->fan_boost_mode_available =2 ; asus->fan_boost_mode_mask = result &ASUS_FAN_BOOST_MODES_MASK ; } -return 0 ; +if (err == -ENODEV ) +return 0 ; + +return err; }static int fan_boost_mode_write (struct asus_wmi *asus)
@@ -1641,12 +1651,15 @@ static int fan_boost_mode_write(struct asus_wmi *asus)int err;u8 value;u32 retval; +u32 dev_id = asus->fan_boost_mode_available ==1 ? +ASUS_WMI_DEVID_FAN_BOOST_MODE : +ASUS_WMI_DEVID_FAN_BOOST_MODE_2 ; value = asus->fan_boost_mode;pr_info ("Set fan boost mode: %u\n" , value); - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_FAN_BOOST_MODE , value, - &retval); + err =asus_wmi_set_devstate (dev_id, value, &retval); +if (err) {pr_warn ("Failed to set fan boost mode: %d\n" , err);return err;
@@ -2000,7 +2013,8 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)return ; } -if (asus->fan_boost_mode_available && code ==NOTIFY_KBD_FBM ) { +if (asus->fan_boost_mode_available && + (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_FBM_2) {fan_boost_mode_switch_next (asus);return ; }
@@ -2177,7 +2191,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,else if (attr == &dev_attr_als_enable.attr) devid =ASUS_WMI_DEVID_ALS_ENABLE ;else if (attr == &dev_attr_fan_boost_mode.attr) - ok = asus->fan_boost_mode_available; + ok = asus->fan_boost_mode_available !=0 ;if (devid !=-1 ) ok = !(asus_wmi_get_devstate_simple (asus, devid) <0 );
include/linux/platform_data/x86/asus-wmi.h +1 -0
@@ -58,6 +58,7 @@#define ASUS_WMI_DEVID_LIGHT_SENSOR 0x00050022/* ?? */ #define ASUS_WMI_DEVID_LIGHTBAR 0x00050025#define ASUS_WMI_DEVID_FAN_BOOST_MODE 0x00110018 +#define ASUS_WMI_DEVID_FAN_BOOST_MODE_2 0x00120075/* Misc */ #define ASUS_WMI_DEVID_CAMERA 0x00060013
Signature · 1 line
1.8.3.1
PATCH v2 3/3 platform/x86: asus_wmi: Set default fan boost mode to normal
In reply to Leonid MaksymchukSet default fan boost mode to normal for multiple reasons:
1) existing code assumes that laptop started in normal mode and that is not always correct.
2) FX705DY/FX505DY starts in silent mode and under heavy CPU load it overheats and drops CPU frequency to 399MHz [1]. Setting fan mode to normal avoids overheating.
[1] Link: https://bugzilla.kernel.org/show_bug.cgi?id=203733
--- drivers/platform/x86/asus-wmi.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/platform/x86/asus-wmi.c +13 -0
@@ -1674,6 +1674,18 @@ static int fan_boost_mode_write(struct asus_wmi *asus)return 0 ; } +static int fan_boost_mode_set_default (struct asus_wmi *asus) +{ +int result =0 ; + +if (asus->fan_boost_mode_available) { + asus->fan_boost_mode =ASUS_FAN_BOOST_MODE_NORMAL ; + result =fan_boost_mode_write (asus); + } + +return result; +} +static int fan_boost_mode_switch_next (struct asus_wmi *asus) {u8 mask = asus->fan_boost_mode_mask;
@@ -2450,6 +2462,7 @@ static int asus_wmi_add(struct platform_device *pdev) err =fan_boost_mode_check_present (asus);if (err) goto fail_fan_boost_mode; +fan_boost_mode_set_default (asus); err =asus_wmi_sysfs_init (asus->platform_device);if (err)
Signature · 1 line
1.8.3.1
kbuild test robot
build botRe: [PATCH v2 2/3] platform/x86: asus_wmi: Support fan boost mode on FX505DY/FX705DY
In reply to Leonid MaksymchukThank you for the patch! Yet something to improve:
Hi Leonid,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.4-rc6 next-20191031]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Leonid-Maksymchuk/asus_wmi-Support-of-ASUS-TUF-laptops-on-Ryzen-CPUs/20191105-054154 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git a99d8080aaf358d5d23581244e5da23b35e340b9 config: x86_64-rhel (attached as .config) compiler: gcc-7 (Debian 7.4.0-14) 7.4.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
drivers/platform/x86/asus-wmi.c: In function 'asus_wmi_handle_event_code':
>> drivers/platform/x86/asus-wmi.c:2017:57: error: expected ')' before '{' token
(code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_FBM_2) {
^
>> drivers/platform/x86/asus-wmi.c:2028:1: error: expected expression before '}' token
}
^ At top level:
drivers/platform/x86/asus-wmi.c:1909:12: warning: 'is_display_toggle' defined but not used [-Wunused-function]
static int is_display_toggle(int code)
^~~~~~~~~~~~~~~~~
drivers/platform/x86/asus-wmi.c:1677:12: warning: 'fan_boost_mode_switch_next' defined but not used [-Wunused-function]
static int fan_boost_mode_switch_next(struct asus_wmi *asus)
^~~~~~~~~~~~~~~~~~~~~~~~~~
vim +2017 drivers/platform/x86/asus-wmi.c
1966
1967 static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
1968 {
1969 int orig_code;
1970 unsigned int key_value = 1;
1971 bool autorelease = 1;
1972
1973 orig_code = code;
1974
1975 if (asus->driver->key_filter) {
1976 asus->driver->key_filter(asus->driver, &code, &key_value,
1977 &autorelease);
1978 if (code == ASUS_WMI_KEY_IGNORE)
1979 return;
1980 }
1981
1982 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
1983 code = ASUS_WMI_BRN_UP;
1984 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
1985 code = ASUS_WMI_BRN_DOWN;
1986
1987 if (code == ASUS_WMI_BRN_DOWN || code == ASUS_WMI_BRN_UP) {
1988 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
1989 asus_wmi_backlight_notify(asus, orig_code);
1990 return;
1991 }
1992 }
1993
1994 if (code == NOTIFY_KBD_BRTUP) {
1995 kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
1996 return;
1997 }
1998 if (code == NOTIFY_KBD_BRTDWN) {
1999 kbd_led_set_by_kbd(asus, asus->kbd_led_wk - 1);
2000 return;
2001 }
2002 if (code == NOTIFY_KBD_BRTTOGGLE) {
2003 if (asus->kbd_led_wk == asus->kbd_led.max_brightness)
2004 kbd_led_set_by_kbd(asus, 0);
2005 else
2006 kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
2007 return;
2008 }
2009
2010 if (code == NOTIFY_FNLOCK_TOGGLE) {
2011 asus->fnlock_locked = !asus->fnlock_locked;
2012 asus_wmi_fnlock_update(asus);
2013 return;
2014 }
2015
2016 if (asus->fan_boost_mode_available &&
> 2017 (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_FBM_2) {
2018 fan_boost_mode_switch_next(asus);
2019 return;
2020 }
2021
2022 if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle)
2023 return;
2024
2025 if (!sparse_keymap_report_event(asus->inputdev, code,
2026 key_value, autorelease))
2027 pr_info("Unknown key %x pressed\n", code);
> 2028 }2029
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH v2 3/3] platform/x86: asus_wmi: Set default fan boost mode to normal
In reply to Leonid MaksymchukQuoted 14 lines · Leonid Maksymchuk
Set default fan boost mode to normal for multiple reasons:
1) existing code assumes that laptop started in normal mode and that is not always correct.
2) FX705DY/FX505DY starts in silent mode and under heavy CPU load it overheats and drops CPU frequency to 399MHz [1]. Setting fan mode to normal avoids overheating.[1] Link: https://bugzilla.kernel.org/show_bug.cgi?id=203733
Signed-off-by Leonid Maksymchuk <[email protected]>drivers/platform/x86/asus-wmi.c +1
-0+static int fan_boost_mode_set_default (struct asus_wmi *asus)
drivers/platform/x86/asus-wmi.c static int fan_boost_mode_write(struct asus_wmi *asus) · line 1687
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10
-0+{ +int result =0 ; + +if (asus->fan_boost_mode_available) { + asus->fan_boost_mode =ASUS_FAN_BOOST_MODE_NORMAL ; + result =fan_boost_mode_write (asus); + } + +return result; +}
This can be refactored
if (!foo)
return 0;
...
return bar(asus);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/3] platform/x86: asus_wmi: Support fan boost mode on FX505DY/FX705DY
In reply to kbuild test robotQuoted 7 lines · kbuild test robot
Hi Leonid,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.4-rc6 next-20191031]
Leonid, I may not accept patches that contributor didn't even compile. How had you tested?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Leonid Maksymchuk
Hi,
this patch series adds support of ASUS TUF laptops on Ryzen CPUs to existing
asus_wmiplatform driver and also fixes minor bug.v2: fixed indentation.
Usual versioning
RFC [RFC v2, ...]
v1
v2, ...
Okay, next one will be v3 to avoid overlapping.
I'll take first patch later, but I also will give more comments to patch 2. Please, give me time to review it properly.
Quoted 13 lines
Leonid Maksymchuk (3):
asus_wmi: Fix return value offan_boost_mode_store
asus_wmi: Add support for fan boost mode on FX505DY/FX705DY
asus_wmi: Set default fan boost mode to normaldrivers/platform/x86/asus-wmi.c | 57 ++++++++++++++++++++++-------- include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 43 insertions(+), 15 deletions(-)--
1.8.3.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/3] platform/x86: asus_wmi: Support fan boost mode on FX505DY/FX705DY
In reply to Leonid MaksymchukQuoted 13 lines · Leonid Maksymchuk
On ASUS FX505DY/FX705DY laptops fan boost mode is same as in other TUF laptop models but have different ACPI device ID and different key code.
drivers/platform/x86/asus-wmi.c +6
-1+if (err ==0 && + (result &ASUS_WMI_DSTS_PRESENCE_BIT ) && + (result &ASUS_FAN_BOOST_MODES_MASK )) { + asus->fan_boost_mode_available =1 ; + asus->fan_boost_mode_mask = result &ASUS_FAN_BOOST_MODES_MASK ; +return 0 ; } - if ((result & ASUS_WMI_DSTS_PRESENCE_BIT) &&
drivers/platform/x86/asus-wmi.c static int fan_boost_mode_check_present(struct asus_wmi *asus) · line 1641
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +6
-1+ err =asus_wmi_get_devstate (asus,ASUS_WMI_DEVID_FAN_BOOST_MODE_2 , + &result); + +if (err ==0 && + (result &ASUS_WMI_DSTS_PRESENCE_BIT ) && (result &ASUS_FAN_BOOST_MODES_MASK )) { - asus->fan_boost_mode_available = true; + asus->fan_boost_mode_available =2 ; asus->fan_boost_mode_mask = result &ASUS_FAN_BOOST_MODES_MASK ; }
The above differs only in one value to give and one value to set, I suppose you may introduce an additional helper to it
drivers/platform/x86/asus-wmi.c static int fan_boost_mode_check_present(struct asus_wmi *asus) · line 1644
Quoted 2 lines
drivers/platform/x86/asus-wmi.c +2
-0+if (err == -ENODEV ) +return 0 ;
This should be explained or even separated to another patch. It changes behaviour of the original code, why?
drivers/platform/x86/asus-wmi.c static int fan_boost_mode_write(struct asus_wmi *asus) · line 1656
Quoted 3 lines
drivers/platform/x86/asus-wmi.c +3
-0+u32 dev_id = asus->fan_boost_mode_available ==1 ? +ASUS_WMI_DEVID_FAN_BOOST_MODE : +ASUS_WMI_DEVID_FAN_BOOST_MODE_2 ;
I would prefer to see
if (...)
call with mode
else
call with mode_2
below.
Quoted 3 lines
drivers/platform/x86/asus-wmi.c +1
-2- err =asus_wmi_set_devstate (ASUS_WMI_DEVID_FAN_BOOST_MODE , value, - &retval); + err =asus_wmi_set_devstate (dev_id, value, &retval);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/3] platform/x86: asus_wmi: Support fan boost mode on FX505DY/FX705DY
Thanks for review, I will do suggested changes.
Quoted 20 lines
Quoted 9 lines
drivers/platform/x86/asus-wmi.c +6
-1+if (err ==0 && + (result &ASUS_WMI_DSTS_PRESENCE_BIT ) && + (result &ASUS_FAN_BOOST_MODES_MASK )) { + asus->fan_boost_mode_available =1 ; + asus->fan_boost_mode_mask = result &ASUS_FAN_BOOST_MODES_MASK ; +return 0 ; } - if ((result & ASUS_WMI_DSTS_PRESENCE_BIT) &&drivers/platform/x86/asus-wmi.c static int fan_boost_mode_check_present(struct asus_wmi *asus) · line 1641
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +6
-1+ err =asus_wmi_get_devstate (asus,ASUS_WMI_DEVID_FAN_BOOST_MODE_2 , + &result); + +if (err ==0 && + (result &ASUS_WMI_DSTS_PRESENCE_BIT ) && (result &ASUS_FAN_BOOST_MODES_MASK )) { - asus->fan_boost_mode_available = true; + asus->fan_boost_mode_available =2 ; asus->fan_boost_mode_mask = result &ASUS_FAN_BOOST_MODES_MASK ; }
Quoted 2 lines
The above differs only in one value to give and one value to set, I suppose you may introduce an additional helper to it
Maybe it's better to add additional argument with index to fan_boost_mode_check_present and
call it twice?
Quoted 6 lines
drivers/platform/x86/asus-wmi.c static int fan_boost_mode_check_present(struct asus_wmi *asus) · line 1644
Quoted 2 lines
drivers/platform/x86/asus-wmi.c +2
-0+if (err == -ENODEV ) +return 0 ;This should be explained or even separated to another patch. It changes behaviour of the original code, why?
Original code also have this check to continue module initialization when fan_boost_mode device
is not present. It's return value is checked in asus_wmi_add() function and it'll fail module probing.