From patchwork Wed Oct 11 07:24:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 115514 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp437894qgn; Wed, 11 Oct 2017 00:25:01 -0700 (PDT) X-Received: by 10.98.16.81 with SMTP id y78mr15511295pfi.114.1507706701099; Wed, 11 Oct 2017 00:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507706701; cv=none; d=google.com; s=arc-20160816; b=xrLIGamJsADdAM2cTjPi20GEvHDL3nXG3kOlOdUd+dthOshT/nmOSh74bBGwSNg3bb LV3hXIwmIGfi1Ywul8fo+t42CLCpkRSNzZfk/9vZt+81dPTnP6yKHQsB/ns6GOrEe0kD NtF4rt/iRLpx6DiiwK35sQ5jm1bYz6MZau9BbjgEZSvTPz6Huq6aDWbmZ5Y6WIII4V2X baaW+tXseGueP5gDapAb7aPgyzx81hhHaY+kYsSudmNumBDJDnkf+0RSoivtoICr+4G+ hGOGUAwarA4tnlEczRhinm8LqnLimKxlrWHR9xi/dZSvUcltb6LTuEToutxCy4V5GDXa EZLg== 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=+EvDB4S+S/4HK7dx6TlIznzXvikzDBuTdFNyAbtvn9o=; b=nM3hj8yVHnwaYERtP6d/2WOLjm9tKgY65Y3vbVCNMWoAtxTU27t6k71cdFc/7UAx3A bVWp5Iu8CixlKJl5EqpRsaftF3EzplFOUPlRej7J5VpLQ8XxmIFAma6KCnmUYyUEziPR qw823YiO9XrF/t8bzADn2/E/61KR26Qk8v8veP2gAtHv4rPMSj9zGoT2RgKxrXL8N8gk oljGQkc39Q3AuVjmQQ7B4HLvYuGGWgfJ8dJbpqSKlQpdQBBZ1eajGiRYcoMWQb7FNzqq UCljKRIyJ8kVc6kj+Vdl8TUmxx5LSXX9UlDRmk1zI8AkkSe0j//V8GcFwPcwszdk/UyA ah3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JMCHrRET; 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 o82si4750361pfj.249.2017.10.11.00.25.00; Wed, 11 Oct 2017 00:25:01 -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=JMCHrRET; 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 S1757043AbdJKHY6 (ORCPT + 12 others); Wed, 11 Oct 2017 03:24:58 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:55914 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756638AbdJKHYz (ORCPT ); Wed, 11 Oct 2017 03:24:55 -0400 Received: by mail-pg0-f45.google.com with SMTP id b11so554486pgn.12 for ; Wed, 11 Oct 2017 00:24:55 -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=+EvDB4S+S/4HK7dx6TlIznzXvikzDBuTdFNyAbtvn9o=; b=JMCHrRETAQS+dmrX1zfmtFLqgBdmAMdVQy5wai0tntyMUWjd57Mv+ByB9YxwEqTkto QGOganD+a+BOUjtwO0kw8/riAvwrCHi8Ppk/C6Xj/yrRWGr0+yzaBn+d4PQavWGkBS1+ vn33QC4cNJ5AY8yXIEDjDUwXioHYCCyJa2ocE= 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=+EvDB4S+S/4HK7dx6TlIznzXvikzDBuTdFNyAbtvn9o=; b=Vcd8xrity36ZLWc+Oh5HVhOzLE+DhQcypTSW+9aHcJPXi59kM5jD0MTlaVYXS4fzNA XBIAQRW75y6di6wxJd0yDmCtx8QCD/H/25KjvPyxzK63Z4uOxdO2DvQ7dwv9lIOuFpvZ XNYqKJzc0vcXne9/VQld+1jQBpuzt5LdfvI9vOpF0Q/Og9bwYMkcJAjp/Yy4ELiD6xwO 9BpRARHPngIgdW33Lg1KhYyygSoP4XzFvQIzoy4creJaqFDhXFUby/QcM8rD2k7BpXYp LM1PVMlokC5hDVMY9JU3uxu27msA+r8SKUEWCRh72lnsSJJafxl8MsPHSJ+ulgPVru3A WzgA== X-Gm-Message-State: AMCzsaWMHcQTvRVm32kM2WIFykUu+pPwwYSs5MjVz/J6PC77HeA9hraI VPf6XF0vu5IEZqVtg+qEF0omQg== X-Google-Smtp-Source: AOwi7QDCdgITpuJCR+Vne2DbvDw8Whc0GyvahoSXLTl26qVG0v6oJZCpRNZ+f/eusROp8n//vWAVtA== X-Received: by 10.84.129.229 with SMTP id b92mr14936598plb.362.1507706695157; Wed, 11 Oct 2017 00:24:55 -0700 (PDT) Received: from localhost ([122.172.169.205]) by smtp.gmail.com with ESMTPSA id 66sm21082623pgh.31.2017.10.11.00.24.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 00:24:54 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ulf.hansson@linaro.org, Kevin Hilman , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Nishanth Menon , robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, sudeep.holla@arm.com, linux-kernel@vger.kernel.org, Len Brown , Pavel Machek , Andy Gross , David Brown Subject: [PATCH V11 3/7] OPP: Add dev_pm_opp_{un}register_get_pstate_helper() Date: Wed, 11 Oct 2017 12:54:15 +0530 Message-Id: <0e5c4f9e8c51ac8b1226932dbcb30e31610a3ed3.1507703370.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 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 adds the dev_pm_opp_{un}register_get_pstate_helper() helper routines which will be used to set the get_pstate() callback for a device. This callback will be later called internally by the OPP core to get performance state corresponding to an OPP. This is required temporarily until the time we have proper DT bindings to include the performance state information. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/opp/opp.h | 2 ++ include/linux/pm_opp.h | 10 +++++++ 3 files changed, 90 insertions(+) -- 2.7.4 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 0ce8069d6843..92fa94a6dcc1 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1036,6 +1036,9 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, return ret; } + if (opp_table->get_pstate) + new_opp->pstate = opp_table->get_pstate(dev, new_opp->rate); + list_add(&new_opp->node, head); mutex_unlock(&opp_table->lock); @@ -1548,6 +1551,81 @@ void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper); /** + * dev_pm_opp_register_get_pstate_helper() - Register get_pstate() helper. + * @dev: Device for which the helper is getting registered. + * @get_pstate: Helper. + * + * TODO: Remove this callback after the same information is available via Device + * Tree. + * + * This allows a platform to initialize the performance states of individual + * OPPs for its devices, until we get similar information directly from DT. + * + * This must be called before the OPPs are initialized for the device. + */ +struct opp_table *dev_pm_opp_register_get_pstate_helper(struct device *dev, + int (*get_pstate)(struct device *dev, unsigned long rate)) +{ + struct opp_table *opp_table; + int ret; + + if (!get_pstate) + return ERR_PTR(-EINVAL); + + opp_table = dev_pm_opp_get_opp_table(dev); + if (!opp_table) + return ERR_PTR(-ENOMEM); + + /* This should be called before OPPs are initialized */ + if (WARN_ON(!list_empty(&opp_table->opp_list))) { + ret = -EBUSY; + goto err; + } + + /* Already have genpd_performance_state set */ + if (WARN_ON(opp_table->genpd_performance_state)) { + ret = -EBUSY; + goto err; + } + + opp_table->genpd_performance_state = true; + opp_table->get_pstate = get_pstate; + + return opp_table; + +err: + dev_pm_opp_put_opp_table(opp_table); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_register_get_pstate_helper); + +/** + * dev_pm_opp_unregister_get_pstate_helper() - Releases resources blocked for + * get_pstate() helper + * @opp_table: OPP table returned from dev_pm_opp_register_get_pstate_helper(). + * + * Release resources blocked for platform specific get_pstate() helper. + */ +void dev_pm_opp_unregister_get_pstate_helper(struct opp_table *opp_table) +{ + if (!opp_table->genpd_performance_state) { + pr_err("%s: Doesn't have performance states set\n", + __func__); + return; + } + + /* Make sure there are no concurrent readers while updating opp_table */ + WARN_ON(!list_empty(&opp_table->opp_list)); + + opp_table->genpd_performance_state = false; + opp_table->get_pstate = NULL; + + dev_pm_opp_put_opp_table(opp_table); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_get_pstate_helper); + +/** * dev_pm_opp_add() - Add an OPP table from a table definitions * @dev: device for which we do this operation * @freq: Frequency in Hz for this OPP diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index e8f767ab5814..4d00061648a3 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -140,6 +140,7 @@ enum opp_table_access { * @genpd_performance_state: Device's power domain support performance state. * @set_opp: Platform specific set_opp callback * @set_opp_data: Data to be passed to set_opp callback + * @get_pstate: Platform specific get_pstate callback * @dentry: debugfs dentry pointer of the real device directory (not links). * @dentry_name: Name of the real dentry. * @@ -177,6 +178,7 @@ struct opp_table { int (*set_opp)(struct dev_pm_set_opp_data *data); struct dev_pm_set_opp_data *set_opp_data; + int (*get_pstate)(struct device *dev, unsigned long rate); #ifdef CONFIG_DEBUG_FS struct dentry *dentry; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 849d21dc4ca7..6c2d2e88f066 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -125,6 +125,8 @@ struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name); void dev_pm_opp_put_clkname(struct opp_table *opp_table); struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); +struct opp_table *dev_pm_opp_register_get_pstate_helper(struct device *dev, int (*get_pstate)(struct device *dev, unsigned long rate)); +void dev_pm_opp_unregister_get_pstate_helper(struct opp_table *opp_table); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); @@ -245,6 +247,14 @@ static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {} +static inline struct opp_table *dev_pm_opp_register_get_pstate_helper(struct device *dev, + int (*get_pstate)(struct device *dev, unsigned long rate)) +{ + return ERR_PTR(-ENOTSUPP); +} + +static inline void dev_pm_opp_unregister_get_pstate_helper(struct opp_table *opp_table) {} + static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) { return ERR_PTR(-ENOTSUPP);