From patchwork Thu Oct 6 15:38:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1687053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mjwbp1zcjz20Pd for ; Fri, 7 Oct 2022 02:39:34 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ogSy6-0002S1-Oy; Thu, 06 Oct 2022 15:39:26 +0000 Received: from mail-pg1-f179.google.com ([209.85.215.179]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ogSy4-0002QA-56 for kernel-team@lists.ubuntu.com; Thu, 06 Oct 2022 15:39:24 +0000 Received: by mail-pg1-f179.google.com with SMTP id bh13so2205616pgb.4 for ; Thu, 06 Oct 2022 08:39:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=zxLqU9d/TZlZOU4rkW9/8vIhRiy+TIKDpkKmRTuxmlM=; b=40KtA0hLKMNdYjkDevdrRxDfhkjoKJZIVVliYIwJkmeIed6jcp3fv9GJOqAM0s/L9q 1mPO8Dhi9xbayJrNIVeQlx4Tl6fZqHZS591PzsCoLtOJx9TvRef74BED3n/UCfIoes/J 5vmzM96LhPkLNDDkhTdNqpUW80Yr5xmnyJxWHRUUN/SsSd+jp7k4NUilwHNgaUV5PJND Uj4EajzQPCgVBFBeIOOCvKsqvm63b323O4XHQ+cF6RhA3kwbXd2QkmVrkPkYxClNM5Ae jrFKQ88eQfjLiwUoIaS/U6xsCgY2is6zvm6vtdm/nog4M/XfvQ7jEVenAiQA/0Qs4X48 DjNw== X-Gm-Message-State: ACrzQf18INHX+c/VJG1p4D/LuCW3CqBUeEEVeTG4An3oIm3NEomsxMe2 9/ehb1Bg0/tq6BzWm+LMDl1BRhJmq0U= X-Google-Smtp-Source: AMsMyM5X3OB6aEeGLeQLVQfVbKHZtgAj2qBH48JXa3VUz+BXLdWA5c9fgCY2t23mBk0+UFbAFTnGkA== X-Received: by 2002:a63:5243:0:b0:43c:96a:8528 with SMTP id s3-20020a635243000000b0043c096a8528mr403869pgl.47.1665070761562; Thu, 06 Oct 2022 08:39:21 -0700 (PDT) Received: from localhost.localdomain (61-227-97-62.dynamic-ip.hinet.net. [61.227.97.62]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0017829f986a5sm12723872plg.133.2022.10.06.08.39.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 08:39:20 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/3][SRU][OEM-6.0/Unstable] platform/x86/amd/pmf: Add sysfs to toggle CnQF Date: Thu, 6 Oct 2022 23:38:33 +0800 Message-Id: <20221006153834.573628-3-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221006153834.573628-1-vicamo.yang@canonical.com> References: <20221006153834.573628-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.179; envelope-from=vicamo@gmail.com; helo=mail-pg1-f179.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Shyam Sundar S K BugLink: https://bugs.launchpad.net/bugs/1991609 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 Signed-off-by: Shyam Sundar S K Link: https://lore.kernel.org/r/20220922131202.56529-3-Shyam-sundar.S-k@amd.com Signed-off-by: Hans de Goede (cherry picked from commit 3dae5825295d7b3284fc349cd6bfa641f4033e16 linux-next) Signed-off-by: You-Sheng Yang (vicamo) --- drivers/platform/x86/amd/pmf/cnqf.c | 60 +++++++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/core.c | 6 +++ drivers/platform/x86/amd/pmf/pmf.h | 1 + 3 files changed, 67 insertions(+) diff --git a/drivers/platform/x86/amd/pmf/cnqf.c b/drivers/platform/x86/amd/pmf/cnqf.c index 27fc3f909960..927f3c8cd971 100644 --- a/drivers/platform/x86/amd/pmf/cnqf.c +++ b/drivers/platform/x86/amd/pmf/cnqf.c @@ -302,6 +302,66 @@ static int amd_pmf_load_defaults_cnqf(struct amd_pmf_dev *dev) return 0; } +static ssize_t cnqf_enable_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct amd_pmf_dev *pdev = dev_get_drvdata(dev); + int mode, result, src; + bool input; + + mode = amd_pmf_get_pprof_modes(pdev); + if (mode < 0) + return mode; + + result = kstrtobool(buf, &input); + if (result) + return result; + + src = amd_pmf_cnqf_get_power_source(pdev); + pdev->cnqf_enabled = input; + + if (pdev->cnqf_enabled && pdev->current_profile == PLATFORM_PROFILE_BALANCED) { + amd_pmf_set_cnqf(pdev, src, config_store.current_mode, NULL); + } else { + if (is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) + amd_pmf_update_slider(pdev, SLIDER_OP_SET, mode, NULL); + } + + dev_dbg(pdev->dev, "Received CnQF %s\n", input ? "on" : "off"); + return count; +} + +static ssize_t cnqf_enable_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct amd_pmf_dev *pdev = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%s\n", pdev->cnqf_enabled ? "on" : "off"); +} + +static DEVICE_ATTR_RW(cnqf_enable); + +static umode_t cnqf_feature_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct amd_pmf_dev *pdev = dev_get_drvdata(dev); + + return pdev->cnqf_supported ? attr->mode : 0; +} + +static struct attribute *cnqf_feature_attrs[] = { + &dev_attr_cnqf_enable.attr, + NULL +}; + +const struct attribute_group cnqf_feature_attribute_group = { + .is_visible = cnqf_feature_is_visible, + .attrs = cnqf_feature_attrs, +}; + void amd_pmf_deinit_cnqf(struct amd_pmf_dev *dev) { cancel_delayed_work_sync(&dev->work_buffer); diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index 5782b56e708b..6646e2490707 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -388,10 +388,16 @@ static int amd_pmf_remove(struct platform_device *pdev) return 0; } +static const struct attribute_group *amd_pmf_driver_groups[] = { + &cnqf_feature_attribute_group, + NULL, +}; + static struct platform_driver amd_pmf_driver = { .driver = { .name = "amd-pmf", .acpi_match_table = amd_pmf_acpi_ids, + .dev_groups = amd_pmf_driver_groups, }, .probe = amd_pmf_probe, .remove = amd_pmf_remove, diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 41493508d5cb..3983f1315e75 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -422,5 +422,6 @@ int apmf_get_dyn_slider_def_dc(struct amd_pmf_dev *pdev, struct apmf_dyn_slider_ int amd_pmf_init_cnqf(struct amd_pmf_dev *dev); void amd_pmf_deinit_cnqf(struct amd_pmf_dev *dev); int amd_pmf_trans_cnqf(struct amd_pmf_dev *dev, int socket_power, ktime_t time_lapsed_ms); +extern const struct attribute_group cnqf_feature_attribute_group; #endif /* PMF_H */