@@ -1185,6 +1185,17 @@ static int _set_opp(struct device *dev, struct opp_table *opp_table,
dev_err(dev, "Failed to set bw: %d\n", ret);
return ret;
}
+
+ if (opp_table->config_regulators) {
+ ret = opp_table->config_regulators(dev, old_opp, opp,
+ opp_table->regulators,
+ opp_table->regulator_count);
+ if (ret) {
+ dev_err(dev, "Failed to set regulator voltages: %d\n",
+ ret);
+ return ret;
+ }
+ }
}
if (opp_table->set_opp) {
@@ -1202,6 +1213,17 @@ static int _set_opp(struct device *dev, struct opp_table *opp_table,
/* Scaling down? Configure required OPPs after frequency */
if (scaling_down) {
+ if (opp_table->config_regulators) {
+ ret = opp_table->config_regulators(dev, old_opp, opp,
+ opp_table->regulators,
+ opp_table->regulator_count);
+ if (ret) {
+ dev_err(dev, "Failed to set regulator voltages: %d\n",
+ ret);
+ return ret;
+ }
+ }
+
ret = _set_opp_bw(opp_table, opp, dev);
if (ret) {
dev_err(dev, "Failed to set bw: %d\n", ret);
@@ -2246,6 +2268,38 @@ static void _opp_unregister_set_opp_helper(struct opp_table *opp_table)
}
}
+/**
+ * _opp_set_config_regulators_helper() - Register custom set regulator helper.
+ * @dev: Device for which the helper is getting registered.
+ * @config_regulators: Custom set regulator helper.
+ *
+ * This is useful to support platforms with multiple regulators per device.
+ *
+ * This must be called before any OPPs are initialized for the device.
+ */
+static int _opp_set_config_regulators_helper(struct opp_table *opp_table,
+ struct device *dev, config_regulators_t config_regulators)
+{
+ /* Another CPU that shares the OPP table has set the helper ? */
+ if (!opp_table->config_regulators)
+ opp_table->config_regulators = config_regulators;
+
+ return 0;
+}
+
+/**
+ * _opp_put_config_regulators_helper() - Releases resources blocked for
+ * config_regulators helper.
+ * @opp_table: OPP table returned from _opp_set_config_regulators_helper().
+ *
+ * Release resources blocked for platform specific config_regulators helper.
+ */
+static void _opp_put_config_regulators_helper(struct opp_table *opp_table)
+{
+ if (opp_table->config_regulators)
+ opp_table->config_regulators = NULL;
+}
+
static void _detach_genpd(struct opp_table *opp_table)
{
int index;
@@ -2372,8 +2426,10 @@ static void _opp_clear_config(struct opp_config_data *data)
_opp_put_regulators(data->opp_table);
if (data->flags & OPP_CONFIG_SUPPORTED_HW)
_opp_put_supported_hw(data->opp_table);
- if (data->flags & OPP_CONFIG_REGULATOR_HELPER)
+ if (data->flags & OPP_CONFIG_REGULATOR_HELPER) {
+ _opp_put_config_regulators_helper(data->opp_table);
_opp_unregister_set_opp_helper(data->opp_table);
+ }
if (data->flags & OPP_CONFIG_PROP_NAME)
_opp_put_prop_name(data->opp_table);
if (data->flags & OPP_CONFIG_CLK)
@@ -2455,6 +2511,16 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
data->flags |= OPP_CONFIG_REGULATOR_HELPER;
}
+ /* Configure config_regulators helper */
+ if (config->config_regulators) {
+ ret = _opp_set_config_regulators_helper(opp_table, dev,
+ config->config_regulators);
+ if (ret)
+ goto err;
+
+ data->flags |= OPP_CONFIG_REGULATOR_HELPER;
+ }
+
/* Configure supported hardware */
if (config->supported_hw) {
ret = _opp_set_supported_hw(opp_table, config->supported_hw,
@@ -172,6 +172,7 @@ enum opp_table_access {
* @prop_name: A name to postfix to many DT properties, while parsing them.
* @clk_configured: Clock name is configured by the platform.
* @clk: Device's clock handle
+ * @config_regulators: Platform specific config_regulators() callback.
* @regulators: Supply regulators
* @regulator_count: Number of power supply regulators. Its value can be -1
* (uninitialized), 0 (no opp-microvolt property) or > 0 (has opp-microvolt
@@ -224,6 +225,7 @@ struct opp_table {
const char *prop_name;
bool clk_configured;
struct clk *clk;
+ config_regulators_t config_regulators;
struct regulator **regulators;
int regulator_count;
struct icc_path **paths;
@@ -90,12 +90,17 @@ struct dev_pm_set_opp_data {
struct device *dev;
};
+typedef int (*config_regulators_t)(struct device *dev,
+ struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
+ struct regulator **regulators, unsigned int count);
+
/**
* struct dev_pm_opp_config - Device OPP configuration values
* @clk_names: Clk name.
* @clk_count: Number of clocks, max 1 for now.
* @prop_name: Name to postfix to properties.
* @set_opp: Custom set OPP helper.
+ * @config_regulators: Custom set regulator helper.
* @supported_hw: Array of hierarchy of versions to match.
* @supported_hw_count: Number of elements in the array.
* @regulator_names: Array of pointers to the names of the regulator.
@@ -111,6 +116,7 @@ struct dev_pm_opp_config {
unsigned int clk_count;
const char *prop_name;
int (*set_opp)(struct dev_pm_set_opp_data *data);
+ config_regulators_t config_regulators;
unsigned int *supported_hw;
unsigned int supported_hw_count;
const char * const *regulator_names;