Skip to content

Commit 59d65b7

Browse files
ilina-linarorafaeljw
authored andcommitted
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: Ulf Hansson <[email protected]> Signed-off-by: Lina Iyer <[email protected]> Acked-by: Ulf Hansson <[email protected]> Reviewed-by: Kevin Hilman <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 1001354 commit 59d65b7

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

arch/arm/mach-imx/gpc.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,6 @@ static struct pu_domain imx6q_pu_domain = {
380380
.name = "PU",
381381
.power_off = imx6q_pm_pu_power_off,
382382
.power_on = imx6q_pm_pu_power_on,
383-
.states = {
384-
[0] = {
385-
.power_off_latency_ns = 25000,
386-
.power_on_latency_ns = 2000000,
387-
},
388-
},
389-
.state_count = 1,
390383
},
391384
};
392385

@@ -430,6 +423,16 @@ static int imx_gpc_genpd_init(struct device *dev, struct regulator *pu_reg)
430423
if (!IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS))
431424
return 0;
432425

426+
imx6q_pu_domain.base.states = devm_kzalloc(dev,
427+
sizeof(*imx6q_pu_domain.base.states),
428+
GFP_KERNEL);
429+
if (!imx6q_pu_domain.base.states)
430+
return -ENOMEM;
431+
432+
imx6q_pu_domain.base.states[0].power_off_latency_ns = 25000;
433+
imx6q_pu_domain.base.states[0].power_on_latency_ns = 2000000;
434+
imx6q_pu_domain.base.state_count = 1;
435+
433436
pm_genpd_init(&imx6q_pu_domain.base, NULL, false);
434437
return of_genpd_add_provider_onecell(dev->of_node,
435438
&imx_gpc_onecell_data);

drivers/base/power/domain.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,21 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
12821282
}
12831283
EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain);
12841284

1285+
static int genpd_set_default_power_state(struct generic_pm_domain *genpd)
1286+
{
1287+
struct genpd_power_state *state;
1288+
1289+
state = kzalloc(sizeof(*state), GFP_KERNEL);
1290+
if (!state)
1291+
return -ENOMEM;
1292+
1293+
genpd->states = state;
1294+
genpd->state_count = 1;
1295+
genpd->free = state;
1296+
1297+
return 0;
1298+
}
1299+
12851300
/**
12861301
* pm_genpd_init - Initialize a generic I/O PM domain object.
12871302
* @genpd: PM domain object to initialize.
@@ -1293,6 +1308,8 @@ EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain);
12931308
int pm_genpd_init(struct generic_pm_domain *genpd,
12941309
struct dev_power_governor *gov, bool is_off)
12951310
{
1311+
int ret;
1312+
12961313
if (IS_ERR_OR_NULL(genpd))
12971314
return -EINVAL;
12981315

@@ -1325,19 +1342,12 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
13251342
genpd->dev_ops.start = pm_clk_resume;
13261343
}
13271344

1328-
if (genpd->state_idx >= GENPD_MAX_NUM_STATES) {
1329-
pr_warn("Initial state index out of bounds.\n");
1330-
genpd->state_idx = GENPD_MAX_NUM_STATES - 1;
1331-
}
1332-
1333-
if (genpd->state_count > GENPD_MAX_NUM_STATES) {
1334-
pr_warn("Limiting states to %d\n", GENPD_MAX_NUM_STATES);
1335-
genpd->state_count = GENPD_MAX_NUM_STATES;
1336-
}
1337-
13381345
/* Use only one "off" state if there were no states declared */
1339-
if (genpd->state_count == 0)
1340-
genpd->state_count = 1;
1346+
if (genpd->state_count == 0) {
1347+
ret = genpd_set_default_power_state(genpd);
1348+
if (ret)
1349+
return ret;
1350+
}
13411351

13421352
mutex_lock(&gpd_list_lock);
13431353
list_add(&genpd->gpd_list_node, &gpd_list);
@@ -1377,6 +1387,7 @@ static int genpd_remove(struct generic_pm_domain *genpd)
13771387
list_del(&genpd->gpd_list_node);
13781388
mutex_unlock(&genpd->lock);
13791389
cancel_work_sync(&genpd->power_off_work);
1390+
kfree(genpd->free);
13801391
pr_debug("%s: removed %s\n", __func__, genpd->name);
13811392

13821393
return 0;

include/linux/pm_domain.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
/* Defines used for the flags field in the struct generic_pm_domain */
2020
#define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */
2121

22-
#define GENPD_MAX_NUM_STATES 8 /* Number of possible low power states */
23-
2422
enum gpd_status {
2523
GPD_STATE_ACTIVE = 0, /* PM domain is active */
2624
GPD_STATE_POWER_OFF, /* PM domain is off */
@@ -70,9 +68,10 @@ struct generic_pm_domain {
7068
void (*detach_dev)(struct generic_pm_domain *domain,
7169
struct device *dev);
7270
unsigned int flags; /* Bit field of configs for genpd */
73-
struct genpd_power_state states[GENPD_MAX_NUM_STATES];
71+
struct genpd_power_state *states;
7472
unsigned int state_count; /* number of states */
7573
unsigned int state_idx; /* state that genpd will go to when off */
74+
void *free; /* Free the state that was allocated for default */
7675

7776
};
7877

0 commit comments

Comments
 (0)