All of lore.kernel.org
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Dmitry Osipenko <digetx@gmail.com>,
	Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>,
	Stephen Boyd <sboyd@kernel.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
	linux-pm@vger.kernel.org,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Rafael Wysocki <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] opp: Prepare for ->set_opp() helper to work without regulators
Date: Tue, 19 Jan 2021 12:05:51 +0530	[thread overview]
Message-ID: <302c014726dbd9fcde852985528c139d2214a1f2.1611038066.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <fb69353c-a35b-9b7c-46bc-d464c6dab6f5@gmail.com>

Until now the ->set_opp() helper (i.e. special implementation for
setting the OPPs for platforms) was implemented only to take care of
multiple regulators case, but going forward we would need that for other
use cases as well.

This patch prepares for that by allocating the regulator specific part
from dev_pm_opp_set_regulators() and the opp helper part from
dev_pm_opp_register_set_opp_helper().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
Dmitry,

I haven't tested this patch, can you please help with that ?

 drivers/opp/core.c | 81 ++++++++++++++++++++++++----------------------
 drivers/opp/opp.h  |  2 ++
 2 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index b1a2296f3065..f80b6f1ca108 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1817,38 +1817,6 @@ void dev_pm_opp_put_prop_name(struct opp_table *opp_table)
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name);
 
-static int _allocate_set_opp_data(struct opp_table *opp_table)
-{
-	struct dev_pm_set_opp_data *data;
-	int len, count = opp_table->regulator_count;
-
-	if (WARN_ON(!opp_table->regulators))
-		return -EINVAL;
-
-	/* space for set_opp_data */
-	len = sizeof(*data);
-
-	/* space for old_opp.supplies and new_opp.supplies */
-	len += 2 * sizeof(struct dev_pm_opp_supply) * count;
-
-	data = kzalloc(len, GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	data->old_opp.supplies = (void *)(data + 1);
-	data->new_opp.supplies = data->old_opp.supplies + count;
-
-	opp_table->set_opp_data = data;
-
-	return 0;
-}
-
-static void _free_set_opp_data(struct opp_table *opp_table)
-{
-	kfree(opp_table->set_opp_data);
-	opp_table->set_opp_data = NULL;
-}
-
 /**
  * dev_pm_opp_set_regulators() - Set regulator names for the device
  * @dev: Device for which regulator name is being set.
@@ -1865,6 +1833,8 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
 					    const char * const names[],
 					    unsigned int count)
 {
+	struct dev_pm_opp_supply *supplies;
+	struct dev_pm_set_opp_data *data;
 	struct opp_table *opp_table;
 	struct regulator *reg;
 	int ret, i;
@@ -1906,10 +1876,20 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
 
 	opp_table->regulator_count = count;
 
-	/* Allocate block only once to pass to set_opp() routines */
-	ret = _allocate_set_opp_data(opp_table);
-	if (ret)
+	supplies = kmalloc_array(count * 2, sizeof(*supplies), GFP_KERNEL);
+	if (!supplies) {
+		ret = -ENOMEM;
 		goto free_regulators;
+	}
+
+	mutex_lock(&opp_table->lock);
+	opp_table->sod_supplies = supplies;
+	if (opp_table->set_opp_data) {
+		data = opp_table->set_opp_data;
+		data->old_opp.supplies = supplies;
+		data->new_opp.supplies = supplies + count;
+	}
+	mutex_unlock(&opp_table->lock);
 
 	return opp_table;
 
@@ -1952,9 +1932,16 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table)
 	for (i = opp_table->regulator_count - 1; i >= 0; i--)
 		regulator_put(opp_table->regulators[i]);
 
-	_free_set_opp_data(opp_table);
+	mutex_lock(&opp_table->lock);
+	if (opp_table->sod_supplies) {
+		opp_table->set_opp_data->old_opp.supplies = NULL;
+		opp_table->set_opp_data->new_opp.supplies = NULL;
+	}
+	mutex_unlock(&opp_table->lock);
 
+	kfree(opp_table->sod_supplies);
 	kfree(opp_table->regulators);
+	opp_table->sod_supplies = NULL;
 	opp_table->regulators = NULL;
 	opp_table->regulator_count = -1;
 
@@ -2046,6 +2033,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_clkname);
 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
 			int (*set_opp)(struct dev_pm_set_opp_data *data))
 {
+	struct dev_pm_set_opp_data *data;
 	struct opp_table *opp_table;
 
 	if (!set_opp)
@@ -2062,8 +2050,23 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
 	}
 
 	/* Another CPU that shares the OPP table has set the helper ? */
-	if (!opp_table->set_opp)
-		opp_table->set_opp = set_opp;
+	if (opp_table->set_opp)
+		return opp_table;
+
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return ERR_PTR(-ENOMEM);
+
+	mutex_lock(&opp_table->lock);
+	opp_table->set_opp_data = data;
+	if (opp_table->sod_supplies) {
+		data->old_opp.supplies = opp_table->sod_supplies;
+		data->new_opp.supplies = opp_table->sod_supplies +
+					 opp_table->regulator_count;
+	}
+	mutex_unlock(&opp_table->lock);
+
+	opp_table->set_opp = set_opp;
 
 	return opp_table;
 }
@@ -2085,6 +2088,8 @@ void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table)
 	WARN_ON(!list_empty(&opp_table->opp_list));
 
 	opp_table->set_opp = NULL;
