Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2801407lqz; Wed, 3 Apr 2024 09:00:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWFXabYfYLjzqcsF52J5FeZKjAlAQFdo8kqaaADoRbdYCstiDzCaKl6FsSJcAvb1tk2Aand3DKB+uf+294CNxcbQQAI29xFjP7FcPDPWw== X-Google-Smtp-Source: AGHT+IHppcye+l2JAOXZcBbVupNdz30erziQ4S/YKEozaVFGDXMPS5MBiP3h9y3JF4datfeqNcbW X-Received: by 2002:a05:6a00:3ccb:b0:6ea:c2c7:5d6a with SMTP id ln11-20020a056a003ccb00b006eac2c75d6amr21424952pfb.2.1712160039561; Wed, 03 Apr 2024 09:00:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712160039; cv=pass; d=google.com; s=arc-20160816; b=GwbN0JaqzG9XHE3nDK5GJRQZBqBKizMwn9fRfI9BbFovmqRk8ZicO++zaRec7pdyIr f8xH1sUbMbKOUXdIPyiAfZ/VuE0Ne8ssDgs+ttuExrzJZR37pME2Ay1J4LDpRbxGFduA UDCwTIFWnsWhzc2J+pJL/35loBQM4RR2QVoBF83g+YNX0eyYdnuDjJni2DU6K4FqoG2q Du0J9qBYuEgoa5r+D3nQJEdMB3XSDimiUHhwgcE0QtX+Icy5IMWdbspnpEyXu/s7GZ9H oG1BZivizwjZHcD6S+U3ka0fUCAzFj5NjLFFfHVeVtMySLDmx6y36Ycl4bfwFAt5i1sU HxeQ== 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=Fh+2CW+cMocU82j5vKTQfOwv3Quf/Rw9S4d6TiRQLck=; fh=FmC2hJpJhN2HT2Kov+KiTeKhNOezP0K1ntHb8ZYpOKY=; b=VsLcTZVoYOnR1/hdWiNdOWIwbQlKfaaD1Wvi6RNPOC2FGSEc7PE2fn+Se/vEersMo9 MR1fUWaKdYIxre+hswWS0+IQc6dPgy/LRn1EVeLlBjgttVYUg3ov5a/73JRADiEPX7m8 LRlxZ3NC0XNzNhw1EEst17dlsuHMsNMdzNLreG2uZORZYiahzCDTvfP7Kit3uxY/1aIl 7wsQtUXvCA1+TOTtQXvQpKmlS36KpdukF41mdSC8mOcXdMeNwV5fRDp1a+Fkj8THbPEj EFMiXIt8MegDdpQmDsAKcezlUhdt5QvdWYfljIZohmHaDxN9RdsYQWAnu9XqtQIzcQRt DKFA==; 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-130129-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s25-20020aa78d59000000b006ead4e87791si12848012pfe.6.2024.04.03.09.00.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 09:00:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130129-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-130129-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130129-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 59056291533 for ; Wed, 3 Apr 2024 15:50:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFC9A14BFB8; Wed, 3 Apr 2024 15:49:30 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 592DD14AD19; Wed, 3 Apr 2024 15:49:28 +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=1712159370; cv=none; b=Pl7FH/usXxTO7YwfsxxwrKBiKR0hKyO/Qwt4bwEEadKBJ6i+qBS/5p/DyebDgfaux2AagmaUsyzqMy30nrQlZOHoLnuXWXBnY7kFLcR4gGXjZdykIe8/iH0Q0aSLtC2XYciXIkvs5aJNK9reimPzfCpDm00Cy7LbhlblM6g2zKk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712159370; c=relaxed/simple; bh=w4tmkP98AiEoSSbRmXKPM8b84i8vRUgubnaUqN+P9Mk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ky3DUSL81Ojz61+B35+pCjvr1FM4tTZcpPJ1ScSotTR5xwSO1RbHtYOEm+zwy7WJ0s3lcb5L4DhSrU8ck8uimHRQEPEPtVqCfbBhdDOtVGDfdJqaAwJAEgwffg+8ckf1VlSPyhIKg2rZ91jbWKGmfXzZ/tr81NvIWDw4/mknvzw= 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 A85571595; Wed, 3 Apr 2024 08:49:58 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.72.191]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1BC2B3F7B4; Wed, 3 Apr 2024 08:49:24 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@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, viresh.kumar@linaro.org, krzysztof.kozlowski@linaro.org, alim.akhtar@samsung.com, m.szyprowski@samsung.com, mhiramat@kernel.org Subject: [PATCH v5 1/4] OPP: OF: Export dev_opp_pm_calc_power() for usage from EM Date: Wed, 3 Apr 2024 16:49:04 +0100 Message-Id: <20240403154907.1420245-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240403154907.1420245-1-lukasz.luba@arm.com> References: <20240403154907.1420245-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. Acked-by: Viresh Kumar Reviewed-by: Dietmar Eggemann 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..dd7c8441af424 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