Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/x86/amd/pmf: Add sysfs to toggle CnQF

Whether to turn CnQF on/off by default upon driver load would be decided
by a BIOS flag. Add a sysfs node to provide a way to the user whether to
use static slider or CnQF .

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Link: https://lore.kernel.org/r/20220922131202.56529-3-Shyam-sundar.S-k@amd.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Shyam Sundar S K and committed by
Hans de Goede
3dae5825 1738061c

+67
+60
drivers/platform/x86/amd/pmf/cnqf.c
··· 302 302 return 0; 303 303 } 304 304 305 + static ssize_t cnqf_enable_store(struct device *dev, 306 + struct device_attribute *attr, 307 + const char *buf, size_t count) 308 + { 309 + struct amd_pmf_dev *pdev = dev_get_drvdata(dev); 310 + int mode, result, src; 311 + bool input; 312 + 313 + mode = amd_pmf_get_pprof_modes(pdev); 314 + if (mode < 0) 315 + return mode; 316 + 317 + result = kstrtobool(buf, &input); 318 + if (result) 319 + return result; 320 + 321 + src = amd_pmf_cnqf_get_power_source(pdev); 322 + pdev->cnqf_enabled = input; 323 + 324 + if (pdev->cnqf_enabled && pdev->current_profile == PLATFORM_PROFILE_BALANCED) { 325 + amd_pmf_set_cnqf(pdev, src, config_store.current_mode, NULL); 326 + } else { 327 + if (is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) 328 + amd_pmf_update_slider(pdev, SLIDER_OP_SET, mode, NULL); 329 + } 330 + 331 + dev_dbg(pdev->dev, "Received CnQF %s\n", input ? "on" : "off"); 332 + return count; 333 + } 334 + 335 + static ssize_t cnqf_enable_show(struct device *dev, 336 + struct device_attribute *attr, 337 + char *buf) 338 + { 339 + struct amd_pmf_dev *pdev = dev_get_drvdata(dev); 340 + 341 + return sysfs_emit(buf, "%s\n", pdev->cnqf_enabled ? "on" : "off"); 342 + } 343 + 344 + static DEVICE_ATTR_RW(cnqf_enable); 345 + 346 + static umode_t cnqf_feature_is_visible(struct kobject *kobj, 347 + struct attribute *attr, int n) 348 + { 349 + struct device *dev = kobj_to_dev(kobj); 350 + struct amd_pmf_dev *pdev = dev_get_drvdata(dev); 351 + 352 + return pdev->cnqf_supported ? attr->mode : 0; 353 + } 354 + 355 + static struct attribute *cnqf_feature_attrs[] = { 356 + &dev_attr_cnqf_enable.attr, 357 + NULL 358 + }; 359 + 360 + const struct attribute_group cnqf_feature_attribute_group = { 361 + .is_visible = cnqf_feature_is_visible, 362 + .attrs = cnqf_feature_attrs, 363 + }; 364 + 305 365 void amd_pmf_deinit_cnqf(struct amd_pmf_dev *dev) 306 366 { 307 367 cancel_delayed_work_sync(&dev->work_buffer);
+6
drivers/platform/x86/amd/pmf/core.c
··· 391 391 return 0; 392 392 } 393 393 394 + static const struct attribute_group *amd_pmf_driver_groups[] = { 395 + &cnqf_feature_attribute_group, 396 + NULL, 397 + }; 398 + 394 399 static struct platform_driver amd_pmf_driver = { 395 400 .driver = { 396 401 .name = "amd-pmf", 397 402 .acpi_match_table = amd_pmf_acpi_ids, 403 + .dev_groups = amd_pmf_driver_groups, 398 404 }, 399 405 .probe = amd_pmf_probe, 400 406 .remove = amd_pmf_remove,
+1
drivers/platform/x86/amd/pmf/pmf.h
··· 422 422 int amd_pmf_init_cnqf(struct amd_pmf_dev *dev); 423 423 void amd_pmf_deinit_cnqf(struct amd_pmf_dev *dev); 424 424 int amd_pmf_trans_cnqf(struct amd_pmf_dev *dev, int socket_power, ktime_t time_lapsed_ms); 425 + extern const struct attribute_group cnqf_feature_attribute_group; 425 426 426 427 #endif /* PMF_H */