+	kfree(opp_table->set_opp_data);
+	opp_table->set_opp_data = NULL;
 	dev_pm_opp_put_opp_table(opp_table);
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper);
diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h
index 4ced7ffa8158..4408cfcb0f31 100644
--- a/drivers/opp/opp.h
+++ b/drivers/opp/opp.h
@@ -155,6 +155,7 @@ enum opp_table_access {
  * @genpd_performance_state: Device's power domain support performance state.
  * @is_genpd: Marks if the OPP table belongs to a genpd.
  * @set_opp: Platform specific set_opp callback
+ * @sod_supplies: Set opp data supplies
  * @set_opp_data: Data to be passed to set_opp callback
  * @dentry:	debugfs dentry pointer of the real device directory (not links).
  * @dentry_name: Name of the real dentry.
@@ -202,6 +203,7 @@ struct opp_table {
 	bool is_genpd;
 
 	int (*set_opp)(struct dev_pm_set_opp_data *data);
+	struct dev_pm_opp_supply *sod_supplies;
 	struct dev_pm_set_opp_data *set_opp_data;
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.25.0.rc1.19.g042ed3e048af


  reply	other threads:[~2021-01-19  6:37 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18  0:55 [PATCH v3 00/12] OPP API fixes and improvements Dmitry Osipenko
2021-01-18  0:55 ` [PATCH v3 01/12] opp: Fix adding OPP entries in a wrong order if rate is unavailable Dmitry Osipenko
2021-01-18  7:44   ` Viresh Kumar
2021-01-18 18:46     ` Dmitry Osipenko
2021-01-18  0:55 ` [PATCH v3 02/12] opp: Filter out OPPs based on availability of a required-OPP Dmitry Osipenko
2021-01-18  8:11   ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 03/12] opp: Correct debug message in _opp_add_static_v2() Dmitry Osipenko
2021-01-18  8:14   ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 04/12] opp: Add dev_pm_opp_sync_regulators() Dmitry Osipenko
2021-01-18  4:19   ` kernel test robot
2021-01-18  8:20   ` Viresh Kumar
2021-01-18 18:35     ` Dmitry Osipenko
2021-01-19  4:58       ` Viresh Kumar
2021-01-19 22:42         ` Dmitry Osipenko
2021-01-18 11:00   ` Viresh Kumar
2021-01-18 11:06     ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 05/12] opp: Add dev_pm_opp_set_voltage() Dmitry Osipenko
2021-01-18  9:52   ` Viresh Kumar
2021-01-18 19:14     ` Dmitry Osipenko
2021-01-20 21:57       ` Dmitry Osipenko
2021-01-21 11:20         ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 06/12] opp: Add dev_pm_opp_find_level_ceil() Dmitry Osipenko
2021-01-18  9:58   ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 07/12] opp: Add dev_pm_opp_get_required_pstate() Dmitry Osipenko
2021-01-18 10:50   ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 08/12] opp: Add devm_pm_opp_register_set_opp_helper Dmitry Osipenko
2021-01-18 11:07   ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 09/12] opp: Add devm_pm_opp_attach_genpd Dmitry Osipenko
2021-01-18 11:14   ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 10/12] opp: Support set_opp() customization without requiring to use regulators Dmitry Osipenko
2021-01-18 11:44   ` Viresh Kumar
2021-01-18 18:48     ` Dmitry Osipenko
2021-01-19  6:35       ` Viresh Kumar [this message]
2021-01-19 17:16         ` [PATCH] opp: Prepare for ->set_opp() helper to work without regulators Dmitry Osipenko
2021-01-20  7:39           ` Viresh Kumar
2021-01-20 14:50             ` Dmitry Osipenko
2021-01-21 11:25               ` Viresh Kumar
2021-01-19 17:18         ` Dmitry Osipenko
2021-01-20  8:08         ` Viresh Kumar
2021-01-21 11:28           ` Viresh Kumar
2021-01-19  6:36       ` [PATCH v3 10/12] opp: Support set_opp() customization without requiring to use regulators Viresh Kumar
2021-01-21 11:30       ` [PATCH V2] opp: Prepare for ->set_opp() helper to work without regulators Viresh Kumar
2021-01-21 21:02         ` Dmitry Osipenko
2021-01-22  3:05           ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 11/12] opp: Handle missing OPP table in dev_pm_opp_xlate_performance_state() Dmitry Osipenko
2021-01-18 11:18   ` Viresh Kumar
2021-01-18  0:55 ` [PATCH v3 12/12] opp: Print OPP level in debug message of _opp_add_static_v2() Dmitry Osipenko
2021-01-18 11:18   ` Viresh Kumar
2021-01-18 11:46 ` [PATCH v3 00/12] OPP API fixes and improvements Viresh Kumar
2021-01-19 17:35   ` Dmitry Osipenko
2021-01-20 15:41     ` Dmitry Osipenko
2021-01-21  7:51       ` Viresh Kumar
2021-01-21 20:30         ` Dmitry Osipenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=302c014726dbd9fcde852985528c139d2214a1f2.1611038066.git.viresh.kumar@linaro.org \
    --to=viresh.kumar@linaro.org \
    --cc=digetx@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=rjw@rjwysocki.net \
    --cc=sboyd@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vireshk@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.