From patchwork Mon Nov 16 10:37:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 56577 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1237837lbb; Mon, 16 Nov 2015 02:38:43 -0800 (PST) X-Received: by 10.66.216.38 with SMTP id on6mr53642798pac.53.1447670322918; Mon, 16 Nov 2015 02:38:42 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7si38803900pat.185.2015.11.16.02.38.41; Mon, 16 Nov 2015 02:38:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752447AbbKPKif (ORCPT + 28 others); Mon, 16 Nov 2015 05:38:35 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:36309 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752322AbbKPKi2 (ORCPT ); Mon, 16 Nov 2015 05:38:28 -0500 Received: by pacdm15 with SMTP id dm15so171548247pac.3 for ; Mon, 16 Nov 2015 02:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=prxUaVdf/gnH870qreH66gZQln54Vhk6DfKlI7Dhz6I=; b=JDnhc0EDT8WfEHCdhw9fS+2V83fZpDGLPd7HQPDa8DMlAhWhqrAVc9mKW53YU9VfDg 3QYFPYeYXQJpd72YCtZ+KUwli2khChuC3okDeFUFmGQ/QsXNjMOPTn+lscUFD9Av6UM5 J+rZQKLGXEfBJNMLW6ATRGgFH6lEHOERJLb53m9o59UEwhY05w5Dg7fICaR2iwKpa9v4 1HDpuI834EYW7ZAJ5Iv2syLPGcdFRC/2Fz40rFsBbW1N0bhuzxCmuEdJ5cC17JdBDTQ6 YOIodPyqlBjUiJwYYCY552jGKSjvnTPABgy1agYauzA79b9G4WBc795Bly4XLqVm8rxq fm0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=prxUaVdf/gnH870qreH66gZQln54Vhk6DfKlI7Dhz6I=; b=EEfHgvsqNZaGrEhN49K04+ySJ9zLsB4/I2jK/ePBUxWQgc8WUAFL4GHY8rHBGi0cqw T7nevJeowdGh0aV1+ypZUh+MOr3Rh1SWVWGpf2RdhOqzhcKpU4jD8C7E/cEzMroC3Hkz h5BxwfW+J+wb7QTdOIJJZFWcZu/M3JTozbcRc2TMkPrhcePfobbsYQKeQtAmFvat5Lg5 h0xmkk+OPR9xZMgrtyVGUope0RiqUmvoYHvtrA17kDw+KmcOOG9MeMyOppM/UQenwaEr nUCrBcLKtHl97fPkXAs/fMhUT6vo6CCN/jpgR2qJNYrBort7kLr+/qIJDpbPhsrKFLFc c7iw== X-Gm-Message-State: ALoCoQkxbuYr0PrLtieabrJT2epukt/xYdk4S+rM8y74Herj9kRBU5OMgqzsHXSRixfPoJADHxsy X-Received: by 10.68.165.97 with SMTP id yx1mr1862769pbb.55.1447670308064; Mon, 16 Nov 2015 02:38:28 -0800 (PST) Received: from localhost ([122.167.29.19]) by smtp.gmail.com with ESMTPSA id tn2sm35662519pbc.9.2015.11.16.02.38.26 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 16 Nov 2015 02:38:27 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, robh+dt@kernel.org, nm@ti.com, Viresh Kumar , Bartlomiej Zolnierkiewicz , Dmitry Torokhov , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek , Shawn Guo Subject: [PATCH 3/3] PM / OPP: Parse 'opp--' bindings Date: Mon, 16 Nov 2015 16:07:28 +0530 Message-Id: X-Mailer: git-send-email 2.6.2.198.g614a2ac In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org OPP bindings (for few properties) allow a platform to choose a value/range among a set of available options. The options are present as opp--, where the platform needs to supply the string. The OPP properties which allow such an option are: opp-microvolt and opp-microamp. Add support to the OPP-core to parse these bindings, by introducing dev_pm_opp_{set|put}_prop_name() APIs. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 148 ++++++++++++++++++++++++++++++++++++++---- drivers/base/power/opp/opp.h | 2 + include/linux/pm_opp.h | 9 +++ 3 files changed, 146 insertions(+), 13 deletions(-) -- 2.6.2.198.g614a2ac -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 29fe251bf9ec..b3750aa9552f 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -105,6 +105,15 @@ struct device_opp *_find_device_opp(struct device *dev) return ERR_PTR(-ENODEV); } +static void _opp_create_prop_name(char *name, const char *prefix, + const char *postfix) +{ + if (postfix) + sprintf(name, "%s-%s", prefix, postfix); + else + sprintf(name, "%s", prefix); +} + /** * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp * @opp: opp for which voltage has to be returned for @@ -562,6 +571,9 @@ static void _remove_device_opp(struct device_opp *dev_opp) if (dev_opp->supported_hw) return; + if (dev_opp->prop_name) + return; + list_dev = list_first_entry(&dev_opp->dev_list, struct device_list_opp, node); @@ -794,20 +806,32 @@ static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, } /* TODO: Support multiple regulators */ -static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev) +static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, + struct device_opp *dev_opp) { u32 microvolt[3] = {0}; u32 val; int count, ret; + struct property *prop; + char name[NAME_MAX]; - /* Missing property isn't a problem, but an invalid entry is */ - if (!of_find_property(opp->np, "opp-microvolt", NULL)) - return 0; + /* Search for both "opp-microvolt-" and "opp-microvolt" */ + _opp_create_prop_name(name, "opp-microvolt", dev_opp->prop_name); - count = of_property_count_u32_elems(opp->np, "opp-microvolt"); + prop = of_find_property(opp->np, name, NULL); + if (!prop) { + _opp_create_prop_name(name, "opp-microvolt", NULL); + prop = of_find_property(opp->np, name, NULL); + + /* Missing property isn't a problem, but an invalid entry is */ + if (!prop) + return 0; + } + + count = of_property_count_u32_elems(opp->np, name); if (count < 0) { - dev_err(dev, "%s: Invalid opp-microvolt property (%d)\n", - __func__, count); + dev_err(dev, "%s: Invalid %s property (%d)\n", + __func__, name, count); return count; } @@ -818,11 +842,9 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev) return -EINVAL; } - ret = of_property_read_u32_array(opp->np, "opp-microvolt", microvolt, - count); + ret = of_property_read_u32_array(opp->np, name, microvolt, count); if (ret) { - dev_err(dev, "%s: error parsing opp-microvolt: %d\n", __func__, - ret); + dev_err(dev, "%s: error parsing %s: %d\n", __func__, name, ret); return -EINVAL; } @@ -830,7 +852,15 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev) opp->u_volt_min = microvolt[1]; opp->u_volt_max = microvolt[2]; - if (!of_property_read_u32(opp->np, "opp-microamp", &val)) + /* Search for both "opp-microamp-" and "opp-microamp" */ + _opp_create_prop_name(name, "opp-microamp", dev_opp->prop_name); + prop = of_find_property(opp->np, name, NULL); + if (!prop) { + _opp_create_prop_name(name, "opp-microamp", NULL); + prop = of_find_property(opp->np, name, NULL); + } + + if (prop && !of_property_read_u32(opp->np, "opp-microamp", &val)) opp->u_amp = val; return 0; @@ -935,6 +965,98 @@ void dev_pm_opp_put_supported_hw(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw); +/** + * dev_pm_opp_set_prop_name() - Set prop-extn name + * @dev: Device for which the regulator has to be set. + * @name: name to postfix to properties. + * + * This is required only for the V2 bindings, and it enables a platform to + * specify the extn to be used for certain property names. The properties to + * which the extension will apply are opp-microvolt and opp-microamp. OPP core + * should postfix the property name with - while looking for them. + */ +int dev_pm_opp_set_prop_name(struct device *dev, const char *name) +{ + struct device_opp *dev_opp; + int ret = 0; + + if (!dev || !name) { + pr_err("%s: Invalid arguments, dev:0x%p, name:%p\n", __func__, + dev, name); + return -EINVAL; + } + + /* Operations on OPP structures must be done from within rcu locks */ + rcu_read_lock(); + + dev_opp = _add_device_opp(dev); + if (!dev_opp) + return -ENOMEM; + + /* Do we already have a prop-name associated with dev_opp? */ + if (dev_opp->prop_name) { + dev_err(dev, "%s: Already have prop-name %s\n", __func__, + dev_opp->prop_name); + ret = -EINVAL; + goto unlock; + } + + dev_opp->prop_name = kstrdup(name, GFP_KERNEL); + if (!dev_opp->prop_name) { + ret = -ENOMEM; + goto unlock; + } + +unlock: + rcu_read_unlock(); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name); + +/** + * dev_pm_opp_put_prop_name() - Releases resources blocked for prop-name + * @dev: Device for which the regulator has to be set. + * + * This is required only for the V2 bindings, and is called for a matching + * dev_pm_opp_set_prop_name(). Until this is called, the device_opp structure + * will not be freed. + */ +void dev_pm_opp_put_prop_name(struct device *dev) +{ + struct device_opp *dev_opp; + + if (!dev) { + pr_err("%s: Invalid argument dev:0x%p\n", __func__, dev); + return; + } + + /* Operations on OPP structures must be done from within rcu locks */ + rcu_read_lock(); + + /* Check for existing list for 'dev' first */ + dev_opp = _find_device_opp(dev); + if (IS_ERR(dev_opp)) { + dev_err(dev, "Failed to find dev_opp: %ld\n", PTR_ERR(dev_opp)); + goto unlock; + } + + if (!dev_opp->prop_name) { + dev_err(dev, "%s: Doesn't have a prop-name\n", __func__); + goto unlock; + } + + kfree(dev_opp->prop_name); + dev_opp->prop_name = NULL; + + /* Try freeing device_opp if this was the last blocking resource */ + _remove_device_opp(dev_opp); + +unlock: + rcu_read_unlock(); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name); + static bool _opp_is_supported(struct device *dev, struct device_opp *dev_opp, struct device_node *np) { @@ -1047,7 +1169,7 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np) if (!of_property_read_u32(np, "clock-latency-ns", &val)) new_opp->clock_latency_ns = val; - ret = opp_parse_supplies(new_opp, dev); + ret = opp_parse_supplies(new_opp, dev, dev_opp); if (ret) goto free_opp; diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index 70f4564a6ab9..690638ef36ee 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -131,6 +131,7 @@ struct device_list_opp { * @suspend_opp: Pointer to OPP to be used during device suspend. * @supported_hw: Array of version number to support. * @supported_hw_count: Number of elements in supported_hw array. + * @prop_name: A name to postfix to many DT properties, while parsing them. * @dentry: debugfs dentry pointer of the real device directory (not links). * @dentry_name: Name of the real dentry. * @@ -157,6 +158,7 @@ struct device_opp { unsigned int *supported_hw; unsigned int supported_hw_count; + const char *prop_name; #ifdef CONFIG_DEBUG_FS struct dentry *dentry; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index d12471ed14a2..eec973130951 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -58,6 +58,8 @@ struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev); int dev_pm_opp_set_supported_hw(struct device *dev, u32 *versions, unsigned int count); void dev_pm_opp_put_supported_hw(struct device *dev); +int dev_pm_opp_set_prop_name(struct device *dev, const char *name); +void dev_pm_opp_put_prop_name(struct device *dev); #else static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) { @@ -141,6 +143,13 @@ static inline int dev_pm_opp_set_supported_hw(struct device *dev, u32 *versions, static inline void dev_pm_opp_put_supported_hw(struct device *dev) {} +static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name) +{ + return -EINVAL; +} + +static inline void dev_pm_opp_put_prop_name(struct device *dev) {} + #endif /* CONFIG_PM_OPP */ #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)