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 | 97 | #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1 |
| 98 | 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 | 106 | #define USB_INTEL_XUSB2PR 0xD0 |
| 101 | 107 | #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 |
| 102 | 108 | |
| @@ -286,8 +292,8 @@ struct asus_wmi { · 183 unmodified lines | ||
| 286 | 292 | u32 kbd_rgb_dev; |
| 287 | 293 | bool kbd_rgb_state_available; |
| 288 | 294 | |
| 289 | − bool throttle_thermal_policy_available; | |
| 290 | 295 | u8 throttle_thermal_policy_mode; |
| 296 | + u32 throttle_thermal_policy_dev; | |
| 291 | 297 | |
| 292 | 298 | bool cpu_fan_curve_available; |
| 293 | 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 | 3168 | int err, fan_idx; |
| 3163 | 3169 | u8 mode = 0; |
| 3164 | 3170 | |
| 3165 | − if (asus->throttle_thermal_policy_available) | |
| 3171 | + if (asus->throttle_thermal_policy_dev) | |
| 3166 | 3172 | mode = asus->throttle_thermal_policy_mode; |
| 3167 | 3173 | /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */ |
| 3168 | 3174 | if (mode == 2) |
| @@ -3369,7 +3375,7 @@ static ssize_t fan_curve_enable_store(struct device *dev, · 200 unmodified lines | ||
| 3369 | 3375 | * For machines with throttle this is the only way to reset fans |
| 3370 | 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 | 3379 | err = throttle_thermal_policy_write(asus); |
| 3374 | 3380 | if (err) |
| 3375 | 3381 | return err; |
| @@ -3586,8 +3592,8 @@ static const struct attribute_group asus_fan_curve_attr_group = { · 210 unmodified lines | ||
| 3586 | 3592 | __ATTRIBUTE_GROUPS(asus_fan_curve_attr); |
| 3587 | 3593 | |
| 3588 | 3594 | /* |
| 3589 | − * Must be initialised after throttle_thermal_policy_check_present() as | |
| 3590 | − * we check the status of throttle_thermal_policy_available during init. | |
| 3595 | + * Must be initialised after throttle_thermal_policy_dev is set as | |
| 3596 | + * we check the status of throttle_thermal_policy_dev during init. | |
| 3591 | 3597 | */ |
| 3592 | 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 | 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 | 3637 | static int throttle_thermal_policy_write(struct asus_wmi *asus) |
| 3655 | 3638 | { |
| 3656 | − int err; | |
| 3657 | − u8 value; | |
| 3639 | + u8 value = asus->throttle_thermal_policy_mode; | |
| 3658 | 3640 | u32 retval; |
| 3641 | + int err; | |
| 3659 | 3642 | |
| 3660 | − value = asus->throttle_thermal_policy_mode; | |
| 3661 | − | |
| 3662 | − err = asus_wmi_set_devstate(ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY, | |
| 3643 | + err = asus_wmi_set_devstate(asus->throttle_thermal_policy_dev, | |
| 3663 | 3644 | value, &retval); |
| 3664 | 3645 | |
| 3665 | 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 | 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 | 3674 | return 0; |
| 3694 | 3675 | |
| 3695 | 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 | 3682 | u8 new_mode = asus->throttle_thermal_policy_mode + 1; |
| 3702 | 3683 | int err; |
| 3703 | 3684 | |
| 3704 | − if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT) | |
| 3685 | + if (new_mode > PLATFORM_PROFILE_MAX) | |
| 3705 | 3686 | new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; |
| 3706 | 3687 | |
| 3707 | 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 | 3721 | if (result < 0) |
| 3741 | 3722 | return result; |
| 3742 | 3723 | |
| 3743 | − if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT) | |
| 3724 | + if (new_mode > PLATFORM_PROFILE_MAX) | |
| 3744 | 3725 | return -EINVAL; |
| 3745 | 3726 | |
| 3746 | 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 | 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 | 3744 | static DEVICE_ATTR_RW(throttle_thermal_policy); |
| 3762 | 3745 | |
| 3763 | 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 | 3787 | static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof, |
| 3765 | 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 | 3791 | int tp; |
| 3769 | 3792 | |
| 3770 | 3793 | asus = container_of(pprof, struct asus_wmi, platform_profile_handler); |
| 3771 | − | |
| 3772 | 3794 | tp = asus->throttle_thermal_policy_mode; |
| 3773 | 3795 | |
| 3774 | − switch (tp) { | |
| 3796 | + switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) { | |
| 3775 | 3797 | case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT: |
| 3776 | 3798 | *profile = PLATFORM_PROFILE_BALANCED; |
| 3777 | 3799 | break; |
| @@ -3810,7 +3832,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof, · 32 unmodified lines | ||
| 3810 | 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 | 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 | 3845 | * Not an error if a component platform_profile relies on is unavailable |
| 3824 | 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 | 3849 | return 0; |
| 3828 | 3850 | |
| 3829 | 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 | 4260 | if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) { |
| 4239 | 4261 | if (asus->fan_boost_mode_available) |
| 4240 | 4262 | fan_boost_mode_switch_next(asus); |
| 4241 | − if (asus->throttle_thermal_policy_available) | |
| 4263 | + if (asus->throttle_thermal_policy_dev) | |
| 4242 | 4264 | throttle_thermal_policy_switch_next(asus); |
| 4243 | 4265 | return; |
| 4244 | 4266 | |
| @@ -4410,7 +4432,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, · 165 unmodified lines | ||
| 4410 | 4432 | else if (attr == &dev_attr_fan_boost_mode.attr) |
| 4411 | 4433 | ok = asus->fan_boost_mode_available; |
| 4412 | 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 | 4436 | else if (attr == &dev_attr_ppt_pl2_sppt.attr) |
| 4415 | 4437 | devid = ASUS_WMI_DEVID_PPT_PL2_SPPT; |
| 4416 | 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 | 4724 | else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2)) |
| 4703 | 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 | 4732 | err = fan_boost_mode_check_present(asus); |
| 4706 | 4733 | if (err) |
| 4707 | 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 | 4736 | err = platform_profile_setup(asus); |
| 4716 | 4737 | if (err) |
| 4717 | 4738 | goto fail_platform_profile_setup; |
| @@ -4806,7 +4827,6 @@ fail_hwmon: · 88 unmodified lines | ||
| 4806 | 4827 | fail_input: |
| 4807 | 4828 | asus_wmi_sysfs_exit(asus->platform_device); |
| 4808 | 4829 | fail_sysfs: |
| 4809 | −fail_throttle_thermal_policy: | |
| 4810 | 4830 | fail_custom_fan_curve: |
| 4811 | 4831 | fail_platform_profile_setup: |
| 4812 | 4832 | if (asus->platform_profile_support) |
| @@ -68,6 +68,7 @@ · 67 unmodified lines | ||
| 68 | 68 | #define ASUS_WMI_DEVID_SCREENPAD_LIGHT 0x00050032 |
| 69 | 69 | #define ASUS_WMI_DEVID_FAN_BOOST_MODE 0x00110018 |
| 70 | 70 | #define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY 0x00120075 |
| 71 | +#define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO 0x00110019 | |
| 71 | 72 | |
| 72 | 73 | /* Misc */ |
| 73 | 74 | #define ASUS_WMI_DEVID_PANEL_OD 0x00050019 |