Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK to adjust power limits. These fan profiles have a different device id than the ROG series and different order. This reorders the existing modes. As part of keeping the patch clean the throttle_thermal_policy_available boolean stored in the driver struct is removed and throttle_thermal_policy_dev is used in place (as on init it is zeroed).
Unified · Split
| @@ -97,6 +97,12 @@ module_param(fnlock_default, bool, 0444); · 96 unmodified lines | |||
| 97 | #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1 | 97 | #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1 |
| 98 | #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2 | 98 | #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2 |
| 99 | 99 | ||
| 100 | #define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO 0 | ||
| 101 | #define ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO 1 | ||
| 102 | #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO 2 | ||
| 103 | |||
| 104 | #define PLATFORM_PROFILE_MAX 2 | ||
| 105 | |||
| 100 | #define USB_INTEL_XUSB2PR 0xD0 | 106 | #define USB_INTEL_XUSB2PR 0xD0 |
| 101 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 | 107 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 |
| 102 | 108 | ||
| @@ -286,8 +292,8 @@ struct asus_wmi { · 183 unmodified lines | |||
| 286 | u32 kbd_rgb_dev; | 292 | u32 kbd_rgb_dev; |
| 287 | bool kbd_rgb_state_available; | 293 | bool kbd_rgb_state_available; |
| 288 | 294 | ||
| 289 | bool throttle_thermal_policy_available; | ||
| 290 | u8 throttle_thermal_policy_mode; | 295 | u8 throttle_thermal_policy_mode; |
| 296 | u32 throttle_thermal_policy_dev; | ||
| 291 | 297 | ||
| 292 | bool cpu_fan_curve_available; | 298 | bool cpu_fan_curve_available; |
| 293 | bool gpu_fan_curve_available; | 299 | bool gpu_fan_curve_available; |
| @@ -3162,7 +3168,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev) · 2868 unmodified lines | |||
| 3162 | int err, fan_idx; | 3168 | int err, fan_idx; |
| 3163 | u8 mode = 0; | 3169 | u8 mode = 0; |
| 3164 | 3170 | ||
| 3165 | if (asus->throttle_thermal_policy_available) | 3171 | if (asus->throttle_thermal_policy_dev) |
| 3166 | mode = asus->throttle_thermal_policy_mode; | 3172 | mode = asus->throttle_thermal_policy_mode; |
| 3167 | /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */ | 3173 | /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */ |
| 3168 | if (mode == 2) | 3174 | if (mode == 2) |
| @@ -3369,7 +3375,7 @@ static ssize_t fan_curve_enable_store(struct device *dev, · 200 unmodified lines | |||
| 3369 | * For machines with throttle this is the only way to reset fans | 3375 | * For machines with throttle this is the only way to reset fans |
| 3370 | * to default mode of operation (does not erase curve data). | 3376 | * to default mode of operation (does not erase curve data). |
| 3371 | */ | 3377 | */ |
| 3372 | if (asus->throttle_thermal_policy_available) { | 3378 | if (asus->throttle_thermal_policy_dev) { |
| 3373 | err = throttle_thermal_policy_write(asus); | 3379 | err = throttle_thermal_policy_write(asus); |
| 3374 | if (err) | 3380 | if (err) |
| 3375 | return err; | 3381 | return err; |
| @@ -3586,8 +3592,8 @@ static const struct attribute_group asus_fan_curve_attr_group = { · 210 unmodified lines | |||
| 3586 | __ATTRIBUTE_GROUPS(asus_fan_curve_attr); | 3592 | __ATTRIBUTE_GROUPS(asus_fan_curve_attr); |
| 3587 | 3593 | ||
| 3588 | /* | 3594 | /* |
| 3589 | * Must be initialised after throttle_thermal_policy_check_present() as | 3595 | * Must be initialised after throttle_thermal_policy_dev is set as |
| 3590 | * we check the status of throttle_thermal_policy_available during init. | 3596 | * we check the status of throttle_thermal_policy_dev during init. |
| 3591 | */ | 3597 | */ |
| 3592 | static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus) | 3598 | static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus) |
| 3593 | { | 3599 | { |
| @@ -3628,38 +3634,13 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus) · 34 unmodified lines | |||
| 3628 | } | 3634 | } |
| 3629 | 3635 | ||
| 3630 | /* Throttle thermal policy ****************************************************/ | 3636 | /* Throttle thermal policy ****************************************************/ |
| 3631 | |||
| 3632 | static int throttle_thermal_policy_check_present(struct asus_wmi *asus) | ||
| 3633 | { | ||
| 3634 | u32 result; | ||
| 3635 | int err; | ||
| 3636 | |||
| 3637 | asus->throttle_thermal_policy_available = false; | ||
| 3638 | |||
| 3639 | err = asus_wmi_get_devstate(asus, | ||
| 3640 | ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY, | ||
| 3641 | &result); | ||
| 3642 | if (err) { | ||
| 3643 | if (err == -ENODEV) | ||
| 3644 | return 0; | ||
| 3645 | return err; | ||
| 3646 | } | ||
| 3647 | |||
| 3648 | if (result & ASUS_WMI_DSTS_PRESENCE_BIT) | ||
| 3649 | asus->throttle_thermal_policy_available = true; | ||
| 3650 | |||
| 3651 | return 0; | ||
| 3652 | } | ||
| 3653 | |||
| 3654 | static int throttle_thermal_policy_write(struct asus_wmi *asus) | 3637 | static int throttle_thermal_policy_write(struct asus_wmi *asus) |
| 3655 | { | 3638 | { |
| 3656 | int err; | 3639 | u8 value = asus->throttle_thermal_policy_mode; |
| 3657 | u8 value; | ||
| 3658 | u32 retval; | 3640 | u32 retval; |
| 3641 | int err; | ||
| 3659 | 3642 | ||
| 3660 | value = asus->throttle_thermal_policy_mode; | 3643 | err = asus_wmi_set_devstate(asus->throttle_thermal_policy_dev, |
| 3661 | |||
| 3662 | err = asus_wmi_set_devstate(ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY, | ||
| 3663 | value, &retval); | 3644 | value, &retval); |
| 3664 | 3645 | ||
| 3665 | sysfs_notify(&asus->platform_device->dev.kobj, NULL, | 3646 | sysfs_notify(&asus->platform_device->dev.kobj, NULL, |
| @@ -3689,7 +3670,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus) · 23 unmodified lines | |||
| 3689 | 3670 | ||
| 3690 | static int throttle_thermal_policy_set_default(struct asus_wmi *asus) | 3671 | static int throttle_thermal_policy_set_default(struct asus_wmi *asus) |
| 3691 | { | 3672 | { |
| 3692 | if (!asus->throttle_thermal_policy_available) | 3673 | if (!asus->throttle_thermal_policy_dev) |
| 3693 | return 0; | 3674 | return 0; |
| 3694 | 3675 | ||
| 3695 | asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; | 3676 | asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; |
| @@ -3701,7 +3682,7 @@ static int throttle_thermal_policy_switch_next(struct asus_wmi *asus) · 5 unmodified lines | |||
| 3701 | u8 new_mode = asus->throttle_thermal_policy_mode + 1; | 3682 | u8 new_mode = asus->throttle_thermal_policy_mode + 1; |
| 3702 | int err; | 3683 | int err; |
| 3703 | 3684 | ||
| 3704 | if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT) | 3685 | if (new_mode > PLATFORM_PROFILE_MAX) |
| 3705 | new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; | 3686 | new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; |
| 3706 | 3687 | ||
| 3707 | asus->throttle_thermal_policy_mode = new_mode; | 3688 | asus->throttle_thermal_policy_mode = new_mode; |
| @@ -3740,7 +3721,7 @@ static ssize_t throttle_thermal_policy_store(struct device *dev, · 32 unmodified lines | |||
| 3740 | if (result < 0) | 3721 | if (result < 0) |
| 3741 | return result; | 3722 | return result; |
| 3742 | 3723 | ||
| 3743 | if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT) | 3724 | if (new_mode > PLATFORM_PROFILE_MAX) |
| 3744 | return -EINVAL; | 3725 | return -EINVAL; |
| 3745 | 3726 | ||
| 3746 | asus->throttle_thermal_policy_mode = new_mode; | 3727 | asus->throttle_thermal_policy_mode = new_mode; |
| @@ -3757,10 +3738,52 @@ static ssize_t throttle_thermal_policy_store(struct device *dev, · 10 unmodified lines | |||
| 3757 | return count; | 3738 | return count; |
| 3758 | } | 3739 | } |
| 3759 | 3740 | ||
| 3760 | // Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent | 3741 | /* |
| 3742 | * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent | ||
| 3743 | */ | ||
| 3761 | static DEVICE_ATTR_RW(throttle_thermal_policy); | 3744 | static DEVICE_ATTR_RW(throttle_thermal_policy); |
| 3762 | 3745 | ||
| 3763 | /* Platform profile ***********************************************************/ | 3746 | /* Platform profile ***********************************************************/ |
| 3747 | static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus, int mode) | ||
| 3748 | { | ||
| 3749 | bool vivo; | ||
| 3750 | |||
| 3751 | vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO; | ||
| 3752 | |||
| 3753 | if (vivo) { | ||
| 3754 | switch (mode) { | ||
| 3755 | case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT: | ||
| 3756 | return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO; | ||
| 3757 | case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST: | ||
| 3758 | return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO; | ||
| 3759 | case ASUS_THROTTLE_THERMAL_POLICY_SILENT: | ||
| 3760 | return ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO; | ||
| 3761 | } | ||
| 3762 | } | ||
| 3763 | |||
| 3764 | return mode; | ||
| 3765 | } | ||
| 3766 | |||
| 3767 | static int asus_wmi_platform_profile_mode_from_vivo(struct asus_wmi *asus, int mode) | ||
| 3768 | { | ||
| 3769 | bool vivo; | ||
| 3770 | |||
| 3771 | vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO; | ||
| 3772 | |||
| 3773 | if (vivo) { | ||
| 3774 | switch (mode) { | ||
| 3775 | case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO: | ||
| 3776 | return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; | ||
| 3777 | case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO: | ||
| 3778 | return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST; | ||
| 3779 | case ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO: | ||
| 3780 | return ASUS_THROTTLE_THERMAL_POLICY_SILENT; | ||
| 3781 | } | ||
| 3782 | } | ||
| 3783 | |||
| 3784 | return mode; | ||
| 3785 | } | ||
| 3786 | |||
| 3764 | static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof, | 3787 | static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof, |
| 3765 | enum platform_profile_option *profile) | 3788 | enum platform_profile_option *profile) |
| 3766 | { | 3789 | { |
| @@ -3768,10 +3791,9 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof, · 1 unmodified line | |||
| 3768 | int tp; | 3791 | int tp; |
| 3769 | 3792 | ||
| 3770 | asus = container_of(pprof, struct asus_wmi, platform_profile_handler); | 3793 | asus = container_of(pprof, struct asus_wmi, platform_profile_handler); |
| 3771 | |||
| 3772 | tp = asus->throttle_thermal_policy_mode; | 3794 | tp = asus->throttle_thermal_policy_mode; |
| 3773 | 3795 | ||
| 3774 | switch (tp) { | 3796 | switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) { |
| 3775 | case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT: | 3797 | case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT: |
| 3776 | *profile = PLATFORM_PROFILE_BALANCED; | 3798 | *profile = PLATFORM_PROFILE_BALANCED; |
| 3777 | break; | 3799 | break; |
| @@ -3810,7 +3832,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof, · 32 unmodified lines | |||
| 3810 | return -EOPNOTSUPP; | 3832 | return -EOPNOTSUPP; |
| 3811 | } | 3833 | } |
| 3812 | 3834 | ||
| 3813 | asus->throttle_thermal_policy_mode = tp; | 3835 | asus->throttle_thermal_policy_mode = asus_wmi_platform_profile_to_vivo(asus, tp); |
| 3814 | return throttle_thermal_policy_write(asus); | 3836 | return throttle_thermal_policy_write(asus); |
| 3815 | } | 3837 | } |
| 3816 | 3838 | ||
| @@ -3823,7 +3845,7 @@ static int platform_profile_setup(struct asus_wmi *asus) · 6 unmodified lines | |||
| 3823 | * Not an error if a component platform_profile relies on is unavailable | 3845 | * Not an error if a component platform_profile relies on is unavailable |
| 3824 | * so early return, skipping the setup of platform_profile. | 3846 | * so early return, skipping the setup of platform_profile. |
| 3825 | */ | 3847 | */ |
| 3826 | if (!asus->throttle_thermal_policy_available) | 3848 | if (!asus->throttle_thermal_policy_dev) |
| 3827 | return 0; | 3849 | return 0; |
| 3828 | 3850 | ||
| 3829 | dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n"); | 3851 | dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n"); |
| @@ -4238,7 +4260,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus) · 408 unmodified lines | |||
| 4238 | if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) { | 4260 | if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) { |
| 4239 | if (asus->fan_boost_mode_available) | 4261 | if (asus->fan_boost_mode_available) |
| 4240 | fan_boost_mode_switch_next(asus); | 4262 | fan_boost_mode_switch_next(asus); |
| 4241 | if (asus->throttle_thermal_policy_available) | 4263 | if (asus->throttle_thermal_policy_dev) |
| 4242 | throttle_thermal_policy_switch_next(asus); | 4264 | throttle_thermal_policy_switch_next(asus); |
| 4243 | return; | 4265 | return; |
| 4244 | 4266 | ||
| @@ -4410,7 +4432,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, · 165 unmodified lines | |||
| 4410 | else if (attr == &dev_attr_fan_boost_mode.attr) | 4432 | else if (attr == &dev_attr_fan_boost_mode.attr) |
| 4411 | ok = asus->fan_boost_mode_available; | 4433 | ok = asus->fan_boost_mode_available; |
| 4412 | else if (attr == &dev_attr_throttle_thermal_policy.attr) | 4434 | else if (attr == &dev_attr_throttle_thermal_policy.attr) |
| 4413 | ok = asus->throttle_thermal_policy_available; | 4435 | ok = asus->throttle_thermal_policy_dev != 0; |
| 4414 | else if (attr == &dev_attr_ppt_pl2_sppt.attr) | 4436 | else if (attr == &dev_attr_ppt_pl2_sppt.attr) |
| 4415 | devid = ASUS_WMI_DEVID_PPT_PL2_SPPT; | 4437 | devid = ASUS_WMI_DEVID_PPT_PL2_SPPT; |
| 4416 | else if (attr == &dev_attr_ppt_pl1_spl.attr) | 4438 | else if (attr == &dev_attr_ppt_pl1_spl.attr) |
| @@ -4702,16 +4724,15 @@ static int asus_wmi_add(struct platform_device *pdev) · 285 unmodified lines | |||
| 4702 | else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2)) | 4724 | else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2)) |
| 4703 | asus->kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2; | 4725 | asus->kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2; |
| 4704 | 4726 | ||
| 4727 | if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY)) | ||
| 4728 | asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY; | ||
| 4729 | else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO)) | ||
| 4730 | asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO; | ||
| 4731 | |||
| 4705 | err = fan_boost_mode_check_present(asus); | 4732 | err = fan_boost_mode_check_present(asus); |
| 4706 | if (err) | 4733 | if (err) |
| 4707 | goto fail_fan_boost_mode; | 4734 | goto fail_fan_boost_mode; |
| 4708 | 4735 | ||
| 4709 | err = throttle_thermal_policy_check_present(asus); | ||
| 4710 | if (err) | ||
| 4711 | goto fail_throttle_thermal_policy; | ||
| 4712 | else | ||
| 4713 | throttle_thermal_policy_set_default(asus); | ||
| 4714 | |||
| 4715 | err = platform_profile_setup(asus); | 4736 | err = platform_profile_setup(asus); |
| 4716 | if (err) | 4737 | if (err) |
| 4717 | goto fail_platform_profile_setup; | 4738 | goto fail_platform_profile_setup; |
| @@ -4806,7 +4827,6 @@ fail_hwmon: · 88 unmodified lines | |||
| 4806 | fail_input: | 4827 | fail_input: |
| 4807 | asus_wmi_sysfs_exit(asus->platform_device); | 4828 | asus_wmi_sysfs_exit(asus->platform_device); |
| 4808 | fail_sysfs: | 4829 | fail_sysfs: |
| 4809 | fail_throttle_thermal_policy: | ||
| 4810 | fail_custom_fan_curve: | 4830 | fail_custom_fan_curve: |
| 4811 | fail_platform_profile_setup: | 4831 | fail_platform_profile_setup: |
| 4812 | if (asus->platform_profile_support) | 4832 | if (asus->platform_profile_support) |
| @@ -68,6 +68,7 @@ · 67 unmodified lines | |||
| 68 | #define ASUS_WMI_DEVID_SCREENPAD_LIGHT 0x00050032 | 68 | #define ASUS_WMI_DEVID_SCREENPAD_LIGHT 0x00050032 |
| 69 | #define ASUS_WMI_DEVID_FAN_BOOST_MODE 0x00110018 | 69 | #define ASUS_WMI_DEVID_FAN_BOOST_MODE 0x00110018 |
| 70 | #define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY 0x00120075 | 70 | #define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY 0x00120075 |
| 71 | #define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO 0x00110019 | ||
| 71 | 72 | ||
| 72 | /* Misc */ | 73 | /* Misc */ |
| 73 | #define ASUS_WMI_DEVID_PANEL_OD 0x00050019 | 74 | #define ASUS_WMI_DEVID_PANEL_OD 0x00050019 |