@@ -2421,8 +2421,35 @@ static void _opp_detach_genpd(struct opp_table *opp_table)
mutex_unlock(&opp_table->genpd_virt_dev_lock);
}
+/**
+ * _opp_set_required_opps_helper() - Register custom set required opps helper.
+ * @dev: Device for which the helper is getting registered.
+ * @set_required_opps: Custom set required opps helper.
+ *
+ * This must be called before any OPPs are initialized for the device.
+ */
+static void _opp_set_required_opps_helper(struct opp_table *opp_table,
+ set_required_opps_t set_required_opps)
+{
+ opp_table->set_required_opps = set_required_opps;
+}
+
+/**
+ * _opp_put_required_opps_helper() - Releases resources blocked for
+ * required opps helper.
+ * @opp_table: OPP table returned from _opp_set_required_opps_helper().
+ *
+ * Release resources blocked for platform specific required opps helper.
+ */
+static void _opp_put_required_opps_helper(struct opp_table *opp_table)
+{
+ opp_table->set_required_opps = NULL;
+}
+
static void _opp_clear_config(struct opp_config_data *data)
{
+ if (data->flags & OPP_CONFIG_REQUIRED_OPPS)
+ _opp_put_required_opps_helper(data->opp_table);
if (data->flags & OPP_CONFIG_GENPD)
_opp_detach_genpd(data->opp_table);
if (data->flags & OPP_CONFIG_REGULATOR)
@@ -2546,6 +2573,14 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
data->flags |= OPP_CONFIG_GENPD;
}
+ /* Required opps helper */
+ if (config->set_required_opps) {
+ _opp_set_required_opps_helper(opp_table,
+ config->set_required_opps);
+
+ data->flags |= OPP_CONFIG_REQUIRED_OPPS;
+ }
+
ret = xa_alloc(&opp_configs, &id, data, XA_LIMIT(1, INT_MAX),
GFP_KERNEL);
if (ret)
@@ -35,6 +35,7 @@ extern struct list_head opp_tables, lazy_opp_tables;
#define OPP_CONFIG_PROP_NAME BIT(3)
#define OPP_CONFIG_SUPPORTED_HW BIT(4)
#define OPP_CONFIG_GENPD BIT(5)
+#define OPP_CONFIG_REQUIRED_OPPS BIT(6)
/**
* struct opp_config_data - data for set config operations
@@ -235,8 +236,7 @@ struct opp_table {
bool enabled;
bool genpd_performance_state;
bool is_genpd;
- int (*set_required_opps)(struct device *dev,
- struct opp_table *opp_table, struct dev_pm_opp *opp, bool scaling_down);
+ set_required_opps_t set_required_opps;
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
@@ -64,6 +64,9 @@ typedef int (*config_regulators_t)(struct device *dev,
typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table,
struct dev_pm_opp *opp, void *data, bool scaling_down);
+typedef int (*set_required_opps_t)(struct device *dev, struct opp_table *opp_table,
+ struct dev_pm_opp *opp, bool scaling_down);
+
/**
* struct dev_pm_opp_config - Device OPP configuration values
* @clk_names: Clk names, NULL terminated array.
@@ -76,6 +79,7 @@ typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table,
* @genpd_names: Null terminated array of pointers containing names of genpd to
* attach.
* @virt_devs: Pointer to return the array of virtual devices.
+ * @set_required_opps: Custom set required opps helper.
*
* This structure contains platform specific OPP configurations for the device.
*/
@@ -90,6 +94,7 @@ struct dev_pm_opp_config {
const char * const *regulator_names;
const char * const *genpd_names;
struct device ***virt_devs;
+ set_required_opps_t set_required_opps;
};
#if defined(CONFIG_PM_OPP)
We currently configure required-opps only for genpds, as we aren't really sure what's required of the other use cases. This patch allows platforms to add their own set_required_opps() helper. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> --- Jun, I think this can replace the cpufreq notification from the devfreq driver (get_target_freq_with_cpufreq()), which is used currently only by mtk-cci-devfreq.c. Instead of the notification, the aggregation of the requests for the devfreq device can be done within this callback. What do you say ? --- drivers/opp/core.c | 35 +++++++++++++++++++++++++++++++++++ drivers/opp/opp.h | 4 ++-- include/linux/pm_opp.h | 5 +++++ 3 files changed, 42 insertions(+), 2 deletions(-)