Lines Matching +full:attr +full:- +full:max +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * that are present in many gaming and some non-gaming ASUS laptops.
31 #include <linux/platform_data/x86/asus-wmi.h>
36 #include "asus-armoury.h"
39 #define ASUS_NB_WMI_EVENT_GUID "0B3CBB35-E3C2-45ED-91C2-4C5A6D195D1C"
47 /* New modes for devices with 3 mini-led mode types */
52 /* Power tunable attribute name defines */
118 kobject_uevent(&asus_armoury.fw_attr_dev->kobj, KOBJ_CHANGE); in asus_set_reboot_and_signal_event()
121 static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) in pending_reboot_show() argument
128 static bool asus_bios_requires_reboot(struct kobj_attribute *attr) in asus_bios_requires_reboot() argument
130 return !strcmp(attr->attr.name, "gpu_mux_mode") || in asus_bios_requires_reboot()
131 !strcmp(attr->attr.name, "panel_hd_mode"); in asus_bios_requires_reboot()
135 * armoury_has_devstate() - Check presence of the WMI function state.
153 * armoury_get_devstate() - Get the WMI function state.
154 * @attr: NULL or the kobj_attribute associated to called WMI function.
157 * * non-NULL pointer to where to store the value returned from WMI
163 * * %-ENODEV - method ID is unsupported.
164 * * %0 - successful and retval is filled.
165 * * %other - error from WMI call.
167 static int armoury_get_devstate(struct kobj_attribute *attr, u32 *retval, u32 dev_id) in armoury_get_devstate() argument
173 if (attr) in armoury_get_devstate()
174 pr_err("Failed to get %s: %d\n", attr->attr.name, err); in armoury_get_devstate()
191 * armoury_set_devstate() - Set the WMI function state.
192 * @attr: The kobj_attribute associated to called WMI function.
208 * * %-EINVAL - attempt to set a dangerous or unsupported value.
209 * * %-EIO - WMI function returned an error.
210 * * %0 - successful and retval is filled.
211 * * %other - error from WMI call.
213 static int armoury_set_devstate(struct kobj_attribute *attr, in armoury_set_devstate() argument
231 return -EINVAL; in armoury_set_devstate()
241 if (attr) in armoury_set_devstate()
242 pr_err("Failed to set %s: %d\n", attr->attr.name, err); in armoury_set_devstate()
254 pr_err("Failed to set %s: (result): 0x%x\n", attr->attr.name, result); in armoury_set_devstate()
255 return -EIO; in armoury_set_devstate()
277 ssize_t armoury_attr_uint_store(struct kobject *kobj, struct kobj_attribute *attr, in armoury_attr_uint_store() argument
278 const char *buf, size_t count, u32 min, u32 max, in armoury_attr_uint_store() argument
288 if (value < min || value > max) in armoury_attr_uint_store()
289 return -EINVAL; in armoury_attr_uint_store()
291 err = armoury_set_devstate(attr, value, NULL, wmi_dev); in armoury_attr_uint_store()
297 sysfs_notify(kobj, NULL, attr->attr.name); in armoury_attr_uint_store()
299 if (asus_bios_requires_reboot(attr)) in armoury_attr_uint_store()
305 ssize_t armoury_attr_uint_show(struct kobject *kobj, struct kobj_attribute *attr, in armoury_attr_uint_show() argument
311 err = armoury_get_devstate(attr, &result, wmi_dev); in armoury_attr_uint_show()
318 static ssize_t enum_type_show(struct kobject *kobj, struct kobj_attribute *attr, in enum_type_show() argument
324 static ssize_t int_type_show(struct kobject *kobj, struct kobj_attribute *attr, in int_type_show() argument
330 /* Mini-LED mode **************************************************************/
332 /* Values map for mini-led modes on 2023 and earlier models. */
338 /* Values map for mini-led modes on 2024 and later models. */
346 struct kobj_attribute *attr, char *buf) in mini_led_mode_current_value_show() argument
365 pr_err("Unrecognized mini-LED device: %u\n", asus_armoury.mini_led_dev_id); in mini_led_mode_current_value_show()
366 return -ENODEV; in mini_led_mode_current_value_show()
369 err = armoury_get_devstate(attr, &mode, asus_armoury.mini_led_dev_id); in mini_led_mode_current_value_show()
379 pr_warn("Unrecognized mini-LED mode: %u", mode); in mini_led_mode_current_value_show()
380 return -EINVAL; in mini_led_mode_current_value_show()
384 struct kobj_attribute *attr, in mini_led_mode_current_value_store() argument
408 pr_err("Unrecognized mini-LED devid: %u\n", asus_armoury.mini_led_dev_id); in mini_led_mode_current_value_store()
409 return -EINVAL; in mini_led_mode_current_value_store()
413 pr_warn("mini-LED mode unrecognized device: %u\n", mode); in mini_led_mode_current_value_store()
414 return -ENODEV; in mini_led_mode_current_value_store()
417 return armoury_attr_uint_store(kobj, attr, buf, count, in mini_led_mode_current_value_store()
423 struct kobj_attribute *attr, char *buf) in mini_led_mode_possible_values_show() argument
431 return -ENODEV; in mini_led_mode_possible_values_show()
434 ASUS_ATTR_GROUP_ENUM(mini_led_mode, "mini_led_mode", "Set the mini-LED backlight mode");
437 struct kobj_attribute *attr, in gpu_mux_mode_current_value_store() argument
454 return -ENODEV; in gpu_mux_mode_current_value_store()
464 return -EBUSY; in gpu_mux_mode_current_value_store()
468 err = armoury_set_devstate(attr, optimus ? 1 : 0, NULL, asus_armoury.gpu_mux_dev_id); in gpu_mux_mode_current_value_store()
472 sysfs_notify(kobj, NULL, attr->attr.name); in gpu_mux_mode_current_value_store()
481 struct kobj_attribute *attr, const char *buf, in dgpu_disable_current_value_store() argument
497 return -EBUSY; in dgpu_disable_current_value_store()
502 err = armoury_set_devstate(attr, disable ? 1 : 0, NULL, ASUS_WMI_DEVID_DGPU); in dgpu_disable_current_value_store()
507 sysfs_notify(kobj, NULL, attr->attr.name); in dgpu_disable_current_value_store()
523 * armoury_pci_rescan() - Performs a PCI rescan
544 static ssize_t egpu_enable_current_value_store(struct kobject *kobj, struct kobj_attribute *attr, in egpu_enable_current_value_store() argument
555 return -EINVAL; in egpu_enable_current_value_store()
568 return -ENOENT; in egpu_enable_current_value_store()
579 return -ENODEV; in egpu_enable_current_value_store()
583 err = armoury_set_devstate(attr, enable, &result, ASUS_WMI_DEVID_EGPU); in egpu_enable_current_value_store()
585 pr_err("Failed to set %s: %d\n", attr->attr.name, err); in egpu_enable_current_value_store()
591 * performing a pci rescan will bring up the device in pci-e 3.0 speed, in egpu_enable_current_value_store()
601 err = armoury_get_devstate(attr, &result, ASUS_WMI_DEVID_EGPU); in egpu_enable_current_value_store()
608 return -EBUSY; in egpu_enable_current_value_store()
619 return -EIO; in egpu_enable_current_value_store()
629 sysfs_notify(kobj, NULL, attr->attr.name); in egpu_enable_current_value_store()
634 static ssize_t egpu_enable_current_value_show(struct kobject *kobj, struct kobj_attribute *attr, in egpu_enable_current_value_show() argument
641 err = armoury_get_devstate(attr, &status, ASUS_WMI_DEVID_EGPU); in egpu_enable_current_value_show()
651 return -EIO; in egpu_enable_current_value_show()
654 static ssize_t egpu_enable_possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, in egpu_enable_possible_values_show() argument
679 static ssize_t apu_mem_current_value_show(struct kobject *kobj, struct kobj_attribute *attr, in apu_mem_current_value_show() argument
685 err = armoury_get_devstate(attr, &mem, ASUS_WMI_DEVID_APU_MEM); in apu_mem_current_value_show()
699 return -EIO; in apu_mem_current_value_show()
702 static ssize_t apu_mem_current_value_store(struct kobject *kobj, struct kobj_attribute *attr, in apu_mem_current_value_store() argument
713 return -EINVAL; in apu_mem_current_value_store()
716 err = armoury_set_devstate(attr, mem, NULL, ASUS_WMI_DEVID_APU_MEM); in apu_mem_current_value_store()
723 sysfs_notify(kobj, NULL, attr->attr.name); in apu_mem_current_value_store()
730 static ssize_t apu_mem_possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, in apu_mem_possible_values_show() argument
775 "Set the Nvidia max thermal limit");
807 * is_power_tunable_attr - Determines if an attribute is a power-related tunable
808 * @name: The name of the attribute to check
810 * This function checks if the given attribute name is related to power tuning.
812 * Return: true if the attribute is a power-related tunable, false otherwise
814 static bool is_power_tunable_attr(const char *name) in is_power_tunable_attr() argument
825 if (!strcmp(name, power_tunable_attrs[i])) in is_power_tunable_attr()
833 * has_valid_limit - Checks if a power-related attribute has a valid limit value
834 * @name: The name of the attribute to check
837 * This function checks if a power-related attribute has a valid limit value.
842 static bool has_valid_limit(const char *name, const struct power_limits *limits) in has_valid_limit() argument
849 if (!strcmp(name, ATTR_PPT_PL1_SPL)) in has_valid_limit()
850 limit_value = limits->ppt_pl1_spl_max; in has_valid_limit()
851 else if (!strcmp(name, ATTR_PPT_PL2_SPPT)) in has_valid_limit()
852 limit_value = limits->ppt_pl2_sppt_max; in has_valid_limit()
853 else if (!strcmp(name, ATTR_PPT_PL3_FPPT)) in has_valid_limit()
854 limit_value = limits->ppt_pl3_fppt_max; in has_valid_limit()
855 else if (!strcmp(name, ATTR_PPT_APU_SPPT)) in has_valid_limit()
856 limit_value = limits->ppt_apu_sppt_max; in has_valid_limit()
857 else if (!strcmp(name, ATTR_PPT_PLATFORM_SPPT)) in has_valid_limit()
858 limit_value = limits->ppt_platform_sppt_max; in has_valid_limit()
859 else if (!strcmp(name, ATTR_NV_DYNAMIC_BOOST)) in has_valid_limit()
860 limit_value = limits->nv_dynamic_boost_max; in has_valid_limit()
861 else if (!strcmp(name, ATTR_NV_TEMP_TARGET)) in has_valid_limit()
862 limit_value = limits->nv_temp_target_max; in has_valid_limit()
863 else if (!strcmp(name, ATTR_NV_BASE_TGP) || in has_valid_limit()
864 !strcmp(name, ATTR_NV_TGP)) in has_valid_limit()
865 limit_value = limits->nv_tgp_max; in has_valid_limit()
876 const char *name; in asus_fw_attr_add() local
887 &asus_armoury.fw_attr_dev->kobj); in asus_fw_attr_add()
889 err = -ENOMEM; in asus_fw_attr_add()
893 err = sysfs_create_file(&asus_armoury.fw_attr_kset->kobj, &pending_reboot.attr); in asus_fw_attr_add()
906 err = sysfs_create_group(&asus_armoury.fw_attr_kset->kobj, in asus_fw_attr_add()
909 pr_err("Failed to create sysfs-group for mini_led\n"); in asus_fw_attr_add()
921 err = sysfs_create_group(&asus_armoury.fw_attr_kset->kobj, in asus_fw_attr_add()
924 pr_err("Failed to create sysfs-group for gpu_mux\n"); in asus_fw_attr_add()
935 name = armoury_attr_groups[i].attr_group->name; in asus_fw_attr_add()
937 /* Check if this is a power-related tunable requiring limits */ in asus_fw_attr_add()
938 if (ac_rog_tunables && ac_rog_tunables->power_limits && in asus_fw_attr_add()
939 is_power_tunable_attr(name)) { in asus_fw_attr_add()
940 limits = ac_rog_tunables->power_limits; in asus_fw_attr_add()
942 should_create = has_valid_limit(name, limits); in asus_fw_attr_add()
944 pr_debug("Missing max value for tunable %s\n", name); in asus_fw_attr_add()
948 err = sysfs_create_group(&asus_armoury.fw_attr_kset->kobj, in asus_fw_attr_add()
951 pr_err("Failed to create sysfs-group for %s\n", in asus_fw_attr_add()
952 armoury_attr_groups[i].attr_group->name); in asus_fw_attr_add()
961 while (i--) { in asus_fw_attr_add()
963 sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, in asus_fw_attr_add()
967 sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, &gpu_mux_mode_attr_group); in asus_fw_attr_add()
970 sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, &mini_led_mode_attr_group); in asus_fw_attr_add()
972 sysfs_remove_file(&asus_armoury.fw_attr_kset->kobj, &pending_reboot.attr); in asus_fw_attr_add()
983 /* Set up the min/max and defaults for ROG tunables */
999 power_data = dmi_id->driver_data; in init_rog_tunables()
1006 ac_limits = power_data->ac_data; in init_rog_tunables()
1014 ac_rog_tunables->power_limits = ac_limits; in init_rog_tunables()
1017 ac_rog_tunables->ppt_pl1_spl = in init_rog_tunables()
1018 ac_limits->ppt_pl1_spl_def ? in init_rog_tunables()
1019 ac_limits->ppt_pl1_spl_def : in init_rog_tunables()
1020 ac_limits->ppt_pl1_spl_max; in init_rog_tunables()
1022 ac_rog_tunables->ppt_pl2_sppt = in init_rog_tunables()
1023 ac_limits->ppt_pl2_sppt_def ? in init_rog_tunables()
1024 ac_limits->ppt_pl2_sppt_def : in init_rog_tunables()
1025 ac_limits->ppt_pl2_sppt_max; in init_rog_tunables()
1027 ac_rog_tunables->ppt_pl3_fppt = in init_rog_tunables()
1028 ac_limits->ppt_pl3_fppt_def ? in init_rog_tunables()
1029 ac_limits->ppt_pl3_fppt_def : in init_rog_tunables()
1030 ac_limits->ppt_pl3_fppt_max; in init_rog_tunables()
1032 ac_rog_tunables->ppt_apu_sppt = in init_rog_tunables()
1033 ac_limits->ppt_apu_sppt_def ? in init_rog_tunables()
1034 ac_limits->ppt_apu_sppt_def : in init_rog_tunables()
1035 ac_limits->ppt_apu_sppt_max; in init_rog_tunables()
1037 ac_rog_tunables->ppt_platform_sppt = in init_rog_tunables()
1038 ac_limits->ppt_platform_sppt_def ? in init_rog_tunables()
1039 ac_limits->ppt_platform_sppt_def : in init_rog_tunables()
1040 ac_limits->ppt_platform_sppt_max; in init_rog_tunables()
1042 ac_rog_tunables->nv_dynamic_boost = in init_rog_tunables()
1043 ac_limits->nv_dynamic_boost_max; in init_rog_tunables()
1044 ac_rog_tunables->nv_temp_target = in init_rog_tunables()
1045 ac_limits->nv_temp_target_max; in init_rog_tunables()
1046 ac_rog_tunables->nv_tgp = ac_limits->nv_tgp_max; in init_rog_tunables()
1048 pr_debug("AC power limits initialized for %s\n", dmi_id->matches[0].substr); in init_rog_tunables()
1054 dc_limits = power_data->dc_data; in init_rog_tunables()
1064 dc_rog_tunables->power_limits = dc_limits; in init_rog_tunables()
1067 dc_rog_tunables->ppt_pl1_spl = in init_rog_tunables()
1068 dc_limits->ppt_pl1_spl_def ? in init_rog_tunables()
1069 dc_limits->ppt_pl1_spl_def : in init_rog_tunables()
1070 dc_limits->ppt_pl1_spl_max; in init_rog_tunables()
1072 dc_rog_tunables->ppt_pl2_sppt = in init_rog_tunables()
1073 dc_limits->ppt_pl2_sppt_def ? in init_rog_tunables()
1074 dc_limits->ppt_pl2_sppt_def : in init_rog_tunables()
1075 dc_limits->ppt_pl2_sppt_max; in init_rog_tunables()
1077 dc_rog_tunables->ppt_pl3_fppt = in init_rog_tunables()
1078 dc_limits->ppt_pl3_fppt_def ? in init_rog_tunables()
1079 dc_limits->ppt_pl3_fppt_def : in init_rog_tunables()
1080 dc_limits->ppt_pl3_fppt_max; in init_rog_tunables()
1082 dc_rog_tunables->ppt_apu_sppt = in init_rog_tunables()
1083 dc_limits->ppt_apu_sppt_def ? in init_rog_tunables()
1084 dc_limits->ppt_apu_sppt_def : in init_rog_tunables()
1085 dc_limits->ppt_apu_sppt_max; in init_rog_tunables()
1087 dc_rog_tunables->ppt_platform_sppt = in init_rog_tunables()
1088 dc_limits->ppt_platform_sppt_def ? in init_rog_tunables()
1089 dc_limits->ppt_platform_sppt_def : in init_rog_tunables()
1090 dc_limits->ppt_platform_sppt_max; in init_rog_tunables()
1092 dc_rog_tunables->nv_dynamic_boost = in init_rog_tunables()
1093 dc_limits->nv_dynamic_boost_max; in init_rog_tunables()
1094 dc_rog_tunables->nv_temp_target = in init_rog_tunables()
1095 dc_limits->nv_temp_target_max; in init_rog_tunables()
1096 dc_rog_tunables->nv_tgp = dc_limits->nv_tgp_max; in init_rog_tunables()
1098 pr_debug("DC power limits initialized for %s\n", dmi_id->matches[0].substr); in init_rog_tunables()
1115 return -ENODEV; in asus_fw_init()
1122 return -ENODEV; in asus_fw_init()
1134 for (i = ARRAY_SIZE(armoury_attr_groups) - 1; i >= 0; i--) { in asus_fw_exit()
1136 sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, in asus_fw_exit()
1141 sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, &gpu_mux_mode_attr_group); in asus_fw_exit()
1144 sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, &mini_led_mode_attr_group); in asus_fw_exit()
1146 sysfs_remove_file(&asus_armoury.fw_attr_kset->kobj, &pending_reboot.attr); in asus_fw_exit()