From patchwork Wed Jun 21 04:59:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 106039 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1747146qgd; Tue, 20 Jun 2017 21:59:52 -0700 (PDT) X-Received: by 10.84.175.67 with SMTP id s61mr40412055plb.151.1498021192745; Tue, 20 Jun 2017 21:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498021192; cv=none; d=google.com; s=arc-20160816; b=KSKdQc6CNT02lMcwRlP66qL/vAjS8r/ZAWWy9l9rdyBQvS+6PTRkURYj6NZFLEG4BX 2Npp6xZQ2K33jLwjYmM+mT4Th0m9oPJOabrrVE/zJHZwezNrp8W/Cpa9wObci2HsMphU ALxWztPUsJ3gSZ8WlL1N9rCXfZWSuzRR/QHl0ZBNIKF8/sctsH1XGeQFLRyul1OfHWaR a7VV4r0V0qi4Fbj/R6ifT1Gsgf2sfvAzck/JK6MlxqFP3gtFHFPi+bmcKQVXymrrIZkL gdE2jN8FuoiGxy040IWRf7j84E7djTeFNcB24gMWEpViHfAhuS7/dION18aTenMFlXF2 mXsA== 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:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=rSySYo1XhLguLaUs+sN8mamlH3IRlFTAmQOL4YCQ7Io=; b=OO5bDD5vYJ4Hq+ffYZNkeKGPnvCS9RE16et/S+rWt63q7coZxmoB7revndfgl1dNGA fB91bgfvO5xTPHujPAG7pTUZrHstINRRIKbXEN7ew5oC5n6AmVvUqi4c1CkKjGvurdCr hWUK355alGO3hg6Ada8WQhpADEbtuii8EH1j5qSdHLmqAAoj5HQVBa6eN4ALEAd0BVL/ x/hfUxSHyX7QuJEyeYvKVVv10nYd9jvyiodCq++L0JoBFz0pC4Dd3dRjbvTQketztBP0 uD/trPKWOmzpeYw7MAh8lBmtA5aM5n6Wfe5WS9bSSlleXko8mZtWuoYbHwUVCEQSc/te d+ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=I8AJfCmh; 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 i62si12144678pfi.231.2017.06.20.21.59.51; Tue, 20 Jun 2017 21:59:52 -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.b=I8AJfCmh; 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 S1752138AbdFUE7u (ORCPT + 14 others); Wed, 21 Jun 2017 00:59:50 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:35910 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751763AbdFUE7t (ORCPT ); Wed, 21 Jun 2017 00:59:49 -0400 Received: by mail-pg0-f51.google.com with SMTP id u62so53073444pgb.3 for ; Tue, 20 Jun 2017 21:59:49 -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; bh=rSySYo1XhLguLaUs+sN8mamlH3IRlFTAmQOL4YCQ7Io=; b=I8AJfCmhhj4bLARyfg8sOqfNHsnpQ/mnEsBg6sccF6LkT06CZCcAGqC9accz6XaQdt CNsV8W1100do6E212Y/UQbBe0/+5XtwI3DU6yEuNwbeUbU2N6LnWnsY6nb3GEOu+r1l4 xKlSeF4LLx3fXOPmaBFh3gwZKFPsksntT3LsI= 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; bh=rSySYo1XhLguLaUs+sN8mamlH3IRlFTAmQOL4YCQ7Io=; b=AzYzhjM6dIQR67zE+lA4c0suKl5DRovpn8NbgdE9VwlMM1BU0+YYAK0ieIPR+6iJha x44OvGX5/GrG/FTsFyyxYnDVuKoubbH0g5iU/bHLB2ukzGI2jI2WUwy+7Qy/5o4KjCuV 9odKYifaHZffbIDJfwihRhFSoybj8pOWjvns5aDOftLq9599CSn4BR7UP01HGtc1FURj SQuPXBP5Ivp5goRi9qXaBtuJkOrZBALYy0UP3glttyhEzxxuxZej9NjzQEmh8ZUYhg3t gPcXdvKzJAy7gLLZ5M2jpdeZHL6UC1SdbZSdrpfNkCZuTUbUls2d3UWfbx5Qf0Nh6T4/ a5Gw== X-Gm-Message-State: AKS2vOzjCMupYUcH0R/4X02UD4ROu2Yi0FF0uQYq0dviuxl2IPcdL2Op k9XHVvFi1bkLr3cu X-Received: by 10.98.44.79 with SMTP id s76mr33915913pfs.189.1498021188819; Tue, 20 Jun 2017 21:59:48 -0700 (PDT) Received: from localhost ([122.172.59.234]) by smtp.gmail.com with ESMTPSA id c66sm27166221pfl.81.2017.06.20.21.59.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 21:59:48 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rajendra Nayak , linux-kernel@vger.kernel.org Subject: [PATCH V2] PM / OPP: Add dev_pm_opp_{set|put}_clkname() Date: Wed, 21 Jun 2017 10:29:13 +0530 Message-Id: <60e18f9d62e5cd65ae468beb065a3e3ebc205aa4.1498021098.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.13.0.71.gd7076ec9c9cb In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In order to support OPP switching, OPP layer needs to get pointer to the clock for the device. Simple cases work fine without using the routines added by this patch (i.e. by passing connection-id as NULL), but for a device with multiple clocks available, the OPP core needs to know the exact name of the clk to use. Add a new set of APIs to get that done. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- V1->V2: - No need to save clk_name, as we wouldn't use it again. drivers/base/power/opp/core.c | 67 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 9 ++++++ 2 files changed, 76 insertions(+) -- 2.13.0.71.gd7076ec9c9cb Reviewed-by: Stephen Boyd diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 5ee7aadf0abf..a8cc14fd8ae4 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -1363,6 +1363,73 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table) EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators); /** + * dev_pm_opp_set_clkname() - Set clk name for the device + * @dev: Device for which clk name is being set. + * @name: Clk name. + * + * In order to support OPP switching, OPP layer needs to get pointer to the + * clock for the device. Simple cases work fine without using this routine (i.e. + * by passing connection-id as NULL), but for a device with multiple clocks + * available, the OPP core needs to know the exact name of the clk to use. + * + * This must be called before any OPPs are initialized for the device. + */ +struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name) +{ + struct opp_table *opp_table; + int ret; + + 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 default clk set, free it */ + if (!IS_ERR(opp_table->clk)) + clk_put(opp_table->clk); + + /* Find clk for the device */ + opp_table->clk = clk_get(dev, name); + if (IS_ERR(opp_table->clk)) { + ret = PTR_ERR(opp_table->clk); + if (ret != -EPROBE_DEFER) { + dev_err(dev, "%s: Couldn't find clock: %d\n", __func__, + ret); + } + goto err; + } + + return opp_table; + +err: + dev_pm_opp_put_opp_table(opp_table); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_set_clkname); + +/** + * dev_pm_opp_put_clkname() - Releases resources blocked for clk. + * @opp_table: OPP table returned from dev_pm_opp_set_clkname(). + */ +void dev_pm_opp_put_clkname(struct opp_table *opp_table) +{ + /* Make sure there are no concurrent readers while updating opp_table */ + WARN_ON(!list_empty(&opp_table->opp_list)); + + clk_put(opp_table->clk); + opp_table->clk = ERR_PTR(-EINVAL); + + dev_pm_opp_put_opp_table(opp_table); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_put_clkname); + +/** * dev_pm_opp_register_set_opp_helper() - Register custom set OPP helper * @dev: Device for which the helper is getting registered. * @set_opp: Custom set OPP helper. diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index a6685b3dde26..51ec727b4824 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -121,6 +121,8 @@ struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) void dev_pm_opp_put_prop_name(struct opp_table *opp_table); struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count); void dev_pm_opp_put_regulators(struct opp_table *opp_table); +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_register_put_opp_helper(struct opp_table *opp_table); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); @@ -257,6 +259,13 @@ static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, co static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {} +static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name) +{ + return ERR_PTR(-ENOTSUPP); +} + +static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {} + static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { return -ENOTSUPP;