Commit 59d65b73 authored by Lina Iyer's avatar Lina Iyer Committed by Rafael J. Wysocki

PM / Domains: Make genpd state allocation dynamic

Allow PM Domain states to be defined dynamically by the drivers. This
removes the limitation on the maximum number of states possible for a
domain.
Suggested-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: default avatarLina Iyer <lina.iyer@linaro.org>
Acked-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Reviewed-by: default avatarKevin Hilman <khilman@baylibre.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 1001354c
...@@ -380,13 +380,6 @@ static struct pu_domain imx6q_pu_domain = { ...@@ -380,13 +380,6 @@ static struct pu_domain imx6q_pu_domain = {
.name = "PU", .name = "PU",
.power_off = imx6q_pm_pu_power_off, .power_off = imx6q_pm_pu_power_off,
.power_on = imx6q_pm_pu_power_on, .power_on = imx6q_pm_pu_power_on,
.states = {
[0] = {
.power_off_latency_ns = 25000,
.power_on_latency_ns = 2000000,
},
},
.state_count = 1,
}, },
}; };
...@@ -430,6 +423,16 @@ static int imx_gpc_genpd_init(struct device *dev, struct regulator *pu_reg) ...@@ -430,6 +423,16 @@ static int imx_gpc_genpd_init(struct device *dev, struct regulator *pu_reg)
if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS)) if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS))
return 0; return 0;
imx6q_pu_domain.base.states = devm_kzalloc(dev,
sizeof(*imx6q_pu_domain.base.states),
GFP_KERNEL);
if (!imx6q_pu_domain.base.states)
return -ENOMEM;
imx6q_pu_domain.base.states[0].power_off_latency_ns = 25000;
imx6q_pu_domain.base.states[0].power_on_latency_ns = 2000000;
imx6q_pu_domain.base.state_count = 1;
pm_genpd_init(&imx6q_pu_domain.base, NULL, false); pm_genpd_init(&imx6q_pu_domain.base, NULL, false);
return of_genpd_add_provider_onecell(dev->of_node, return of_genpd_add_provider_onecell(dev->of_node,
&imx_gpc_onecell_data); &imx_gpc_onecell_data);
......
...@@ -1282,6 +1282,21 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, ...@@ -1282,6 +1282,21 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
} }
EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain); EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain);
static int genpd_set_default_power_state(struct generic_pm_domain *genpd)
{
struct genpd_power_state *state;
state = kzalloc(sizeof(*state), GFP_KERNEL);
if (!state)
return -ENOMEM;
genpd->states = state;
genpd->state_count = 1;
genpd->free = state;
return 0;
}
/** /**
* pm_genpd_init - Initialize a generic I/O PM domain object. * pm_genpd_init - Initialize a generic I/O PM domain object.
* @genpd: PM domain object to initialize. * @genpd: PM domain object to initialize.
...@@ -1293,6 +1308,8 @@ EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain); ...@@ -1293,6 +1308,8 @@ EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain);
int pm_genpd_init(struct generic_pm_domain *genpd, int pm_genpd_init(struct generic_pm_domain *genpd,
struct dev_power_governor *gov, bool is_off) struct dev_power_governor *gov, bool is_off)
{ {
int ret;
if (IS_ERR_OR_NULL(genpd)) if (IS_ERR_OR_NULL(genpd))
return -EINVAL; return -EINVAL;
...@@ -1325,19 +1342,12 @@ int pm_genpd_init(struct generic_pm_domain *genpd, ...@@ -1325,19 +1342,12 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
genpd->dev_ops.start = pm_clk_resume; genpd->dev_ops.start = pm_clk_resume;
} }
if (genpd->state_idx >= GENPD_MAX_NUM_STATES) {
pr_warn("Initial state index out of bounds.\n");
genpd->state_idx = GENPD_MAX_NUM_STATES - 1;
}
if (genpd->state_count > GENPD_MAX_NUM_STATES) {
pr_warn("Limiting states to %d\n", GENPD_MAX_NUM_STATES);
genpd->state_count = GENPD_MAX_NUM_STATES;
}
/* Use only one "off" state if there were no states declared */ /* Use only one "off" state if there were no states declared */
if (genpd->state_count == 0) if (genpd->state_count == 0) {
genpd->state_count = 1; ret = genpd_set_default_power_state(genpd);
if (ret)
return ret;
}
mutex_lock(&gpd_list_lock); mutex_lock(&gpd_list_lock);
list_add(&genpd->gpd_list_node, &gpd_list); list_add(&genpd->gpd_list_node, &gpd_list);
...@@ -1377,6 +1387,7 @@ static int genpd_remove(struct generic_pm_domain *genpd) ...@@ -1377,6 +1387,7 @@ static int genpd_remove(struct generic_pm_domain *genpd)
list_del(&genpd->gpd_list_node); list_del(&genpd->gpd_list_node);
mutex_unlock(&genpd->lock); mutex_unlock(&genpd->lock);
cancel_work_sync(&genpd->power_off_work); cancel_work_sync(&genpd->power_off_work);
kfree(genpd->free);
pr_debug("%s: removed %s\n", __func__, genpd->name); pr_debug("%s: removed %s\n", __func__, genpd->name);
return 0; return 0;
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
/* Defines used for the flags field in the struct generic_pm_domain */ /* Defines used for the flags field in the struct generic_pm_domain */
#define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */ #define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */
#define GENPD_MAX_NUM_STATES 8 /* Number of possible low power states */
enum gpd_status { enum gpd_status {
GPD_STATE_ACTIVE = 0, /* PM domain is active */ GPD_STATE_ACTIVE = 0, /* PM domain is active */
GPD_STATE_POWER_OFF, /* PM domain is off */ GPD_STATE_POWER_OFF, /* PM domain is off */
...@@ -70,9 +68,10 @@ struct generic_pm_domain { ...@@ -70,9 +68,10 @@ struct generic_pm_domain {
void (*detach_dev)(struct generic_pm_domain *domain, void (*detach_dev)(struct generic_pm_domain *domain,
struct device *dev); struct device *dev);
unsigned int flags; /* Bit field of configs for genpd */ unsigned int flags; /* Bit field of configs for genpd */
struct genpd_power_state states[GENPD_MAX_NUM_STATES]; struct genpd_power_state *states;
unsigned int state_count; /* number of states */ unsigned int state_count; /* number of states */
unsigned int state_idx; /* state that genpd will go to when off */ unsigned int state_idx; /* state that genpd will go to when off */
void *free; /* Free the state that was allocated for default */
}; };
......
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