From patchwork Mon Apr 9 11:43:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 133032 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp168467ljb; Mon, 9 Apr 2018 04:44:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/iS2QtfwsX4WVuJOm4disy5bmNr6UxeCZYpc9GhiUN7LjU1ByQLT0zLAdpWgc+a4jn8OC X-Received: by 2002:a17:902:a70f:: with SMTP id w15-v6mr38616529plq.344.1523274282728; Mon, 09 Apr 2018 04:44:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523274282; cv=none; d=google.com; s=arc-20160816; b=KNrXd3Ug1zxfvLv4eDQ9rIeyEnKE5SCD513iOxE2rmfP+Y2OYr7BNXg/EeVY1RjTTD czUbDh9vONJKFYzSb1QecwZGZHelz4hg+hynKgICsfPEchJ5jiaEMG6dw8Zpfdp1Kvyi 6eyuYJj+kUGLOjfSwkqCvHf6svrAfecXC9kV91Wj2RxLmRV/+w4+licv2LtbEq3mYSev TWCQEmxvyOXUpZu2/VXdA4O7SPWlcz5/1Ta4DsHOKCfZlWSJp6ZQFCRvop2nIi6egcmn EyKCpB0G1AXCmlgIUOjROysqr2CdPfHOJWYbkoLway0CgZrE/ik+pwMJYwbM7Z0siN0x d1Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=b66fYmTqfnBB5WbKJetCcqHsTA7X6RwIkxdR9YdwXqw=; b=QNXWS7W4e2F9iLl5aKUpRo1geYLqkUGA4d+xSawcaAGozdSaFr9hmgtYYktg8fOmVC obC7Ba7Ah/pexv4wPTxhr5lNYYTDT5n4yTaxkfRwffjGgOsw6LffCwcI4CU8eRTllPd9 abLFeC5kQw9mRiciAFQCbvsKDTbPhhRiCT7JNgu24/+9otUYhwR4GTl3+wl9xJIMpAQt Siyi9cwzEAX/6IPnjpxacRspbR8JQZrdhD5nkCCsFQtPdgGqadtHAZYx1/affLKz80ZU QWWDWwuiN6Ew3yQIDberM+CIFiAMbRigE4L17yvD+HlGK2vNLZTMGCqBNpPMpq+JJa2y KdtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g8ON9qmz; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si153720pls.422.2018.04.09.04.44.42; Mon, 09 Apr 2018 04:44:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g8ON9qmz; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752249AbeDILoi (ORCPT + 11 others); Mon, 9 Apr 2018 07:44:38 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:43369 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752234AbeDILog (ORCPT ); Mon, 9 Apr 2018 07:44:36 -0400 Received: by mail-pl0-f68.google.com with SMTP id a39-v6so4949733pla.10 for ; Mon, 09 Apr 2018 04:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=b66fYmTqfnBB5WbKJetCcqHsTA7X6RwIkxdR9YdwXqw=; b=g8ON9qmzcrWX3fZ6h60eu519e8pNZvwZbdmPWdj0A0D/Rndb7gzG+cE8iSyomNQdII SF53s+1GVRP62qyXaJJxSAwRRR3KRukia3MeNcLJjAnVXWLJ7RAgrcti0lTV7FqO1mj0 uptYvwlaseYQOrqyk+zwm7zLI5hE2BUcfNrQM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=b66fYmTqfnBB5WbKJetCcqHsTA7X6RwIkxdR9YdwXqw=; b=Khkd4wVFjS5NgnxzIYVH/XwpY5o3nPlhSkdSlcNSNiMlP1YOuvsr+XkDn+dOXUtPJ0 2LrsoRt5xIgO/w1ZPZGgcFO93H+w3T+dGedEeWRrSFtMa5flaImazMOxjYg0DIuF7YQK JMax13FH28AZ+U9ZZShSJvbjLl2EMnOOAU49qUZqv/NgJqk1PUAfaGpN1C51inE3aUzm s1PPRQzQm/QaoRVkcMLN1eS4Pxs07oSyAGNRwXJTMOBCZGRNHz405PKnr7HMz2zqB+T6 QSzWdhnoGxjh4BWTsWwdqU8er400JwGDdbRyrappukeJhVuZ5on7dpjGaO8zC09M0dkG 4Q1A== X-Gm-Message-State: AElRT7HCkO1r9HgYziWOBw0qRFu7KFOl1rVObl1lLAVJyAEFBsPpPO/g XnifOsUBvhUe65Wenm/rRvra2w== X-Received: by 2002:a17:902:7045:: with SMTP id h5-v6mr38459311plt.1.1523274276388; Mon, 09 Apr 2018 04:44:36 -0700 (PDT) Received: from localhost ([122.171.228.188]) by smtp.gmail.com with ESMTPSA id q15sm621844pfi.140.2018.04.09.04.44.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Apr 2018 04:44:35 -0700 (PDT) From: Viresh Kumar To: Ulf Hansson , Stephen Boyd , "Rafael J. Wysocki" , Kevin Hilman , Len Brown , Pavel Machek Cc: Viresh Kumar , Rajendra Nayak , Vincent Guittot , linux-pm@vger.kernel.org Subject: [PATCH V2 09/11] PM / Domain: Implement of_dev_pm_genpd_opp_to_performance_state() Date: Mon, 9 Apr 2018 17:13:49 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This implements of_dev_pm_genpd_opp_to_performance_state() which can be used from the device drivers or the OPP core to find the performance state encoded in the "required-opps" property of a node. Normally this would be called only once for each OPP of the device for which the OPP table of the device is getting generated. Different platforms may encode the performance state differently using the OPP table (they may simply return value of opp-hz or opp-microvolt, or apply some algorithm on top of those values) and so a new callback ->opp_to_performance_state() is implemented to allow platform specific drivers to convert the power domain OPP to a performance state value. Signed-off-by: Viresh Kumar --- drivers/base/power/domain.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 12 ++++++++++++ 2 files changed, 60 insertions(+) -- 2.15.0.194.g9af6a3dea062 Acked-by: Ulf Hansson Signed-off-by: Viresh Kumar Acked-by: Ulf Hansson diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 5c0019d70d76..5efdf67220f8 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2412,6 +2412,54 @@ int of_genpd_parse_idle_states(struct device_node *dn, } EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states); +/** + * of_dev_pm_genpd_opp_to_performance_state- Gets performance state of device's + * power domain corresponding to a DT node's "required-opps" property. + * + * @dev: Device for which the performance-state needs to be found. + * @opp_node: DT node where the "required-opps" property is present. This can be + * the device node itself (if it doesn't have an OPP table) or a node + * within the OPP table of a device (if device has an OPP table). + * @state: Pointer to return performance state. + * + * Returns performance state corresponding to the "required-opps" property of + * a DT node. This calls platform specific genpd->opp_to_performance_state() + * callback to translate power domain OPP to performance state. + * + * Returns performance state on success and 0 on failure. + */ +unsigned int of_dev_pm_genpd_opp_to_performance_state(struct device *dev, + struct device_node *opp_node) +{ + struct generic_pm_domain *genpd; + struct dev_pm_opp *opp; + int state = 0; + + genpd = dev_to_genpd(dev); + if (IS_ERR(genpd)) + return 0; + + if (unlikely(!genpd->set_performance_state)) + return 0; + + genpd_lock(genpd); + + opp = of_dev_pm_opp_find_required_opp(&genpd->dev, opp_node); + if (IS_ERR(opp)) { + state = PTR_ERR(opp); + goto unlock; + } + + state = genpd->opp_to_performance_state(genpd, opp); + dev_pm_opp_put(opp); + +unlock: + genpd_unlock(genpd); + + return state; +} +EXPORT_SYMBOL_GPL(of_dev_pm_genpd_opp_to_performance_state); + #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index aaacaa35005d..fc1b723b03a1 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -47,6 +47,7 @@ struct genpd_power_state { }; struct genpd_lock_ops; +struct dev_pm_opp; struct generic_pm_domain { struct device dev; @@ -68,6 +69,8 @@ struct generic_pm_domain { unsigned int performance_state; /* Aggregated max performance state */ int (*power_off)(struct generic_pm_domain *domain); int (*power_on)(struct generic_pm_domain *domain); + unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd, + struct dev_pm_opp *opp); int (*set_performance_state)(struct generic_pm_domain *genpd, unsigned int state); struct gpd_dev_ops dev_ops; @@ -244,6 +247,8 @@ extern int of_genpd_add_subdomain(struct of_phandle_args *parent, extern struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); extern int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n); +extern unsigned int of_dev_pm_genpd_opp_to_performance_state(struct device *dev, + struct device_node *opp_node); int genpd_dev_pm_attach(struct device *dev); #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ @@ -279,6 +284,13 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn, return -ENODEV; } +static inline unsigned int +of_dev_pm_genpd_opp_to_performance_state(struct device *dev, + struct device_node *opp_node) +{ + return -ENODEV; +} + static inline int genpd_dev_pm_attach(struct device *dev) { return -ENODEV;