Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1028870lqp; Fri, 22 Mar 2024 03:32:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKlRIjNVIloGxVf0pHgPY+QGvemFWZ4cGlufHFKjX7mV8yYi25fvoQaB0ITSvMKbLaGw7k+zTImTcL1GPvkrgaYJUmrNxDtMepEP7Kog== X-Google-Smtp-Source: AGHT+IECx1crIAepBWPcoeVRY4MKDZQRTQqkKF0Pig/Cw0vTvHO028Agl7hjZto8fiVY+bftl6f1 X-Received: by 2002:a17:906:57d6:b0:a47:31c7:877a with SMTP id u22-20020a17090657d600b00a4731c7877amr828493ejr.36.1711103578302; Fri, 22 Mar 2024 03:32:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711103578; cv=pass; d=google.com; s=arc-20160816; b=ku9HMn/RwVgQVdY0fecRlRIPhGvXWcr2ZVHbi7jDEKS62raDaAcTWn8FUwuKV8+tb3 c4eKijobGAll/dTKwAqPrC6zaDIeq4R3sTTqV3N3Y7TwGN/xpJPx9pWcakqPDQ51QGe0 dTvQG55A85hGE3kNn4lxSYkiFErOWvfRlkl0FHVSifnfHz0tNKzYrqKKeIkC+mLf6KMz 2/mCouBj30KmlmZ7yG6ukn+DthFVBL5rgkzUz2/sDYBSPCcA1FsEBzRkM7aRyz8Xh3OP uv3JOp2ayHWMg2MrD0MPuzqygdN364rMEvFfIirJ106QmMNm9zJX052xSS1dUve/ltCe l0xQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=zO0qrSVC1R5O3AS+aIFyop7Gs2mxc9B7/Sq9zMX2faE=; fh=76fY95VCn/tTPDURHIWBg4FyCkia1KFHdPTfdxMrHno=; b=CkjbDvwwpMqf578M7IyVvNSyDJElctb7nWaeqTjrKGCGVdzwbTu6BIBP5D2P6gfdBN 8ONus7ZpY3WtlZ40rUUeX6DziJ/AwvtJMdg6fUXufFU8JT+N+WoP9y4CvzR9k3i2bj3A pF760obLeVMmgBx41X0saqyGbP56hZScVxZ6pX0V9lK3YffjF3lfk/Z0K0ZwAMZJy9fb ejPzMNOOMA6+E4M6dX6uFXf/m+9hm2SW1C8nV5VRE4QV+JBl4TNdH+5NqJMgmyz6Aum4 84A7eE6Cwk/I/5EVzMjpQPlHNWqRtp/REzGf/uOM5ATk4AK45N56fiOSrSxdzs2h3lJ7 pe/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-111298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111298-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bm19-20020a170906c05300b00a46960a6004si819303ejb.692.2024.03.22.03.32.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 03:32:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-111298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111298-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0BD921F23D5F for ; Fri, 22 Mar 2024 10:32:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D97773E48C; Fri, 22 Mar 2024 10:32:39 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBBCD3D0B3; Fri, 22 Mar 2024 10:32:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711103559; cv=none; b=hNZMd9Swxt8RZldMnsgG+VuKY/X5W6Hb16+iQn4TtZt3Q+PGVyUDcDhjdiauHL8LaGwodbtvj+MEfakeroSbKJRyONdNzeYAMVy8GKyzXTqneUO+bwSPzL1krgzxs8/P722LpOdxIgBhcBUwVLpGwCRrapFT4HHDW6AmOsLZQDY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711103559; c=relaxed/simple; bh=bFPxBTU77mGhL91p/41T1PoxIRZa3kPq4lKmoQM1d+c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cb0dbITZpJI9qAfkg7FXo8o94TSDhKYke9e+25acwKXKOK3aBn0j3JRLqIZiugXTU7aN0FgZHbaYNNe1ABdHg7H350E1orwT30G2hMEo8LHAeVDdJIZVG0RrL549CKHgG9mDc4uq39HT6qipY0DHxtnpDX9QoFG3bFQT4Ie9jQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3F3671063; Fri, 22 Mar 2024 03:33:11 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.71.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A035E3F64C; Fri, 22 Mar 2024 03:32:34 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, linux-arm-kernel@lists.infradead.org, sboyd@kernel.org, nm@ti.com, linux-samsung-soc@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org, viresh.kumar@linaro.org, krzysztof.kozlowski@linaro.org, alim.akhtar@samsung.com, m.szyprowski@samsung.com, mhiramat@kernel.org Subject: [PATCH v2 1/4] OPP: OF: Export dev_opp_pm_calc_power() for usage from EM Date: Fri, 22 Mar 2024 10:32:18 +0000 Message-Id: <20240322103221.47594-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240322103221.47594-1-lukasz.luba@arm.com> References: <20240322103221.47594-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There are device drivers which can modify voltage values for OPPs. It could be due to the chip binning and those drivers have specific chip knowledge about it. This adjustment can happen after Energy Model is registered, thus EM can have stale data about power. Export dev_opp_pm_calc_power() which can be used by Energy Model to calculate new power with the new voltage for OPPs. Signed-off-by: Lukasz Luba --- drivers/opp/of.c | 17 ++++++++++++----- include/linux/pm_opp.h | 8 ++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index f9f0b22bccbb4..282eb5966fd03 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -1494,20 +1494,26 @@ _get_dt_power(struct device *dev, unsigned long *uW, unsigned long *kHz) return 0; } -/* - * Callback function provided to the Energy Model framework upon registration. +/** + * dev_pm_opp_calc_power() - Calculate power value for device with EM + * @dev : Device for which an Energy Model has to be registered + * @uW : New power value that is calculated + * @kHz : Frequency for which the new power is calculated + * * This computes the power estimated by @dev at @kHz if it is the frequency * of an existing OPP, or at the frequency of the first OPP above @kHz otherwise * (see dev_pm_opp_find_freq_ceil()). This function updates @kHz to the ceiled * frequency and @uW to the associated power. The power is estimated as * P = C * V^2 * f with C being the device's capacitance and V and f * respectively the voltage and frequency of the OPP. + * It is also used as a callback function provided to the Energy Model + * framework upon registration. * * Returns -EINVAL if the power calculation failed because of missing * parameters, 0 otherwise. */ -static int __maybe_unused _get_power(struct device *dev, unsigned long *uW, - unsigned long *kHz) +int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW, + unsigned long *kHz) { struct dev_pm_opp *opp; struct device_node *np; @@ -1544,6 +1550,7 @@ static int __maybe_unused _get_power(struct device *dev, unsigned long *uW, return 0; } +EXPORT_SYMBOL_GPL(dev_pm_opp_calc_power); static bool _of_has_opp_microwatt_property(struct device *dev) { @@ -1619,7 +1626,7 @@ int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus) goto failed; } - EM_SET_ACTIVE_POWER_CB(em_cb, _get_power); + EM_SET_ACTIVE_POWER_CB(em_cb, dev_pm_opp_calc_power); register_em: ret = em_dev_register_perf_domain(dev, nr_opp, &em_cb, cpus, true); diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 065a47382302c..31370deb9905f 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -476,6 +476,8 @@ struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp); int of_get_required_opp_performance_state(struct device_node *np, int index); int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table); int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus); +int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW, + unsigned long *kHz); static inline void dev_pm_opp_of_unregister_em(struct device *dev) { em_dev_unregister_perf_domain(dev); @@ -539,6 +541,12 @@ static inline void dev_pm_opp_of_unregister_em(struct device *dev) { } +static inline int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW, + unsigned long *kHz) +{ + return -EOPNOTSUPP; +} + static inline int of_get_required_opp_performance_state(struct device_node *np, int index) { return -EOPNOTSUPP; -- 2.25.1