Commit 5e5e3a42 authored by Javier Martinez Canillas's avatar Javier Martinez Canillas Committed by Mark Brown

regulator: of: Add support for parsing initial and suspend modes

Some regulators support their operating mode to be changed on startup
or by consumers when the system is running while others only support
their operating mode to be changed while the system has entered in a
suspend state.

The regulator Device Tree binding documents a set of properties to
configure the regulators operating modes from a FDT. This patch builds
on (40e20d68 regulator: of: Add support for parsing regulator_state for
suspend state) and adds support to parse those properties and fill the
regulator constraints so the regulator core can call the right suspend
handlers when the system enters into sleep.

The modes are defined in the Device Tree using the hardware specific
modes supported by the regulators. Regulator drivers have to define a
translation function that is used to map the hardware specific modes
to the standard ones.
Signed-off-by: default avatarJavier Martinez Canillas <javier.martinez@collabora.co.uk>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 75d6b2fa
...@@ -25,7 +25,8 @@ static const char *const regulator_states[PM_SUSPEND_MAX + 1] = { ...@@ -25,7 +25,8 @@ static const char *const regulator_states[PM_SUSPEND_MAX + 1] = {
}; };
static void of_get_regulation_constraints(struct device_node *np, static void of_get_regulation_constraints(struct device_node *np,
struct regulator_init_data **init_data) struct regulator_init_data **init_data,
const struct regulator_desc *desc)
{ {
const __be32 *min_uV, *max_uV; const __be32 *min_uV, *max_uV;
struct regulation_constraints *constraints = &(*init_data)->constraints; struct regulation_constraints *constraints = &(*init_data)->constraints;
...@@ -81,6 +82,19 @@ static void of_get_regulation_constraints(struct device_node *np, ...@@ -81,6 +82,19 @@ static void of_get_regulation_constraints(struct device_node *np,
if (!ret) if (!ret)
constraints->enable_time = pval; constraints->enable_time = pval;
if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) {
if (desc && desc->of_map_mode) {
ret = desc->of_map_mode(pval);
if (ret == -EINVAL)
pr_err("%s: invalid mode %u\n", np->name, pval);
else
constraints->initial_mode = ret;
} else {
pr_warn("%s: mapping for mode %d not defined\n",
np->name, pval);
}
}
for (i = 0; i < ARRAY_SIZE(regulator_states); i++) { for (i = 0; i < ARRAY_SIZE(regulator_states); i++) {
switch (i) { switch (i) {
case PM_SUSPEND_MEM: case PM_SUSPEND_MEM:
...@@ -100,6 +114,21 @@ static void of_get_regulation_constraints(struct device_node *np, ...@@ -100,6 +114,21 @@ static void of_get_regulation_constraints(struct device_node *np,
if (!suspend_np || !suspend_state) if (!suspend_np || !suspend_state)
continue; continue;
if (!of_property_read_u32(suspend_np, "regulator-mode",
&pval)) {
if (desc && desc->of_map_mode) {
ret = desc->of_map_mode(pval);
if (ret == -EINVAL)
pr_err("%s: invalid mode %u\n",
np->name, pval);
else
suspend_state->mode = ret;
} else {
pr_warn("%s: mapping for mode %d not defined\n",
np->name, pval);
}
}
if (of_property_read_bool(suspend_np, if (of_property_read_bool(suspend_np,
"regulator-on-in-suspend")) "regulator-on-in-suspend"))
suspend_state->enabled = true; suspend_state->enabled = true;
...@@ -140,7 +169,7 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev, ...@@ -140,7 +169,7 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
if (!init_data) if (!init_data)
return NULL; /* Out of memory? */ return NULL; /* Out of memory? */
of_get_regulation_constraints(node, &init_data); of_get_regulation_constraints(node, &init_data, desc);
return init_data; return init_data;
} }
EXPORT_SYMBOL_GPL(of_get_regulator_init_data); EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment