Skip to content

Commit fc6fa50

Browse files
committed
PM: domains: Support required OPPs in dev_pm_domain_attach_list()
JIRA: https://issues.redhat.com/browse/RHEL-81536 commit 98d277a Author: Ulf Hansson <ulf.hansson@linaro.org> Date: Thu, 10 Oct 2024 14:13:49 +0000 In the multiple PM domain case we need platform code to specify the index of the corresponding required OPP in DT for a device, which is what *_opp_attach_genpd() is there to help us with. However, attaching a device to its PM domains is in general better done with dev_pm_domain_attach_list(). To avoid having two different ways to manage this and to prepare for the removal of *_opp_attach_genpd(), let's extend dev_pm_domain_attach|detach_list() to manage the required OPPs too. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Link: https://lore.kernel.org/r/20241002122232.194245-5-ulf.hansson@linaro.org Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent 3665672 commit fc6fa50

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

drivers/base/power/common.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/pm_clock.h>
1212
#include <linux/acpi.h>
1313
#include <linux/pm_domain.h>
14+
#include <linux/pm_opp.h>
1415

1516
#include "power.h"
1617

@@ -222,13 +223,15 @@ int dev_pm_domain_attach_list(struct device *dev,
222223
if (!pds)
223224
return -ENOMEM;
224225

225-
size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links);
226+
size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links) +
227+
sizeof(*pds->opp_tokens);
226228
pds->pd_devs = kcalloc(num_pds, size, GFP_KERNEL);
227229
if (!pds->pd_devs) {
228230
ret = -ENOMEM;
229231
goto free_pds;
230232
}
231233
pds->pd_links = (void *)(pds->pd_devs + num_pds);
234+
pds->opp_tokens = (void *)(pds->pd_links + num_pds);
232235

233236
if (link_flags && pd_flags & PD_FLAG_DEV_LINK_ON)
234237
link_flags |= DL_FLAG_RPM_ACTIVE;
@@ -244,6 +247,19 @@ int dev_pm_domain_attach_list(struct device *dev,
244247
goto err_attach;
245248
}
246249

250+
if (pd_flags & PD_FLAG_REQUIRED_OPP) {
251+
struct dev_pm_opp_config config = {
252+
.required_dev = pd_dev,
253+
.required_dev_index = i,
254+
};
255+
256+
ret = dev_pm_opp_set_config(dev, &config);
257+
if (ret < 0)
258+
goto err_link;
259+
260+
pds->opp_tokens[i] = ret;
261+
}
262+
247263
if (link_flags) {
248264
struct device_link *link;
249265

@@ -264,9 +280,11 @@ int dev_pm_domain_attach_list(struct device *dev,
264280
return num_pds;
265281

266282
err_link:
283+
dev_pm_opp_clear_config(pds->opp_tokens[i]);
267284
dev_pm_domain_detach(pd_dev, true);
268285
err_attach:
269286
while (--i >= 0) {
287+
dev_pm_opp_clear_config(pds->opp_tokens[i]);
270288
if (pds->pd_links[i])
271289
device_link_del(pds->pd_links[i]);
272290
dev_pm_domain_detach(pds->pd_devs[i], true);
@@ -361,6 +379,7 @@ void dev_pm_domain_detach_list(struct dev_pm_domain_list *list)
361379
return;
362380

363381
for (i = 0; i < list->num_pds; i++) {
382+
dev_pm_opp_clear_config(list->opp_tokens[i]);
364383
if (list->pd_links[i])
365384
device_link_del(list->pd_links[i]);
366385
dev_pm_domain_detach(list->pd_devs[i], true);

include/linux/pm_domain.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@
3030
* supplier and its PM domain when creating the
3131
* device-links.
3232
*
33+
* PD_FLAG_REQUIRED_OPP: Assign required_devs for the required OPPs. The
34+
* index of the required OPP must correspond to the
35+
* index in the array of the pd_names. If pd_names
36+
* isn't specified, the index just follows the
37+
* index for the attached PM domain.
38+
*
3339
*/
3440
#define PD_FLAG_NO_DEV_LINK BIT(0)
3541
#define PD_FLAG_DEV_LINK_ON BIT(1)
42+
#define PD_FLAG_REQUIRED_OPP BIT(2)
3643

3744
struct dev_pm_domain_attach_data {
3845
const char * const *pd_names;
@@ -43,6 +50,7 @@ struct dev_pm_domain_attach_data {
4350
struct dev_pm_domain_list {
4451
struct device **pd_devs;
4552
struct device_link **pd_links;
53+
u32 *opp_tokens;
4654
u32 num_pds;
4755
};
4856

0 commit comments

Comments
 (0)