Advertisement
Guest User

asus_wmi.patch

a guest
Nov 3rd, 2019
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. diff -purN a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
  2. --- a/drivers/platform/x86/asus-wmi.c 2019-09-16 00:19:32.000000000 +0300
  3. +++ b/drivers/platform/x86/asus-wmi.c 2019-11-03 13:40:38.768657383 +0200
  4. @@ -58,6 +58,7 @@ MODULE_LICENSE("GPL");
  5. #define NOTIFY_KBD_BRTDWN 0xc5
  6. #define NOTIFY_KBD_BRTTOGGLE 0xc7
  7. #define NOTIFY_KBD_FBM 0x99
  8. +#define NOTIFY_KBD_FBM_2 0xae
  9.  
  10. #define ASUS_WMI_FNLOCK_BIOS_DISABLED BIT(0)
  11.  
  12. @@ -182,7 +183,7 @@ struct asus_wmi {
  13. int asus_hwmon_num_fans;
  14. int asus_hwmon_pwm;
  15.  
  16. - bool fan_boost_mode_available;
  17. + int fan_boost_mode_available;
  18. u8 fan_boost_mode_mask;
  19. u8 fan_boost_mode;
  20.  
  21. @@ -1492,24 +1493,36 @@ static int fan_boost_mode_check_present(
  22. u32 result;
  23. int err;
  24.  
  25. - asus->fan_boost_mode_available = false;
  26. + asus->fan_boost_mode_available = 0;
  27.  
  28. err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_BOOST_MODE,
  29. &result);
  30. - if (err) {
  31. - if (err == -ENODEV)
  32. +
  33. + if (err == 0) {
  34. + if ((result & ASUS_WMI_DSTS_PRESENCE_BIT) &&
  35. + (result & ASUS_FAN_BOOST_MODES_MASK)) {
  36. + asus->fan_boost_mode_available = 1;
  37. + asus->fan_boost_mode_mask = result & ASUS_FAN_BOOST_MODES_MASK;
  38. return 0;
  39. - else
  40. - return err;
  41. + }
  42. }
  43. -
  44. - if ((result & ASUS_WMI_DSTS_PRESENCE_BIT) &&
  45. - (result & ASUS_FAN_BOOST_MODES_MASK)) {
  46. - asus->fan_boost_mode_available = true;
  47. - asus->fan_boost_mode_mask = result & ASUS_FAN_BOOST_MODES_MASK;
  48. + else {
  49. + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_BOOST_MODE_2,
  50. + &result);
  51. +
  52. + if (err == 0 &&
  53. + (result & ASUS_WMI_DSTS_PRESENCE_BIT) &&
  54. + (result & ASUS_FAN_BOOST_MODES_MASK)) {
  55. + asus->fan_boost_mode_available = 2;
  56. + asus->fan_boost_mode_mask = result & ASUS_FAN_BOOST_MODES_MASK;
  57. + return 0;
  58. + }
  59. }
  60.  
  61. - return 0;
  62. + if (err == -ENODEV)
  63. + return 0;
  64. +
  65. + return err;
  66. }
  67.  
  68. static int fan_boost_mode_write(struct asus_wmi *asus)
  69. @@ -1521,8 +1534,10 @@ static int fan_boost_mode_write(struct a
  70. value = asus->fan_boost_mode;
  71.  
  72. pr_info("Set fan boost mode: %u\n", value);
  73. - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_FAN_BOOST_MODE, value,
  74. - &retval);
  75. + err = asus_wmi_set_devstate(asus->fan_boost_mode_available == 1 ?
  76. + ASUS_WMI_DEVID_FAN_BOOST_MODE : ASUS_WMI_DEVID_FAN_BOOST_MODE_2,
  77. + value,
  78. + &retval);
  79.  
  80. if (err) {
  81. pr_warn("Failed to set fan boost mode: %d\n", err);
  82. @@ -1538,6 +1553,18 @@ static int fan_boost_mode_write(struct a
  83. return 0;
  84. }
  85.  
  86. +static int fan_boost_mode_set_default(struct asus_wmi *asus) {
  87. + int result = 0;
  88. +
  89. + if (asus->fan_boost_mode_available) {
  90. + // Set default fan mode to normal
  91. + asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_NORMAL;
  92. + result = fan_boost_mode_write(asus);
  93. + }
  94. +
  95. + return result;
  96. +}
  97. +
  98. static int fan_boost_mode_switch_next(struct asus_wmi *asus)
  99. {
  100. u8 mask = asus->fan_boost_mode_mask;
  101. @@ -1595,7 +1622,7 @@ static ssize_t fan_boost_mode_store(stru
  102. asus->fan_boost_mode = new_mode;
  103. fan_boost_mode_write(asus);
  104.  
  105. - return result;
  106. + return count;
  107. }
  108.  
  109. // Fan boost mode: 0 - normal, 1 - overboost, 2 - silent
  110. @@ -1879,7 +1906,8 @@ static void asus_wmi_handle_event_code(i
  111. return;
  112. }
  113.  
  114. - if (asus->fan_boost_mode_available && code == NOTIFY_KBD_FBM) {
  115. + if (asus->fan_boost_mode_available &&
  116. + (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_FBM_2)) {
  117. fan_boost_mode_switch_next(asus);
  118. return;
  119. }
  120. @@ -2063,7 +2091,7 @@ static umode_t asus_sysfs_is_visible(str
  121. else if (attr == &dev_attr_als_enable.attr)
  122. devid = ASUS_WMI_DEVID_ALS_ENABLE;
  123. else if (attr == &dev_attr_fan_boost_mode.attr)
  124. - ok = asus->fan_boost_mode_available;
  125. + ok = asus->fan_boost_mode_available != 0;
  126.  
  127. if (devid != -1)
  128. ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
  129. @@ -2324,6 +2352,7 @@ static int asus_wmi_add(struct platform_
  130. err = fan_boost_mode_check_present(asus);
  131. if (err)
  132. goto fail_fan_boost_mode;
  133. + fan_boost_mode_set_default(asus);
  134.  
  135. err = asus_wmi_sysfs_init(asus->platform_device);
  136. if (err)
  137. diff -purN a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h
  138. --- a/include/linux/platform_data/x86/asus-wmi.h 2019-09-16 00:19:32.000000000 +0300
  139. +++ b/include/linux/platform_data/x86/asus-wmi.h 2019-11-03 11:59:28.926438572 +0200
  140. @@ -58,6 +58,7 @@
  141. #define ASUS_WMI_DEVID_LIGHT_SENSOR 0x00050022 /* ?? */
  142. #define ASUS_WMI_DEVID_LIGHTBAR 0x00050025
  143. #define ASUS_WMI_DEVID_FAN_BOOST_MODE 0x00110018
  144. +#define ASUS_WMI_DEVID_FAN_BOOST_MODE_2 0x00120075
  145.  
  146. /* Misc */
  147. #define ASUS_WMI_DEVID_CAMERA 0x00060013
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement