@@ -97,6 +97,12 @@ module_param(fnlock_default, bool, 0444);
9797#define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1
9898#define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2
9999
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+
100106#define USB_INTEL_XUSB2PR 0xD0
101107#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
102108
@@ -286,8 +292,8 @@ struct asus_wmi {
286292 u32 kbd_rgb_dev ;
287293 bool kbd_rgb_state_available ;
288294
289- bool throttle_thermal_policy_available ;
290295 u8 throttle_thermal_policy_mode ;
296+ u32 throttle_thermal_policy_dev ;
291297
292298 bool cpu_fan_curve_available ;
293299 bool gpu_fan_curve_available ;
@@ -3162,7 +3168,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)
31623168 int err , fan_idx ;
31633169 u8 mode = 0 ;
31643170
3165- if (asus -> throttle_thermal_policy_available )
3171+ if (asus -> throttle_thermal_policy_dev )
31663172 mode = asus -> throttle_thermal_policy_mode ;
31673173 /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
31683174 if (mode == 2 )
@@ -3369,7 +3375,7 @@ static ssize_t fan_curve_enable_store(struct device *dev,
33693375 * For machines with throttle this is the only way to reset fans
33703376 * to default mode of operation (does not erase curve data).
33713377 */
3372- if (asus -> throttle_thermal_policy_available ) {
3378+ if (asus -> throttle_thermal_policy_dev ) {
33733379 err = throttle_thermal_policy_write (asus );
33743380 if (err )
33753381 return err ;
@@ -3586,8 +3592,8 @@ static const struct attribute_group asus_fan_curve_attr_group = {
35863592__ATTRIBUTE_GROUPS (asus_fan_curve_attr );
35873593
35883594/*
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.
35913597 */
35923598static int asus_wmi_custom_fan_curve_init (struct asus_wmi * asus )
35933599{
@@ -3628,38 +3634,13 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
36283634}
36293635
36303636/* 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-
36543637static int throttle_thermal_policy_write (struct asus_wmi * asus )
36553638{
3656- int err ;
3657- u8 value ;
3639+ u8 value = asus -> throttle_thermal_policy_mode ;
36583640 u32 retval ;
3641+ int err ;
36593642
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 ,
36633644 value , & retval );
36643645
36653646 sysfs_notify (& asus -> platform_device -> dev .kobj , NULL ,
@@ -3689,7 +3670,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
36893670
36903671static int throttle_thermal_policy_set_default (struct asus_wmi * asus )
36913672{
3692- if (!asus -> throttle_thermal_policy_available )
3673+ if (!asus -> throttle_thermal_policy_dev )
36933674 return 0 ;
36943675
36953676 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)
37013682 u8 new_mode = asus -> throttle_thermal_policy_mode + 1 ;
37023683 int err ;
37033684
3704- if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT )
3685+ if (new_mode > PLATFORM_PROFILE_MAX )
37053686 new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT ;
37063687
37073688 asus -> throttle_thermal_policy_mode = new_mode ;
@@ -3740,7 +3721,7 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
37403721 if (result < 0 )
37413722 return result ;
37423723
3743- if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT )
3724+ if (new_mode > PLATFORM_PROFILE_MAX )
37443725 return - EINVAL ;
37453726
37463727 asus -> throttle_thermal_policy_mode = new_mode ;
@@ -3757,21 +3738,62 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
37573738 return count ;
37583739}
37593740
3760- // Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
3741+ /*
3742+ * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
3743+ */
37613744static DEVICE_ATTR_RW (throttle_thermal_policy );
37623745
37633746/* 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+
37643787static int asus_wmi_platform_profile_get (struct platform_profile_handler * pprof ,
37653788 enum platform_profile_option * profile )
37663789{
37673790 struct asus_wmi * asus ;
37683791 int tp ;
37693792
37703793 asus = container_of (pprof , struct asus_wmi , platform_profile_handler );
3771-
37723794 tp = asus -> throttle_thermal_policy_mode ;
37733795
3774- switch (tp ) {
3796+ switch (asus_wmi_platform_profile_mode_from_vivo ( asus , tp ) ) {
37753797 case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT :
37763798 * profile = PLATFORM_PROFILE_BALANCED ;
37773799 break ;
@@ -3810,7 +3832,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
38103832 return - EOPNOTSUPP ;
38113833 }
38123834
3813- asus -> throttle_thermal_policy_mode = tp ;
3835+ asus -> throttle_thermal_policy_mode = asus_wmi_platform_profile_to_vivo ( asus , tp ) ;
38143836 return throttle_thermal_policy_write (asus );
38153837}
38163838
@@ -3823,7 +3845,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
38233845 * Not an error if a component platform_profile relies on is unavailable
38243846 * so early return, skipping the setup of platform_profile.
38253847 */
3826- if (!asus -> throttle_thermal_policy_available )
3848+ if (!asus -> throttle_thermal_policy_dev )
38273849 return 0 ;
38283850
38293851 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)
42384260 if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP ) {
42394261 if (asus -> fan_boost_mode_available )
42404262 fan_boost_mode_switch_next (asus );
4241- if (asus -> throttle_thermal_policy_available )
4263+ if (asus -> throttle_thermal_policy_dev )
42424264 throttle_thermal_policy_switch_next (asus );
42434265 return ;
42444266
@@ -4410,7 +4432,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
44104432 else if (attr == & dev_attr_fan_boost_mode .attr )
44114433 ok = asus -> fan_boost_mode_available ;
44124434 else if (attr == & dev_attr_throttle_thermal_policy .attr )
4413- ok = asus -> throttle_thermal_policy_available ;
4435+ ok = asus -> throttle_thermal_policy_dev != 0 ;
44144436 else if (attr == & dev_attr_ppt_pl2_sppt .attr )
44154437 devid = ASUS_WMI_DEVID_PPT_PL2_SPPT ;
44164438 else if (attr == & dev_attr_ppt_pl1_spl .attr )
@@ -4702,16 +4724,15 @@ static int asus_wmi_add(struct platform_device *pdev)
47024724 else if (asus_wmi_dev_is_present (asus , ASUS_WMI_DEVID_TUF_RGB_MODE2 ))
47034725 asus -> kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2 ;
47044726
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+
47054732 err = fan_boost_mode_check_present (asus );
47064733 if (err )
47074734 goto fail_fan_boost_mode ;
47084735
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-
47154736 err = platform_profile_setup (asus );
47164737 if (err )
47174738 goto fail_platform_profile_setup ;
@@ -4806,7 +4827,6 @@ static int asus_wmi_add(struct platform_device *pdev)
48064827fail_input :
48074828 asus_wmi_sysfs_exit (asus -> platform_device );
48084829fail_sysfs :
4809- fail_throttle_thermal_policy :
48104830fail_custom_fan_curve :
48114831fail_platform_profile_setup :
48124832 if (asus -> platform_profile_support )
0 commit comments